Skip to content

amruth-sn/kong

Repository files navigation

Kong: The Agentic Reverse Engineer

PyPI - Version X (formerly Twitter) URL

Kong: World's first AI reverse engineer

LLM orchestration for reverse engineering binaries

What is Kong?

Most tasks follow a linear relationship: the more difficult a task, the longer it usually takes. Reverse engineering (and binary analysis) is a task in which the actual difficulty is somewhat trivial, but the time-to-execute can be on the order of hours (and days!), even for a binary with a couple hundred functions.

Kong automates the mechanical layer, using an NSA-grade reverse engineering framework. Kong can take a fully obfuscated, stripped binary and run a full analysis pipeline: triaging functions, building call-graph context, recovering types and symbols through LLM-guided decompilation, and writing the results back into Ghidra's program database. The output is a binary where some FUN_00401a30 is now parse_http_header, with recovered structs, parameter names, and calling conventions.

Why this exists

Stripped binaries lose all the context that makes code readable: function names, type information, variable names, struct layouts. Recovering that context is the bulk of the work in most RE tasks, and it's largely pattern matching: recognizing standard library functions, inferring types from usage, propagating names through call graphs.

LLMs are good at exactly this kind of pattern matching. But pointing an LLM at raw decompiler output and asking "what does this do?" gives you mediocre results. The model lacks calling context, cross-reference information, and the broader picture of how the binary is structured. In addition, most obfuscated binaries introduce extreme techniques in order to prevent reverse engineering.

Kong solves this by building rich context windows from Ghidra's program analysis (call graphs, cross-references, string references, data flow) before ever touching the LLM, then orchestrating the analysis in dependency order so each function benefits from its callees already being named. Additionally, Kong introduces its own, first-of-its-kind, agentic deobfuscation pipeline.

In Action

Kong: World's first AI reverse engineer

Kong: World's first AI reverse engineer

Features

  • Fully Autonomous Pipeline: A single command runs the complete analysis. Triage, function analysis, cleanup, semantic synthesis, and export. No manual intervention required.
  • In-Process Ghidra Integration: Runs Ghidra's analysis engine in-process via PyGhidra and JPype. No server, no RPC, no subprocess overhead. Direct access to the program database.
  • Call-Graph-Ordered Analysis: Functions are analyzed bottom-up from the call graph. Leaf functions are named first, so callers benefit from already-resolved context in their decompilation.
  • Rich Context Windows: Each LLM prompt includes the target function's decompilation plus cross-references, string references, caller/callee signatures, and neighboring data; not just raw decompiler output in isolation.
  • Semantic Synthesis: A post-analysis pass that unifies naming conventions across the binary, synthesizes struct definitions from field access patterns, and resolves inconsistencies between independently analyzed functions.
  • Signature Matching: Known standard library and cryptographic functions are identified by pattern before LLM analysis, skipping expensive inference for functions with known identities.
  • Syntactic Normalization: Decompiler output is cleaned up (modulo recovery, negative literal reconstruction, dead assignment removal) before reaching the LLM, reducing noise and token waste.
  • Agentic Deobfuscation: Kong uses an agentic deobfuscation pipeline which can identify and remove obfuscation techniques (Control flow flattening, bogus control flow, instruction substitution, string encryption, VM protection, etc.) from the decompiler output.
  • Eval Framework: Built-in evaluation harness that scores analysis output against ground-truth source code, measuring symbol accuracy (word-based Jaccard) and type accuracy (signature component scoring).
  • Multi-Provider LLM Support: Works with Anthropic (Claude) and OpenAI (GPT-4o) out of the box. An interactive setup wizard configures providers and smart routing auto-selects whichever has a valid key.
  • Cost-Tracking: Tracks token usage and costs per model across providers, with provider-aware pricing.

Supported Architectures

Kong works with most Ghidra-decompilable binaries (for now, more to come).

Confidence

C C++ Go Rust
x86 High High Medium Medium
x86-64 High High Medium Medium
ARM (32-bit) High High Medium Low
AArch64 High High Medium Low
MIPS Medium Medium Low Low
PowerPC Medium Medium Low Low

High: Kong reliably decompiles, deobfuscates, and recovers names, types, and structure.

Medium: Decompilation is usable but noisier. Expect partial recovery and lower confidence scores.

Low: Decompilation has significant gaps and results will stay incomplete, noisy, or unreadable.

Note: Binary size scales positively with function count, LLM cost, and time to completion. However, binary size also scales negatively with confidence, so keep this in mind when analyzing larger binaries.

Architecture

Kong uses a five-phase pipeline orchestrated by a supervisor that coordinates triage, parallel analysis, and post-processing:

                    ┌──────────────────────┐
                    │       Triage         │
                    │  enumerate, classify,│
                    │  build call graph,   │
                    │  match signatures    │
                    └──────────┬───────────┘
                               │
                               ▼
              ┌────────────────┼────────────────┐
              │                │                │
              ▼                ▼                ▼
     ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
     │   Analyze    │ │   Analyze    │ │     ...      │
     │  (leaf fns)  │ │ (next tier)  │ │              │
     └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
            │                │                │
            └────────┬───────┴────────────────┘
                     │
                     ▼
            ┌──────────────────────┐
            │      Cleanup         │
            │  normalize, dedupe   │
            └──────────┬───────────┘
                       │
                       ▼
            ┌──────────────────────┐
            │     Synthesis        │
            │  unify names, build  │
            │  structs, deobfuscate│
            └──────────┬───────────┘
                       │
                       ▼
            ┌──────────────────────┐
            │       Export         │
            │  analysis.json +     │
            │  Ghidra writeback    │
            └──────────────────────┘

How it works

Triage enumerates all functions in the binary, classifies them by size (trivial / small / medium / large), builds the call graph, detects the source language, and runs signature matching against known standard library and crypto functions. Functions matched by signature are marked as resolved and skip LLM analysis entirely.

Analysis processes functions in bottom-up order from the call graph using a work queue. For each function, Kong builds a context window from Ghidra's program database — decompilation, cross-references, string references, and the signatures of already-analyzed callees — normalizes the decompiler output, and sends it to the LLM for name, type, and parameter recovery. If obfuscation is detected in a function's decompilation, Kong runs an agentic deobfuscation pass with symbolic tool access before producing the analysis. Results are written back to Ghidra immediately so downstream callers see updated names.

Cleanup unifies struct types from proposals accumulated during analysis and retries any function signatures that failed to apply during the analysis pass.

Synthesis takes a global view across all analyzed functions. A single LLM call reviews the most-connected functions, unifies naming conventions, synthesizes struct definitions from field access patterns, and refines names that look inconsistent in the broader context.

Export writes the final analysis.json and applies all recovered names, types, and signatures back to the Ghidra program database.

Stack

Setup

Prerequisites

  • Python 3.11+ — (python.org or your system package manager)
  • uv — Python package manager (Install uv)
  • Ghidra — The National Security Agency's reverse engineering framework (Install Ghidra)
  • JDK 21+ — Required by Ghidra (Adoptium)
  • LLM API key — At least one of:

Quick Start

# 1. Install Kong
uv pip install kong-re

# 2. Set your API key(s)
export ANTHROPIC_API_KEY="sk-ant-..."
# and/or
export OPENAI_API_KEY="sk-..."

# 3. Run the setup wizard (first time only)
kong setup

# 4. Analyze a binary
kong analyze ./path/to/stripped_binary

The setup wizard lets you pick which LLM providers to use and sets a default. Kong auto-detects your Ghidra and JDK installations, loads the binary into an in-process Ghidra instance, and runs the full pipeline.

From source

git clone https://github.com/amruth-sn/kong.git
cd kong
uv sync
uv run kong setup
uv run kong analyze ./path/to/stripped_binary

Environment Variables

Variable Required Description
ANTHROPIC_API_KEY At least one Anthropic API key (Claude)
OPENAI_API_KEY At least one OpenAI API key (GPT-4o)
GHIDRA_INSTALL_DIR No Path to Ghidra installation (auto-detected if not set)
JAVA_HOME No Path to JDK (auto-detected if not set)
KONG_CONFIG_DIR No Override config directory (default: ~/.config/kong)

Usage

# Run the setup wizard
kong setup

# Analyze a stripped binary (uses your configured default provider)
kong analyze ./binary

# Analyze with a specific provider
kong analyze ./binary --provider openai

# Override the model
kong analyze ./binary --provider openai --model gpt-4o-mini

# Show binary metadata without running analysis
kong info ./binary

# Evaluate analysis output against ground-truth source
kong eval ./analysis.json ./source.c

Output

Results are written to the output directory (default: ./kong_output_{binary_name}/):

kong_output_{binary_name}/
├── analysis.json         # All recovered function names, types, parameters
└── events.log            # Pipeline execution trace

Project Layout

kong/
├── __main__.py           # CLI entry point (click)
├── config.py             # KongConfig, LLMProvider, LLMConfig
├── db.py                 # SQLite config store (~/.config/kong/)
├── banner.py             # ASCII banner, API key helpers
├── agent/
│   ├── supervisor.py     # Pipeline orchestrator
│   ├── triage.py         # Function enumeration + classification
│   ├── analyzer.py       # LLM-guided function analysis
│   ├── queue.py          # BFS work queue from call graph
│   ├── signatures.py     # Known function signature matching
│   ├── prompts.py        # System prompt + output schema
│   ├── events.py         # Phase/event types for pipeline tracing
│   └── models.py         # FunctionResult dataclass
├── ghidra/
│   ├── client.py         # In-process GhidraClient (PyGhidra/JPype)
│   ├── types.py          # FunctionInfo, BinaryInfo, XRef, etc.
│   └── environment.py    # Ghidra/JDK auto-detection
├── llm/
│   ├── client.py         # AnthropicClient
│   ├── openai_client.py  # OpenAIClient
│   ├── usage.py          # TokenUsage, cost tracking, pricing registry
│   └── limits.py         # Model-specific limits + rate limiter
├── normalizer/
│   └── syntactic.py      # Decompiler output normalization
├── synthesis/
│   └── semantic.py       # Global name unification + struct synthesis
├── evals/
│   ├── harness.py        # Ground-truth extraction + scoring
│   └── metrics.py        # symbol_accuracy, type_accuracy
├── export/
│   └── source.py         # analysis.json + Ghidra writeback
├── signatures/
│   ├── stdlib.json       # C standard library signatures
│   └── crypto.json       # Cryptographic function signatures
└── tui/
    └── app.py            # Textual TUI

License

APACHE

Kong is licensed under the Apache License 2.0. Kong is a free and open source project.

This license is compatible with the Ghidra license, and allows for commercial use.

Contributing

Issues and feature requests are welcome via GitHub Issues.

Also, don't hesitate to reach out to me on X or LinkedIn!

Acknowledgments

A big shoutout to KeygraphHQ's Shannon project, which provided the inspiration for this project. My motivation was driven by replicating the same kind of pipeline that Shannon uses for its web-based pentesting tool, and adapting it for binary analysis and decompilation.


Fear the monkey.


Kong
Kong: The world's first AI reverse engineer