fix string order

This commit is contained in:
Jean-Marie 'Histausse' Mineau 2024-02-15 16:36:52 +01:00
parent 0b8dce9266
commit 3a7208f1b5
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
4 changed files with 227 additions and 56 deletions

104
test.py
View file

@ -22,43 +22,43 @@ with z.ZipFile(APK_NAME) as zipf:
apk = Apk()
apk.add_dex_file(dex)
# clazz_id = IdType("Lcom/example/testapplication/ui/home/HomeViewModel;")
# proto_id = IdMethodType(IdType("Ljava/lang/String;"), [])
# method_id = IdMethod("text_gen", proto_id, clazz_id)
#
# clazz = apk.classes[clazz_id]
# method = clazz.virtual_methods[method_id]
# code = method.code
#
clazz_id = IdType("Lcom/example/testapplication/ui/home/HomeViewModel;")
proto_id = IdMethodType(IdType("Ljava/lang/String;"), [])
method_id = IdMethod("text_gen", proto_id, clazz_id)
clazz = apk.classes[clazz_id]
method = clazz.virtual_methods[method_id]
code = method.code
logging.getLogger().setLevel(logging.WARNING)
#
# print(f"[+] Code of {method_id} ")
# for i in code.insns:
# print(f" {i}")
# print("[+] Modify code")
#
# new_insns = []
# for i in code.insns:
# if isinstance(i, ins.ConstString):
# if i.lit == "Hello":
# i = ins.ConstString(i.reg, DexString("Degemer Mat"))
# elif i.lit == "Bye":
# i = ins.ConstString(i.reg, DexString("Kenavo"))
# new_insns.append(i)
#
# # This need improving!
# code = Code(code.registers_size, code.ins_size, code.outs_size, new_insns)
# apk.set_method_code(method_id, code)
# # apk.set_method_code(method.descriptor, code)
#
#
# clazz = apk.classes[clazz_id]
# method = clazz.virtual_methods[method_id]
# code = method.code
# print(f"[+] New code of {method_id} ")
# for i in code.insns:
# print(f" {i}")
#
print(f"[+] Code of {method_id} ")
for i in code.insns:
print(f" {i}")
print("[+] Modify code")
new_insns = []
for i in code.insns:
if isinstance(i, ins.ConstString):
if i.lit == "Hello":
i = ins.ConstString(i.reg, DexString("Degemer Mat"))
elif i.lit == "Bye":
i = ins.ConstString(i.reg, DexString("Kenavo"))
new_insns.append(i)
# This need improving!
code = Code(code.registers_size, code.ins_size, code.outs_size, new_insns)
apk.set_method_code(method_id, code)
# apk.set_method_code(method.descriptor, code)
clazz = apk.classes[clazz_id]
method = clazz.virtual_methods[method_id]
code = method.code
print(f"[+] New code of {method_id} ")
for i in code.insns:
print(f" {i}")
# # Strip class for debugging
# classes = list(
# filter(
@ -80,22 +80,22 @@ print("[+] Recompile")
dex_raw = apk.gen_raw_dex()
new_apk = Apk()
for dex in dex_raw:
new_apk.add_dex_file(dex)
# new_apk = Apk()
# for dex in dex_raw:
# new_apk.add_dex_file(dex)
# print("[+] Repackage")
#
# utils.replace_dex(
# APK_NAME,
# APK_NAME.parent / (APK_NAME.name.removesuffix(".apk") + "-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",
# )
#
print("[+] Repackage")
utils.replace_dex(
APK_NAME,
APK_NAME.parent / (APK_NAME.name.removesuffix(".apk") + "-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",
)
last_id = None
MAX_REQ = 1
@ -167,8 +167,8 @@ def cmp_list(a, b, req=0):
cmp(a[i], b[i], req + 1)
apk_eq = new_apk == apk
print(f"[+] apk are equals: {nice_bool(apk_eq)}")
# apk_eq = new_apk == apk
# print(f"[+] apk are equals: {nice_bool(apk_eq)}")
# if not apk_eq:
# cmp(new_apk, apk)