一个功能齐全的apk解析器。
APK签名块42中包含的信息:
# type: ignore;cargo install apk-info-cli
A command-line tool to inspect and extract APK files
Usage: apk-info [COMMAND]
Commands:
show Show basic information about apk file
extract Unpack apk files as zip archive [aliases: x]
axml Read and pretty-print binary AndroidManifest.xml
completion Generate shell completion
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
uv pip install apk-info
from apk_info import APK
apk = APK("./path-to-file.apk")
package_name = apk.get_package_name()
main_activities = apk.get_main_activities()
min_sdk = apk.get_min_sdk_version()
print(f"Package Name: {package_name}")
print(f"Minimal SDK: {min_sdk}")
if not main_activities:
print("apk is not launchable!")
exit()
print(f"Main Activity: {package_name}/{main_activities[0]}")
import sys
from apk_info import APK, Signature
if len(sys.argv) < 2:
print(f"usage: {sys.argv[0]} <apk>")
sys.exit(1)
file = sys.argv[1]
apk = APK(file)
signatures = apk.get_signatures()
for signature in signatures:
match signature:
case Signature.V1() | Signature.V2() | Signature.V3() | Signature.V31():
for cert in signature.certificates:
print(f"{cert.subject=} {cert.issuer=} {cert.valid_from=} {cert.valid_until=}")
case Signature.ApkChannelBlock():
print(f"got apk channel block: {signature.value}")
case _:
print(f"oh, cool, library added some new feature - {signature}")
环境:
脚本:
apk-info 库:
release-lto;测试用例(干净集合):
| # | apk-info | androguard |
|---|---|---|
| 1 |
测试用例(恶意样本集合):
[!IMPORTANT] 该集合包含大量恶意样本,androguard根本无法解析。
| # | apk-info | androguard |
|---|---|---|
| 1 |
平均速度提升约10倍。
主要优势在于apk-info能够解析比androguard更多的恶意文件。
我几乎所有的项目都源于某些工具使用起来不够方便。Androguard本身是一个很好的工具,但(在我看来)它几乎无法维护,并且不适合生产级代码。由于所有逻辑编写得不够优化,它也不适用于分析大量文件。
该库仅设计为只读模式,因为我需要一个能够轻松快速提取apk信息的优秀工具。市面上还有许多其他优秀的工具可供修改使用。
| 0.98s user 4.32s system 80% cpu 6.584 total |
| 57.39s user 4.88s system 97% cpu 1:03.85 total |
| 2 | 0.96s user 4.23s system 79% cpu 6.486 total | 57.98s user 5.04s system 97% cpu 1:04.80 total |
| 3 | 0.95s user 4.15s system 79% cpu 6.422 total | 55.56s user 4.48s system 97% cpu 1:01.55 total |
| 2.49s user 4.74s system 73% cpu 9.840 total |
| 141.29s user 6.86s system 98% cpu 2:31.09 total |
| 2 | 2.50s user 4.77s system 75% cpu 9.641 total | 138.04s user 6.32s system 97% cpu 2:27.33 total |
| 3 | 2.49s user 4.78s system 75% cpu 9.650 total | 139.33s user 6.65s system 98% cpu 2:28.87 total |