refactor: project structure change

This commit is contained in:
zx
2024-09-01 16:18:40 -04:00
parent 2c74cdb0b3
commit 104964ac56
10 changed files with 107 additions and 37 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
__pycache__/

View File

@@ -1,2 +0,0 @@
[mypy]
python_version = 3.12.3

View File

@@ -1,5 +1,7 @@
line-length = 78
indent-width = 4
line-length = 79
indent-width = 2
target-version = "py312"
[lint]
select = ["E", "F"]
select = ["W", "E", "F", "C"]

View File

@@ -22,3 +22,4 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

View File

@@ -5,3 +5,10 @@ rewriting [pyzule](https://github.com/asdfzxcvbn/pyzule), but actually good this
this is pretty much just a hobby project that i'll work on when i'm bored. pyzule in its current state is kinda ugly, but it works and i haven't really had the motivation to work on it. there really isn't any need for improvements, anyway..
`cyan` will target python v3.12 (finally!), be pep8-compliant (hopefully..), and be type-hinted!
## plan
- have a __main__ file ofc, this is what `cyan` command runs
- also have a cyan file, it should have the main logic of the program
- have other files for a class of the ipa/app, main executable, etc

32
cyan.py
View File

@@ -1,32 +0,0 @@
#!/usr/bin/python3
# cyan, aka pyzule-rw; by zx, 2024
import os
import sys
import argparse
parser = argparse.ArgumentParser(
description="cyan, an azule \"clone\" for modifying iOS apps")
parser.add_argument("-o", metavar="output",
help="if unspecified, overwrites input")
parser.add_argument("-f", metavar="file", nargs="+",
help="a tweak to inject/item to be added to the bundle")
parser.add_argument("--overwrite", action="store_true",
help="skip overwrite confirmation")
parser.add_argument("input", help="the app to be modified (.app/.ipa)")
args = parser.parse_args()
INPUT = os.path.realpath(args.input)
WORKING_DIR = os.getcwd()
PZ_DIR = os.path.expanduser("~/.config/cyan")
changed = False
if not (INPUT.endswith(".ipa") or INPUT.endswith(".app")):
sys.exit("[!] input must be a .ipa/.app")
elif not os.path.exists(INPUT):
sys.exit("[!] input does not exist")
elif not args.o and (input("[<] override your input file? [y/N] ").strip()
.lower() not in ("y", "yes")):
sys.exit("[!] not overriding input, missing -o")

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
lief

49
src/__main__.py Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python3
# cyan, aka pyzule-rw; by zx, 2024
import argparse
import cyan
def main() -> None:
parser = argparse.ArgumentParser(
description="cyan, an azule \"clone\" for modifying iOS apps"
)
parser.add_argument(
"-i", "--input", metavar="input", required=True,
help="the app to be modified (.app/.ipa)"
)
parser.add_argument(
"-o", "--output", metavar="output",
help="if unspecified, overwrites input"
)
parser.add_argument(
"-f", metavar="file", nargs="+",
help="a tweak to inject/item to be added to the bundle"
)
parser.add_argument(
"--overwrite", action="store_true",
help="skip overwrite confirmation"
)
cyan.main(parser)
if __name__ == "__main__":
main()
# INPUT = os.path.realpath(args.input)
# WORKING_DIR = os.getcwd()
# PZ_DIR = os.path.expanduser("~/.config/cyan")
# changed = False
# if not (INPUT.endswith(".ipa") or INPUT.endswith(".app")):
# sys.exit("[!] input must be a .ipa/.app")
# elif not os.path.exists(INPUT):
# sys.exit("[!] input does not exist")
# elif not args.o and (input("[<] override your input file? [y/N] ").strip()
# .lower() not in ("y", "yes")):
# sys.exit("[!] not overriding input, missing -o")

25
src/cyan.py Normal file
View File

@@ -0,0 +1,25 @@
import os
from argparse import ArgumentParser
import tbhutils
def main(parser: ArgumentParser) -> None:
args = parser.parse_args()
args.i = os.path.normpath(args.input)
if args.output is not None:
args.o = os.path.normpath(args.output)
if not (args.o.endswith(".app") or args.o.endswith(".ipa")):
print("[?] output's file extension not specified; will create ipa")
args.o += ".ipa"
else:
args.o = args.i
arg_err = tbhutils.validate_inputs(args)
if arg_err is not None:
parser.error(arg_err)
# verbose notices
if args.o

17
src/tbhutils.py Normal file
View File

@@ -0,0 +1,17 @@
import os
from typing import Optional
from argparse import Namespace
def validate_inputs(args: Namespace) -> Optional[str]:
if not (
args.i.endswith(".ipa")
or args.i.endswith(".app")
):
return "the input file must be an ipa/app"
if not os.path.exists(args.i):
return f"{args.i} does not exist"