Skip to content

About

A zero-dependency Python command-line tool for identifying and unpacking `UPDATE.APP` and `update.bin` files from Huawei firmware.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

HuaweiFirmwareExtractor

简体中文 · English

简体中文

一个零依赖的 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。

合并多个 sparse super 分片

部分 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 与 CRC32 chunk;输入分片必须具有相同的块大小和总块数。
  • --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。


English

A dependency-free Python command-line utility that detects and extracts Huawei UPDATE.APP and update.bin firmware packages.

Highlights

  • Auto-detects UPDATE.APP and update.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 super fragments with --merge-super
  • Streams large images in chunks and uses only the Python standard library

Usage

# 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_images

Run 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.

About

A zero-dependency Python command-line tool for identifying and unpacking `UPDATE.APP` and `update.bin` files from Huawei firmware.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages