Skip to content

A robust Python tool to unpack and repack oeminfo.img files. Features secure path handling, streaming I/O, and automatic data classification for Huawei/Honor devices.

License

Notifications You must be signed in to change notification settings

ud3v0id/huawei-oeminfo-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Huawei/Honor OEMInfo Tool

A robust, high-performance, and secure command-line tool for analyzing, unpacking, and repacking oeminfo.img files found in Huawei and Honor devices (EMUI / MagicOS).

This tool allows developers and ROM modders to inspect the proprietary oeminfo partition structure, extract data blocks (including images, logs, and configuration files), and rebuild the image after modification.

🚀 Features

  • Enhanced Robustness & Error Handling:
    • Ghost Block Filtering: Automatically identifies and ignores "ghost blocks" (misidentified headers within another block's payload), preventing structural conflicts and ambiguous data.
    • Conflict Resolution: Intelligently resolves overlaps between Standard blocks and subsequent blocks by reclassifying the former as STANDARD_COMPACT (preserving 512-byte headers while relaxing strict 4KB tail alignment).
    • Flexible Layout Handling: Correctly parses and includes legitimate data blocks located beyond the conventional TOTAL_REGION_SIZE (64MB) limit of OEMINFO images.
  • Comprehensive Parsing: Automatically detects and classifies data blocks:
    • Standard Blocks: 4KB aligned blocks.
    • Standard Compact Blocks: 512-byte header blocks that are not 4KB aligned or resolve alignment conflicts.
    • Reused Blocks: Efficient storage for repeated data.
    • Images: Auto-detection of GZIP and BMP boot logos/animations.
    • TLV Data: Parses Type-Length-Value structures automatically.
    • Text/Configuration: Identifies and previews ASCII/UTF-8 content.
  • High Performance:
    • Streaming I/O: Uses stream-based processing for repacking, allowing manipulation of large images with minimal RAM usage.
    • Optimized Search: Utilizes pre-compiled structs and C-level byte comparison for extremely fast padding and header scanning.
  • Secure & Robust:
    • Path Traversal Protection: Prevents malicious filenames from writing outside the target directory.
    • Atomic Writes: Uses temporary files during repacking to ensure the output file is never corrupted if the process is interrupted.
    • Binary Fidelity: Preserves non-ASCII characters in image version strings, preventing data loss.
  • User Friendly:
    • Detailed ASCII previews for text blocks.
    • Improved manifest.json: offset values are now represented as clear hexadecimal strings (e.g., "0x1000"), significantly enhancing readability and ease of editing for advanced users. Image version strings are also stored as Hex for full transparency.
    • Verbose debug logging.

📋 Requirements

  • Python 3.6+
  • Standard libraries only (No pip install required).

🛠️ Usage

1. List Content

Quickly view the contents of an image without extracting files.

python oeminfo_tool.py list -i oeminfo.img

Options:

  • -p, --preview: Show a text preview of ASCII data blocks.
  • -d, --debug: Enable detailed debug logging.

2. Unpack

Extract all data blocks into a directory. This generates a manifest.json file required for repacking.

python oeminfo_tool.py unpack -i oeminfo.img -o output_folder

Output Structure:

output_folder/
├── manifest.json               # Layout and metadata definition
├── 15_1_standard_active.txt    # Extracted text block
├── 351_28_standard_active.gz   # Extracted boot animation (GZIP)
└── ...

Options:

  • -f, --force: Force overwrite if the output directory already exists.

3. Repack

Rebuild an oeminfo.img file from an extracted directory. You can modify the files or the manifest.json before repacking.

python oeminfo_tool.py repack -i output_folder -o new_oeminfo.img

Note: The tool automatically handles padding calculation and block alignment based on block types (STANDARD, STANDARD_COMPACT, REUSED).

Options:

  • -f, --force: Force overwrite if the output file already exists.

🛡️ Safety & Architecture

This tool works by mapping the original file structure into a manifest.json.

  • Unpacking: It safely extracts data, intelligently resolving structural conflicts and detecting file types (GZIP/BMP/Text/TLV) and adding appropriate extensions.
  • Repacking: It reads the manifest.json, reconstructs the specific OEM headers, and stitches the file back together.

Atomic Write Mechanism: When repacking, the tool writes to filename.img.tmp first. Only after a successful write is the file renamed to the final filename.img. This prevents data loss or corruption of existing files during a crash.

⚠️ Disclaimer

This tool is for educational and research purposes only. Modifying critical system partitions like oeminfo carries a risk of bricking your device. Always keep a backup of your original partition. The author is not responsible for any damage caused by the use of this tool.

📄 License

MIT License

About

A robust Python tool to unpack and repack oeminfo.img files. Features secure path handling, streaming I/O, and automatic data classification for Huawei/Honor devices.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages