一个零依赖的 Python 命令行工具,用于识别并解包华为固件中的 UPDATE.APP 与 update.bin 文件。
- 自动识别
UPDATE.APP与update.bin格式 - 列出包内全部条目,包括名称、大小和数据偏移
- 只提供固件路径时,默认提取全部分区
- 按名称提取一个或多个指定分区
- 支持以空格或逗号传入多个分区名
- 自动处理重复分区名,例如多个
super会输出为super.img、super_2.img - 可将两个或三个 sparse
super分片合并为一个完整 sparse 镜像 - 大文件以分块方式读取,不会将整个固件载入内存
- 不依赖第三方库
- Python 3.9 或更高版本
先查看固件中的条目:
python huawei_firmware_extractor.py UPDATE.APP --list仅传入固件路径会提取全部分区:
python huawei_firmware_extractor.py UPDATE.APP默认输出目录为固件同级的 <固件文件名>_extracted。例如 UPDATE.APP 的默认输出目录为 UPDATE_extracted。
部分 UPDATE.APP 固件会包含两个或三个同名的 super 条目。使用 --merge-super 时,工具会先按常规方式提取全部分片,再根据 Android sparse 的全局块布局生成 super_merged.img:
# 提取全部分区,并在发现多个 super 分片时合并
python huawei_firmware_extractor.py UPDATE.APP --merge-super
# 仅提取并合并 super 分片
python huawei_firmware_extractor.py UPDATE.APP -p super --merge-super合并仅在本次提取到两个或更多 super 分片时执行;只有一个 super 时会跳过。原始 super.img、super_2.img、super_3.img 会保留,合并结果写入同一输出目录的 super_merged.img。已有合并结果时默认不会覆盖;如需重建,请加 --overwrite。
合并不会展开 sparse 镜像为 raw 镜像,但仍需要为原始分片和新的 super_merged.img 预留足够的磁盘空间。
该功能会验证 sparse 头部、块大小、总块数和 chunk 结构,并保留 sparse 格式。对于重叠的有效数据块,后出现的 super 分片优先;DONT_CARE 块不会覆盖其他分片中的有效数据。
使用 -p 或 --partition 指定分区名,名称不区分大小写,也可省略 .img 后缀:
# 用空格分隔
python huawei_firmware_extractor.py UPDATE.APP -p boot system vendor
# 用逗号分隔
python huawei_firmware_extractor.py update.bin -p boot,system,vendor
# 指定输出目录
python huawei_firmware_extractor.py UPDATE.APP -p boot recovery -o extracted_images| 参数 | 说明 |
|---|---|
firmware |
必填,UPDATE.APP 或 update.bin 的路径 |
-l, --list |
仅列出包内条目,不提取 |
-p NAME [NAME ...], --partition NAME [NAME ...] |
仅提取指定分区;可用空格或逗号分隔多个名称 |
-o DIR, --output-dir DIR |
指定输出目录 |
--type {auto,update-app,update-bin} |
手动指定格式;默认 auto 自动识别 |
--merge-super |
提取后合并两个或更多 sparse super 分片为 super_merged.img |
--overwrite |
覆盖已经存在的输出镜像 |
-h, --help |
显示帮助 |
UPDATE.APP:按标准记录头顺序读取,并自动跳过头部前导数据和 4 字节对齐填充。update.bin:支持组件表及签名类型0x06、0x08的包结构。- sparse
super合并:支持RAW、FILL、DONT_CARE与CRC32chunk;输入分片必须具有相同的块大小和总块数。 --list会显示所有可读条目,其中可能包含版本信息、校验信息等元数据,不一定都是可启动分区。- 提取前建议先执行
--list,确认所需名称;没有匹配到名称时工具会停止并提示。 - 已存在同名输出文件时默认不会覆盖,避免误覆盖已有镜像;确认无误后加
--overwrite。
| 文件 | 说明 |
|---|---|
huawei_firmware_extractor.py |
推荐使用的独立解包工具 |
merge.py |
原始 sparse 合并/分割脚本,保留作合并逻辑参考;日常使用无需单独运行 |
unpack_UPDATE.APP_package.py |
原始 UPDATE.APP 脚本,保留作参考 |
unpack_update.bin_package.py |
原始 update.bin 脚本,保留作参考 |
欢迎通过 Issue 或 Pull Request 报告新的固件变体、解析问题和改进建议。提交问题时请勿附带完整固件或敏感设备数据;请提供可公开的头部十六进制片段、错误信息和设备/版本信息即可。
仓库公开发布前请添加 LICENSE 文件并明确许可证类型;常见选择包括 MIT、Apache-2.0 和 GPL-3.0。
A dependency-free Python command-line utility that detects and extracts Huawei UPDATE.APP and update.bin firmware packages.
- Auto-detects
UPDATE.APPandupdate.bin - Lists every readable package entry with its size and offset
- Extracts all entries when invoked with only a firmware path
- Extracts one or more named partitions with
-p/--partition - Handles duplicate partition names safely
- Merges two or more sparse
superfragments with--merge-super - Streams large images in chunks and uses only the Python standard library
# List entries without extracting
python huawei_firmware_extractor.py UPDATE.APP --list
# Extract every entry to UPDATE_extracted/
python huawei_firmware_extractor.py UPDATE.APP
# Extract selected partitions
python huawei_firmware_extractor.py update.bin -p boot system vendor
# Extract and merge multiple sparse super fragments
python huawei_firmware_extractor.py UPDATE.APP -p super --merge-super
# Comma-separated names and a custom destination
python huawei_firmware_extractor.py UPDATE.APP -p boot,system,vendor -o extracted_imagesRun python huawei_firmware_extractor.py --help for the complete CLI reference. Python 3.9+ is required.
When --merge-super is used, the tool keeps the extracted super fragments and writes the merged sparse image as super_merged.img. The merge validates sparse headers and block layouts; later fragments take precedence for overlapping data while DONT_CARE chunks do not replace valid data.
Firmware files and extracted images are intentionally excluded from this repository. Only process firmware you are legally entitled to use or distribute.