Skip to content

Commit

Permalink
feat: manually modified dylib support (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfzxcvbn committed Oct 31, 2024
1 parent 8c873a8 commit 0808fd8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cyan/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def main() -> None:
)

parser.add_argument(
"--version", action="version", version="cyan v1.3"
"--version", action="version", version="cyan v1.4b"
)

from cyan import logic
Expand Down
59 changes: 45 additions & 14 deletions cyan/tbhtypes/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,31 @@ class Executable:
idylib = f"{specific}/insert_dylib"

starters = ("\t/Library/", "\t@rpath", "\t@executable_path")

# substrate could show up as
# CydiaSubstrate.framework, libsubstrate.dylib, EVEN CydiaSubstrate.dylib
# AND PROBABLY EVEN MORE !!!! IT'S CRAZY.
common = {
# substrate could show up as
# CydiaSubstrate.framework, libsubstrate.dylib, EVEN CydiaSubstrate.dylib
# AND PROBABLY EVEN MORE !!!! IT'S CRAZY.

"CydiaSubstrate.framework": "CydiaSubstrate.framework",
"Orion.framework": "Orion.framework",
"Cephei.framework": "Cephei.framework",
"CepheiUI.framework": "CepheiUI.framework",
"CepheiPrefs.framework": "CepheiPrefs.framework"
"ubstrate.": {
"name": "CydiaSubstrate.framework",
"path": "@rpath/CydiaSubstrate.framework/CydiaSubstrate"
},
"orion.": {
"name": "Orion.framework",
"path": "@rpath/Orion.framework/Orion"
},
"cephei.": {
"name": "Cephei.framework",
"path": "@rpath/Cephei.framework/Cephei"
},
"cepheiui.": {
"name": "CepheiUI.framework",
"path": "@rpath/CepheiUI.framework/CepheiUI"
},
"cepheiprefs.": {
"name": "CepheiPrefs.framework",
"path": "@rpath/CepheiPrefs.framework/CepheiPrefs"
}
}

def __init__(self, path: str):
Expand Down Expand Up @@ -64,14 +79,33 @@ def change_dependency(self, old: str, new: str) -> None:
stderr=subprocess.DEVNULL
)

def fix_dependencies(self, tweaks: dict[str, str], need: set[str]) -> None:
def fix_common_dependencies(self, needed: set[str]) -> None:
self.remove_signature()

for dep in self.get_dependencies():
for cname in (tweaks | self.common):
for common, info in self.common.items():
if common in dep.lower() and dep != info["path"]:
self.change_dependency(dep, info["path"])
print(
f"[*] fixed common dependency in {self.bn}: "
f"{dep} -> {info['path']}"
)

needed.add(common)

# orion has a *weak* dependency to substrate,
# but will still crash without it. nice !!!!!!!!!!!
if common == "orion.":
needed.add("ubstrate.")

def fix_dependencies(self, tweaks: dict[str, str]) -> None:
for dep in self.get_dependencies():
for cname in tweaks:
if cname in dep:
# i wonder if there's a better way to do this?
if cname.endswith(".framework"):
# nah, not gonna parse the plist,
# i've never seen a framework with a "mismatched" name
npath = f"@rpath/{cname}/{cname[:-10]}"
else:
npath = f"@rpath/{cname}"
Expand All @@ -80,9 +114,6 @@ def fix_dependencies(self, tweaks: dict[str, str], need: set[str]) -> None:
self.change_dependency(dep, npath)
print(f"[*] fixed dependency in {self.bn}: {dep} -> {npath}")

if cname in self.common:
need.add(cname)

def get_dependencies(self) -> list[str]:
proc = subprocess.run(
[self.otool, "-L", self.path],
Expand Down
14 changes: 7 additions & 7 deletions cyan/tbhtypes/main_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ def inject(self, tweaks: dict[str, str], tmpdir: str) -> None:
os.chdir(cwd) # i fucking hate jailbroken iOS utils.

needed: set[str] = set()

# inject/fix user things
for bn, path in tweaks.items():
if bn.endswith(".appex"):
fpath = f"{PLUGINS_DIR}/{bn}"
existed = tbhutils.delete_if_exists(fpath, bn)
shutil.copytree(path, fpath)
elif bn.endswith(".dylib"):
path = shutil.copy2(path, tmpdir)
Executable(path).fix_dependencies(tweaks, needed)

e = Executable(path)
e.fix_common_dependencies(needed)
e.fix_dependencies(tweaks)

fpath = f"{FRAMEWORKS_DIR}/{bn}"
existed = tbhutils.delete_if_exists(fpath, bn)
Expand All @@ -87,13 +92,8 @@ def inject(self, tweaks: dict[str, str], tmpdir: str) -> None:
if not existed:
print(f"[*] injected {bn}")

# orion has a *weak* dependency to substrate,
# but will still crash without it. nice !!!!!!!!!!!
if "Orion.framework" in needed:
needed.add("CydiaSubstrate.framework")

for missing in needed:
real = self.common[missing] # "real" name, thanks substrate!
real = self.common[missing]["name"] # e.g. "Orion.framework"
ip = f"{FRAMEWORKS_DIR}/{real}"
existed = tbhutils.delete_if_exists(ip, real)
shutil.copytree(f"{self.install_dir}/extras/{real}", ip)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="cyan",
version="1.3",
version="1.4b",
description="finally, pyzule doesn't suck",
author="zx",
author_email="zx@hrzn.email",
Expand Down

0 comments on commit 0808fd8

Please sign in to comment.