50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import logging
|
|
|
|
FORMAT = "[%(levelname)s] %(name)s %(filename)s:%(lineno)d: %(message)s"
|
|
logging.basicConfig(format=FORMAT)
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
|
|
|
import androscalpel as asc
|
|
import zipfile as z
|
|
from androscalpel import *
|
|
|
|
# APK_NAME = "test.apk"
|
|
APK_NAME = "/home/histausse/workspace/androscalpel/apk_frauder/app-release.apk"
|
|
DEX_NAME = "classes.dex"
|
|
|
|
with z.ZipFile(APK_NAME) as zipf:
|
|
with zipf.open(DEX_NAME, "r") as dex:
|
|
dex = dex.read()
|
|
|
|
apk = asc.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]
|
|
|
|
print("Code of {method_id}")
|
|
for i in method.code.insns:
|
|
print(i)
|
|
|
|
new_insns = []
|
|
for i in method.code.insns:
|
|
if isinstance(i, asc.ins.ConstString):
|
|
if i.lit == "Hello":
|
|
i.lit = DexString("Degemer Mat")
|
|
elif i.lit == "Bye":
|
|
i.lit = DexString("Kenavo")
|
|
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
|
|
|
|
|
|
dex_raw = apk.gen_raw_dex()
|