Working with system software of mobile devices requires not only an understanding of the operating system architecture, but also knowledge of specific tools for manipulating binary files. Users are often faced with the need to extract the contents of an image firmware for modification, security analysis, or restoration of individual system components. The decompression process is not trivial, since manufacturers use various data packaging formats, from standard archives to specific block devices.

Depending on what specific goal you are pursuing - customizing the interface, removing pre-installed software, or in-depth analysis of the kernel - decompression methods will vary significantly. Some archives are simple ZIP containers that can be opened using standard tools, while others are raw images of file system partitions that require conversion and mounting. Android uses a complex partition structure, where each component, be it the bootloader or user data, is isolated in a separate file.

Before proceeding with active actions, it is critical Create a backup of all important data on your device. Any error when working with low-level files can lead to complete inoperability of the gadget, the so-called โ€œbrickโ€. In this material, we will analyze in detail the algorithms for working with the most common image formats used in the Google mobile OS ecosystem.

Classification of firmware formats and their structure

Understanding the type of file you are dealing with is the first and most important step. Firmware files for devices based on Android usually have a .zip or .img extension, but these extensions can hide completely different data structures. Official updates from manufacturers are often delivered as ZIP archives containing installation scripts and compressed partition images. At the same time, dumps obtained through the Download Mode or Fastbootmode are often direct disk images.

Inside the standard update ZIP archive, you can find files named system.img, boot.img, recovery.img and vendor.img. Each of them is responsible for a specific function: boot contains the kernel and ramdisk, system stores operating system and application files, and vendor includes drivers and hardware-specific software. However, simply opening such a file in an archiver is often not enough, since the images themselves inside can be additionally compressed or encrypted.

Particular attention should be paid to the Sparse IMG format. This is a special format used to Android ave space when writing empty file system blocks. Direct mounting or unpacking of such a file is impossible without first converting it to a raw format. Ignoring this nuance will result in you receiving a file with garbage instead of structured data.

โš ๏ธ Attention: Never try to edit files inside the firmware image without creating a full backup copy of the original file. Even one changed byte sequence in the partition header can make the device unable to boot.

There is also the concept of a โ€œsuper imageโ€ (super.img), introduced in new versions of Android with dynamic partitions. This file combines the system, product and vendor sections into a single container. Working with it requires special utilities that can extract logical partitions from the physical container before further processing.

๐Ÿ“Š For what purpose do you plan to unpack the firmware?
Modification of system applications
Security analysis
Recovery of deleted files
Educational interest/Learning Linux

Preparing the working environment and necessary software

To successfully unpack the firmware, you will need a computer running an operating system with command line support. Although some operations are possible in the Windows GUI, most professional tools are designed for or require terminal emulation. Setting up the correct environment will eliminate many compatibility errors and problems with file access rights. Linux or require terminal emulation. Setting up the right environment will eliminate a lot of compatibility errors and file permissions issues.

The basic set of tools includes utilities for working with archives, image converters and file system mounting tools. In the Windows environment, a popular solution is to use WSL (Windows Subsystem for Linux), which allows you to run native Linux utilities without the need to install a second OS on a virtual machine. This greatly simplifies the work with tools such as simg2img and imgextractor.

You must also make sure that the ADB and Fastboot drivers are installed on your computer if you plan to interact with the device directly. However, for purely programmatic unpacking of files already downloaded to a PC, these drivers are not required. It is enough to have a Python interpreter to work with a number of modern unpacking scripts.

  • ๐Ÿ› ๏ธ Python 3.x โ€”needed to work with modern unpacking scripts, such as payload_dumper or lpunpack.
  • ๐Ÿ’ป 7-Zip or WinRAR โ€”basic archivers for extracting initial ZIP or TAR containers.
  • ๐Ÿง WSL or Linux virtual machine โ€”the recommended environment for executing image conversion commands.
  • ๐Ÿ“‚ Text Editor (Notepad++, VS Code) โ€”for viewing and editing configuration files inside the unpacked firmware.

It is important to keep track of the versions of the software you are using. Utilities written several years ago may not correctly handle new compression formats used in recent versions Android 13 or 14. Always check tool developer repositories for updates that support the latest encryption and packaging algorithms.

๐Ÿ’ก

Use separate folders for each firmware version. Chaotic storage of system.img files from different devices in the same directory often leads to accidental overwriting and data loss.

Unpacking standard ZIP and TAR archives

The simplest scenario is working with official updates distributed in the form of ZIP archives. Such files can often be found on manufacturers' websites or in the recovery mode of the device. The first step is always to check the contents of the archive using any convenient archive manager. If inside you see the usual folder structure with .apk or .xml files, then the process can be considered complete.

However, most often there are other archives or images inside the ZIP archive. For example, the file system.new.dat.br indicates the use of the Brotli compression algorithm, which requires a specific approach for decompression. In this case, standard WinRar will not help, and you will have to use specialized Python scripts. The command to unpack such a file usually looks like running a script indicating the path to the archive.

For TAR files, which are often found in Samsung firmware, the process is similar. You extract the contents of the TAR archive, resulting in a set of .lz4 or .img.lz4 files. Next comes the decompression stage of the LZ4 algorithm, after which you get clean partition images. This two-step process (TAR -> LZ4 -> IMG) is standard for many vendors.

File extension Compression type Required tool Result
.zip Deflate / Store 7-Zip, WinRAR Set of files or images
.tar Tape Archive 7-Zip, tar (Linux) Firmware files (often .lz4)
.lz4 LZ4 Compression lz4, unlz4 Raw image (raw img)
.br Brotli brotli, unbrotli Raw image (raw img)

After receiving raw images (.img), you move on to the next difficulty level. If the file is a multiple of the filesystem block size (usually 4096 bytes) and is not a Sparse image, you can attempt to mount it directly. Otherwise, conversion is required.

โš ๏ธ Attention: When unpacking Samsung firmware, remember that the files inside the TAR archive may have checksums. Changing the content without recalculating the hashes will result in a verification error when trying to write back to the device.

โ˜‘๏ธ Checking the archive type

Done: 0 / 4

Converting and working with Sparse IMG images

Sparse IMG is an optimized image format that does not take up disk space for empty blocks. An attempt to open such a file through a regular archiver or mount it as a regular disk will result in an error or display of incorrect data. To work with it, you need to convert it to a Raw IMG (raw image), which contains a complete copy of the data, including zero blocks.

The main tool for this task is the utility simg2img, which is part of the Android SDK Build Tools. The conversion process is performed via the command line. You need to specify the input file (sparse) and the output file name (raw). The command is executed quickly, but the resulting file can be several times larger than the original one, since it is filled with real zeros.

simg2img system_sparse.img system_raw.img

After successful conversion, you receive a file that you can work with using standard tools. However, if the image is encrypted (which is often the case with a partition userdata), you will only be able to see the file system header, but not the files themselves. Decryption requires keys that are unique to each device and are generated based on hardware identifiers, making the process extremely difficult for the average user.

In some cases, the image may be split into several parts (system_sparse.img.0, system_sparse.img.1, etc.). In such a situation, you first need to merge these parts into one file using the command cat in Linux or specialized utilities in Windows, and only then apply the conversion. simg2img.

What to do if simg2img gives an error?

The error often occurs if the file is damaged or is not a real sparse image. Try checking the file header in a HEX editor: the first bytes must correspond to the magic number of the Android Sparse format.

Extracting data from files system.new.dat and payload.bin

Modern firmware, especially for Google Pixel devices and many Chinese brands, use the A/B (Seamless Updates) update mechanism. In such firmware, the data is packed into a file payload.bin, which contains the delta (difference) between the old and new versions of the system, or a full image compressed in a specific way. Direct unpacking of this file is impossible without using payload_dumper.

The utility payload_dumper is written in Python and allows you to extract individual partition images (system, boot, vendor) from a binary container. The process requires a file payload_properties.txtthat sometimes comes with the firmware, as it contains metadata about versions and hashes. Without this file, some versions of dumpers may fail to work.

Another common format is system.new.dat (sometimes paired with system.transfer.list). This format was used in OTA updates prior to the introduction of Project Treble. The .dat file contains compressed data, and the .list file contains instructions on how this data should be written to disk (which blocks to erase, which to move). To extract files from such a pair, use a script dat2img or similar tools in Python.

After extracting the image from payload.bin or dat-file, you get an .img file again. Often this file is still a Sparse image, so the cycle of "Extract -> Convert to Raw -> Mount" is repeated. This is a multi-step process that requires care at every step.

  • ๐Ÿ“ฆ payload.bin โ€” a container for A/B updates, requires payload_dumper.
  • ๐Ÿ“ system.transfer.list โ€” a block map for recovery from a .dat file.
  • ๐Ÿ”‘ meta-data โ€” a file with information about the sizes and types of partitions inside the payload.
  • ๐Ÿ”„ A/B Partition โ€” a diagram partitions where the data can be located in slot _a or _b.

โš ๏ธ Attention: The structure of payload.bin files and the compression formats inside them change with each new major Android update. A script that worked for Android 10 may not work for Android 14. Always look for a more recently released version of the tool.

๐Ÿ’ก

Successfully unpacking payload.bin gives you access to clean partition images, but does not guarantee that you will be able to modify them and write them back without violating the bootloader's digital signature.

Mounting images and analyzing the file system

The final stage of unpacking is gaining access to the files inside the image. Once you have received the Raw IMG, you need to mount it into the operating system as a virtual disk. In Linux, this is done easily through the command mount indicating the file system type (usually ext4 or erofs). On Windows, you will need third-party drivers, such as Ext2Fsd or WSL2 functionality.

Modern devices are increasingly switching to the file system EROFS (Enhanced Read-Only File System) for the system partition. This system is read-only and provides better performance and compression. It is difficult to mount EROFS using standard Linux tools; it often requires compiling special kernel modules or using a utility fsck.erofs to extract files without mounting.

After mounting, you get access to the directories /system/app, /system/framework and others. Here you can extract APK files, .so libraries and configuration XML. Be careful: changing the permissions (chmod) or ownership of files inside a mounted image may prevent the system from reading those files after booting.

You can use the utility imgextractorto extract the entire contents of an image without mounting it. It recursively goes through the image and pulls out all the files into a regular folder on your computer. This is a safe method, since it does not require superuser rights to mount block devices and does not risk damaging the file system structure if unmounted incorrectly.

python3 imgextractor.py system_raw.img output_folder

Analysis of extracted files allows you to understand which applications are system, which libraries are used to operate the hardware, and how the network is configured. This is an indispensable tool for custom firmware developers and security researchers.

๐Ÿ’ก

When working with images in Linux, use the mount -o loop,loop_offset=XXXX option if the image contains a partition table and you want to mount a specific partition inside it, and not the entire file.

Is it possible to unpack the firmware directly on a smartphone?

Technically, this is possible if a terminal emulator and root access is installed on the device. However, due to limited internal memory and low processor speed, this process will be extremely slow and risky. It is recommended to perform all operations on a PC.

What to do if the file has an .ozip extension?

.ozip is an encrypted format of Oppo/Realme firmware. It cannot be unpacked using conventional methods. A special decryption key or the ozipdecrypt utility is required, which often requires selecting a key depending on the device model.

Is it safe to edit boot.img?

Editing boot.img (replacing the kernel or ramdisk) is only safe if you have an unlocked Bootloader. On a locked device, any modification of this file will cause the phone to refuse to boot due to verification of the Verified Boot signature.

Why do you need to unpack recovery.img?

The recovery image contains the recovery environment. It is unpacked to add support for installing firmware from a memory card (Sideload), enable ADB debugging in recovery mode, or replace the standard interface with a custom one (for example, TWRP).

Is it possible to assemble the firmware back after editing?

Yes, this is possible using the utilities make_ext4fs (to create an image from a folder) and img2simg (for compression back to sparse). However, to install such firmware you will need an unlocked bootloader and a signed image, otherwise the device will not accept the changes.