Android Upgrades, Custom ROMs (LineageOS), & Kernels

Reverse Engineering Lab: Extracting and Analyzing Firmware & Android OS Updates from OEM Packages

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction: Unpacking the Black Box of Android Updates

For developers, enthusiasts, and security researchers, the ability to dissect Original Equipment Manufacturer (OEM) update packages is a crucial skill. These packages, often delivered over-the-air (OTA), are a treasure trove of information, containing everything from critical firmware updates to the latest Android operating system components. Understanding how to extract and analyze these elements is fundamental for tasks such as developing custom ROMs like LineageOS, porting new Android versions to unsupported devices, identifying security vulnerabilities, or simply gaining deeper insights into device operations. This guide will walk you through the essential tools and techniques required to reverse engineer OEM update packages, focusing on distinguishing and extracting firmware from Android OS components.

Understanding OEM Update Packages: Firmware vs. Android OS

Before we dive into extraction, it’s vital to clarify the distinction between firmware and Android OS components within an OEM update package. While often delivered together, they serve entirely different, yet interdependent, roles:

  • Firmware: These are low-level software components that directly interface with the hardware. They include the bootloader (which initializes hardware and loads the kernel), modem firmware (handling cellular communication), Digital Signal Processor (DSP) firmware (for audio/video processing), sensor hub firmware, trusted execution environment (TEE) components, and various device tree blobs (DTB) that describe hardware configuration to the kernel. Firmware updates are critical for hardware compatibility, performance, and security patches at the lowest levels. They often reside in partitions like abl, modem, dsp, rpm, tz, sbl, or UEFI-related partitions.
  • Android OS Components: These are the higher-level software layers that constitute the Android operating system itself. Key components include the Linux kernel and its initial ramdisk (bundled in boot.img), the core Android system files (system.img), vendor-specific drivers and libraries (vendor.img), product-specific applications and configurations (product.img), and device tree overlay blobs (dtbo.img) which layer additional hardware configuration onto the base DTB. These updates bring new Android versions, security patches, system apps, and UI enhancements.

OEM update packages often bundle both to ensure a cohesive, functional system. For instance, a new Android version might require updated modem firmware to function correctly, or a security patch might involve both a kernel update and a TEE firmware update.

Tools of the Trade: Your Reverse Engineering Toolkit

To embark on this journey, you’ll need a Linux-based environment (a virtual machine or WSL is perfectly adequate) and a suite of specialized tools. Here are the essentials:

  • Archive Extractors:unzip, 7z (p7zip) for standard ZIP/7Z archives.
  • Disk Image Utilities:simg2img (from AOSP or prebuilt packages like android-sdk-libsparse-utils) for converting Android sparse images to raw images. unyaffs (for older YAFFS2 filesystems), ext4_unpacker (for raw ext4 images), or simply loop mounting.
  • Binary Analysis:binwalk for identifying file types, embedded filesystems, and executables within unknown binaries.
  • Android Image Tools:bootimg_tool, magiskboot (from Magisk distribution), or custom scripts for unpacking/repacking boot.img. payload_dumper.py for extracting images from Google’s A/B OTA payload.bin.
  • Hex Editor:bless, GHex, or xxd for examining raw binary data.

Most of these tools can be installed via your distribution’s package manager:

sudo apt update && sudo apt install unzip p7zip-full android-sdk-libsparse-utils mtools binwalk python3-pip xxd
pip3 install protobuf # For payload_dumper.py

Step-by-Step Extraction & Analysis

1. Acquiring the OEM Update Package

The first step is to obtain the official OEM update package. These are typically found on the manufacturer’s support website, through official OTA captures, or on community forums like XDA Developers. Look for files with extensions like .zip, .tgz, .tar.gz, or sometimes proprietary formats.

2. Initial Decompression and Inspection

Once you have the package, start by extracting it. Most packages are standard ZIP archives:

unzip OEM_Update_Package.zip -d extracted_update

Inside the extracted directory, you’ll often find a collection of files. Key files to look for include:

  • payload.bin (common for Google A/B devices)
  • system.img, vendor.img, boot.img, dtbo.img
  • modem.img, abl.img, tz.img, dsp.img (firmware partitions)
  • firmware-update directory or a similar structure.

If you encounter a .tar.gz or similar, use tar -xf. For more obscure archives, 7z x is often effective.

3. Extracting Images from payload.bin (A/B Updates)

For devices with A/B partitioning, updates often come as a payload.bin file, which is a stream of compressed partition images. You’ll need payload_dumper.py to extract these:

cd extracted_update
python3 payload_dumper.py payload.bin

This script will create a new directory (e.g., output) containing all the individual partition images (e.g., system.img, vendor.img, boot.img, modem.img, etc.).

4. Analyzing and Extracting Android OS Partitions

a. System, Vendor, Product, DTBO Images

These are typically sparse images or raw ext4 filesystem images. Sparse images need to be converted to raw images before they can be mounted:

simg2img system.img system_raw.img

Now, create a mount point and mount the raw image:

mkdir system_mount
sudo mount -o loop system_raw.img system_mount

You can now browse the full Android filesystem within system_mount. Remember to unmount when done:

sudo umount system_mount

b. Boot Image (boot.img)

The boot.img contains the Linux kernel and the initial ramdisk. Extracting it reveals kernel binaries, command lines, and the ramdisk which contains crucial initialization scripts and device configuration.

# Using magiskboot (recommended for modern boot images)
magiskboot unpack boot.img
# This will extract kernel, ramdisk.cpio.gz, dtb, etc. into the current directory

# Or using older tools/scripts
./split_bootimg.pl boot.img # Requires Perl script, often found in Android kitchens

Once extracted, you can further unpack the ramdisk:

mkdir ramdisk_contents
cd ramdisk_contents
cpio -idmv < ../ramdisk.cpio

This allows you to inspect init.rc files, fstab entries, and other low-level OS configurations.

5. Analyzing and Extracting Firmware Partitions

Firmware images like modem.img, abl.img (bootloader), tz.img (TrustZone), and dsp.img are often raw binary blobs. They typically do not contain standard mountable filesystems like ext4. This is where binwalk shines.

binwalk -Me modem.img

The -Me flags tell binwalk to recursively extract all known file system signatures and embedded files. You might find various embedded filesystems (like squashfs), firmware images for specific chips, or raw executables within. Often, these contain proprietary vendor code that can be challenging to analyze without reverse engineering expertise (e.g., Ghidra, IDA Pro).

For deeper inspection, a hex editor is invaluable:

xxd modem.img | less

This allows you to see the raw hexadecimal and ASCII representation, sometimes revealing human-readable strings or key identifiers.

6. Distinguishing Key Differences in Practice

After extraction, you can observe the practical differences:

  • Android OS Components: Inside system_mount, you’ll find standard Android directories (/app, /bin, /etc, /framework, /lib, /priv-app, etc.), APKs, system libraries, and executable binaries. The ramdisk from boot.img will show init.rc scripts, sepolicy files, and kernel modules.
  • Firmware Components: Analyzing modem_mount (if binwalk found a filesystem) or the extracted files from modem.img with binwalk, you’ll see binaries specific to the cellular baseband, often with less discernible structure compared to Android’s Linux environment. Bootloader (abl.img) will contain code responsible for hardware initialization, often featuring minimal filesystem structures or raw executable code that loads subsequent stages.

Practical Applications

The ability to perform these extractions opens up a world of possibilities:

  • Custom ROM Development: Extracting vendor.img and dtbo.img is crucial for building custom ROMs like LineageOS, as they contain device-specific blobs and hardware configurations. Analyzing the kernel from boot.img allows for custom kernel development.
  • Security Research: Identifying vulnerabilities in bootloaders, modem firmware, or Android system services.
  • Device Porting: Adapting Android to new devices by understanding existing hardware configurations and drivers.
  • Debugging & Forensics: Analyzing system behavior post-update or recovering data from damaged devices.

Conclusion: Empowering Your Android Development Journey

Reverse engineering OEM update packages is a powerful skill that demystifies the intricate layers of modern Android devices. By systematically extracting and analyzing both firmware and Android OS components, you gain an unparalleled understanding of how your device operates at a fundamental level. While the process can be complex and requires patience, the insights gained are invaluable for advanced Android development, security analysis, and pushing the boundaries of what your device can do. Always proceed with caution and respect intellectual property rights when working with proprietary firmware.

Android Mobile Specs & Compare Directory

Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!

Compare Devices Specs →
Google AdSense Inline Placement - Content Footer banner