update test script
This commit is contained in:
parent
6426ad6dea
commit
1bd786c9d7
1 changed files with 64 additions and 46 deletions
110
test.py
110
test.py
|
|
@ -4,6 +4,7 @@ FORMAT = "[%(levelname)s] %(name)s %(filename)s:%(lineno)d: %(message)s"
|
||||||
logging.basicConfig(format=FORMAT)
|
logging.basicConfig(format=FORMAT)
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
import json
|
||||||
import androscalpel as asc
|
import androscalpel as asc
|
||||||
import zipfile as z
|
import zipfile as z
|
||||||
from androscalpel import *
|
from androscalpel import *
|
||||||
|
|
@ -27,49 +28,66 @@ clazz = apk.classes[clazz_id]
|
||||||
method = clazz.virtual_methods[method_id]
|
method = clazz.virtual_methods[method_id]
|
||||||
code = method.code
|
code = method.code
|
||||||
|
|
||||||
# logging.getLogger().setLevel(logging.ERROR)
|
logging.getLogger().setLevel(logging.ERROR)
|
||||||
#
|
|
||||||
# print(f"Code of {method_id}")
|
print(f"[+] Code of {method_id} ")
|
||||||
# for i in code.insns:
|
for i in code.insns:
|
||||||
# print(i)
|
print(f" {i}")
|
||||||
#
|
print("[+] Modify code")
|
||||||
# new_insns = []
|
new_insns = []
|
||||||
# for i in code.insns:
|
for i in code.insns:
|
||||||
# if isinstance(i, asc.ins.ConstString):
|
if isinstance(i, asc.ins.ConstString):
|
||||||
# if i.lit == "Hello":
|
if i.lit == "Hello":
|
||||||
# i = asc.ins.ConstString(i.reg, DexString("Degemer Mat"))
|
i = asc.ins.ConstString(i.reg, DexString("Degemer Mat"))
|
||||||
# elif i.lit == "Bye":
|
elif i.lit == "Bye":
|
||||||
# i = asc.ins.ConstString(i.reg, DexString("Kenavo"))
|
i = asc.ins.ConstString(i.reg, DexString("Kenavo"))
|
||||||
# new_insns.append(i)
|
new_insns.append(i)
|
||||||
#
|
|
||||||
## This need improving!
|
# This need improving!
|
||||||
# code = asc.Code(code.registers_size, code.ins_size, code.outs_size, new_insns)
|
code = asc.Code(code.registers_size, code.ins_size, code.outs_size, new_insns)
|
||||||
# apk.set_method_code(method_id, code)
|
apk.set_method_code(method_id, code)
|
||||||
## apk.set_method_code(method.descriptor, code)
|
# apk.set_method_code(method.descriptor, code)
|
||||||
#
|
|
||||||
# clazz = apk.classes[clazz_id]
|
|
||||||
# method = clazz.virtual_methods[method_id]
|
clazz = apk.classes[clazz_id]
|
||||||
# code = method.code
|
method = clazz.virtual_methods[method_id]
|
||||||
#
|
code = method.code
|
||||||
# print(f"Code of {method_id}")
|
print(f"[+] New code of {method_id} ")
|
||||||
# for i in code.insns:
|
for i in code.insns:
|
||||||
# print(i)
|
print(f" {i}")
|
||||||
#
|
|
||||||
# dex_raw = apk.gen_raw_dex()
|
# Strip class for debugging
|
||||||
# assert len(dex_raw) == 1
|
classes = list(
|
||||||
# with open(DEX_NAME, "wb") as file:
|
filter(
|
||||||
# file.write(dex_raw[0])
|
lambda x: x
|
||||||
#
|
not in [
|
||||||
#
|
IdType("Lcom/example/testapplication/ui/home/HomeViewModel;"),
|
||||||
# with open(DEX_NAME, "rb") as file:
|
IdType("Landroidx/navigation/NavDeepLink$Builder;"),
|
||||||
# dex = file.read()
|
IdType("Landroidx/constraintlayout/core/widgets/ConstraintWidget$1;"),
|
||||||
# new_apk = asc.Apk()
|
],
|
||||||
# new_apk.add_dex_file(dex)
|
apk.classes.keys(),
|
||||||
#
|
)
|
||||||
# clazz = new_apk.classes[clazz_id]
|
)
|
||||||
# method = clazz.virtual_methods[method_id]
|
for cls in classes:
|
||||||
# code = method.code
|
apk.remove_class(cls)
|
||||||
#
|
|
||||||
# print(f"Code of {method_id} in new apk")
|
print("[+] Recompile")
|
||||||
# for i in code.insns:
|
|
||||||
# print(i)
|
dex_raw = apk.gen_raw_dex()
|
||||||
|
assert len(dex_raw) == 1
|
||||||
|
with open(DEX_NAME, "wb") as file:
|
||||||
|
file.write(dex_raw[0])
|
||||||
|
|
||||||
|
print("[+] Load new dex")
|
||||||
|
with open(DEX_NAME, "rb") as file:
|
||||||
|
dex = file.read()
|
||||||
|
new_apk = asc.Apk()
|
||||||
|
new_apk.add_dex_file(dex)
|
||||||
|
|
||||||
|
clazz = new_apk.classes[clazz_id]
|
||||||
|
method = clazz.virtual_methods[method_id]
|
||||||
|
code = method.code
|
||||||
|
|
||||||
|
print(f"[+] Code of {method_id} in new apk")
|
||||||
|
for i in code.insns:
|
||||||
|
print(f" {i}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue