DexLego: Reassembleable Bytecode Extraction for Aiding Static Analysis

Zhenyu Ning, Fengwei Zhang

TL;DR

DexLego is a novel system that bridges the gap between dynamic and static analysis for Android malware. It extracts bytecode and metadata at runtime using a modified Android Runtime (ART) and reassembles them into a valid, "static-analysis-ready" DEX file that captures hidden behaviors like packing, reflection, and self-modifying code.

What Problem Does This Paper Address?

Static analysis tools (like FlowDroid or DroidSafe) are the workhorses of Android security research, but they have a massive blind spot: code hiding. Malware authors use "packers" to encrypt the original code, dynamic loading to fetch malicious payloads at runtime, and self-modifying code to change instructions on the fly.

While dynamic analysis (running the app) can see this code as it executes, it suffers from poor "code coverage"—it only sees what actually runs during a specific session. Furthermore, dynamic tools often struggle with "implicit flows" (logic-based data leaks) that static tools handle well. The challenge is: how do we give static analysis tools the "unpacked" view of an app without losing the structural integrity required for them to function?

Methods

DexLego introduces a "just-in-time" (JIT) extraction and reassembly pipeline consisting of three main parts:

  1. Instruction-Level Extraction: The authors modified the Android Runtime (ART) interpreter. As the app runs, DexLego intercepts every instruction and piece of metadata (strings, field names, etc.) right before execution.
  2. The Tree Model for Self-Modification: This is the paper's most clever innovation. Standard "memory dumping" fails if code changes over time (e.g., a method that modifies its own instructions). DexLego uses a tree structure where each node represents a version of the code. If an instruction at a specific index changes, DexLego "forks" a new branch in the tree.
  3. Offline Reassembling: To make the results readable by standard tools, DexLego merges these tree branches back into a single DEX file. It handles self-modifying code by inserting conditional branches based on a dummy "Modification" class. This trick "tricks" static analysis tools into exploring both the original and the modified code paths.
  4. Force Execution: To solve the coverage problem, DexLego identifies "Uncovered Conditional Branches" (UCBs). It then manually manipulates the interpreter to force the app down these unexplored paths, ensuring more of the hidden code is extracted.

Datasets

The authors evaluated DexLego using a mix of synthetic and real-world targets:

  • DroidBench: A standard benchmark for Android data flow analysis. The authors added 15 new, more complex samples involving advanced reflection and self-modifying code.
  • Public Packers: They tested against eight major commercial and public packing platforms, including 360, Alibaba, Tencent, and Baidu.
  • Real-World Malware: A selection of packed applications from Google Play, 360 Market, and Wandoujia.
  • F-Droid: Five open-source apps used specifically to measure the effectiveness of the "Force Execution" module.

Key Insights and Ideas

  • Reassembly is the Key: Simply dumping code isn't enough. By reassembling the extracted data into a valid DEX format, DexLego allows researchers to use the entire existing ecosystem of static analysis tools without modification.
  • Handling the "Time" Dimension: Most unpackers assume there is a single "point" where code is fully unpacked. DexLego recognizes that code is a moving target. Its tree-based approach treats code modifications as logical branches rather than overwrites.
  • Reflection De-obfuscation: DexLego simplifies static analysis by replacing complex, string-based reflective calls (which are hard for static tools to resolve) with direct function calls during the extraction phase.

Key Results

  • Accuracy Boost: When using DexLego-reassembled files, the F-measure (a balance of precision and recall) for popular static tools increased significantly: FlowDroid (+33.3%), DroidSafe (+31.1%), and HornDroid (+23.6%).
  • Packer Defeat: DexLego successfully reconstructed apps protected by all five functional public packers tested (360, Alibaba, Tencent, Baidu, and Bangcle).
  • Coverage Improvement: The "Force Execution" module increased average instruction coverage from 32% to 82% on the F-Droid test set.
  • Real-World Impact: In a test of 9 popular packed apps, DexLego revealed that all of them were leaking sensitive data (like IMEI, location, or SSID) to remote servers—leaks that were invisible to static analysis on the original packed files.

Limitations and Future Work

  • Native Code (JNI): Currently, DexLego only extracts Java/Dalvik bytecode. It cannot yet reassemble or analyze malicious behavior hidden in native C/C++ libraries (JNI), though the authors suggest this as a future direction.
  • Anti-Analysis Techniques: While DexLego is transparent to many obfuscations, sophisticated malware could potentially detect the modified ART environment or the "Force Execution" logic.
  • Performance: The system introduces roughly a 2x slowdown during the initial app launch/extraction phase. While acceptable for security analysts, it remains a bottleneck for high-throughput automated scanning.

Summary updated

BibTeX
@inproceedings{ning2018dexlego,
  author = {Zhenyu Ning and Fengwei Zhang},
  title = {{DexLego: Reassembleable Bytecode Extraction for Aiding Static Analysis}},
  booktitle = {Dsn},
  year = {2018},
  doi = {10.1109/dsn.2018.00075},
}
Figure