Behavior Specification-Guided Program Synthesis for Binary Deobfuscation
Analyze & explore related research in Conceptio
Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.
Behavior Specification-Guided Program Synthesis for Binary Deobfuscation Kangchen Zhu∗† , Shangwen Wang∗‡ , Zhiliang Tian∗ , Zhouyang Jia∗ Xiaoling Li∗ , Jun Ma∗ , Jie Yu∗ , Xiaoguang Mao∗† ∗ College of Computer Science and Technology, National University of Defense Technology, Changsha, China † Also with the State Key Laboratory of Complex and Critical Software Environment
arXiv:2608.20628v1 [cs.SE] 21 Aug 2026
‡ Corresponding authors
Abstract—Deobfuscation is critical for reverse engineering and security analysis, as it restores readability and analyzability to obfuscated code. However, existing research primarily targets source-code deobfuscation, leaving binary-level deobfuscation, a more critical task given the unavailability of source code in real-world scenarios, largely underexplored. Current binary deobfuscation methods typically decompile binaries into pseudocode before applying structural transformations. However, this decompilation-based paradigm suffers from the loss of high-level semantics during compilation, such as precise types and source-level structures, often producing low-quality code and making it difficult to validate whether the recovered code preserves the intended runtime behavior of the original program. To address these limitations, we propose a paradigm shift from structural transformation to behavior-driven synthesis. Our core insight is that although obfuscation distorts a program’s internal structure, semantics-preserving transformations must retain its observable execution behavior. Building on this insight, we introduce B IN M IRROR, an approach that reframes binary deobfuscation as a behavior-specificationguided program synthesis task. By treating dynamic execution traces and interaction snapshots as behavioral specifications, B IN M IRROR synthesizes high-quality source code that is validated against observed runtime behaviors extracted from heavily obfuscated binaries. Extensive evaluations on 1.5 million synthetic obfuscated binaries show that B IN M IRROR significantly outperforms state-of-the-art baselines, achieving a 74.5% unit-test Pass@1 under extreme obfuscation. Furthermore, integrating B IN M IRROR into a downstream malware detection pipeline improves the detection of obfuscated in-thewild malware, increasing accuracy by 33.3% and F1-score by 37.1% compared with direct binary analysis. These results demonstrate the practical utility of B IN M IRROR for restoring semantic clarity in real-world security analysis.
1. Introduction Code obfuscation is a widely adopted software protection mechanism that applies semantics-preserving transformations to render programs structurally opaque while preserving their intended functionality [1]. Common transformations include dead code insertion [2], identifier renaming [3], instruction substitution [4], and control-flow flat-
tening [5]. While these techniques help protect intellectual property [6], [7], they are also frequently abused by attackers to hide malicious behaviors and evade detection [8]. Therefore, deobfuscation is essential for reverse engineering and downstream security tasks such as malware analysis and software plagiarism detection. Existing deobfuscation techniques are largely designed for source-code settings [1], [9], [10], [11], [12], [13]. These methods benefit from source-level information such as precise types, meaningful identifiers, and structured syntax, which guide pattern matching, program transformation, or learning-based rewriting. However, such assumptions rarely hold in practical security scenarios, where analysts often face stripped binary executables rather than source code [14], [15], [16]. A common workaround is to first decompile the obfuscated binary into C-like pseudocode and then apply source-level deobfuscation tools [1], [12]. Unfortunately, compilation and decompilation can remove or mis-recover high-level semantics, including variable types, source-level control structures, and contextual metadata [17]. As a result, decompilation-based pipelines may produce misleading pseudocode and make it difficult to check whether a reconstructed representation preserves observed runtime behavior. To overcome these limitations, we propose a paradigm shift: bypassing the static pattern matching on flawed decompiled pseudocode in favor of analyzing dynamic execution behavior. Our core insight is that while semanticspreserving obfuscation distorts a program’s internal structure and syntax, it must preserve the program’s observable behavior on executed paths [18], [19]. Specifically, for a given execution, the program’s externally observable interactions and side-effects should remain consistent [20], [21]. Here, we define execution behavior as the set of characteristics observed during runtime [22], and side-effects as state changes beyond simple value computation, such as modifying non-local variables, updating memory through references, or performing I/O operations [23]. Therefore, rather than treating decompiled pseudo as a reliable semantic substrate, we use observed runtime effects as an empirical behavioral anchor for guiding deobfuscation. Building upon the above observation, we propose B IN M IRROR, a novel end-to-end approach that reframes binary deobfuscation as a behavior-specification-guided program
synthesis task. This formulation does not claim that program synthesis is new in general; instead, its novelty lies in applying behavior-constrained synthesis to security-oriented binary deobfuscation, where static structure and decompiled pseudocode are often unreliable. Recognizing that Large Language Models (LLMs) have set new benchmarks in semantic inference and code synthesis [12], [24], [25], B IN M IRROR integrates an LLM as its core synthesis engine to translate low-level behavioral specifications, extracted from dynamic execution traces and interaction snapshots, into readable source-level reconstructions that are consistent with observed behavior. Specifically, B IN M IRROR operates in four sequential stages: (1) The Behavior Specification Capture stage observes the program’s dynamic runtime interactions and captures critical external events to construct an observed behavioral specification. By combining syscall-guided greybox fuzzing with dynamic binary instrumentation, it records execution context snapshots at key interaction points. (2) The Specification-Driven Noise Filtering stage extracts the instruction sequence responsible for the observed side-effects. It uses trace-enhanced backward data-flow slicing to filter out executed but behaviorirrelevant trace instructions, such as dispatcher updates, opaque-predicate computations, and MBA junk computations that do not contribute to the monitored behavior. (3) The Specification-Guided Code Synthesis stage reconstructs readable source-level code under the constraints imposed by the captured behavioral specifications. Leveraging a large language model as a semantic lifter, this stage constrains the code generation using captured input/output states and purified instruction slices, reducing unconstrained hallucination during binary-to-source lifting. Finally, (4) the TestBased Behavioral Validation stage executes the candidate code within a context-aware test harness to perform differential testing against the original binary on observed executions. Any behavioral discrepancies are fed back to the LLM through a closed-loop iterative refinement mechanism, enabling the system to iteratively improve the candidate code until it matches the captured behavioral specifications or reaches a predefined iteration bound. To comprehensively evaluate the effectiveness and practical utility of B IN M IRROR, we conducted extensive experiments. First, we constructed a massive synthetic benchmark, which consists of 1.5 million unique obfuscated binaries. We generate this dataset by applying four industry-standard obfuscators to obfuscate the collected source programs across four instruction architectures (x86, x64, ARM, MIPS) and four compiler optimization levels (O0-O3). We then evaluate the reconstructed code using Unit Test Pass Rate (Pass@1), which measures whether the compiled reconstruction passes the available source-level tests. Our results demonstrate that B IN M IRROR significantly outperforms state-of-the-art (SOTA) baselines, achieving a 74.5% unit-test Pass@1 under extreme obfuscation scenarios. To further understand when B IN M IRROR and existing tools succeed or fail, we also conduct a sample-level overlap and failure analysis, showing that B IN M IRROR is complementary to static, dynamic/symbolic, and learning-based baselines rather than
uniformly dominating them. Furthermore, to assess the quality and readability of the source-level reconstructions produced from multiple obfuscation levels, we measured the CodeBLEU [12], [26] and cyclomatic complexity [15]. The results show that B IN M IRROR yields clean, readable code, achieving an average of 68.4% CodeBLEU score and 76.2% reduction in cyclomatic complexity under extreme obfuscation. Finally, we demonstrated the downstream utility of our approach by integrating B IN M IRROR into a CFG-based Linux malware detector. The integration empowered existing detection engines to detect obfuscated malware with higher accuracy (+33.3%) and F1-scores (+37.1%), confirming that B IN M IRROR is effective in facilitating security analysis tasks. Notably, these validation results are bounded by the available tests and observed executions; B IN M IRROR does not prove semantic equivalence over all possible inputs. In summary, our contributions are as follows: • Paradigm Shift: We introduce a binary deobfuscation paradigm that shifts from traditional syntax-driven structural transformations to behavior-specification-guided program synthesis. • Approach: We propose B IN M IRROR , an end-to-end framework that combines syscall-guided behavior capture, trace-enhanced slicing, LLM-based synthesis, and differential testing to generate source-level reconstructions validated against observed runtime behaviors. • Extensive Evaluation: We evaluate B IN M IRROR on 1.5 million synthetic obfuscated binaries and real-world obfuscated malware, demonstrating strong test-based recovery effectiveness, readability improvement, and downstream malware-detection utility1 .
2. Background and Related Work Binary deobfuscation aims to recover readable and analyzable code from obfuscated binaries. In this paper, we focus on stripped binaries for which source-level information, such as variable names, precise types, and structured control flow, is unavailable or unreliable after compilation and decompilation. Our goal is to synthesize readable source code that is consistent with observed runtime behaviors and available tests. This validation is test-based and observationbounded, rather than a proof of semantic equivalence over all possible inputs. Static, symbolic, and dynamic deobfuscation. Existing binary deobfuscation techniques commonly rely on static analysis, solver-aided reasoning, or dynamic trace analysis [27]. Static tools inspect code structure without execution and apply pattern matching, algebraic simplification, data-flow analysis, or SMT-based reasoning to simplify obfuscation primitives [10], [28], [29], [30]. For instance, D810 [29] integrates into the Hex-Rays [28] microcode pipeline to perform backward variable tracking and pattern-based simplification. Dynamic and trace-based methods execute programs to observe concrete values, executed paths, and runtime side 1 The code and data used in our evaluation are available at https://zenodo. org/records/19067406.
Figure 1. A motivation example. (a) Type information such as uint8_t may be lost or mis-recovered during decompilation, causing a static deobfuscator or simplifier to incorrectly remove an overflow check from the recovered pseudocode. (b) By capturing execution-derived behavioral specifications, our approach constrains synthesis using observed runtime behavior and validates the recovered code against the captured behavior.
effects [1], [16], [31], [32], [33]. Representative systems such as QSynth [16] and Syntia [32] combine dynamic sampling, symbolic reasoning, or synthesis to simplify obfuscated expressions. However, these methods are often optimized for localized simplification rather than end-toend source recovery. They can be limited by predefined rules, state explosion, path coverage, and the cost of symbolic or enumerative search, especially when heavy controlflow flattening, bogus branches, MBA transformations, and decompiler-induced type loss make the static representation fragmented or misleading. Learning-based and LLM-based deobfuscation. Recent work increasingly explores learning-based deobfuscation, with LLMs showing strong potential for code understanding and rewriting [12], [13], [15], [26]. Prior studies have evaluated fine-tuned or prompt-based models for source-code deobfuscation, JavaScript deobfuscation, and malicious-code simplification [13], [26], [34]. For binary-level scenarios, a prevalent pipeline first lifts an obfuscated binary into C-like pseudocode or assembly and then applies sourcelevel optimization or LLM-based rewriting [1], [12], [15], [35]. For example, CHISEL [35] performs trace-informed compositional synthesis over decompiled pseudocode, while ChatDEOB [12] uses fine-tuned models after preliminary decompilation. Although effective in many cases, these pipelines remain sensitive to the semantic gap introduced by compilation and decompilation: precise types, identifiers, and source-level structure may be lost or mis-recovered, causing source-oriented models to infer incorrect logic or remove security-relevant behavior. B IN M IRROR addresses this limitation by grounding synthesis in dynamic execution traces and interaction snapshots rather than relying solely on decompiled pseudocode. Execution-derived specifications and program synthesis. Our work is also related to fuzzing, execution-based specification mining, and program synthesis. Greybox fuzzing generates inputs using lightweight feedback such as coverage [36], [37], [38], [39], while specification mining extracts behavioral facts or likely invariants from program executions [40]. These techniques provide empirical evidence
about program behavior, but their results are inherently bounded by observed executions: if an input does not trigger a path, the corresponding behavior cannot be captured. Program synthesis has also been explored for decompilation and structure recovery, such as recovering loops from hardware netlists or synthesizing structured programs from domainspecific intermediate representations [41], [42]. B IN M IR ROR is inspired by these directions but targets a different setting: security-oriented deobfuscation of heavily obfuscated stripped binaries, where source-level types, identifiers, and reliable structured pseudocode are often unavailable. Instead of recovering structure from explicit domain-specific semantics, B IN M IRROR extracts behavioral specifications from dynamic execution, filters trace-level noise, guides LLMbased source-code synthesis, and validates candidate code through differential testing on observed executions. Thus, B IN M IRROR complements prior work by treating observed runtime behavior as a specification for synthesizing and testvalidating readable source code from obfuscated binaries. B IN M IRROR does not claim novelty in dynamic tracing, slicing, synthesis, or LLM inference alone. Its contribution is a behavior-specification-guided reconstruction pipeline that turns runtime behavior into state-transfer constraints, extracts behavior-relevant binary slices, and synthesizes compilable C code validated on held-out executions, distinguishing it from expression-level synthesis and decompiler+LLM pipelines that mainly rely on recovered pseudocode.
3. Motivation Example Many current deobfuscation pipelines lift obfuscated binaries into C-like pseudocode and subsequently apply source-level transformations [1], [12], [15], [35]. However, this approach faces a critical limitation: compilation can remove or obscure high-level semantics, such as function names, source-level control structures, and precise variable types. Because the resulting pseudocode may lack this essential context, source-level tools can struggle to accurately interpret the program’s logic. Hence, this decompilationbased strategy may yield low-quality code or even remove
Behavior Specification Capture
Obfuscated Binary
Syscall-Guided Interaction Exploration Monitor
Behavior Specification Snapshots (Bspec )
Bspec =< k, SysID, Rinit , Minit > Dynamic Execution Instruction Trace (T)
Validated Source Code (Cvalidated )
Yes
Specification-Driven Noise Filtering
Specification-Guided Code Synthesis
LLM-based Semantic Lifter
Context-Aware Test Harness
1 Interpretation
Address Backward Normalization Slicing
Inputs/ Outputs
Instruction Sequence (Lext ) Behavior Snapshots
2 Abstraction 3 Construction
Test-Based Behavioral Validation
Differential Behavior Comparison
Candidate Code
No
Diff
Discrepancy Feedback & Behavior Diff (∆diff )
Execution Trace
Code Synthesis
Core Component
Iterative Refinement
Figure 2. Overview of B IN M IRROR, a four-stage behavior-specification-guided pipeline that captures observed runtime behavior, filters trace-level noise, synthesizes readable source code, and validates candidate programs through differential testing on observed executions.
security-relevant behavior when the decompiled representation is semantically misleading. To illustrate this limitation, we use a standard integeroverflow check as a motivating example. As shown on the left side of Figure 1, the source code is designed to detect an overflow when incrementing an 8-bit unsigned integer (uint8_t). Because a uint8_t occupies one byte, its valid range is 0 to 255. When the variable reaches its maximum value of 255, adding 1 mathematically yields 256 (100000000 in binary). However, under the 8-bit type constraint, the value wraps around to 0 (00000000 in binary). Consequently, the condition 0 < 255 evaluates to true, correctly invoking trigger_alert(). During compilation and decompilation, however, the precise uint8_t type may be lost or mis-recovered, depending on the compiler, optimization level, and decompiler heuristics. As shown in the upper right part of Figure 1, the decompiler may reconstruct the variable from a generic CPU register and promote it to a wider signed integer type, such as int v1. Under this recovered type, the expression v1 + 1 < v1 no longer captures the original 8-bit wraparound behavior and appears mathematically impossible in ordinary signed-integer arithmetic. When a static deobfuscator or simplifier processes this misleading pseudocode, it may conclude that the condition is always false and remove the branch as unreachable. As a result, the decompilationbased pipeline can eliminate a critical security check, even though the original binary still contains runtime behavior that triggers the alert. To overcome this limitation, our intuition is to shift the focus from transforming fragmented static syntax to analyzing observed dynamic execution behavior. For semantics-preserving obfuscation, although internal structure and syntax may be distorted, the externally observ-
able behavior on executed paths should remain consistent. As shown in the lower right part of Figure 1, our approach leverages this behavioral consistency by capturing concrete runtime states. By executing the binary with an overflow-triggering input, e.g., 255, we record the initial memory state (Minit : length = 255) and the observed branch outcome to form an execution-derived behavioral specification. These constraints provide factual runtime evidence for program synthesis and prevent the synthesizer from relying solely on flawed algebraic assumptions derived from decompiled pseudocode. Consequently, the synthesized code can preserve the observed wraparound behavior, for example, by generating a typeaware condition such as if ((uint8_t)(length + 1) < (uint8_t)length). This example highlights a real failure mode of existing decompilation-based deobfuscation pipelines and motivates our proposed solution: prioritizing observed runtime behavior over potentially misleading static syntax. Our idea shifts the paradigm from syntax-driven structural transformation to behavior-specification-guided program synthesis. By capturing dynamic execution states and validating synthesized code against the observed behavior, we reframe binary deobfuscation as a behavior-constrained synthesis task.
4. Approach 4.1. Overview Figure 2 illustrates the overview of B IN M IRROR. B IN M IRROR follows a four-stage pipeline that transforms observed runtime behavior into behavior-constrained sourcecode synthesis and test-based validation.
Phase I: Behavior Specification Capture. This stage observes dynamic runtime interactions and captures critical external events as execution-derived behavioral specifications. It combines syscall-guided greybox exploration with dynamic binary instrumentation (DBI) to record execution contexts at key interaction points. • Phase II: Specification-Driven Noise Filtering. This stage extracts the behavior-relevant instruction sequence from the dynamic trace. Starting from monitored interaction points, it applies trace-enhanced backward slicing to prune executed but behavior-irrelevant instructions, such as dispatcher updates, opaque-predicate computations, and MBA junk instructions. • Phase III: Specification-Guided Program Synthesis. This stage synthesizes readable source code under the constraints of the captured behavioral specifications. An LLM-based semantic lifter translates the purified instruction slice and its behavior snapshot into candidate code. • Phase IV: Test-Based Behavioral Validation. This stage executes the candidate code in a context-aware test harness and compares it with the original binary on observed executions. Behavioral discrepancies are fed back to the LLM through closed-loop refinement until the candidate matches the captured specifications or reaches a predefined iteration bound. •
4.2. Behavior Specification Capture This phase captures execution-derived behavioral specifications from the obfuscated binary Bobf . We focus on externally observable interaction behaviors, such as file I/O and network communication, because semantics-preserving obfuscation may distort internal code structures but should preserve such behaviors on executed paths. These interactions provide empirical runtime anchors for deobfuscation. The input is Bobf and an initial seed corpus I . The output is a set of dynamic instruction traces T = T (1) , T (2) , . . . , T (m) paired with behavior snapshots (1) (2) (m) BSP EC = Bspec , Bspec , . . . , Bspec . Each snapshot is: Bspec = ⟨k, SysID, Rinit , Minit ⟩,
(1)
where k is the trace index of the monitored interaction, SysID is the system call identifier, Rinit is the CPU register state, and Minit is the memory regions of the interaction. Syscall-Guided Exploration. Traditional fuzzing typically optimizes basic-block coverage (Covbb ) [36], [37], but this signal can be distorted by bogus control flows, flattened dispatchers, and opaque predicates in heavily obfuscated binaries. To reduce this distortion, B IN M IRROR adopts syscallguided greybox exploration [43], prioritizing inputs that trigger new externally observable interaction behaviors rather than merely increasing coverage over artificial control-flow structures. B IN M IRROR does not require source-level type information to bootstrap exploration. If sample inputs are available, they are used as seeds; otherwise, B IN M IRROR starts from empty inputs and random byte streams. During execution, the monitor observes input-related syscalls, such
as sys_read, sys_recv, sys_recvfrom, and filebacked input operations, to infer input channels and mutate the corresponding byte streams. The feedback signal is the novelty of interaction behavior instead of source-level coverage or type information. We model an execution’s observable interaction as a syscall sequence Ssys = ⟨s1 , s2 , . . . , sn ⟩, where s ∈ Ssyscall . The fuzzer maintains a global History of observed syscall sequences and preserves an input i ∈ I if executing Bobf (i) produces a new sequence. The objective is: [ max N-grams(Bobf (i)) . (2) i∈I
We set N = 3 to capture local interaction context while avoiding excessive state growth [43]. Syscall boundaries serve as interaction anchors rather than the sole semantic source; computation between boundaries is represented through register/memory snapshots, branch traces, and observed state-transfer relations. Interaction Monitoring and Snapshot Generation. During exploration, B IN M IRROR uses dynamic binary instrumentation (DBI) [31] to monitor runtime side effects. Rather than treating every executed instruction as equally important, the monitor listens for a predefined target syscall set Ωtarget ⊂ Ssyscall covering critical file-system operations, e.g., sys_open, sys_read, and sys_write, and network operations, e.g., sys_socket, and sys_connect. When a syscall in Ωtarget is invoked, the DBI engine suspends execution and triggers a bounded capture handler. The handler performs four steps: (1) interaction identification, reading the syscall number to obtain SysID; (2) pointer tracing, following architecture-specific calling conventions to inspect parameter registers and recursively trace memory pointers with depth limits and page-validity checks; (3) payload extraction, computing the payload length and safely dumping the referenced memory; and (4) state construction, recording the relevant registers and memory payloads as Rinit and Minit . The resulting Bspec serves as an execution-derived constraint for subsequent noise filtering, code synthesis, and behavioral validation.
4.3. Specification-Driven Noise Filtering This phase extracts trace-level instructions that contribute to the observed runtime behavior. Since the input is a dynamic trace, it does not remove never-executed dead code; instead, it filters executed but behavior-irrelevant instructions, such as flattened dispatcher updates, opaque-predicate computations, and MBA junk computations that appear in the trace but do not affect the monitored interaction. Given a dynamic trace T = ⟨i1 , i2 , . . . , in ⟩ and a behavior snapshot Bspec = ⟨k, SysID, Rinit , Minit ⟩ from Phase I, where ik triggers the monitored interaction, this phase outputs a behavior-relevant instruction slice Lext ⊆ T : Lext = ij ∈ T | j ≤ k ∧ Path(ij → ik ) |= Bspec ,
(3)
where Lext retains instructions in the transitive data-flow closure that contribute to the state specified by Bspec .
Address Normalization. Before slicing, B IN M IRROR normalizes runtime addresses to remove the offsets introduced by ASLR [44] and PIE [45]. For each instruction ij with runtime address Addrdyn (ij ), the system parses runtime memory mappings and static ELF headers to identify the dynamic load base Basedyn and the static base Basestatic . It then computes the relocation offset ∆ = Basedyn − Basestatic and maps the instruction to its static address: Addrstatic (ij ) = Addrdyn (ij ) − ∆.
(4)
This mapping aligns dynamic traces with static binary locations, enabling address-consistent dependency analysis. Trace-Driven Backward Slicing. Starting from the specification index k , B IN M IRROR traverses the trace backward and tracks an active dependency set V , initialized with Rinit ∪ Minit . For each instruction ij , the system computes its definition set Def (ij ) and uses the set U se(ij ). If Def (ij ) ∩ V = ∅, the instruction does not influence the monitored state and is discarded. Otherwise, it is added to Lext , and the dependency set is updated as V ← (V \ Def (ij )) ∪ U se(ij ). To further remove control-flow-flattening noise, B IN M IRROR applies an orthogonality check. If an instruction only updates scheduling-related architectural state, such as EFLAGS or RIP, and preserves the transitive dependency closure of V , it is treated as dispatcher noise and skipped. By combining dependency closure filtering with this orthogonality check, B IN M IRROR extracts a compact slice Lext that captures the computation needed to reproduce the monitored interaction while excluding trace-level noise designed to mislead traditional deobfuscators. Slicing is performed over executed instruction semantics rather than decompiler variables. We recover register and memory uses and definitions from architecturespecific operand semantics, including implicit flags, condition codes, stack updates, and ABI syscall arguments. For inter-procedural traces, traced callees are inlined, while unresolved indirect or library calls are summarized by observed arguments, return values, and memory effects. Heap, global, and multi-syscall state are represented through monitored address ranges and ordered protocol windows. Unresolved dependencies are retained conservatively, and unsupported side effects are marked unsupported. The slice preserves observed-execution dependencies, but does not claim all-path static completeness.
4.4. Specification-Guided Code Synthesis This phase lifts the behavior-relevant instruction slice Lext into readable source code that is consistent with the captured behavioral specifications. To reduce hallucinations and uncertainty in LLM-based code generation [46], [47], we ground synthesis in factual execution constraints derived from dynamic runtime behavior. The input consists of Lext and the behavior snapshot Bspec = ⟨k, SysID, Rinit , Minit ⟩; the output is candidate
source code Ccandidate . We formulate synthesis as conditionally constrained generation: arg
max
Ccandidate
P (Ccandidate | Lext , Bspec ).
(5)
Prompt Design. The structured prompt guides the LLM to reason from objective runtime facts rather than unconstrained guesses. It contains four compact components. First, the system prompt assigns the model the role of an expert reverse engineer and defines the task as synthesizing readable code constrained by dynamic execution observations. Second, the input context provides two factual inputs: the behavior-relevant instruction sequence Lext and the behavioral constraints derived from Bspec , including the initial state Spre , composed of Rinit and Minit , and the target interaction boundary Spost , defined by the syscall identifier and target memory state. Third, the instruction body asks the model to reason in three steps: infer the observed statetransfer relation ΦIO : Spre → Spost , abstract low-level instructions into high-level constructs, and construct standard C source code. Finally, the output constraint requires the model to emit only the candidate source code, omitting explanations and markdown metadata. By anchoring generation to the behavior-relevant slice and observed Spre → Spost relation, this stage reduces reliance on flawed pseudocode and guides code toward the captured runtime behavior.
4.5. Test-Based Behavioral Validation This final phase tests whether the synthesized candidate code reproduces the monitored runtime behavior and observable side effects of the original binary on observed executions. It provides test-based behavioral validation with respect to captured specifications. The input includes Ccandidate , Bobf , and the Phase-I behavior snapshot Bspec ; the output is Cvalidated if the candidate reproduces the captured behavior in a contextaware test harness. Context-Aware Test Harness. B IN M IRROR compiles Ccandidate into Binrec and executes it in an isolated Unicorn-based emulator [48]. The harness restores Rinit and Minit from Bspec , aligning the candidate reconstruction with the monitored context of the original binary slice. After synchronization, B IN M IRROR executes Bobf and Binrec under the same observed context. At the target interaction point, it extracts Sorig and Srec and checks behavioral consistency as: Sorig ≡ Srec ⇐⇒ (SysIDorig = SysIDrec ) ∧ (Argsorig = Argsrec ) ∧ (Memorig = Memrec ).
(6)
A candidate passes if the syscall identifiers, arguments, and relevant memory payloads match byte-level observations. This checks consistency with the captured snapshot, not allinput semantic equivalence. Discrepancy Feedback and Refinement. If Sorig ≡ Srec holds on the validation cases, the candidate is promoted
to Cvalidated . Otherwise, B IN M IRROR computes ∆dif f = Sorig ⊖ Srec and summarizes the mismatched syscall ID, argument, register, or memory payload as structured feedback (t+1) to the LLM. The synthesis engine then generates Ccandidate . The loop stops when the monitored discrepancy is eliminated or Nmax is reached, whose sensitivity is studied in § 7.1.
5. Experimental Setup 5.1. Research Questions We evaluate B IN M IRROR from five perspectives: effectiveness against baselines (RQ1), robustness across architectures and compiler optimizations (RQ2), contribution of individual components (RQ3), code quality and readability (RQ4), and downstream utility for CFG-based Linux malware detection (RQ5).
5.2. Datasets We construct two datasets: a controlled Synthetic Benchmark with available source-level tests, and MalBench, a realworld malware benchmark for practical security evaluation. Synthetic Benchmark. We construct the Synthetic Benchmark from CodeNet [49]. From 341,069 C/C++ programs, we retain 1,573 programs that are non-trivial, executable, and suitable for controlled obfuscation, requiring average cyclomatic complexity greater than 15, more than 150 source lines, and successful compilation and evaluationpipeline execution. The retained set is therefore a controlled benchmark rather than a representative sample of all CodeNet programs. We obfuscate the retained programs using O-LLVM [7], Hikari [50], Tigress [51], and Alcatraz [52]. We apply six transformations, BCF, SUB, FLA, MBA, Opaque Predicates, and ImmMov, and combine them into 63 non-empty configurations from L1 to L6. Each configuration is compiled across four architectures, x86, x64, ARM, and MIPS, and four optimization levels, O0–O3, with symbols and debugging information stripped. This expansion yields 1,585,584 synthetic obfuscated binaries from the 1,573 retained source programs. Appendix A reports the filtering reason-code distribution and audit metadata. MalBench. MalBench contains 500 active Linux obfuscated malware samples collected from VirusShare [53] and MalwareBazaar [54] between 2023 and 2025. Following prior malware-evaluation practice [26], [55], we retain samples flagged by at least 10 independent VirusTotal engines and exhibiting high cyclomatic complexity and heavily flattened control flow. Because in-the-wild malware lacks source code and unit tests, we use observed behavioral consistency as the validation oracle: reconstructed code must reproduce the monitored syscall sequences and input-output interactions under the same input harness. This oracle is bounded by observed executions and does not imply all-input semantic equivalence. For downstream detection, MalBench uses malware-family-aware partitions and a benign corpus
TABLE 1. I NPUT- INDUCED PATH COVERAGE .
Metric
Synthetic
MalBench
Basic-block coverage Branch-edge coverage Unique execution paths/sample
95% 90% 12 [4, 20]
88% 70% 8 [2, 16]
matched by platform, executable format, package source, and file-size range. We retain hashes, family labels, first-seen dates, sandbox policy, and benign provenance as metadata, but do not redistribute live malware. See Appendix B for more details about MalBench.
5.3. Evaluation Metrics We use three correctness-oriented metrics and three readability-oriented metrics. Compilation Rate (CR) measures the percentage of reconstructed programs that compile without manual intervention. Unit Test Pass Rate (Pass@1) measures whether the compiled reconstruction passes the available source-level tests in the Synthetic Benchmark. Execution Success Rate (ESR) evaluates MalBench by checking whether the original and reconstructed binaries produce the same monitored syscall sequences and I/O interactions under the same input harness. For code quality, Cyclomatic Complexity Reduction (CCR) measures control-flow simplification relative to raw IDA Pro decompilation, CodeBLEU measures structural and data-flow similarity to available ground-truth source code, and Halstead Effort Reduction (HER) measures lexical and cognitive-complexity reduction. Rates are computed over the full evaluated denominator, including pass, fail, timeout, and unsupported outcomes. LLM-based methods and B IN M IRROR are run five times with independent seeds and reported as mean± SD, while deterministic tools are run once under fixed versions/settings and therefore have SD=0.0. Held-Out Behavioral Validation. For dynamic specification experiments, we split observed executions into refinement and held-out sets before reconstruction. The Synthetic Benchmark uses 16 [8, 30] refinement inputs and 4 [2, 10] held-out inputs per sample, while MalBench uses 12 [3, 20] and 3 [2, 8], reported as median [IQR]. Synthetic inputs come from source-level harnesses and generated tests, whereas MalBench inputs include sandbox stimuli such as arguments, staged files, environment settings, and replay configurations. Only refinement inputs are used for prompts, feedback, and repair; held-out inputs are never exposed to any method or controlled variant. We normalize or mask time-, PID-, path-, and network-dependent fields, and mark unreplayable executions as unsupported. A reconstruction is credited only if it compiles and passes held-out source-level tests on the Synthetic Benchmark or syscall/I/O consistency checks on MalBench. Thus, validation reduces trace-level overfitting but remains bounded by explored executions. Coverage Reporting. We report input-induced path coverage to make the scope of the observation-bounded oracle ex-
TABLE 2. E FFECTIVENESS ON THE S YNTHETIC B ENCHMARK . CR AND PASS @1 ARE REPORTED FOR X 64-O0 BINARIES ACROSS OBFUSCATION LEVELS L0–L6 AS MEAN ± SD OVER FIVE RUNS . Method Ghidra D810 GooMBA ANGR Syntia Llama-3.1 Claude-3.5 GPT-4o CodeLlama Qwen2.5-C DeepSeek-C Recopilot ChatDEOB LLM+Dyn LLM+Dyn+Fb B IN M IRROR
L0 (Baseline) CR P@1 25.4±0.0 18.5±0.0 30.5±0.0 26.4±0.0 28.6±0.0 20.1±0.0 45.2±0.0 38.5±0.0 50.5±1.5 42.1±1.8 62.4±1.2 55.2±1.5 68.5±1.0 62.1±1.2 72.1±0.8 66.5±1.0 74.2±0.9 68.1±1.1 78.1±0.7 72.2±0.9 81.5±0.6 76.2±0.8 84.2±0.5 80.1±0.6 88.1±0.4 84.2±0.5 88.3±0.2 85.2±0.3 89.2±0.5 86.1±0.4 94.5±0.2 92.1±0.3
L1 CR 12.1±0.0 25.2±0.0 22.4±0.0 35.1±1.2 38.4±2.1 50.1±1.8 58.4±1.6 62.5±1.4 64.1±1.5 70.3±1.2 74.1±1.0 78.5±0.9 82.2±0.8 83.5±0.6 85.1±0.3 93.2±0.3
L2 P@1 5.2±0.0 20.1±0.0 15.3±0.0 28.4±1.4 30.5±2.4 42.5±2.0 50.2±2.0 55.4±1.8 56.2±1.8 64.1±1.5 68.3±1.2 72.4±1.2 76.1±1.0 79.1±1.5 80.5±1.2 90.5±0.4
CR 4.5±0.0 15.4±0.0 18.5±0.0 22.4±1.8 28.6±2.8 38.5±2.4 45.2±2.5 50.4±2.2 51.5±2.4 58.2±2.0 64.2±1.8 68.5±1.5 74.1±1.2 77.1±1.3 80.7±0.9 91.5±0.4
L3 P@1 1.0±0.0 10.2±0.0 10.4±0.0 15.6±2.0 20.4±3.1 30.1±2.8 38.4±2.8 42.1±2.6 44.1±2.6 51.2±2.4 56.1±2.1 61.2±1.8 68.2±1.6 69.2±1.4 71.2±1.5 88.2±0.5
plicit. Here, a sample denotes one reconstruction task, while an input denotes an execution stimulus, such as commandline arguments, stdin, staged files, environment settings, or sandbox replay configurations, used to trigger observable behavior. Coverage is measured over the behavior-relevant target region extracted for each reconstruction task, rather than over the entire binary. As shown in Table 1, the execution inputs cover 95% of target-region basic blocks and 90% of branch edges on the Synthetic Benchmark, and 88% and 70% on MalBench, respectively. The median number of unique execution paths per sample is 12 on the Synthetic Benchmark and 8 on MalBench, indicating that validation is not limited to repeatedly replaying a single path. These statistics do not imply complete path coverage or all-input semantic equivalence; instead, they make explicit the behavioral scope over which the reported reconstruction results are validated.
5.4. Baselines To provide a comprehensive evaluation, we compare B IN M IRROR with representative baselines across static analysis, symbolic/dynamic analysis, hybrid synthesis, and LLM-based paradigms. We compare B IN M IRROR with representative baselines from four categories: static tools, including Ghidra [56], D810 [29], and GooMBA [57]; symbolic/dynamic tools, including ANGR [58] and Syntia [32]; general-purpose and code LLMs, including GPT4o [59], Claude-3.5-Sonnet [60], Llama-3.1 [61], Qwen2.5Coder [62], CodeLlama [63], and DeepSeek-Coder [64]; and domain-specific binary/deobfuscation models, including Recopilot [65] and ChatDEOB [12]. To separate method effects from information-budget effects, we additionally include two controlled LLM variants: LLM+DynEvidence (LLM+Dyn), which receives the same bounded runtime traces and monitored snapshots as B IN M IRROR, and LLM+DynEvidence+Feedback (LLM+Dyn+Fb), which further receives the same compile/test feedback budget but does not perform trace-driven slicing or behavior-specificationguided constraint construction.
CR 1.2±0.0 5.1±0.0 8.2±0.0 10.5±2.2 18.2±3.2 25.4±3.1 30.5±3.2 38.2±3.0 38.2±3.1 46.1±2.8 51.4±2.5 56.2±2.2 64.2±2.0 66.8±2.5 72.6±2.6 89.4±0.5
L4 P@1 0.0±0.0 2.5±0.0 4.1±0.0 6.2±2.4 12.5±3.5 18.5±3.4 22.5±3.6 28.5±3.5 31.5±3.4 38.5±3.2 44.2±2.8 48.5±2.5 56.4±2.4 56.7±2.2 61.9±2.7 84.5±0.6
CR 0.0±0.0 1.8±0.0 2.5±0.0 4.2±1.5 10.1±2.6 15.2±2.8 20.1±3.0 25.5±3.2 26.5±3.2 34.2±3.0 38.2±2.9 44.1±2.8 51.5±2.6 56.6±2.8 60.1±3.3 87.2±0.6
L5 P@1 0.0±0.0 0.0±0.0 0.0±0.0 1.5±0.8 5.4±2.0 10.4±2.5 14.2±2.8 18.4±3.0 18.2±3.0 26.4±3.1 31.5±3.2 36.2±3.0 44.1±3.2 43.9±2.7 51.2±2.5 81.1±0.8
CR 0.0±0.0 0.0±0.0 0.0±0.0 1.0±0.5 4.5±1.8 8.5±2.1 12.4±2.5 15.2±2.8 16.4±2.8 22.1±2.8 26.4±3.0 31.2±3.2 38.2±3.5 44.2±3.7 53.8±2.8 84.5±0.8
P@1 0.0±0.0 0.0±0.0 0.0±0.0 0.0±0.0 2.0±1.2 5.2±1.8 8.5±2.2 10.5±2.5 10.5±2.6 14.2±2.9 20.2±3.1 24.4±3.4 31.5±3.8 34.4±3.2 42.5±3.5 77.2±1.0
L6 (Extreme) CR P@1 0.0±0.0 0.0±0.0 0.0±0.0 0.0±0.0 0.0±0.0 0.0±0.0 0.0±0.0 0.0±0.0 1.2±0.5 0.5±0.2 4.2±1.5 2.1±1.0 6.5±1.8 4.2±1.5 8.4±2.1 5.5±1.8 9.5±2.4 5.2±2.0 12.4±2.6 7.5±2.2 16.5±2.8 11.2±2.6 20.5±3.1 14.5±2.9 26.4±3.6 20.2±3.4 35.1±3.4 23.6±3.5 44.2±2.8 39.1±2.9 81.4±1.1 74.5±1.2
Because LLM-based approaches lack native support for direct end-to-end recovery from raw binaries, we first utilized standard decompilers to translate the obfuscated inputs into pseudocode before feeding them into the LLMs. See Appendix C for more details about baselines.
5.5. Implementation Details All experiments were conducted on a workstation equipped with dual Intel Xeon Gold 6248R processors, 512GB of RAM, and four NVIDIA RTX 4090 GPUs, running Ubuntu 22.04 LTS. All LLM-based baselines, controlled variants, and B IN M IRROR use fixed prompt templates, temperature = 0.2, top-p = 1.0, a 4K output cap, and the input budgets specified in Appendix C. We record exact model identifiers, provider/checkpoint information, prompttemplate hashes, retry limits, context-truncation policy, and seeds in the artifact logs. Held-out inputs are excluded from all prompts, feedback messages, repair rounds, and truncation decisions. More implementation details can be found in Appendix D.
6. Evaluation 6.1. RQ1: Effectiveness Table 2 reports CR and Pass@1 on x64-O0 Synthetic Benchmark binaries, with model names abbreviated for space. Specifically, we draw the following key observations. Baselines degrade under compositional obfuscation. Existing methods degrade as obfuscation becomes more compositional. Traditional static tools, such as Ghidra, D810, and GooMBA, and symbolic or dynamic techniques, such as ANGR and Syntia, drop to near-zero accuracy at higher levels because rule-based recovery and bounded exploration struggle with flattened control flow, artificial branches, and complex predicates. LLM-based methods are more resilient but still degrade sharply: GPT-4o drops from 66.5% Pass@1 at L0 to 5.5% at L6, while the domain-specific ChatDEOB reaches only 20.2% Pass@1 at L6. It suggests that larger
TABLE 3. E XECUTION SUCCESS RATE ON M AL B ENCH .
TABLE 4. S AMPLE - LEVEL OVERLAP ANALYSIS .
Method
Category
#Cases
Percentage
Both Succeed B IN M IRROR-Only Baseline-Only Both Fail
1,037 1,331 82 550
34.6% 44.4% 2.7% 18.3%
Ghidra D810 GooMBA ANGR Syntia Llama-3.1 Claude-3.5
ESR (%) 0.0 0.0 0.0 4.2 6.5 8.4 12.5
Method GPT-4o CodeLlama Qwen2.5-C DeepSeek-C Recopilot ChatDEOB B IN M IRROR
ESR (%) 15.2 18.4 22.5 25.4 31.2 36.5 65.8
models or task-specific fine-tuning are insufficient when the input is dominated by misleading obfuscated structure. BinMirror preserves effectiveness under severe obfuscation. In contrast, B IN M IRROR maintains substantially higher effectiveness under severe obfuscation. At L6, B IN M IRROR achieves 74.5% Pass@1, outperforming the strongest evaluated baseline, ChatDEOB, by 54.3 percentage points. It also achieves the highest compilation rate at L6, 81.4%, indicating that behavior-constrained synthesis and closedloop feedback help reduce invalid code generation. These results support the central design choice of reconstructing code from behavior-relevant slices and observed runtime constraints rather than directly transforming the obfuscated code structure. Controlled variants isolate the method effect. To test whether the gains of B IN M IRROR come from the proposed pipeline rather than from simply giving an LLM more runtime evidence, Table 2 includes two evidence-matched controlled variants. LLM+DynEvidence receives the same syscall traces and monitored I/O snapshots as B IN M IR ROR , and LLM+DynEvidence+Feedback further receives the same compile and test feedback budget. However, these variants do not perform trace-driven slicing or behaviorspecification-guided constraint construction, and held-out inputs are never exposed during refinement. Although the controlled variants improve over prior LLM baselines, the strongest one still trails B IN M IRROR by 22.2 percentage points in average Pass@1 and by 35.4 percentage points at L6. This result indicates that the improvement is not explained by a larger information budget alone, but by how B IN M IRROR organizes runtime observations into behaviorrelevant slices and synthesis constraints. BinMirror remains effective on real-world malware. Table 3 reports Execution Success Rate (ESR) on MalBench, a dataset of real-world Linux obfuscated malware. In this setting, traditional static tools such as Ghidra and D810 obtain zero ESR, while ANGR and Syntia reach only 4.2% and 6.5%, respectively. LLM-based methods show limited robustness, ranging from 15.2% for GPT-4o to 36.5% for ChatDEOB. By contrast, B IN M IRROR achieves 65.8% ESR, outperforming the strongest baseline by 29.3 percentage points. This result suggests that behavior-specificationguided reconstruction remains useful beyond controlled synthetic obfuscation, especially when real malware combines structural noise, environmental dependencies, and antianalysis behaviors. We interpret this result as behavioral consistency over the family-aware MalBench split, not as
recovery of complete malware source code. BinMirror covers many cases missed by baselines. We analyze sample-level overlap on 3,000 Synthetic Benchmark cases randomly sampled from L2, L4, and L6. D810, Syntia, and ChatDEOB represent static, dynamic/symbolic, and learning-based baselines, respectively. A sample is counted as a baseline success if any of the three baselines produces a reconstruction that passes the corresponding test suite. Table 4 shows that B IN M IRROR succeeds alone on 1,331 cases, or 44.4%, indicating that it recovers many samples missed by representative baselines. These B IN M IRROR-only cases mainly involve controlflow flattening, opaque predicates, MBA transformations, or decompiler-induced type and structure loss, where static structure becomes unreliable. Baseline-only cases account for 82 cases, or 2.7%, and mainly involve local expressionlevel obfuscation or simple opaque predicates that static or symbolic methods can simplify. The both-fail category accounts for 18.3%, showing that some cases remain difficult for all evaluated approaches, especially when generated inputs do not cover the relevant behavior or synthesis cannot produce compilable code under the captured constraints. Overall, the overlap analysis shows that B IN M IRROR expands the set of recoverable cases rather than merely improving already-solved ones, while still leaving room for complementary static and symbolic techniques on localized simplification tasks.
6.2. RQ2: Robustness To evaluate the robustness across architectures and optimizations, Figure 3 shows the results across different instruction set architectures, including ARM, MIPS, X86, and X64, and compilation optimization levels from O0 to O3. We compare B IN M IRROR with ChatDEOB, the strongest evaluated baseline in RQ1. Architectures. ChatDEOB shows a clear performance drop across different architectures. At Level-1 under O0, ChatDEOB achieves 84.86% on X64 but drops to 74.69% on ARM. This gap suggests a limitation in its reliance on decompiled pseudocode and architecture-specific structural patterns. It performs better on prevalent X64 structures but struggles with the distinct control-flow and instruction representations found in RISC architectures. In contrast, B IN M IRROR demonstrates stronger cross-architecture robustness. At Level-1 under O0, B IN M IRROR achieves 97.58% on X64 and maintains 86.05% on ARM. Even under extreme L6 obfuscation, B IN M IRROR maintains a 78.57% success