test scripts

This commit is contained in:
Jean-Marie Mineau 2024-02-22 14:19:31 +01:00
parent a0ecb1a18d
commit af49057c04
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
3 changed files with 44 additions and 0 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@
*.dex *.dex
*.idsig *.idsig
*.jks *.jks
/tests

View file

@ -2,3 +2,4 @@
- tests - tests
- https://source.android.com/docs/core/runtime/dex-format#system-annotation - https://source.android.com/docs/core/runtime/dex-format#system-annotation
- goto size computation - goto size computation
- ord in python

42
tests/dump_class_names.py Normal file
View file

@ -0,0 +1,42 @@
import logging
FORMAT = "[%(levelname)s] %(name)s %(filename)s:%(lineno)d: %(message)s"
logging.basicConfig(format=FORMAT)
logging.getLogger().setLevel(logging.DEBUG)
import json
import zipfile as z
import re
from pathlib import Path
import argparse
from androscalpel import Apk, IdType, IdMethodType, ins, DexString, IdMethod, Code, utils # type: ignore
RE_CHECK_DEXFILE = re.compile(r"classes\d*.dex")
def is_dexfile(filename: str) -> bool:
return bool(RE_CHECK_DEXFILE.fullmatch(filename))
def load_apk(path_apk: Path) -> Apk:
print(f"[+] Load bytecode ")
apk = Apk()
with z.ZipFile(path_apk) as zipf:
for file in filter(is_dexfile, zipf.namelist()):
print(f"[-] {file}")
with zipf.open(file, "r") as dex_f:
dex = dex_f.read()
apk.add_dex_file(dex)
return apk
if __name__ == "__main__":
parser = argparse.ArgumentParser("Dump the name of classes defined in an apk")
parser.add_argument("apk", type=Path)
args = parser.parse_args()
apk = load_apk(args.apk)
cls = list(map(str, apk.classes.keys()))
cls.sort()
for cl in cls:
print(str(cl))