Decompiles binary functions using GhidraSQL to inspect pseudocode, local variables, parameters, and ctree AST patterns. Useful for reverse engineering and binary analysis.
Ships in ghidrasql. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/ghidrasql:decompilerfrom ghidrasql
npx claudepluginhub 0xeb/ghidrasql-skills --plugin ghidrasqlUse this skill when the user asks for:
pcode_ops, pcode_varnodes, ir_ops, ir_operands)Route to:
annotations for persistent editstypes for declaration import or type recoveryxrefs for caller / callee expansion from a decompiled targetDecompiler-backed tables MUST be function-scoped. Use func_addr for decompiler-backed tables. pseudocode and decomp_lvars also support exact func_name = ... when you need name-based lookup.
| Table | Predicate | Without it |
|---|---|---|
pseudocode | WHERE func_addr = X or exact WHERE func_name = 'name' | Decompiles every function in the program |
decomp_lvars | WHERE func_addr = X or exact WHERE func_name = 'name' | Same — full-program decompile |
decomp_tokens | WHERE func_addr = X | Same |
decomp_comments | WHERE func_addr = X | Same |
pcode_ops, pcode_varnodes, ir_ops, ir_operands | WHERE func_addr = X | Extracts P-code for every function |
Per-function decompile typically takes ~500 ms. Without the filter, the cost scales with the function count — minutes per query for thousands of functions.
The ctree* views also compose over per-function surfaces and are best filtered the same way.
For genuine low-level IR, use pcode_ops/pcode_varnodes or their canonical
ir_ops/ir_operands projections; discover the high and raw rungs through
ir_maturities.
An address-scoped pseudocode row is GhidraSQL's exact-decompile surface. It
maps to one libghidra GetDecompilation(address, timeout_ms) call, backed by the
host extension's DecompilerService/DecompileFunction RPC. On success, text
is the unchanged Ghidra DecompiledFunction.getC() string; GhidraSQL does not
insert agent anchors or annotations into it. func_addr means the canonical
function entry point; an interior address does not satisfy the equality filter.
The same holds for decomp_lvars, decomp_tokens, pcode_ops and
pcode_varnodes: an address inside a function, or one that names no function,
returns no rows rather than another function's.
Require the native success flags when "exact" means that fallback text is not acceptable:
SELECT func_addr, func_name, prototype, text
FROM pseudocode
WHERE func_addr = 0x401000
AND completed = 1
AND is_fallback = 0;
The status columns are completed, is_fallback, error_message, and the
compatibility summary is_stale (1 for incomplete or fallback results). When
Ghidra cannot decompile a function, libghidra may return a synthetic diagnostic
comment in text; it is always identified by is_fallback = 1.
Use decomp_tokens and decomp_lvars for the structured/extended parts of the
same native decompilation. Use decompiler_listing only when its enriched token,
local, and metric columns are actually needed; pseudocode is the direct exact-C
surface.
There is deliberately no separate ex or "extended exact" table: keeping the
unchanged C text in pseudocode.text and exposing tokens/locals in adjacent
tables prevents agent-oriented structure from contaminating the exact artifact.
Direct full-text:
SELECT text FROM pseudocode WHERE func_addr = 0x401000;
Structured rows:
SELECT text FROM pseudocode WHERE func_addr = 0x401000;
SELECT local_id, name, type, storage FROM decomp_lvars WHERE func_addr = 0x401000;
SELECT func_addr, local_id, name, type, storage FROM decomp_lvars WHERE func_name = 'main';
SELECT text, kind, var_name, var_type FROM decomp_tokens WHERE func_addr = 0x401000;
SELECT ordinal, param_name, param_type FROM function_params WHERE func_addr = 0x401000;
pseudocode is the full-function decompiler table. Its materialised rows exist only for the current SQL statement and are discarded when that statement closes. This is also true inside -f scripts and multi-statement REPL input: each following statement re-reads/decompiles from the live source.
-- inside a -f script:
SELECT rename_local(0x401000, '<local_id>', 'configHandle');
SELECT text FROM pseudocode WHERE func_addr = 0x401000;
No cache invalidation step is required. Use refresh_database() only when the underlying source itself needs an explicit reload.
Do not run two ghidrasql clients hitting decompiler tables on the same host in parallel. Overlapping requests against pseudocode/decomp_lvars/decomp_comments can deadlock the host on a fair ReentrantReadWriteLock. Symptoms: queries stop returning, threads in getComments / decompileFunction are parked. Workaround: serialise decompiler-backed work, or kill java.exe and restart if already stuck.
Read pseudocode:
SELECT text FROM pseudocode WHERE func_addr = 0x401000;
Inspect locals (local_id is an opaque key such as local:Stack[-0x18]; read it here and pass it back unchanged. storage looks like Stack[0x4]:4 or a register name):
SELECT local_id, name, type, storage
FROM decomp_lvars
WHERE func_addr = 0x401000;
SELECT func_addr, local_id, name, type, storage
FROM decomp_lvars
WHERE func_name = 'main';
Inspect tokens (structured decompiler output with semantic info):
SELECT text, kind, var_name, var_type
FROM decomp_tokens
WHERE func_addr = 0x401000;
Token kinds: keyword, variable, type, function, parameter, global, const, comment, default, error, special. Filter to variable references only:
SELECT text, kind, var_name, var_type, var_storage
FROM decomp_tokens
WHERE func_addr = 0x401000 AND kind = 'variable';
Inspect parameters:
SELECT ordinal, param_name, param_type
FROM function_params
WHERE func_addr = 0x401000
ORDER BY ordinal;
ghidrasql exposes 16 ctree* views. They are not Ghidra's real PcodeAST. They are a SQL composition over call_edges, loops, blocks, funcs, instructions, and decomp_lvars that simulates an AST-shape catalog (cot_call, cit_for, cit_while, cit_do, cit_if, cit_return). They are useful for pattern queries ("calls inside loops", "leaf functions", "call chains") but not for syntactically exact AST traversal — for that, use decomp_tokens (which IS from the real decompiler).
| View | Composes over | Useful for |
|---|---|---|
ctree | call_edges + loops + blocks (out_degree > 1) + funcs | Master catalog used by the rest |
ctree_call_args | call_edges with attributed callee | Per-call argument inspection |
ctree_v_calls | ctree filtered to cot_call | Every call in a function with callee resolution |
ctree_v_loops | ctree filtered to cit_for/cit_while/cit_do | Loop list per function |
ctree_v_ifs | ctree filtered to cit_if | Branch points per function |
ctree_v_signed_ops | instructions filtered by mnemonic (imul/idiv/sar/sal/sub/add) | Arithmetic-of-interest hits |
ctree_v_comparisons | instructions filtered to cmp/test | Comparison hits |
ctree_v_assignments | instructions filtered to mov/lea | Assignment hits |
ctree_v_derefs | instructions where operand contains [ | Pointer-dereference hits |
ctree_v_calls_in_loops | ctree_v_calls JOIN loops on EA range | "What gets called inside a loop body?" |
ctree_v_calls_in_ifs | ctree_v_calls JOIN if_nodes | "What gets called from a conditional branch?" |
ctree_v_leaf_funcs | Alias over native leaf_funcs (addr, name) | Bottom-up annotation entry points without decompilation |
ctree_v_call_chains | RECURSIVE over ctree_v_calls | Reachability with cycle guard |
ctree_v_returns | funcs (synthetic return at end_addr) | Return-point markers |
ctree_lvars | decomp_lvars with derived stable index | Stable per-function variable index for cross-references |
Worked examples:
-- Every call site inside a loop in this function
SELECT printf('0x%X', addr) AS site, callee_name, loop_op, printf('0x%X', loop_id) AS loop_header
FROM ctree_v_calls_in_loops
WHERE func_addr = 0x401000;
-- Leaf functions (good seed set for bottom-up annotation)
SELECT printf('0x%X', addr) AS addr, name
FROM ctree_v_leaf_funcs
ORDER BY name
LIMIT 50;
-- Call chains rooted at a function (cycle-guarded recursion)
SELECT printf('0x%X', current_func) AS current, depth, path
FROM ctree_v_call_chains
WHERE root_func = 0x401000 AND depth <= 5
ORDER BY depth;
WHERE func_addr = X, or exact WHERE func_name = 'name' for pseudocode/decomp_lvars. Without it you triggered a full-program decompile.curl -X POST -d '' http://127.0.0.1:<sql-port>/cancel. The empty body must be explicitly framed. The cancelled query returns a failure envelope and the server remains reusable.text contains a diagnostic comment instead of C. Inspect completed, is_fallback, and error_message. Exact work must require completed = 1 AND is_fallback = 0; do not treat fallback text as a successful decompilation.decomp_lvars again and use the exact local_id from the result (don't synthesise arg0, query for it).pseudocode still looks stale. Re-query the exact function and check program_revision(). SQL rows are statement-lived, so continued stale output points to the underlying source/decompiler or an unapplied mutation. Use refresh_database() only to request an explicit source reload.java.exe, delete *.lock / *.lock~, restart the host, run sequentially.12 skills in this plugin
/analysisAnalyze binaries with ghidrasql using safe, high-signal query patterns./annotationsApply persistent ghidrasql annotations such as names, comments, signatures, and local-variable edits./connectConnect to ghidrasql sources, verify live access, and route to the right analysis skill./dataQuery strings, bytes, data items, memory blocks, and relocations through ghidrasql./debuggerManage breakpoints and patch bytes through ghidrasql — the breakpoints table and bytes single-byte UPDATE./disassemblyInspect code structure through ghidrasql tables for functions, instructions, blocks, CFG, loops, switches, dominators, and tail calls.Other plugins' skills for the same job