apkutils
简体中文 | English
介绍
一个用于解析APK、Dex、AXML、ARSC的库。
安装教程
❯ pip install apkutils
❯ apkutils --help
Usage: apkutils [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
--help Show this message and exit.
Commands:
arsc 打印arsc
certs 打印证书
files 打印文件
info 打印包名、应用名、版本号、SDK与证书
manifest 打印清单
mtds 获取指定方法中的所有字符串
packages 列出所有的包
strings 打印Dex中的字符串
xref 获取方法的引用方法
zip ZIP 容器层:解压、结构体检、对抗修复
apkutils --version 打印 apkutils 自身的版本号,与 info 打印的 APK 版本号无关。
| 命令 | 用途 | 选项 |
|---|---|---|
arsc |
打印 arsc 资源 | --res_type:string(默认)/ strings / bool / id / color / dimen / integer / public |
certs |
打印证书 | |
files |
打印归档内的文件 | |
info |
打印包名、应用名、版本号、SDK 与证书 | |
manifest |
打印清单原文,并列出 Package、Main Activities 与 Activity Aliases | |
mtds |
获取指定方法中的所有字符串 | -m / --method |
packages |
列出所有的包 | |
strings |
打印 Dex 中的字符串 | |
xref |
获取方法的引用方法 | -m / --method |
zip |
ZIP 容器层子命令:unzip / health / repair |
见下方 zip --help |
mtds / xref 的 -m 形如 top/cls->mtd(Landroid/app/Application;Ljava/lang/String;Ljava/lang/String;)V。
zip 子命令
❯ apkutils zip --help
Usage: apkutils zip [OPTIONS] COMMAND [ARGS]...
ZIP 容器层:解压、结构体检、对抗修复
Options:
--help Show this message and exit.
Commands:
health ZIP 结构层对抗体检(标准工具能否信任)
repair 清除 ZIP 结构层对抗,产出干净副本(标准工具可直接消费)
unzip 解压文件,默认显示zip文件
| 子命令 | 用途 | 选项 |
|---|---|---|
unzip |
解压文件,默认列出 zip 内容 | -t 校验完整性,-e 解压到目录,-o / --output 指定输出目录(默认 out) |
health |
ZIP 结构层对抗体检(标准工具能否信任) | --json 输出 JSON;有对抗/损坏时退出码 2 |
repair |
清除 ZIP 结构层对抗,产出干净副本 | -o / --out 输出目录(默认 clean/);成功输出 JSON,失败退出码 2 |
health / repair 的库 API 见 apkutils.ziphealth。
用法
from apkutils import APK
# 按需解析:这里解析清单、arsc、应用名与图标,不碰 dex
apk = APK.from_file(file_path).parse_resource()
manifest = apk.get_manifest()
app_name = apk.app_name
icons = apk.get_app_icons()
apk.close()
# 也可以不调 parse_resource():拿哪个字段就解析哪部分
with APK.from_file(file_path) as apk:
print(apk.package_name, apk.version_name)
# dex 走 parse_dex():字符串、类、方法、xref 都在这里
with APK.from_file(file_path) as apk:
strings = apk.parse_dex().get_dex_method_strings(mtd)
# 除 from_file 外,还有 from_bytes / from_io
apk = APK.from_bytes(data)
请参考 examples 目录。
ziphealth(ZIP 结构层:体检、修复与宽容读取)
apkutils.ziphealth 回答一个问题:标准 ZIP 工具能不能信任这个文件? 它体检的是 ZIP 结构层对抗手法(伪造加密标志、CRC 抹除、版本字段抬高、CD/LFH 名字不一致、CD 损坏),与内容层的加壳正交——_apkfile 对这类手法一律容忍,因此「本库可读」不代表「apktool/jadx/标准 zipfile 可读」。
from apkutils import ziphealth
report = ziphealth.check(file_path)
# report = {"path": ..., "verdict": "ok|has_flags|cd_damaged|not_a_zip|error",
# "findings": [...], "info": {...}, "sha256": ..., "size": ...}
result = ziphealth.repair(file_path, "clean")
# 清 CDFH/LFH 的对抗标志位(bit0/5/6)+ 归一化异常版本号,产出干净副本,
# 并以标准库 zipfile 验证(verified="testzip");不破解密码学。
宽容读取对同一批对抗样本照常读出内容:read_file_fully / parse_central_directory / find_local_entries / list_entries / extract_entry / get_dex_data。
详见 ADR-0013。
失败处理
自 2.1.0 起,单个部分(manifest、arsc、dex、subfiles、metadata、certs)解析失败不会中断调用:失败被记进 apk.errors(PartError,含部分名、原始异常与可选文件名)并写 apkutils logger;部分内的坏条目(某个 DEX blob、某个 zip 条目)会被跳过,同样记进 apk.errors。
apk = APK.from_file(file_path).parse_resource()
for err in apk.errors:
print(err.part, err.name, err.error)
# 需要失败向外抛出时用 strict=True
apk = APK.from_file(file_path, strict=True).parse_resource()
库代码不写 stdout,诊断只走 logging.getLogger("apkutils"),面向用户的输出都在 CLI。详见 ADR-0002 与 ADR-0003。
备注
从 1.3.0 开始默认按需解析:打开归档不解析任何内容,由 parse_resource()(清单 + arsc + 应用名/图标)与 parse_dex()(dex)按需触发。
License
MIT License,见 LICENSE。
感谢
Metadata
Release files for apkutils 4.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apkutils-4.1.0.tar.gz | 108.1 kB | Without provenance | Details for apkutils-4.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apkutils-4.1.0-py3-none-any.whl | Python 3 | none | any | Details for apkutils-4.1.0-py3-none-any.whl |
Total release size: 223.9 kB
Release files / apkutils-4.1.0.tar.gz
| Download URL | apkutils-4.1.0.tar.gz |
|---|---|
| Size | 108.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
945e979f13a1e3afe2dca78f96f52003129b59a2b0171b8327ef87b6dd1e36c9
|
|
BLAKE2b-256 checksum How to use checksums |
1254c16b5bdf48d52e702fd0da524666aaf5f3e11d6c4ca176f327516a574da6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / apkutils-4.1.0-py3-none-any.whl
| Download URL | apkutils-4.1.0-py3-none-any.whl |
|---|---|
| Size | 115.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e263de40bc0b69e9f59488edeb5e86fed3c24758ea4059d41b2b44bc3fb08a12
|
|
BLAKE2b-256 checksum How to use checksums |
5ea17bc563e034d80ecc6f4aa58a091a21e5129bae23498ff6fdf6c7f8bdc1f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Security for apkutils 4.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.