Abstract
Binary code summarization, while invaluable for understanding code semantics, is challenging due to its labor-intensive nature. This study delves into the potential of large language models (LLMs) for binary code comprehension. To this end, we present BinSum, a comprehensive benchmark and dataset of over 557K binary functions and introduce a novel method for prompt synthesis and optimization. To more accurately gauge LLM performance, we also propose a new semantic similarity metric that surpasses traditional exact-match approaches. Our extensive evaluation of prominent LLMs, including ChatGPT, GPT-4, Llama 2, and Code Llama, reveals 10 pivotal insights. This evaluation generates 4 billion inference tokens, incurred a total expense of 11,418 US dollars and 873 NVIDIA A100 GPU hours. Our findings highlight both the transformative potential of LLMs in this field and the challenges yet to be overcome.
Introduction
Reverse engineering is often considered the "hard mode" of software analysis. When security researchers or developers examine a binary (compiled) program, they are confronted with a complex web of assembly instructions or raw bytes rather than clean source code. Understanding even a small segment of decompiled code—roughly 150 lines—can take a professional nearly 40 minutes.
While Large Language Models (LLMs) have demonstrated remarkable proficiency in summarizing natural language and high-level source code, their ability to handle binary code remains largely unproven. Binary code lacks the high-level semantics, such as descriptive variable names and data types, that LLMs typically rely on. This research addresses three primary hurdles: the lack of large-scale real-world binary datasets, the ambiguity of which code representation (bytes, assembly, or decompiled) LLMs prefer, and the inadequacy of traditional evaluation metrics like BLEU for capturing conceptual correctness.
The BinSum Framework and Dataset
To systematically evaluate LLM performance, the researchers developed BinSum, a massive benchmark consisting of 557,664 binary functions. The dataset was constructed by compiling 44 open-source GNU projects (including binutils, coreutils, and openssl) across four architectures (x86, x64, ARM, MIPS) and four optimization levels.
A custom parser was utilized to map developer comments from the original source code back to the resulting binary functions, creating a reliable "ground truth" for summarization. The dataset provides multiple formats for each function, including raw bytes, assembly (via Capstone), intermediate representation (IR via IDA Pro), and decompiled code (via Ghidra, Hex-Rays, and Angr).
Automated Prompt Engineering
Rather than relying on manual prompt engineering, the study introduced an automated four-step process for prompt synthesis and optimization. This framework leverages LLMs to generate, vary, and optimize the instructions used to elicit summaries, ensuring the models are evaluated under optimal conditions.
Furthermore, the researchers proposed a new semantic similarity metric. Moving beyond simple word-matching, this metric uses pre-trained semantic embeddings to calculate how closely the meaning of an LLM-generated summary aligns with the original developer's comment.
Key Insights and Evaluation
The extensive evaluation of models like ChatGPT, GPT-4, Llama 2, and Code Llama yielded several pivotal insights:
- Decompiled Code is Superior: LLMs perform significantly better on decompiled code than on assembly or raw bytes. The closer the input resembles high-level source code, the more effectively the models can reason about it.
- The "Symbolic" Crutch: Stripping debugging symbols (such as function and variable names) leads to a 55% decrease in semantic similarity. This suggests that LLMs rely heavily on these names to infer context rather than purely analyzing logic. Removing just the function name alone drops performance by over 30%.
- ChatGPT vs. GPT-4: Surprisingly, ChatGPT (GPT-3.5) often produced more concise and clear high-level summaries than GPT-4. GPT-4 tended to provide overly verbose explanations of low-level operations, sometimes getting "distracted" by noisy implementation details.
- Implicit Code Lifting: When fed raw bytes, LLMs appear to perform an internal "lifting" process, generating summaries that describe assembly-like logic (e.g., stack frames and arithmetic) even when those structures are not explicitly visible in the hex data.
Results and Performance
ChatGPT emerged as the top performer, achieving the highest average semantic similarity score (0.543) for binaries with symbols, while also being 2.9x faster than GPT-4. In the open-source category, Code Llama consistently outperformed its base model (Llama 2) by up to 22%, highlighting the value of code-specific fine-tuning.
The study also found that "Zero-shot" prompting provided the best balance of cost and performance. While "Few-shot" prompting (providing examples) improved performance by 10.6%, it increased costs by over 7x due to significantly longer prompts. The total evaluation was a massive undertaking, generating 4 billion tokens and costing $11,418 USD in API fees alongside 873 NVIDIA A100 GPU hours.
Conclusion and Future Work
While LLMs show transformative potential for binary code summarization, challenges remain. The current dataset is based on GNU software; real-world "wild" binaries, such as malware or IoT firmware with intentional obfuscation, present a different set of difficulties. Future research should focus on improving decompilers to better support LLM comprehension and exploring gradient-based prompt tuning to further enhance model performance in this specialized domain.
Summary updated