MalLoc: Toward Fine-grained Android Malicious Payload Localization via LLMs

Tiezhu Sun, Marco Alecci, Aleksandr Pilgun, Yewei Song, Xunzhu Tang, Jordan Samhi, Tegawendé F. Bissyandé, Jacques KleinarXiv 2025

TL;DR

While traditional Android security tools excel at flagging if an app is malicious or identifying its general malware family, they fail to pinpoint the exact code responsible for the harmful behavior. MalLoc bridges this gap by using a two-phase Large Language Model (LLM) framework to precisely localize malicious payloads at the method level and provide human-readable explanations of their roles. By breaking the task into distinct semantic (class-level) and structural (method-level) phases, MalLoc significantly reduces the manual reverse-engineering workload for security analysts.

What Problem Does This Paper Address?

When dealing with Android malware, knowing that an app is dangerous is only half the battle. To build effective defenses, perform robustness testing, or design targeted countermeasures, security analysts need to know exactly which parts of the code are executing the malicious actions.

Fig. 1: The overview of different stages of Android malware analysis.

As shown in Figure 1, traditional analysis stops at Stage 1 (Detection) or Stage 2 (Family Classification). Existing attempts to find the actual payload (Stage 3) usually stop at the class level, which is too coarse-grained. Furthermore, many machine learning models operate as "black boxes," offering no explanation for why a piece of code was flagged. This lack of precision and interpretability leaves analysts sorting through thousands of lines of low-level code, a task made even harder by modern malware tactics like code obfuscation and dynamic behavior triggering.

Methods

MalLoc introduces a structured, two-phase pipeline that leverages the semantic reasoning capabilities of LLMs to analyze Smali code (a human-readable intermediate representation of Android's DEX bytecode).

Rather than asking an LLM to find malicious methods in a single, complex prompt (which the authors show performs poorly), MalLoc decomposes the problem:

  1. Preprocessing: The target APK is decompiled into Smali code using standard tools (ApkTool). The authors also utilize a family behavior lookup table derived from malware benchmarks to narrow down the specific types of malicious behaviors (e.g., privacy theft, SMS abuse) to look for based on the app's malware family.
  2. Phase 1 (Semantic/Class-Level Localization): The LLM is given a Smali class alongside a detailed description of a specific malicious behavior. It determines whether the class implements that behavior and provides a detailed textual explanation of its reasoning. If the class is deemed benign, the analysis for that class stops.
  3. Phase 2 (Structural/Method-Level Localization): If a class is flagged as malicious, it is passed to Phase 2 along with the explanation generated in Phase 1. The LLM is then tasked with drilling down to pinpoint the exact methods involved, describing the specific role of each method, and assigning a confidence score.

The prompt templates illustrating this multi-stage reasoning can be seen below:

Fig. 3: Prompt templates used in: Baseline Approach (left), Phase 1 of MalLoc (middle), and Phase 2 of MalLoc (right).

Datasets

To evaluate MalLoc, the authors utilized two distinct datasets:

  • MalApp: A custom, demo Android app built from scratch by the authors to serve as a controlled benchmark. It contains 51 Smali classes and 165 methods, implementing three specific malicious behaviors (Privacy Stealing, Aggressive Advertising, and Tricky Behavior) across 3 classes and 12 methods. This provided an absolute, fine-grained ground truth for quantitative evaluation.
  • MalRadar Sample (RuMMs Family): To test robustness against real-world, obfuscated threats, the authors selected a sample from the RuMMs family within the established MalRadar benchmark. This real-world APK contained 21 classes and 66 methods, masquerading as an SMS/MMS app with heavy obfuscation (meaningless class/method names and reflection).

Key Insights and Ideas

  • The Compilation Expansion Challenge: A major hurdle in method-level localization is that a single high-level Java/Kotlin method often compiles into multiple synthetic Smali methods due to features like lambdas, anonymous classes, or inner classes. As shown in Figure 2, a single onCreateView() method expanded into five distinct Smali methods, meaning localization tools must be smart enough to map behaviors across these fragmented code units.
Fig. 2: Example of the translation of a Java ‘onCreateView()‘ method into multiple Smali methods.
  • Monolithic Prompting Fails: The authors' baseline experiment—asking the LLM to simultaneously detect malware, classify the behavior, and pinpoint the methods—yielded terrible results. LLMs struggle when forced to perform multi-step semantic and structural reasoning all at once.
  • Prior Knowledge as a Catalyst: By feeding the LLM family-level behavior context (knowing what type of malware family the app belongs to ahead of time), the search space is drastically reduced, allowing the model to focus its attention and achieve much higher precision.

Key Results

The authors evaluated MalLoc using both an open-source model (Phi-4) and a commercial model (GPT-4.1).

  • Controlled Evaluation (MalApp): The baseline monolithic approach performed poorly (Phi-4 scored 0.00 across all metrics; GPT-4.1 achieved a method-level F1-score of 0.64). In contrast, MalLoc with GPT-4.1 achieved a Class-F1 of 0.89 and a Method-F1 of 0.76, capturing a perfect 1.00 recall at both levels.
  • Workload Reduction: By accurately filtering out benign code, MalLoc reduced the manual analysis workload by approximately 87% on the demo app.
  • Real-World Robustness (RuMMs App): When applied to the heavily obfuscated real-world malware sample, MalLoc successfully identified 4 out of 5 annotated behaviors, localizing 6 classes and 17 methods with 100% precision (verified manually by security experts). It successfully unmasked obfuscated methods handling contact exfiltration and unauthorized SMS background services.

Limitations and Future Work

While promising, the authors note several limitations that pave the way for future research:

  • Scalability and Efficiency: Analyzing large, complex commercial apps with thousands of classes via iterative LLM prompting can become slow and expensive.
  • Evaluation Scale: Due to the intensive manual effort required to verify method-level ground truth in real-world malware, the evaluation was limited to a small, representative sample size.
  • Uncertainty Estimation: The framework currently lacks a robust mechanism for confidence calibration, which is vital for human analysts working in high-stakes security environments.

Future work will focus on expanding the evaluation to more diverse malware families, integrating additional LLMs, and improving the framework's scalability.

Summary updated

BibTeX
@misc{sun2025malloc,
  author = {Tiezhu Sun and Marco Alecci and Aleksandr Pilgun and Yewei Song and Xunzhu Tang and Jordan Samhi and Tegawendé F. Bissyandé and Jacques Klein},
  title = {{MalLoc: Toward Fine-grained Android Malicious Payload Localization via LLMs}},
  year = {2025},
  eprint = {2508.17856},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.17856},
}
Figure