XGen-Q: An Explainable Domain-Adaptive LLM Framework with Retrieval-Augmented Generation for Software Security

Hamed Jelodar, Mohammad Meymani, Roozbeh Razavi-Far, Ali Ghorbani · 2025

Read XGen-Q: An Explainable Domain-Adaptive LLM Framework with Retrieval-Augmented Generation for Software Security by Hamed Jelodar, Mohammad Meymani, Roozbeh Razavi-Far, Ali Ghorbani (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2510-19006.txt.

Introduction

Hamed Jelodar and three co-authors present XGen-Q. It is a language model built for software security work. General models read code well. But malware checks need more. A good tool must face hidden or new threats. It must also explain its verdicts.

XGen-Q starts from a code-focused model. It trains on more than one million malware samples. The samples come in source and assembly form. Staged prompts plus search of stored material guide its work. It aims for sound finds and full forensic reports. Analysts get results they can check, not just a label.

Catalog record

CREATORHamed Jelodar, Mohammad Meymani, Roozbeh Razavi-Far, Ali Ghorbani
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE25 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2510-19006

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

XGen-Q: An Explainable Domain-Adaptive LLM Framework with Retrieval-Augmented Generation for Software Security Hamed Jelodar, Mohammad Meymani, Roozbeh Razavi-Far, Ali Ghorbani Abstract Generative AI and large language models (LLMs) have shown strong capabilities in code understanding, but their use in cybersecurity, particularly for malware detection and analysis, remains limited. Existing detection systems often fail to generalize to obfuscated or previously unseen threats, underscoring the need for more adaptable and explainable models. To address this challenge, we introduce XGen-Q, a domain-adapted LLM built on the Qwen-Coder architecture and pretrained on a large-scale corpus of over one million malware samples, spanning both source and assembly code. XGen-Q uses a multi-stage prompt strategy combined with retrieval-augmented generation (RAG) to deliver reliable malware identification and detailed forensic reporting, even in the presence of complex code obfuscation. To further enhance generalization, we design a training pipeline that systematically exposes the model to diverse obfuscation patterns. Experimental results show that XGen-Q achieves significantly lower perplexity than competitive baselines and exhibits strong performance on novel malware samples, demonstrating the promise of LLM-based approaches for interpretable and robust malware analysis. Introduction As software systems become more complex and interconnected, the attack surface for security vulnerabilities continues to grow. Modern threat actors increasingly exploit these vulnerabilities using sophisticated malware capable of evading traditional detection mechanisms [ 1 , 2 ] . While static and dynamic code analysis techniques remain essential, they often struggle to detect obfuscated, polymorphic, or previously unseen threats at scale. This has led to a growing interest in AI-driven solutions that offer adaptability, contextual reasoning, and semantic understanding of software behavior [ 3 , 4 , 5 ] . Fig. 1: This figure illustrates a simple interaction between an input code and our proposed framework, where the system has labeled the input as malware. Recent advances in LLMs have demonstrated exceptional performance in code understanding, generation, and reasoning tasks [ 6 , 7 , 8 ] . Also, there are some work related to malware code analysis [ 9 , 10 , 11 ] . For instance, in [ 12 ] , the authors focused on overcoming the challenges of applying LLMs to Android malware detection, such as large codebases and complex app structures. In other work [ 13 ] , the authors focused on improving malware detection by using fine-grained code features and expanding the dataset with LLM-translated malicious functions from other languages. However, their direct application to cybersecurity remains limited, especially in areas requiring behavioral pattern recognition, threat explanation, and integration with operational workflows. These limitations originate from challenges in dataset availability, model interpretability, and the lack of end-to-end frameworks that map LLM outputs with real-time cybersecurity workflows [ 6 ] . Although general-purpose LLMs have shown promises on malware detection, malware classification, and malware analysis, they are trained predominantly on large-scale but generic programming corpora, often lack the specialized knowledge needed to assess malicious intent or accurately interpret attacker’s strategies [ 8 , 14 , 15 ] . In this work, we propose XGen-Q (Explainable Generation-Driven Qwen Model for Malware Behavior Analysis), a domain-adaptive, retrieval-augmented generative AI framework designed to strengthen prevention, mitigation, and preservation strategies in software security. The primary contributions and innovations of this work are as follows: • We introduce XGen-Q, a systematic large language model framework for malware behavior analysis, trained on a diverse corpus of real-world malware samples in both assembly and source code. This domain-specific pretraining allows the model to capture low-level behavioral patterns that general-purpose LLMs often fail to recognize. • We design a retrieval-augmented generation (RAG) mechanism to dynamically incorporate external cybersecurity knowledge during inference. This improves the model’s contextual awareness and adaptability to emerging threats through behavior keyword extraction and prompt augmentation. • We develop a two-stage prompt architecture that separates structured forensic reporting from final behavior classification. This promotes interpretability, transparency, and operational flexibility by providing both human-readable reports and system-ready verdicts (malware, benign, partially malicious). 1 1 1 The code and LLM framework are open source and available here: https://huggingface.co/JeloH/xGenq-qwen2.5-coder-1.5b-instruct-OKI The rest of the paper is organized as follows: In Section related-works, we review the existing literature on LLMs for code analysis and malware detection. In Section methodology, the details of XGen‑Q framework, including data preparation, domain‑specific pre‑training, model architecture, and multi‑stage prompt design are explained. In Section experiments and implementation, we present our experimental setup, evaluation metrics, and implementation details and discusses XGen‑Q’s performance on malware behavior classification and forensic analysis tasks. In Section limitations and future works, we examine the current limitations of our approach and outlines directions for future improvement. Finally, in Section conclusion, we conclude the paper and highlights promising avenues for further research. Related Works The intersection of LLMs and software security analysis has recently attracted significant attention. Several works explore leveraging pre-trained LLMs for detecting malicious code, understanding malware behavior, and assisting in reverse engineering tasks. Fig. 2: The general diagram of the proposed framework. LLMs for Malware Detection and Analysis: Recent studies [ 9 , 16 , 12 , 11 ] have demonstrated the effectiveness of adapting general-purpose LLMs to malware detection by pre-training on domain-specific datasets. These approaches typically focus on improving detection accuracy and interpretability by incorporating behavioral patterns extracted from static and dynamic analysis. However, there existing challenges in handling obfuscated and polymorphic malware, which demand more nuanced contextual understanding. Domain-Adaptive Pretraining and Retrieval-Augmented Generation: To enhance LLM performance in specialized domains, such as cybersecurity, domain-adaptive pretraining has been proposed and is used by several works [ 17 , 18 , 19 , 20 ] . This involves continued training on security-specific corpora, enabling better modeling of code semantics and malicious patterns. RAG techniques have further improved inference by integrating external knowledge dynamically [ 21 ] . These strategies help models stay up-to-date with emerging threats and mitigate knowledge cutoff issues inherent to static pretraining. Perplexity as a Performance Metric in Code Modeling: Perplexity has been widely used as an intrinsic metric to evaluate the predictive capability of language models on code and natural language tasks. Lower perplexity generally correlates with better token prediction and semantic understanding [ 22 ] . In the context of malware and code analysis, perplexity helps quantify how well models grasp complex, obfuscated code patterns, making it a valuable benchmark for comparing competing models. Works such as [ 23 , 24 , 25 , 26 ] explored this area. To the best of our knowledge, this is the first work to unify domain-specific pretraining, retrieval-augmented generation, and multi-stage prompt engineering for malware analysis with LLMs. In addition to achieving state-of-the-art performance on perplexity benchmarks, our framework enhances interpretability and resilience against evolving threat landscapes. This contribution represents a meaningful stride toward integrating the progress of modern language modeling with the practical demands of cybersecurity. Methodology This section outlines the methodology behind the development of XGen-Q, a novel large language model framework specialized for malware behavior detection and analysis in software security. XGen-Q uses the Qwen-Coder architecture and is trained with malware samples from assembly and source code. It combines RAG with a multi-step prompt approach to provide accurate classification and clear forensic explanations. Figure 1 illustrates a simple interaction between input and our proposed model. The following subsections

Read the complete text