add repackaging to utils

This commit is contained in:
Jean-Marie 'Histausse' Mineau 2024-02-01 23:37:26 +01:00
parent cb34f76063
commit 2cf3963532
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
5 changed files with 52 additions and 8 deletions

29
test.py
View file

@ -8,9 +8,10 @@ import json
import androscalpel as asc
import zipfile as z
from androscalpel import *
from pathlib import Path
# APK_NAME = "test.apk"
APK_NAME = __file__.removesuffix("test.py") + "/apk_frauder/app-release.apk"
# APK_NAME = Path(__file__).parent / "test.apk"
APK_NAME = Path(__file__).parent / "app-release.apk"
DEX_NAME = "classes.dex"
with z.ZipFile(APK_NAME) as zipf:
@ -74,15 +75,27 @@ for i in code.insns:
print("[+] Recompile")
dex_raw = apk.gen_raw_dex()
assert len(dex_raw) == 1
with open(DEX_NAME, "wb") as file:
file.write(dex_raw[0])
utils.replace_dex(
APK_NAME,
APK_NAME.parent / "app-instrumented.apk",
dex_raw,
Path().parent / "my-release-key.jks",
zipalign=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "zipalign",
apksigner=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "apksigner",
)
# assert len(dex_raw) == 1
# with open(DEX_NAME, "wb") as file:
# file.write(dex_raw[0])
#
# with open(DEX_NAME, "rb") as file:
# dex = file.read()
print("[+] Load new dex")
with open(DEX_NAME, "rb") as file:
dex = file.read()
new_apk = asc.Apk()
new_apk.add_dex_file(dex)
for dex in dex_raw:
new_apk.add_dex_file(dex)
clazz = new_apk.classes[clazz_id]
method = clazz.virtual_methods[method_id]