fix: iOS support, lief stuff

This commit is contained in:
zx
2024-09-03 20:44:13 -04:00
parent c2fdf56f5a
commit 9b66b1e59f

View File

@@ -4,7 +4,10 @@ import shutil
import subprocess import subprocess
from typing import Optional from typing import Optional
try:
import lief import lief
except Exception:
pass
from cyan import tbhutils from cyan import tbhutils
@@ -25,7 +28,7 @@ class Executable:
self.bundle_path = bundle_path self.bundle_path = bundle_path
self.bn = os.path.basename(path) self.bn = os.path.basename(path)
self.inj: Optional[lief.MachO.Binary] = None self.inj: Optional = None # type: ignore
if self.specific.endswith("iOS"): if self.specific.endswith("iOS"):
self.inj_func = self.ios_inject self.inj_func = self.ios_inject
@@ -178,8 +181,8 @@ class Executable:
print(f"[*] injected {bn}") print(f"[*] injected {bn}")
# FINALLY !! # FINALLY !!
if self.inj is not None: if self.inj is not None: # type: ignore
self.inj.write(self.path) self.inj.write(self.path) # type: ignore
if has_entitlements: if has_entitlements:
subprocess.run(["ldid", f"-S{ENT_PATH}", self.path]) subprocess.run(["ldid", f"-S{ENT_PATH}", self.path])
@@ -196,8 +199,12 @@ class Executable:
subprocess.run([self.nt, "-change", old, new, self.path]) subprocess.run([self.nt, "-change", old, new, self.path])
def insert_cmd(self, cmd: str) -> None: def insert_cmd(self, cmd: str) -> None:
if self.inj is None: if self.inj is None: # type: ignore
lief.logging.disable() try:
lief.logging.disable() # type: ignore
except Exception:
sys.exit("[!] did you forget to install lief?")
self.inj = lief.parse(self.path) # type: ignore self.inj = lief.parse(self.path) # type: ignore
self.inj.add(lief.MachO.DylibCommand.weak_lib(cmd)) # type: ignore self.inj.add(lief.MachO.DylibCommand.weak_lib(cmd)) # type: ignore