From e09351287bca259769857badf10e7e316250a75e Mon Sep 17 00:00:00 2001 From: zx Date: Tue, 26 Nov 2024 22:07:22 -0500 Subject: [PATCH] feat: plist merging --- cyan/__main__.py | 6 +++++- cyan/logic.py | 2 ++ cyan/tbhtypes/app_bundle.py | 2 +- cyan/tbhtypes/plist.py | 23 ++++++++++++++++++++--- cyan/tbhutils.py | 3 +++ setup.py | 2 +- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cyan/__main__.py b/cyan/__main__.py index deafdbc..6eadc2f 100755 --- a/cyan/__main__.py +++ b/cyan/__main__.py @@ -50,6 +50,10 @@ def main() -> None: "-k", metavar="icon", help="modify the app's icon" ) + parser.add_argument( + "-l", metavar="plist", + help="a plist to merge with the app's Info.plist" + ) parser.add_argument( "-x", metavar="entitlements", help="add or modify entitlements to the main binary" @@ -99,7 +103,7 @@ def main() -> None: ) parser.add_argument( - "--version", action="version", version="cyan v1.4.1" + "--version", action="version", version="cyan v1.4.2b" ) from cyan import logic diff --git a/cyan/logic.py b/cyan/logic.py index 996102f..2d3929f 100644 --- a/cyan/logic.py +++ b/cyan/logic.py @@ -66,6 +66,8 @@ def main(parser: ArgumentParser) -> None: app.plist.change_minimum_version(args.m) if args.k is not None: app.change_icon(args.k, tmpdir) + if args.l is not None: + app.plist.merge_plist(args.l) if args.x is not None: app.executable.merge_entitlements(args.x) diff --git a/cyan/tbhtypes/app_bundle.py b/cyan/tbhtypes/app_bundle.py index 5980b3e..da57e88 100644 --- a/cyan/tbhtypes/app_bundle.py +++ b/cyan/tbhtypes/app_bundle.py @@ -105,7 +105,7 @@ class AppBundle: def change_icon(self, path: str, tmpdir: str) -> None: try: - from PIL import Image + from PIL import Image # type: ignore except Exception: return print("[?] pillow is not installed, -k is not available") diff --git a/cyan/tbhtypes/plist.py b/cyan/tbhtypes/plist.py index 9da0344..c65694c 100644 --- a/cyan/tbhtypes/plist.py +++ b/cyan/tbhtypes/plist.py @@ -10,11 +10,13 @@ class Plist: try: with open(path, "rb") as f: self.data: dict[str, Any] = plistlib.load(f) + + self.success = True except Exception: if throw: sys.exit(f"[!] couldn't read {path}") - else: - return None + + self.success = False self.path = path self.app_path = app_path @@ -44,7 +46,7 @@ class Plist: try: if all(self[key] == val for key in keys): return False - raise KeyError # lets pretend this was always here.. + raise KeyError except KeyError: for key in keys: self[key] = val @@ -121,3 +123,18 @@ class Plist: else: print(f"[?] minimum version was already \"{minimum}\"") + def merge_plist(self, path: str) -> None: + pl = Plist(path, throw=False) + if not pl.success: + return print(f"[!] couldn't parse {path}") + + changed = False + for k, v in pl.data.items(): + if self.change(v, k): + changed = True + + if not changed: + print("[?] no modified plist entries") + else: + print("[*] set plist keys:", ", ".join(pl.data)) + diff --git a/cyan/tbhutils.py b/cyan/tbhutils.py index 933ab80..9d62630 100644 --- a/cyan/tbhutils.py +++ b/cyan/tbhutils.py @@ -67,6 +67,9 @@ def validate_inputs(args: Namespace) -> Optional[str]: if args.k is not None and not os.path.isfile(args.k): sys.exit(f"[!] {args.k} does not exist") + if args.l is not None and not os.path.isfile(args.l): + sys.exit(f"[!] {args.l} does not exist") + if args.cyan is not None and not os.path.isfile(args.cyan): sys.exit(f"[!] {args.cyan} does not exist") diff --git a/setup.py b/setup.py index f65c708..f822414 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup( name="cyan", - version="1.4.1", + version="1.4.2b", description="finally, pyzule doesn't suck", author="zx", author_email="zx@hrzn.email",