Android Hardware Reverse Engineering

Using Ghidra & IDA Pro for Exynos S-Boot Analysis: A Practical Reverse Engineering Guide

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction: Unveiling the Samsung Exynos S-Boot

The Samsung Exynos S-Boot, or Secure Bootloader, is a critical piece of firmware responsible for initializing the hardware, verifying the authenticity of subsequent boot stages, and establishing a trusted execution environment on Exynos-powered devices. Understanding its inner workings is paramount for security researchers, exploit developers, and anyone interested in the foundational layers of Android security. This guide provides a practical, expert-level walkthrough of reverse engineering Exynos S-Boot using two industry-standard tools: Ghidra and IDA Pro.

We will cover everything from obtaining the firmware to performing static analysis, identifying key components, and understanding their security implications. The focus will be on ARM-based Exynos systems, predominantly AArch64 (ARMv8), as these are common in modern Samsung devices.

1. Acquiring the S-Boot Firmware

The first step in any bootloader analysis is obtaining the target firmware. For Samsung Exynos devices, the S-Boot is typically part of the initial bootloader package, often found within the `BL_` or `AP_` tarball from official firmware releases.

1.1. Official Firmware Download

Tools like SamFirm, Frija, or various online firmware archives allow you to download official Samsung firmware packages. Once downloaded, extract the `.tar.md5` file. Inside, you’ll find multiple `.lz4` or raw `.bin` files.

# Example: Extracting a Samsung firmware package
tar -xvf BL_G998BXXU4AUG2_Sboot.tar.md5
# Look for files like sboot.bin, sboot.img, or similar.

1.2. Identifying the S-Boot Component

Within the extracted files, the S-Boot is usually named `sboot.bin`, `sboot.img`, or a similar variant. Sometimes it’s embedded within a larger `boot.img` or `AP.tar.md5` and requires further extraction. Specialized tools like `sboottool` (if available for your specific device model) or a simple `dd` command can help extract the raw binary.

# If sboot.bin is directly available
cp sboot.bin sboot_raw.bin

# If embedded in a larger file (example for a known offset and size)
# Replace `input_file` and `output_file` as needed
# dd if=input_file of=output_file bs=1 skip=<offset> count=<size>

Before loading into disassemblers, ensure you have the raw binary without any Samsung-specific headers that might confuse the tools. Header stripping might involve analyzing the first few bytes for magic numbers or header structures that precede the actual ARM code.

2. Initial Analysis with Ghidra

Ghidra, a powerful open-source reverse engineering framework from the NSA, is an excellent starting point due to its robust decompilation capabilities and ease of use.

2.1. Loading the Binary into Ghidra

  1. Create a New Project: Start Ghidra and create a new non-shared project.
  2. Import File: Drag and drop your `sboot_raw.bin` into the project window or go to File > Import File.
  3. Configure Load Options:
    • Language: Select the appropriate ARM processor. For modern Exynos, this is typically `ARM:LE:64:v8A` (AArch64) or `ARM:LE:32:v7` (ARMv7-A) depending on the boot stage.
    • Base Address: This is crucial. S-Boot usually loads at a specific physical address (e.g., `0x80000000` or `0x02000000` for earlier stages, or often `0x100000` / `0x400000` for secondary bootloaders). Refer to public documentation, kernel source, or other firmware analyses for common base addresses for your specific Exynos SoC. If unsure, start with `0x0` and adjust later.
  4. Analyze: After import, Ghidra will prompt you to analyze the binary. Accept the default options or customize as needed (e.g., enable ‘Non-Returning Functions’ and ‘Stack-Based Parameter Analysis’).

2.2. Identifying Entry Points and Key Functions

Once analyzed, Ghidra’s decompiler will try to convert assembly to C-like pseudo-code. Look for:

  • `_start` or Reset Vector: The initial entry point. If the base address is correct, this should be the first function Ghidra identifies.
  • Hardware Initialization: Functions that configure clocks, memory controllers (DRAM), and essential peripherals like UART. These often involve direct register writes.
  • Secure Boot Verification: Look for cryptographic operations (hashes, signatures), calls to TrustZone functions (`SMC` instructions), or checks against immutable device data.
// Example pseudo-code in Ghidra for a secure boot check
int verify_signature(char *image_ptr, int image_size, char *signature_ptr) {
  hash = calculate_sha256(image_ptr, image_size);
  if (verify_rsa_signature(hash, signature_ptr, public_key_struct) != 0) {
    return -1; // Signature invalid
  }
  return 0; // Signature valid
}

3. Advanced Analysis with IDA Pro

IDA Pro, with its powerful disassembler, graph view, and extensive plugin ecosystem, offers complementary strengths, especially for complex control flow and scripting.

3.1. Loading the Binary into IDA Pro

  1. New File: Open IDA Pro and select ‘New’.
  2. Load Binary File: Choose your `sboot_raw.bin`.
  3. Processor Type: Select the correct ARM processor (e.g., ‘ARM AArch64’ or ‘ARM Little-endian’).
  4. Load Options:
    • Loading Address: Enter the same base address you used in Ghidra.
    • File Offset: Usually `0`.
    • Loading Size: Size of your `sboot_raw.bin`.
  5. Analysis: IDA Pro will perform an initial auto-analysis.

3.2. Leveraging IDA’s Strengths

  • Graph View: Use the graph view (spacebar) to visualize control flow, especially for complex decision trees involved in secure boot.
  • Cross-References (Xrefs): IDA’s xrefs are invaluable for understanding data and function usage. Right-click on a function or data item and select ‘Jump to xrefs to…’ or ‘Jump to xrefs from…’.
  • IDAPython/IDC Scripting: For repetitive tasks, pattern searching, or interacting with the database, IDA’s scripting capabilities are superior.
# Example IDAPython script to find all SMC calls
for ea in Heads(MinEA(), MaxEA()):
if GetMnem(ea) == "SMC": # Or

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