implement method code setter in apk struct
This commit is contained in:
parent
8dce87d569
commit
3a6edf1aa2
3 changed files with 37 additions and 12 deletions
29
test.py
29
test.py
|
|
@ -9,7 +9,7 @@ import zipfile as z
|
|||
from androscalpel import *
|
||||
|
||||
# APK_NAME = "test.apk"
|
||||
APK_NAME = "/home/histausse/workspace/androscalpel/apk_frauder/app-release.apk"
|
||||
APK_NAME = __file__.removesuffix("test.py") + "/apk_frauder/app-release.apk"
|
||||
DEX_NAME = "classes.dex"
|
||||
|
||||
with z.ZipFile(APK_NAME) as zipf:
|
||||
|
|
@ -25,13 +25,16 @@ method_id = IdMethod("text_gen", proto_id, clazz_id)
|
|||
|
||||
clazz = apk.classes[clazz_id]
|
||||
method = clazz.virtual_methods[method_id]
|
||||
code = method.code
|
||||
|
||||
print("Code of {method_id}")
|
||||
for i in method.code.insns:
|
||||
logging.getLogger().setLevel(logging.ERROR)
|
||||
|
||||
print(f"Code of {method_id}")
|
||||
for i in code.insns:
|
||||
print(i)
|
||||
|
||||
new_insns = []
|
||||
for i in method.code.insns:
|
||||
for i in code.insns:
|
||||
if isinstance(i, asc.ins.ConstString):
|
||||
if i.lit == "Hello":
|
||||
i.lit = DexString("Degemer Mat")
|
||||
|
|
@ -40,11 +43,19 @@ for i in method.code.insns:
|
|||
new_insns.append(i)
|
||||
|
||||
# This need improving!
|
||||
new_code = method.code
|
||||
new_code.insns = new_insns
|
||||
method.code = new_code
|
||||
clazz.virtual_methods[method_id] = method
|
||||
apk.classes[clazz_id] = clazz
|
||||
code.insns = 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"Code of {method_id}")
|
||||
for i in code.insns:
|
||||
print(i)
|
||||
|
||||
dex_raw = apk.gen_raw_dex()
|
||||
assert len(dex_raw) == 1
|
||||
with open(DEX_NAME + ".out", "wb") as file:
|
||||
file.write(dex_raw[0])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue