Android Software Reverse Engineering & Decompilation

Case Study: Reverse Engineering Game Resources via resources.arsc for Modding and Analysis

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction to Android Resource Files and Modding

Android applications, including games, bundle their UI layouts, strings, images, animations, and other assets into a highly optimized binary format: resources.arsc. This file is a critical component within an APK, serving as a comprehensive index and container for all application resources. For developers, it’s the bridge between resource IDs and their actual values. For reverse engineers and modders, resources.arsc is a goldmine, offering insights into an app’s structure, enabling asset extraction, and facilitating modifications without recompiling source code. This case study delves into the intricacies of reverse engineering resources.arsc, focusing on how its internal structure can be leveraged for game modding and detailed analysis.

Understanding and manipulating resources.arsc is fundamental for tasks such as:

  • Extracting embedded images, sounds, or other media assets.
  • Modifying text strings (e.g., for localization or cheat messages).
  • Changing layout structures or drawable references.
  • Analyzing resource consumption and optimizing game assets.

Understanding the resources.arsc Format

The resources.arsc file is not a simple archive; it’s a binary resource table designed for efficient lookup at runtime. Its structure is hierarchical and chunk-based, enabling fast access to resources by their integer IDs. Key components of its structure include:

  • Resource Header: Defines the type of chunk (e.g., string pool, package, type spec) and its size.
  • Global String Pool: Contains all unique strings used in the file, such as resource names (e.g., `app_name`, `icon`), package names, and attribute names. These strings are referenced by their index.
  • Package Chunks: Each Android package (like your app itself or libraries) gets its own chunk, containing its specific resources. It includes a package ID and its own string pools.
  • Type Specifications (TypeSpec): Define the attributes common to a set of resources of a particular type (e.g., all drawables, all strings). This includes an ID for the type (e.g., `0x01` for `string`, `0x02` for `drawable`).
  • Type Configurations (TypeConfig): Represent specific configurations for a resource type, such as language, screen density, orientation, etc. (e.g., `drawable-hdpi`, `string-en`).
  • Resource Entries: The actual resource data, pointing to values in the string pools or direct values. Each entry has a flag (e.g., indicating if it’s a reference to another resource) and a data value.

The complexity arises from the interleaving of these chunks and the indirect referencing through indices and IDs. Manually parsing this binary structure requires a deep understanding of its specification, often aided by tools.

Essential Tools for resources.arsc Analysis

To effectively reverse engineer resources.arsc, a combination of specialized tools is indispensable:

  • Apktool

    Apktool is the primary tool for decompiling and recompiling APKs. It extracts resources.arsc and decodes it into human-readable XML files (e.g., `public.xml`, `strings.xml`, `drawables.xml`, `styles.xml`). While it doesn’t expose the raw binary structure directly, it provides an invaluable high-level overview and allows for easy modification of decoded resources.

    apktool d mygame.apk -o mygame_decompiled
  • 010 Editor with ARSC Template

    For a low-level, byte-by-byte analysis, a powerful hex editor like 010 Editor, combined with a custom binary template for the ARSC format, is crucial. These templates parse the binary data and display its structure in a tree-like view, labeling chunks, offsets, and values. This allows for direct inspection of resource IDs, string pool contents, and entry data.

  • AAPT (Android Asset Packaging Tool)

    While primarily for building, AAPT (or `aapt2` from the Android SDK build-tools) can list resource information, helping to verify resource IDs and types. It’s useful for understanding how Android compiles resources.

    aapt2 dump resources mygame.apk
  • Python Scripting (e.g., `arscblame`)

    For automated analysis or specific extraction tasks, custom Python scripts leveraging libraries like `arscblame` (a reverse engineering tool for `resources.arsc`) can be extremely powerful. These scripts can programmatically parse the file, extract specific resource types, or identify references.

Step-by-Step Reverse Engineering a Game’s resources.arsc

Step 1: Obtain and Decompile the APK

First, get the APK file of the target game. Use Apktool to decompile it:

apktool d game.apk -o game_mod

This will create a `game_mod` directory containing `AndroidManifest.xml`, `smali` code, and the decoded `res` directory. Crucially, the raw resources.arsc file will also be present in the root of `game_mod` (or `build/apk/resources.arsc` depending on Apktool version/options), alongside the decoded resources in `game_mod/res/`. The `public.xml` file within `res/values/` is key; it maps resource names to their unique integer IDs.

Step 2: Initial Analysis with Apktool’s Output

Navigate to `game_mod/res/values/`. You’ll find files like `strings.xml`, `colors.xml`, `styles.xml`, etc. These are the decoded representations of resources stored in resources.arsc. For instance, `strings.xml` will show all localized strings:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My Awesome Game</string>
    <string name="welcome_message">Welcome, Player!</string>
</resources>

The `public.xml` file is crucial as it contains the mapping of resource names to their hexadecimal IDs, which are used internally by Android:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <public type="string" name="app_name" id="0x7f010000" />
    <public type="string" name="welcome_message" id="0x7f010001" />
    <public type="drawable" name="background" id="0x7f020000" />
</resources>

This provides the necessary IDs (`0x7f010000`, `0x7f020000`, etc.) which we’ll look for in the raw resources.arsc file.

Step 3: Deep Dive into the Raw resources.arsc with a Hex Editor (e.g., 010 Editor)

Open the raw `resources.arsc` file (from the decompiled `game_mod` directory, or extracted directly from the APK) in 010 Editor with an ARSC template loaded. The template will automatically parse the file, displaying its chunk structure.

Identifying Key Chunks:

  • Header: The file usually starts with a `ResTable_header` chunk.
  • Global String Pool: Following the header, you’ll find a `ResStringPool_header`. Expand this to see all global strings. These often include resource names, package names, and attribute names.
  • Package Chunks: Look for `ResTable_package` chunks. Each package has its own ID (e.g., `0x7f` for the app’s main package). Inside, you’ll find more string pools (often for specific resource types) and arrays of `ResTable_typeSpec` and `ResTable_type` entries.

Locating Resource Entries:

Let’s say we want to find the resource corresponding to the `background` drawable with ID `0x7f020000`. The ID format is `0xPPTTIIII`:

  • `PP`: Package ID (e.g., `7f` for the app’s main package).
  • `TT`: Type ID (e.g., `02` for `drawable` as seen in `public.xml`).
  • `IIII`: Entry Index (e.g., `0000` for the first drawable entry).

1. Navigate to the `ResTable_package` chunk corresponding to `0x7f`.
2. Within this package, find the `ResTable_typeSpec` chunk for type `0x02` (drawable). This chunk contains flags for each entry of this type.
3. After the `ResTable_typeSpec` (or adjacent to it depending on configurations), locate `ResTable_type` chunks. These specify configurations (e.g., default, `hdpi`, `xhdpi`).
4. Inside a `ResTable_type` chunk, there’s an array of `ResTable_entry` structs. These entries are indexed by the `IIII` part of the resource ID. Find the entry at index `0x0000` (the first one).

Each `ResTable_entry` will contain a `Res_value` struct. This `Res_value` typically has a `dataType` and `data` field. For drawables, the `dataType` might indicate a `Res_value_TYPE_STRING` (if it’s a path to an asset in `assets/` or `res/raw/`) or a `Res_value_TYPE_REFERENCE` (if it points to another resource). If it’s a string, the `data` field will be an index into one of the package’s string pools, pointing to the actual filename (e.g., `res/drawable-hdpi/background.png`).

Example: Tracing a Drawable

Suppose the `Res_value` for `0x7f020000` has `dataType = 0x03` (String) and `data = 0x000000AB`. This `0xAB` is an index into the package’s resource string pool. By navigating to that string pool and looking up index `0xAB`, you might find the string `res/drawable/background.png`. This tells you exactly where the graphical asset is located within the APK.

This manual tracing process is tedious but provides an unparalleled understanding of the resource linkage.

Modding Implications and Asset Extraction

Once you understand the mapping from resource IDs to actual values or file paths, modding becomes straightforward:

  • Asset Replacement: Identify the path to an image or audio file (e.g., `res/drawable-hdpi/game_icon.png`). Replace the original `game_icon.png` in the decompiled `game_mod/res/drawable-hdpi/` directory with your modified image.
  • String Modification: Edit `game_mod/res/values/strings.xml` to change game text, messages, or even add new language support.
  • Layout Changes: Modify XML layouts in `game_mod/res/layout/` to rearrange UI elements, add/remove components, or change attributes.
  • Direct Binary Patching: For advanced modding, if Apktool fails to decode certain aspects or if you need to perform very specific, low-level changes (e.g., altering a direct integer value referenced by a resource ID that isn’t easily exposed in XML), you might directly patch the `resources.arsc` file using a hex editor, referencing the offsets and values discovered during analysis. This is highly risky and requires extreme precision.

After making your desired changes, recompile the APK using Apktool:

apktool b game_mod -o game_modded.apk

Then, sign the `game_modded.apk` with a new key and install it on your device.

Conclusion

Reverse engineering resources.arsc is a powerful technique for understanding Android application internals, extracting assets, and enabling extensive modding capabilities for games. While tools like Apktool provide a high-level abstraction, a deeper understanding of the binary format using hex editors and templates unlocks granular control and allows for modifications that might otherwise be impossible. This case study demonstrates that with the right tools and a systematic approach, the seemingly opaque world of compiled Android resources can be fully explored and manipulated, opening new avenues for customization and analysis.

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