Skip to content

Commit

Permalink
feat: plist merging
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfzxcvbn committed Nov 27, 2024
1 parent 403e5d6 commit e093512
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cyan/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cyan/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion cyan/tbhtypes/app_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def remove_encrypted_extensions(self) -> None:

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")

Expand Down
23 changes: 20 additions & 3 deletions cyan/tbhtypes/plist.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def __init__(
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
Expand Down Expand Up @@ -44,7 +46,7 @@ def change(self, val: Any, *keys: str) -> bool:
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
Expand Down Expand Up @@ -121,3 +123,18 @@ def change_minimum_version(self, minimum: str) -> None:
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))

3 changes: 3 additions & 0 deletions cyan/tbhutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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.4.1",
version="1.4.2b",
description="finally, pyzule doesn't suck",
author="zx",
author_email="zx@hrzn.email",
Expand Down

0 comments on commit e093512

Please sign in to comment.