LAMD: Context-driven Android Malware Detection and Classification with LLMs

Xingzhi Qian, Xinran Zheng, Yiling He, Shuo Yang, Lorenzo Cavallaro · DOI

Introduction

Detecting Android malware is a persistent challenge characterized by a continuous "cat-and-mouse" game between security researchers and attackers. Traditional detection systems primarily rely on supervised learning, where models are trained on specific features of known malware. However, these models frequently suffer from "concept drift"—a phenomenon where attackers evolve their tactics, causing new malware to deviate significantly from the training data. Furthermore, these "black box" models rarely provide actionable explanations for their classifications, leaving security analysts without context.

Large Language Models (LLMs) present a promising alternative due to their zero-shot reasoning capabilities. However, directly applying LLMs to Android applications is impractical. APKs often contain thousands of classes and millions of lines of boilerplate or library code, which far exceed the context windows of modern LLMs. Moreover, malicious intent is often buried under a mountain of benign functionality, and the structural complexity of code—represented by webs of interdependencies—is difficult for sequence-based models to navigate.

The LAMD Framework

To address these hurdles, we introduce LAMD (Large language model-based Android Malware Detection). LAMD optimizes the analysis process through a two-pronged approach: Key Context Extraction and Tier-wise Code Reasoning.

Key Context Extraction

Rather than attempting to analyze an entire application, LAMD focuses on "suspicious APIs" (e.g., those involved in location access or data transmission). It employs Backward Program Slicing to isolate only the specific instructions and variables that influence those calls. This technique effectively prunes irrelevant "support code," drastically increasing the signal-to-noise ratio and ensuring the relevant logic fits within the LLM's context window.

The LAMD framework architecture, featuring Key Context Extraction and Tier-wise Code Reasoning.

Tier-wise Code Reasoning

To manage structural complexity, LAMD decomposes the analysis into three hierarchical tiers:

  1. Tier 1 (Function Level): Summarizes the behavior of individual sliced functions.
  2. Tier 2 (API Level): Analyzes how these functions interact to form a specific intent (e.g., determining if data is logged locally or exfiltrated to a remote server).
  3. Tier 3 (APK Level): Synthesizes these insights to make a final judgment and generate a human-readable explanation.

To mitigate potential hallucinations, LAMD includes a Factual Consistency Verification mechanism. This component prompts the LLM to identify data relationships within the code and validates them against ground-truth dependencies extracted via static analysis.

Experimental Evaluation

We evaluated LAMD using a dataset of 13,794 Android APKs sourced from Androzoo, spanning the years 2014 to 2023. To test resilience against concept drift, the data was divided into three temporal test sets. LAMD was compared against established baselines, including Drebin, DeepDrebin, and Malscan.

Performance comparison of LAMD against traditional baselines across three temporal test sets.

As shown in the results, LAMD achieved a superior F1-score of approximately 90% across all test sets. Notably, while the performance of traditional models degraded on more recent data (Test 3), LAMD remained stable. On the newest test set, LAMD's False Negative Rate (FNR) was only 8.47%, significantly lower than Drebin's 37%, demonstrating its ability to catch "stealthy" new malware families.

Discussion and Insights

The success of LAMD highlights that LLMs do not require the entire program to be effective; they require the relevant program. By using program slicing, we reduced millions of lines of code to a manageable size for models like GPT-4o-mini. Because the LLM understands code logic rather than just memorizing patterns, it exhibits remarkable zero-shot resilience. Furthermore, LAMD bridges the explainability gap by providing "Key Findings" reports, allowing analysts to verify logic such as insecure SSL handling or unauthorized data exfiltration via reflection.

Conclusion and Future Work

While LAMD is highly effective, operational costs (averaging ~$0.20 per APK) and the latency of cloud-based APIs remain considerations for large-scale deployment. Future research will explore the use of locally deployed LLMs (e.g., Llama 3) to address privacy and cost concerns. Additionally, further refinements in code representation are needed to prevent "over-squashing" in exceptionally complex applications.

Summary updated

BibTeX
@inproceedings{qian2025lamd,
  author = {Xingzhi Qian and Xinran Zheng and Yiling He and Shuo Yang and Lorenzo Cavallaro},
  title = {{LAMD: Context-driven Android Malware Detection and Classification with LLMs}},
  booktitle = {SP (Workshops)},
  year = {2025},
  url = {https://openreview.net/forum?id=gbXmh44MOr},
}
Figure