ShieldedCode: Learning Robust Representations for Virtual Machine Protected Code

Mingqiao Mo, Yunlong Tan, Hao Zhang, Heng Zhang, Yangfan He

TL;DR

ShieldedCode introduces the first protection-aware Large Language Model (LLM) framework designed to generate and represent Virtual Machine Protected (VMP) code. By using a novel hierarchical attention mechanism and dual contrastive learning objectives, the model learns to heavily obfuscate code while preserving its original functionality, outperforming both commercial protection tools and state-of-the-art LLMs like GPT-4o.

The Challenge of Software Protection

Software security relies heavily on protecting intellectual property and preventing malicious tampering. Currently, the gold standard for this is Virtual Machine Protection (VMP), which translates standard machine code (like x86) into custom, proprietary bytecode that runs on a private virtual interpreter.

Comparison of Source Code, Standard Assembly, and VMP Protected Code

However, traditional VMP systems have a fatal flaw: they rely on rigid, rule-based transformations. Because these rules are static, they leave behind recurring patterns. Modern reverse-engineering tools—especially those powered by machine learning and neural decompilation—can spot these patterns and automate the recovery of the original code. Designing new, pattern-free VMP systems manually is incredibly expensive and requires deep domain expertise. The authors tackle this by asking: Can we use LLMs to automatically learn and generate dynamic, polymorphic VMP code that resists both human and machine analysis?

ShieldedCode Methodology

To build an LLM capable of understanding and generating VMP code, the authors introduce several key innovations built on top of large-scale paired datasets of source code and normalized VM implementations:

Overview of ShieldedCode's Hierarchical Attention and Contrastive Learning Design
  • Hierarchical Dependency Modeling: Standard LLMs use "flat" causal attention, which struggles with assembly-like VMP code. ShieldedCode introduces a 3-level hierarchical mask:
  • Intra-instruction: Tokens within a single virtual instruction attend to each other and are summarized by a special [VINST] anchor token.
  • Preceding-instruction: Tokens can look at the [VINST] marker of the immediately preceding instruction to understand short-range flow (like register reuse).
  • Inter-instruction: Tokens can look at all past [VINST] markers to grasp long-range obfuscation semantics.
  • Dual Contrastive Learning: The model must balance two competing goals: changing the code's appearance (obfuscation) while keeping its behavior the same (functionality). They use two custom losses:
  • Functionality Contrastive Learning (FCL): Pulls embeddings of the same function together, ensuring the model understands they do the same thing despite looking different.
  • Protection Contrastive Learning (PCL): Pushes embeddings apart linearly based on their "protection level" (L0 to L3), forcing the model to understand the strength of the obfuscation.
  • Protection Effectiveness Optimization (PEO): A training task that uses hard-negative mining to teach the model to rank and distinguish highly obfuscated variants of the same source code.

Key Insights and Results

While most research focuses on using LLMs to decompile or write clean code, this paper proves LLMs are highly effective at the inverse: intentionally obfuscating code to defend against analysis. The introduction of the [VINST] token is a massive architectural win, forcing the LLM to treat instructions as cohesive semantic units rather than a random string of text tokens.

Extensive experiments demonstrate ShieldedCode's robust capabilities:

  • Code Generation: ShieldedCode achieved 26.95% Pass@1 on L0 VM code generation, outperforming GPT-4o (22.58%) and vastly outperforming standard code models.
  • Binary Similarity Detection: It improves binary similarity detection Recall@1 by 10% over state-of-the-art methods like jTrans.
  • Human Reverse Engineering Resistance: In a user study with security researchers, ShieldedCode proved exceptionally difficult to crack. It took humans an average of 14.7 hours to reverse with only a 17% success rate. For comparison, commercial tools like VMProtect took 3.4 hours with a 67% success rate.
  • Automated Attack Resistance: ShieldedCode's polymorphic generation completely defeated pattern-matching attacks (0% success) and caused massive path explosions in symbolic execution tools like angr (only a 3% completion rate).

Limitations and Future Work

Currently, the framework relies on execution-based validation (running unit tests) to ensure the generated protected code actually works. It does not provide formal mathematical guarantees that the obfuscated code is strictly equivalent to the source. Future directions include integrating differential testing against symbolic execution engines, incorporating program synthesis techniques with "correctness-by-construction" guarantees, or using theorem provers to formally verify the equivalence between the source and the protected implementations.

Summary updated

BibTeX
@inproceedings{mo2026shieldedcode,
  author = {Mingqiao Mo and Yunlong Tan and Hao Zhang and Heng Zhang and Yangfan He},
  title = {{ShieldedCode: Learning Robust Representations for Virtual Machine Protected Code}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=9F9UFVcDkV},
}
Figure