用于 Android apk/xapk/apkm/apks 文件的快速、抗恶意软件解析器。
文档:https://delvinru.github.io/apk-info/
$ apk-info show apkstest.apk
apkstest.apk
Package io.github.delvinru.apkstest
Label APKS Test
Version 1.0.7 (7)
SDK min 21 · target 35
Main activity io.github.delvinru.apkstest/.MainActivity
ABIs x86_64
BadPack 技术(关于它的优秀文章)以及 ZIP64;APK Signing Block 中包含的信息:
# type: ignore;解析过程会释放 GIL,因此线程可以并行运行;使用 Homebrew:
brew install delvinru/tap/apk-info
或使用 cargo:
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 the APK file
extract Unpack apk files as zip archive [alias: x]
axml Read and pretty-print binary AndroidManifest.xml
repack Repack a BadPack-damaged APK into a clean, well-formed zip archive
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() | Signature.V32():
for cert in signature.certificates:
print(f"{cert.subject=} {cert.issuer=} {cert.valid_from=} {cert.valid_until=}")
case Signature.ApkChannelBlock() | Signature.VasDollyV2() | Signature.ByteDance():
print(f"got channel block: {signature.value}")
case _:
print(f"oh, cool, library added some new feature - {signature}")
# For `xapk`/`apkm`/`apks` containers, `get_container_signatures()` returns the
# distributor's signature on the outer archive, separate from the app.
container_signatures = apk.get_container_signatures()
单线程、冷页缓存,每个工具从 Python 读取相同的元数据。Apple M3 Pro,macOS 26.6.1。
干净应用:来自应用商店的 5,714 个 APK 和 XAPK 文件,429 GB。
| 时间 | 文件/秒 | 峰值内存 | 失败 | |
|---|---|---|---|---|
| apk-info 1.1.0 | 29.7 s | 192 | 745 MB | 0 |
| apk-info 1.0.13 | 71.4 s | 80 | 770 MB | 0 |
| androguard 4.1.4 | 926.3 s | 6 | 5.8 GB | 784 |
恶意软件:来自 VirusShare Android 集合 的 23,745 个文件,106 GB。
| 时间 | 文件/秒 | 峰值内存 | 失败 | |
|---|---|---|---|---|
| apk-info 1.1.0 | 44.7 s | 531 | 88 MB | 692 |
| apk-info 1.0.13 | 76.0 s | 312 | 87 MB | 691 |
| androguard 4.1.4 | 362.6 s | 65 | 794 MB | 737 |
方法论、逐文件计时和失败原因:基准测试。
我的几乎所有项目都源于某些使用起来不方便的东西。 Androguard 本身是一个很棒的工具,但在我看来它根本无法维护,也不适合用于生产就绪的代码。它也不适合分析大量文件,因为它的逻辑没有经过良好优化。
该库在设计上是只读的:我需要一个能轻松快速地从 APK 中提取信息的好工具。还有许多其他用于修改 APK 的优秀工具。
repack 命令会生成一个未签名的 APK。要重新签名,我推荐 uber-apk-signer,这是一个简单的单命令工具,可在一次操作中完成 v1/v2/v3 签名和 zipalign:
java -jar uber-apk-signer.jar --apks ./malware.repacked.apk