add unreferenced strings
This commit is contained in:
parent
b47c9dd666
commit
6637745cdf
4 changed files with 114 additions and 68 deletions
127
test.py
127
test.py
|
|
@ -21,61 +21,60 @@ with z.ZipFile(APK_NAME) as zipf:
|
|||
|
||||
apk = Apk()
|
||||
apk.add_dex_file(dex)
|
||||
exit()
|
||||
|
||||
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}")
|
||||
|
||||
# Strip class for debugging
|
||||
classes = list(
|
||||
filter(
|
||||
lambda x: x
|
||||
not in [
|
||||
IdType("Lcom/example/testapplication/ui/home/HomeViewModel;"),
|
||||
IdType("Landroidx/navigation/NavDeepLink$Builder;"),
|
||||
IdType("Landroidx/constraintlayout/core/widgets/ConstraintWidget$1;"),
|
||||
IdType("Landroidx/appcompat/app/ActionBar;"),
|
||||
IdType("Landroidx/constraintlayout/core/state/WidgetFrame;"),
|
||||
],
|
||||
apk.classes.keys(),
|
||||
)
|
||||
)
|
||||
# for cls in classes:
|
||||
# apk.remove_class(cls)
|
||||
#
|
||||
# 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(
|
||||
# lambda x: x
|
||||
# not in [
|
||||
# IdType("Lcom/example/testapplication/ui/home/HomeViewModel;"),
|
||||
# IdType("Landroidx/navigation/NavDeepLink$Builder;"),
|
||||
# IdType("Landroidx/constraintlayout/core/widgets/ConstraintWidget$1;"),
|
||||
# IdType("Landroidx/appcompat/app/ActionBar;"),
|
||||
# IdType("Landroidx/constraintlayout/core/state/WidgetFrame;"),
|
||||
# ],
|
||||
# apk.classes.keys(),
|
||||
# )
|
||||
# )
|
||||
# # for cls in classes:
|
||||
# # apk.remove_class(cls)
|
||||
|
||||
print("[+] Recompile")
|
||||
|
||||
|
|
@ -86,17 +85,17 @@ 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue