refactor: use python zipfile

this might cause some issues with some specific apps bc of that stupid 1980 error thingy, but idc
This commit is contained in:
zx
2024-09-05 22:50:48 -04:00
parent 6addd38674
commit c399faeb00
6 changed files with 33 additions and 24 deletions

View File

@@ -10,6 +10,8 @@ this is pretty much just a hobby project that i'll work on when i'm bored. pyzul
cyan is pretty much "v1.0" now i guess. injection works and is stable, and iOS (should..) have all the right fixes for running cyan, however a bug in python3.9 from procursus prevents it from running.
so to reaffirm this, **iOS is currently not supported until an updated python for iOS gets released**
to install on linux + macos, make sure you have python 3.9 or later, `bash`, `zip`, and `lief`
to install lief: `pip install lief`

View File

@@ -27,11 +27,20 @@ def main() -> None:
help="a tweak to inject/item to be added to the bundle"
)
parser.add_argument(
"-c", "--compress", metavar="level", type=int, default=6,
help="the compression level of the ipa (0-9, defaults to 6)",
action="store", choices=range(0, 10)
)
parser.add_argument(
"--ignore-encrypted", action="store_true",
help="skip main binary encryption check"
)
parser.add_argument(
"-v", "--version", action="version", version="cyan v1.0b"
)
from cyan import logic
logic.main(parser)

View File

@@ -42,24 +42,16 @@ def main(parser: ArgumentParser) -> None:
if args.f is not None:
app.executable.inject(args.f, tmpdir)
# done!
if OUTPUT_IS_IPA:
print("[*] generating ipa..")
run(
["bash", f"{tbhtypes.Executable.install_dir}/tools/compressIPA.sh"],
env={
"TMPDIR": tmpdir,
"OUTPUT": args.o
}
)
print(f"[*] generated ipa at {args.o}")
else:
# create subdirectories if necessary
if "/" in args.o:
os.makedirs(os.path.dirname(args.o), exist_ok=True)
# done !
if OUTPUT_IS_IPA:
print("[*] generating ipa..")
tbhutils.make_ipa(tmpdir, args.o, args.compress)
print(f"[*] generated ipa at {args.o}")
else:
if os.path.isdir(args.o):
shutil.rmtree(args.o)

View File

@@ -5,7 +5,7 @@ import zipfile
import platform
import plistlib
import subprocess
from glob import glob
from glob import glob, iglob
from argparse import Namespace
from importlib import resources # type: ignore
from typing import Optional, Any
@@ -150,3 +150,14 @@ def extract_deb(deb: str, tweaks: dict[str, str], tmpdir: str) -> None:
print(f"[*] extracted {os.path.basename(deb)}")
del tweaks[os.path.basename(deb)]
def make_ipa(tmpdir: str, output: str, level: int) -> None:
# ensure names are written as Payload/...
os.chdir(tmpdir)
with zipfile.ZipFile(
output, "w", zipfile.ZIP_DEFLATED, compresslevel=level
) as zf:
for f in iglob("Payload/**", recursive=True):
zf.write(f)

View File

@@ -1,5 +0,0 @@
cd $TMPDIR
mkdir -p `dirname $OUTPUT`
rm $OUTPUT &> /dev/null
zip -r $OUTPUT Payload > /dev/null

View File

@@ -7,8 +7,8 @@ setup(
author="zx",
author_email="hi@zxcvbn.fyi",
packages=["cyan", "cyan.tbhtypes"],
# install_requires=["lief"],
python_requires=">=3.9",
install_requires=["lief"],
python_requires=">=3.10",
include_package_data=True,
entry_points={
"console_scripts": ["cyan=cyan.__main__:main"],