arXiv:2610.18787cs.CROct 2026

Manuscript Offprint

arXiv:2610.18787

Bytes to Threats: Byte-Sequence Transformer For Malware Detection

Abdelrahman Yassin Eljamal, Abdeltawab Hendawi

1st1^{st} Abdelrahman Yassin Eljamal

Department of Computer Science

University of Rhode Island

Kingston, USA

abdelrahman.eljamal@uri.edu

2nd2^{nd} Abdeltawab Hendawi

Department of Computer Science

University of Rhode Island

Kingston, USA

hendawi@uri.edu

Abstract—Existing malware detection approaches heavily rely on handcrafted features derived from static or dynamic analysis of the executable files. These methods require specialized domain expertise, dedicated analysis tools, and time-consuming analysis, which limits their scalability and robustness in the face of the increasing complexity and diversity of modern malware. Consequently, there is a growing interest in approaches that operate directly on raw bytes, which contain rich semantic and structural information. However, capturing long-range dependencies within executable files remains challenging for conventional static and CNN-based methods. This paper presents MalwareFormer, a transformer-based, byte-level malware detection framework that operates directly on raw bytes, without requiring domain knowledge or feature extraction. MalwareFormer achieves an accuracy of 98.35%, a balanced accuracy of 98.32%, a macro-F1 of 98.32%, and a false positive rate of 1.94%, outperforming both baselines across all threshold-dependent classification metrics and demonstrating that transformers provide a powerful and scalable approach for byte-level malware detection.

Index Terms—Malware detection, Byte-level analysis, Transformer models, Deep learning, Static analysis, Dynamic analysis, Malware classification

I. INTRODUCTION

The rapid growth of malware variants poses a significant and escalating economic threat. Recent estimates project that the global cost of cybercrime will reach approximately 10.5trillionannuallyby2025,underscoringitsscaleasoneofthelargesteconomicthreatsworldwide.Attheorganizationallevel,theaveragecostofasingledatabreachisestimatedat10.5 trillion annually by 2025, underscoring its scale as one of the largest economic threats worldwide. At the organizational level, the average cost of a single data breach is estimated at4.44 million globally. Ransomware and phishing attacks remain dominant, accounting for approximately 44% and 16% of reported breaches, respectively [1]. In the past year alone, cyber incidents led to substantial financial losses, including an estimated 3.09billionimpactonUnitedHealthanda3.09 billion impact on UnitedHealth and a50 million ransom demand targeting CDK Global [2]. According to Kaspersky [3], their detection systems identified an average of 467,000 malicious files per day in 2024, with Trojan-based attacks showing a notable increase compared to 2023. Despite continuous advancements, anti-virus technologies are struggling to keep pace with the rapid evolution and sophistication of modern malware, highlighting the need for more adaptive detection methods.

Existing machine learning approaches rely heavily on handcrafted features extracted from executable files, including header information, imported libraries, and opcode statistics [4], [5]. While effective, these methods require significant domain expertise and extensive effort to extract such features. For instance, dynamic analysis captures behavioral and runtime features by executing malware in a controlled environment, such as a virtual machine. This allows the collection of system call traces, registry changes, file and network activity, and process behaviors, but the approach is slow, resource-intensive, and difficult to scale. Static analysis, in contrast, operates directly on the file without execution, making it faster and less resource-demanding. However, its effectiveness remains limited by the handcrafted features and specialized tools required for tasks such as extracting PE header information, imported libraries, opcode sequences, strings, and metadata, as well as performing reverse engineering and parsing of embedded resources, all of which necessitate expert knowledge.

Deep learning approaches have emerged as a promising alternative by enabling direct processing of raw bytes without feature engineering. CNN-based models such as MalConv [6] demonstrated the feasibility of learning patterns from entire executable files; however, their reliance on local convolutional filters limits their ability to capture long-range dependencies inherent in executable files. Transformer architectures, with their global self-attention mechanism, offer a better framework for modeling byte sequences.

To address these limitations, this paper proposes MalwareFormer, a transformer-based, byte-level malware detection framework designed to operate directly on raw bytes without requiring hand-crafted features or domain knowledge. At its core, MalwareFormer leverages a transformer model, ByteFormer [7], which is fine-tuned within our framework to efficiently capture long-range dependencies in malware byte sequences. We conducted extensive experiments to evaluate the model's effectiveness, comparing training from scratch with fine-tuning and analyzing their impact on convergence speed and final performance. We further examine how

© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works. DOI: 10.1109/ICAD69378.2026.11608884 varying input sequence lengths influence model accuracy and stability. To contextualize its performance, we compare MalwareFormer against two strong CNN-based baselines, MalConv2 [8] and AvastNet [9], using a 50K-byte input size. MalwareFormer achieves an accuracy of 98.35%, a balanced accuracy of 98.32%, a macro-F1 of 98.32%, and a false positive rate of 1.94%, outperforming both baselines across all threshold-dependent classification metrics. MalConv attains 95.71% accuracy, a macro-F1 of 95.64%, and a false positive rate of 3.56%, while AvastNet achieves 97.98% accuracy, a macro-F1 of 97.94%, and a false positive rate of 2.46%. Notably, while AvastNet attains a marginally higher ROC-AUC (99.68% vs. 99.61%), MalwareFormer yields a better trade-off between detection rate and false alarm rate at the operating threshold used in practice. These results demonstrate that transformer-based byte modeling enables MalwareFormer to capture long-range structural dependencies within executables that CNN-based approaches struggle to model, translating into more reliable detection under realistic deployment conditions.

This paper investigates the capabilities of transformer-based, byte-level malware detection by addressing the following research questions. RQ1: How effective is a transformer-based model compared to established CNN-based baselines in classifying malware? RQ2: How does fine-tuning pretrained representations impact training convergence and detection performance? RQ3: Can accurate detection be achieved without processing the entire executable file? RQ4: How does entropy affect classification accuracy, and what asymmetric failure modes emerge in high-entropy regions?

Our key contributions are summarized as follows:

• We present MalwareFormer, a byte-level transformer framework for malware detection that incorporates dataset integrity verification, label consistency validation, byte-sequence extraction, and model fine-tuning, achieving 98.35% accuracy and a false positive rate of 1.94% without requiring handcrafted features or domain expertise.

• Investigate the transferability of pretrained ByteFormer representations to the malware domain by fine-tuning the model and analyzing their impact on training convergence and detection performance across varying input sequence lengths. To the best of our knowledge, this is the first work to utilize the ByteFormer model for malware detection.

  • Compare this transformer-based model with established CNN-based baselines, providing empirical evidence of its effectiveness for static malware detection.

• We conduct an entropy-stratified analysis of model predictions, revealing an asymmetric failure mode in high-entropy regions (entropy 7–8) where FPR reaches 14.24% while FNR drops to 0.08%, exposing a fundamental limitation of byte-level detection in entropy-ambiguous regimes and motivating future entropy-aware approaches.

The rest of our paper is organized as follows. Section II reviews related work. Section III presents the MalwareFormer framework, detailing its transformer-based, byte-level architecture and the dataset employed in our experiments. Section IV provides the experimental setup. Section V presents the experimental results. Section VI provides an analysis and discussion of the results. Finally, Section VII concludes our work.

References (33)