StackSight: Unveiling WebAssembly through Large Language Models and Neurosymbolic Chain-of-Thought Decompilation

Weike Fang, Zhejian Zhou, Junzhou He, Weihang Wang

Abstract

WebAssembly (WASM) serves as a high-performance binary instruction format for the web, yet its implicit stack-based architecture and lack of high-level semantic information render it a "black box" for security analysis and reverse engineering. We present StackSight, a neurosymbolic decompilation framework that leverages Large Language Models (LLMs) and static program analysis to transform opaque WASM bytecode into readable, functionally correct C++ code. By integrating symbolic stack visualization with neural Chain-of-Thought (CoT) prompting, StackSight achieves a 70% improvement in functional correctness over baseline methods, providing a robust solution for interpreting low-level web binaries.

Introduction

WebAssembly has become a standard for high-performance web applications, but it poses significant challenges for security researchers. Unlike traditional binaries, WASM utilizes an implicit stack machine and restricts data to four basic numeric types, stripping away variable names and complex data structures. Existing decompilers often produce "verbatim" code that, while syntactically correct, lacks human readability. Conversely, Large Language Models (LLMs) struggle with the low-level nature of WASM due to limited training data and a tendency toward logical hallucinations during stack operation interpretation. StackSight addresses these issues by making the implicit logic of WASM explicit for the LLM.

The StackSight Framework

StackSight employs a multi-stage neurosymbolic pipeline designed to guide an LLM through the decompilation process, mimicking the workflow of a human reverse engineer.

The StackSight neurosymbolic decompilation pipeline.

The framework consists of two primary components:

  1. Symbolic Stack Visualization: A custom static analysis tool parses the WASM text format (.wat) and annotates each line with the current state of the virtual stack. This step transforms implicit operations into explicit data flows, providing a "mental crutch" for the model to track variable state.
  2. Neural Chain-of-Thought (CoT) Prompting: Rather than performing direct translation, the LLM is prompted to execute four sequential tasks:
  3. Data Type Prediction: Identifying high-level types (e.g., pointers, booleans) based on stack usage.
  4. Semantic Variable Recovery: Replacing generic indexes (e.g., l0) with meaningful names (e.g., array_ptr).
  5. Natural Language Summarization: Describing the function's logic in plain English to establish a logical anchor.
  6. C++ Code Generation: Producing the final decompiled code based on the accumulated insights.

Experimental Setup

The framework was evaluated using the C++ splits of two prominent benchmarks: HumanEval-X, featuring 164 human-written problems, and MBXP, containing 974 snippets derived from Python problems. These were compiled into WASM using the Emscripten toolchain to provide a ground-truth dataset for testing functional correctness via a test oracle.

Evaluation and Results

Quantitative analysis demonstrates that StackSight significantly outperforms standard in-context learning (1-shot to 10-shot) baselines across multiple LLMs, including GPT-3.5, Code Llama, and GPT-4.

Quantitative results comparing StackSight against various LLM baselines.

Key findings include:

  • Functional Correctness: Using GPT-4, StackSight increased the percentage of functionally correct code (pass-rate) by 16.8 percentage points on HumanEval-X and 17.2 percentage points on MBXP compared to standard 1-shot prompting.
  • Ablation Success: Removing the symbolic stack visualization resulted in a performance drop of up to 7.8%, confirming that providing explicit stack context is critical for reducing hallucinations.
  • Human Readability: A user study with 15 C++ developers indicated a strong preference for StackSight-generated code due to its superior semantic accuracy and readability compared to traditional decompilers.

Discussion and Conclusion

StackSight demonstrates that the primary barrier to LLM-based decompilation is not syntax, but the lack of explicit context regarding the stack state. By treating decompilation as a reasoning task rather than a simple translation, the framework allows models to correct their own misunderstandings. While current limitations include context window constraints for large modules and the need for manual fixes in certain pass-by-reference scenarios, StackSight represents a significant step toward transparent and human-readable WebAssembly decompilation. Future work will focus on scaling the framework to handle obfuscated and malicious binaries found in real-world environments.

Summary updated

BibTeX
@inproceedings{fang2024stacksight,
  author = {Weike Fang and Zhejian Zhou and Junzhou He and Weihang Wang},
  title = {{StackSight: Unveiling WebAssembly through Large Language Models and Neurosymbolic Chain-of-Thought Decompilation}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=gn5AsHIIwb},
}
Figure