diff --git a/frida/theseus_frida/__init__.py b/frida/theseus_frida/__init__.py index 77820df..f982129 100644 --- a/frida/theseus_frida/__init__.py +++ b/frida/theseus_frida/__init__.py @@ -11,6 +11,7 @@ import shutil import lzma from pathlib import Path from typing import TextIO, Any +from collections.abc import Callable from .app_exploration import explore_app @@ -319,6 +320,7 @@ def collect_runtime( output: TextIO, adb_path: Path | None = None, android_sdk_path: Path | None = None, + apk_explorer: None | Callable[[], None] = None, ): env = dict(os.environ) @@ -344,7 +346,7 @@ def collect_runtime( if device.enumerate_applications([app]): # Uninstall the APK if it already exist subprocess.run([adb, "uninstall", app], env=env) - subprocess.run([adb, "install", str(apk.absolute())], env=env) + subprocess.run([adb, "install", "-g", str(apk.absolute())], env=env) with FRIDA_SCRIPT.open("r") as file: jsscript = file.read() @@ -400,7 +402,10 @@ def collect_runtime( # time.sleep(0.3) # print(f"[*] Classloader list received" + " " * 20) - explore_app(app, device=device.id, android_sdk=android_sdk_path) + if apk_explorer is None: + explore_app(app, device=device.id, android_sdk=android_sdk_path) + else: + apk_explorer() # Try to find the Main class loader main_class_loader: str | None = None diff --git a/theseus_autopatcher/src/theseus_autopatcher/__init__.py b/theseus_autopatcher/src/theseus_autopatcher/__init__.py index 0f52813..15c0509 100644 --- a/theseus_autopatcher/src/theseus_autopatcher/__init__.py +++ b/theseus_autopatcher/src/theseus_autopatcher/__init__.py @@ -106,6 +106,12 @@ def main(): the package. (static x86_64 linux build with musl optimized for binary size instead of speed)", type=Path, ) + parser.add_argument( + "--runner-script", + required=False, + help="Script to run to test the application. Must be a .py (python) or .sh (bash).", + type=Path, + ) args = parser.parse_args() if args.zipalign is None: @@ -121,6 +127,12 @@ def main(): else: keytool = args.keytool + runner_f = None + if args.runner_script is not None and args.runner_script.name.endswith(".py"): + runner_f = lambda: subprocess.run(["python3", str(args.runner_script)]) + elif args.runner_script is not None and args.runner_script.name.endswith(".sh"): + runner_f = lambda: subprocess.run(["bash", str(args.runner_script)]) + if zipalign is None: print( "Could not find zipalign, please install an android build-tools package. " @@ -158,6 +170,7 @@ def main(): file_storage=tmpd / "dex", output=fp, android_sdk_path=get_android_sdk_path(), + apk_explorer=runner_f, ) patch_apk( runtime_data=tmpd / "runtime.json", diff --git a/theseus_autopatcher/test.sh b/theseus_autopatcher/test.sh index a05b3f2..43862d7 100644 --- a/theseus_autopatcher/test.sh +++ b/theseus_autopatcher/test.sh @@ -21,6 +21,6 @@ pip install "${FOLDER}/dist/theseus_autopatcher-0.1.0-py3-none-any.whl[grodd]" adb wait-for-device #theseus-autopatch -a "${FOLDER}/../test_apks/dynloading/build/test_dynloading.apk" -o /tmp/patched_dynloading.apk -k "${FOLDER}/../test_apks/dynloading/ToyKey.keystore" -theseus-autopatch -a "${FOLDER}/../test_apks/dynloading/build/test_dynloading.apk" -o /tmp/patched_dynloading.apk -k /tmp/kstore.keystore -kp 'P@ssw0rd!' +theseus-autopatch -a "${FOLDER}/../test_apks/dyn_and_ref/build/test_dyn_and_ref.apk" -o /tmp/patched_dynloading.apk -k /tmp/kstore.keystore -kp 'P@ssw0rd!' --runner-script "${FOLDER}/../test_apks/dyn_and_ref/tests/test_apk.py" rm -rf "${TMP}"