Skip to content

Commit 56697fa

Browse files
Support executables on path taking priority over repo executables
1 parent 0218b8d commit 56697fa

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

Sundancer

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,93 +135,107 @@ def image3_decrypt(src: Path, dest: Path, iv: str, key: str, keep_cont: bool = F
135135
args += ["-decrypt"]
136136

137137
_run(
138-
SCRIPT_ROOT / "executables" / "xpwntool",
139-
args)
138+
EXECUTABLES["xpwntool"],
139+
args
140+
)
140141

141142
debug("decrypted Image3 at %s to %s" % (src.name, dest.name))
142143

143144
def image3_create(src: Path, dest: Path, template: Path):
144145
_run(
145-
SCRIPT_ROOT / "executables" / "xpwntool",
146-
[str(src), str(dest), "-t", str(template)])
146+
EXECUTABLES["xpwntool"],
147+
[str(src), str(dest), "-t", str(template)]
148+
)
147149

148150
debug("created Image3 at %s from %s with template %s" % (dest.name, src.name, template.name))
149151

150152
def dmg_extract(src: Path, dest: Path, key: str):
151153
_run(
152-
SCRIPT_ROOT / "executables" / "dmg",
153-
["extract", str(src), str(dest), "-k", key])
154+
EXECUTABLES["dmg"],
155+
["extract", str(src), str(dest), "-k", key]
156+
)
154157

155158
debug("decrypted DMG at %s to %s" % (src.name, dest.name))
156159

157160
def dmg_build(src: Path, dest: Path):
158161
_run(
159-
SCRIPT_ROOT / "executables" / "dmg",
160-
["build", str(src), str(dest)])
162+
EXECUTABLES["dmg"],
163+
["build", str(src), str(dest)]
164+
)
161165

162166
debug("built DMG at %s to %s" % (src.name, dest.name))
163167

164168
def hfsplus_grow(dmg: Path, size: int):
165169
_run(
166-
SCRIPT_ROOT / "executables" / "hfsplus",
167-
[str(dmg), "grow", str(size)])
170+
EXECUTABLES["hfsplus"],
171+
[str(dmg), "grow", str(size)]
172+
)
168173

169174
debug("grown HFS+ image at %s to %d bytes" % (dmg.name, size))
170175

171176
def hfsplus_extract(dmg: Path, src: str, dest: Path):
172177
_run(
173-
SCRIPT_ROOT / "executables" / "hfsplus",
174-
[str(dmg), "extract", src, str(dest)])
178+
EXECUTABLES["hfsplus"],
179+
[str(dmg), "extract", src, str(dest)]
180+
)
175181

176182
debug("extracted %s to %s from HFS+ image at %s" % (src, dest.name, dmg.name))
177183

178184
def hfsplus_replace(dmg: Path, src: Path, dest: str, uid: int = 0, gid: int = 0, mode: int = 0o644):
179185
_run(
180-
SCRIPT_ROOT / "executables" / "hfsplus",
181-
[str(dmg), "rm", dest])
186+
EXECUTABLES["hfsplus"],
187+
[str(dmg), "rm", dest]
188+
)
182189

183190
hfsplus_add(dmg, src, dest, uid, gid, mode)
184191

185192
def hfsplus_add(dmg: Path, src: Path, dest: str, uid: int = 0, gid: int = 0, mode: int = 0o644):
186193
_run(
187-
SCRIPT_ROOT / "executables" / "hfsplus",
188-
[str(dmg), "add", str(src), dest])
194+
EXECUTABLES["hfsplus"],
195+
[str(dmg), "add", str(src), dest]
196+
)
189197

190198
_run(
191-
SCRIPT_ROOT / "executables" / "hfsplus",
192-
[str(dmg), "chown", "%d:%d" % (uid, gid), dest])
199+
EXECUTABLES["hfsplus"],
200+
[str(dmg), "chown", "%d:%d" % (uid, gid), dest]
201+
)
193202

194203
_run(
195-
SCRIPT_ROOT / "executables" / "hfsplus",
196-
[str(dmg), "chmod", "%o" % (mode), dest])
204+
EXECUTABLES["hfsplus"],
205+
[str(dmg), "chmod", "%o" % (mode), dest]
206+
)
197207

198208
debug("added %s in HFS+ image at %s to %s" % (src.name, dmg.name, dest))
199209

200210
def hfsplus_rm(dmg: Path, path: str):
201211
_run(
202-
SCRIPT_ROOT / "executables" / "hfsplus",
203-
[str(dmg), "rm", path])
212+
EXECUTABLES["hfsplus"],
213+
[str(dmg), "rm", path]
214+
)
204215

205216
debug("removed %s from HFS+ image at %s" % (path, dmg.name))
206217

207218
def hfsplus_rmdir(dmg: Path, dir: str):
208219
_run(
209-
SCRIPT_ROOT / "executables" / "hfsplus",
210-
[str(dmg), "rmall", dir])
220+
EXECUTABLES["hfsplus"],
221+
[str(dmg), "rmall", dir]
222+
)
211223

212224
debug("removed %s folder from HFS+ image at %s" % (dir, dmg.name))
213225

214226
def hfsplus_mv(dmg: Path, src: str, dest: str):
215227
_run(
216-
SCRIPT_ROOT / "executables" / "hfsplus",
217-
[str(dmg), "mv", src, dest])
228+
EXECUTABLES["hfsplus"],
229+
[str(dmg), "mv", src, dest]
230+
)
218231

219232
debug("moved %s to %s in HFS+ image at %s" % (src, dest, dmg.name))
220233

221234
def hfsplus_untar(dmg: Path, tar: Path, dest: str):
222235
_run(
223-
SCRIPT_ROOT / "executables" / "hfsplus",
224-
[str(dmg), "untar", str(tar), dest])
236+
EXECUTABLES["hfsplus"],
237+
[str(dmg), "untar", str(tar), dest]
238+
)
225239

226240
debug("untar'd %s to %s in HFS+ image at %s" % (tar.name, dest, dmg.name))
227241

@@ -716,6 +730,11 @@ def process(args):
716730
args.output
717731
)
718732

733+
def find_execs(exec_names):
734+
for exec_bin in exec_names:
735+
sys_path = shutil.which(exec_bin)
736+
EXECUTABLES[exec_bin] = Path(sys_path) if sys_path else EXECUTABLES_ROOT / exec_bin
737+
719738
def _load_config(original_ipsw: IPSW, destination_ipsw: IPSW) -> Tuple[Config, BuildIdentity, BuildIdentity]:
720739
# Big O is watching me!
721740
matches = []
@@ -751,11 +770,13 @@ def _load_config(original_ipsw: IPSW, destination_ipsw: IPSW) -> Tuple[Config, B
751770
return matches.pop()
752771

753772
SCRIPT_ROOT = Path(__file__).parent
773+
EXECUTABLES_ROOT = SCRIPT_ROOT / "executables"
754774
RESOURCES_ROOT = SCRIPT_ROOT / "resources"
755775
ARTIFACTS_ROOT = SCRIPT_ROOT / "artifacts"
756776
CONFIGS_ROOT = SCRIPT_ROOT / "configs"
757777

758778
gCfg = None
779+
EXECUTABLES = {}
759780

760781
def main():
761782
parser = argparse.ArgumentParser(description="convert iPod touch 3 iOS 5.1.1 IPSW to iOS 6.x")
@@ -793,6 +814,7 @@ def main():
793814
print("destination IPSW does NOT exist")
794815
exit(-1)
795816

817+
find_execs(["dmg", "hfsplus", "xpwntool"])
796818
process(args)
797819

798820
log("DONE!")

0 commit comments

Comments
 (0)