WIP tests

This commit is contained in:
Jean-Marie Mineau 2025-04-17 16:45:21 +02:00
parent 83fd9d387a
commit 7f46d6c12f
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
3 changed files with 21 additions and 3 deletions

View file

@ -11,6 +11,7 @@ import shutil
import lzma import lzma
from pathlib import Path from pathlib import Path
from typing import TextIO, Any from typing import TextIO, Any
from collections.abc import Callable
from .app_exploration import explore_app from .app_exploration import explore_app
@ -319,6 +320,7 @@ def collect_runtime(
output: TextIO, output: TextIO,
adb_path: Path | None = None, adb_path: Path | None = None,
android_sdk_path: Path | None = None, android_sdk_path: Path | None = None,
apk_explorer: None | Callable[[], None] = None,
): ):
env = dict(os.environ) env = dict(os.environ)
@ -344,7 +346,7 @@ def collect_runtime(
if device.enumerate_applications([app]): if device.enumerate_applications([app]):
# Uninstall the APK if it already exist # Uninstall the APK if it already exist
subprocess.run([adb, "uninstall", app], env=env) 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: with FRIDA_SCRIPT.open("r") as file:
jsscript = file.read() jsscript = file.read()
@ -400,7 +402,10 @@ def collect_runtime(
# time.sleep(0.3) # time.sleep(0.3)
# print(f"[*] Classloader list received" + " " * 20) # 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 # Try to find the Main class loader
main_class_loader: str | None = None main_class_loader: str | None = None

View file

@ -106,6 +106,12 @@ def main():
the package. (static x86_64 linux build with musl optimized for binary size instead of speed)", the package. (static x86_64 linux build with musl optimized for binary size instead of speed)",
type=Path, 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() args = parser.parse_args()
if args.zipalign is None: if args.zipalign is None:
@ -121,6 +127,12 @@ def main():
else: else:
keytool = args.keytool 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: if zipalign is None:
print( print(
"Could not find zipalign, please install an android build-tools package. " "Could not find zipalign, please install an android build-tools package. "
@ -158,6 +170,7 @@ def main():
file_storage=tmpd / "dex", file_storage=tmpd / "dex",
output=fp, output=fp,
android_sdk_path=get_android_sdk_path(), android_sdk_path=get_android_sdk_path(),
apk_explorer=runner_f,
) )
patch_apk( patch_apk(
runtime_data=tmpd / "runtime.json", runtime_data=tmpd / "runtime.json",

View file

@ -21,6 +21,6 @@ pip install "${FOLDER}/dist/theseus_autopatcher-0.1.0-py3-none-any.whl[grodd]"
adb wait-for-device 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 "${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}" rm -rf "${TMP}"