TraceRAG: A LLM-Based Framework for Explainable Android Malware Detection and Behavior Analysis

Guangyu Zhang, Xixuan Wang, Shiyu Sun, Peiyan Xiao, Kun Sun, Yanhai XiongarXiv 2025 · DOI

Abstract

Traditional Android malware detection often suffers from a lack of transparency and vulnerability to code obfuscation. TraceRAG addresses these issues by combining Retrieval-Augmented Generation (RAG) with Large Language Models (LLMs) to create an explainable detection pipeline. By preprocessing decompiled Java code into semantic summaries and utilizing an iterative retrieval mechanism, TraceRAG achieves a 96% detection accuracy while providing detailed, code-linked security reports.

Introduction

The landscape of Android malware is characterized by a constant arms race between attackers and defenders. Modern malware employs sophisticated evasion and obfuscation techniques that frequently bypass traditional static and dynamic analysis tools. Furthermore, existing security solutions often operate as "black boxes," providing binary labels (malicious vs. benign) without explaining the underlying intent or the specific code paths responsible for the threat. TraceRAG was developed to bridge this gap, offering a traceable and human-readable justification for malware classification.

The TraceRAG Framework

TraceRAG utilizes an agentic pipeline, primarily powered by OpenAI’s o3-mini, to transform raw Android Package Kit (APK) files into a searchable knowledge base. The architecture is divided into three distinct phases: Vector Database Construction, Iterative Retrieval, and Report Generation.

The complete TraceRAG architecture, illustrating the transition from raw APK input to the final security report through vector database construction and iterative retrieval.

1. Vector Database Construction

The process begins with the decompilation of APKs into Java source code using JADX. This code is then partitioned into method-level chunks. To ensure high-quality analysis, an LLM-Cleanser module removes unreachable code and noise. The core innovation lies in the LLM-Describer, which generates natural language summaries of each method. These summaries, rather than the raw code itself, are embedded into a vector database, facilitating semantic search based on security queries.

2. Iterative Retrieval and Analysis

TraceRAG performs a multi-turn analysis using an LLM-Analyzer. The system executes predefined queries targeting specific malicious behaviors (e.g., SMS theft, privilege escalation). If a retrieved code snippet references external functions, the analyzer generates follow-up queries to "walk" the call chain, effectively reconstructing complex malicious logic that spans multiple files.

3. Explainable Report Generation

The final phase involves the LLM-Organizer, which synthesizes the gathered evidence into a structured APK Report. This report includes high-level summaries and specific code-level evidence, making the analysis accessible to human experts.

An example of the LLM-Describer's input and output, showing how raw obfuscated code is translated into a structured security analysis.

Evaluation and Results

The framework was evaluated using a dataset of 100 APKs from AndroZoo, with ground truth labels verified via VirusTotal. TraceRAG demonstrated exceptional performance:

  • Detection Accuracy: 96% accuracy in binary classification.
  • Behavior Identification: 83.81% accuracy in identifying specific malicious traits.
  • Coverage: Unlike traditional sandboxes that often miss obfuscated behaviors, TraceRAG achieved 100% coverage by linking every identified behavior to its source code implementation.

Expert validation from the Google Android Security Team further confirmed the utility of the generated reports, with high scores for clarity and practical application in real-world security workflows.

Discussion and Future Work

While TraceRAG represents a significant step forward in explainable AI for security, certain limitations remain. The current implementation is restricted to Java code, potentially missing threats in native C/C++ libraries. Additionally, the operational cost of high-end LLM APIs remains a barrier to massive-scale deployment. Future research will focus on extending support to native libraries and optimizing the pipeline for local, cost-effective model execution.

Summary updated

BibTeX
@misc{zhang2025tracerag,
  author = {Guangyu Zhang and Xixuan Wang and Shiyu Sun and Peiyan Xiao and Kun Sun and Yanhai Xiong},
  title = {{TraceRAG: A LLM-Based Framework for Explainable Android Malware Detection and Behavior Analysis}},
  year = {2025},
  eprint = {2509.08865},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.08865},
}
Figure