Orchestrates recursive bottom-up source recovery by annotating leaf callees first and working up through the call graph. Useful for reverse engineering binaries with GhidraSQL.
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.
Methodology skill, not new SQL. The pieces are already exposed by decompiler, annotations, types, xrefs, and the function_tags progress catalog — this skill orchestrates them into a campaign.
Use this skill when the user asks to:
Route to:
decompiler for inspection (pseudocode, decomp_lvars, ctree*)annotations for the per-function read → write → save looptypes for parse_decls() and apply_type_* viewsxrefs to walk the call graphA binary becomes readable when its callees are readable. Pick leaf functions first — they have no internal calls, so their behaviour is constrained by their inputs and outputs. Annotate one leaf, then move up: every annotated callee makes its callers easier to read.
Cross-function struct correlation: a single function rarely reveals a full struct layout. Function A(s) might only read s->flags; B(s) reads s->name; C(s) writes s->size. The struct's full layout is the union of every accessor — which means you have to look at multiple callers and callees of the same function to discover all fields. The ctree* views and decomp_tokens are how you find those access patterns.
Project scope: ghidrasql can list many programs in one Ghidra project via
project_programs, but every analysis table in this workflow is scoped to the
one active program. For a multi-program campaign, list targets first, then work
one domain path at a time:
SELECT path, name FROM project_programs ORDER BY path;
Switch programs by saving/closing and reopening a different path, or by
re-invoking ghidrasql --program /path/in/project. Do not mix progress tags
from different active programs unless your tag names include the program path.
Start with native leaf_funcs, which finds functions with no outgoing call
references without decompiling them. It already includes size, end_addr,
namespace, and prototype. The two views ctree_v_leaf_funcs and
disasm_v_leaf_funcs are identical addr, name aliases over this table, not
separate decompiler and disassembly heuristics.
SELECT printf('0x%X', addr) AS addr, name, size
FROM leaf_funcs
ORDER BY name
LIMIT 50;
Filter to non-trivial leaves (some are short stubs). This still enumerates the
program's functions and outgoing call references; size filters and LIMIT
reduce returned rows, not the initial native enumeration:
SELECT printf('0x%X', addr) AS addr, name, size
FROM leaf_funcs
WHERE size BETWEEN 64 AND 2048
ORDER BY size DESC
LIMIT 30;
Tag the seed set so progress is visible across sessions:
INSERT OR IGNORE INTO function_tags (name, comment)
VALUES ('progress:seed', 're-source seed set, picked from leaf_funcs');
INSERT INTO function_tag_mappings (func_addr, tag_name)
SELECT addr, 'progress:seed'
FROM leaf_funcs
WHERE size BETWEEN 64 AND 2048
ORDER BY size DESC
LIMIT 30;
For each seed, hand off to annotations with the standard mutation loop:
SELECT text FROM pseudocode WHERE func_addr = 0xADDR; — read.SELECT local_id, name, type FROM decomp_lvars WHERE func_addr = 0xADDR; — discover variables. If only the name is known, exact func_name = 'name' is also pushed down for discovery.apply_type_param / apply_type_local / set_local_type().rename_local(0xADDR, local_id, new_name).UPDATE funcs SET prototype = '...' WHERE addr = 0xADDR;.INSERT INTO comments (addr, comment, source) VALUES (0xADDR, 'summary', 'plate');.INSERT INTO function_tag_mappings (func_addr, tag_name) VALUES (0xADDR, 'progress:annotated');.SELECT save_database(); as a periodic checkpoint; normal managed
shutdown saves once by default.If the decompilation now "looks like source", drop the seed tag and move up.
Find callers of the just-annotated function, prioritise by fan-in:
-- Direct callers, ranked by how many of their callees are already annotated
WITH annotated AS (
SELECT func_addr FROM function_tag_mappings WHERE tag_name = 'progress:annotated'
),
caller_progress AS (
SELECT ce.src_func_addr AS caller,
COUNT(*) AS total_callees,
SUM(CASE WHEN ce.dst_func_addr IN (SELECT func_addr FROM annotated) THEN 1 ELSE 0 END) AS done_callees
FROM callgraph_edges ce
GROUP BY ce.src_func_addr
)
SELECT printf('0x%X', cp.caller) AS addr,
f.name,
cp.done_callees, cp.total_callees,
round(100.0 * cp.done_callees / NULLIF(cp.total_callees, 0), 1) AS pct
FROM caller_progress cp
JOIN funcs f ON f.addr = cp.caller
WHERE cp.done_callees >= cp.total_callees
AND cp.caller NOT IN (SELECT func_addr FROM annotated)
ORDER BY cp.total_callees DESC
LIMIT 20;
Functions whose callees are all annotated are the next-best candidates — every variable and call site they reference now has a name and type.
Pick a struct candidate (a parameter type that recurs across many functions but is still void * or undefined4 *):
-- Pointer parameters that probably represent a shared structure
SELECT param_type, COUNT(DISTINCT func_addr) AS funcs_using
FROM function_params
WHERE param_type LIKE '%void *%' OR param_type LIKE '%undefined% *%'
GROUP BY param_type
ORDER BY funcs_using DESC
LIMIT 20;
For each function that takes that pointer, find the field-offset accesses in pseudocode / ctree_v_derefs / decomp_tokens. Combine offsets across functions to discover the full layout:
-- All deref sites in functions that take the candidate parameter type
WITH candidates AS (
SELECT DISTINCT func_addr FROM function_params WHERE param_type = 'void *'
)
SELECT printf('0x%X', d.func_addr) AS func,
printf('0x%X', d.addr) AS site,
d.expr
FROM ctree_v_derefs d
JOIN candidates c ON c.func_addr = d.func_addr
ORDER BY d.func_addr, d.addr
LIMIT 100;
(ctree_v_derefs is mnemonic-derived, so it surfaces patterns like [ebx+0x10] — the offsets are what you correlate.)
Once you've collected offsets, build the struct via parse_decls():
The typedefs below assume a target with 32-bit unsigned int and 16-bit
unsigned short; verify its data organization before declaring those names.
SELECT parse_decls('typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef struct {
uint32_t magic; // offset 0
uint32_t flags; // offset 4
char tag[8]; // offset 8
uint16_t version; // offset 16 (observed in CalleeC at 0x401234)
} Session;');
Apply via apply_type_param:
INSERT INTO apply_type_param (func_addr, ordinal, type_name)
SELECT func_addr, 0, 'Session *'
FROM function_params
WHERE param_type = 'void *' AND ordinal = 0
AND func_addr IN (SELECT func_addr FROM function_tag_mappings WHERE tag_name = 'progress:annotated');
Re-decompile each affected function and verify the new field accesses look right:
-- Each SQL statement reads/decompiles from the live source.
SELECT text FROM pseudocode WHERE func_addr = <callee_addr>; -- substitute each affected callee
If a field access still looks wrong, refine the struct (UPDATE type_members SET member_type = ... or INSERT INTO type_members ...) and re-decompile.
Use function_tags + function_tag_mappings (no idasql-style netnode_kv exists in ghidrasql). Suggested tag taxonomy:
| Tag | Meaning |
|---|---|
progress:seed | In the current campaign's seed set |
progress:reviewed | Function has been read and understood |
progress:typed | Parameters and locals have been retyped |
progress:annotated | Function is named, prototyped, plate-commented |
recovered:struct:<Name> | A function contributed evidence to recovering struct <Name> |
crypto, network, parser, state-machine | Analytical buckets |
Cross-session resume:
-- "What's left to annotate?"
SELECT printf('0x%X', f.addr) AS addr, f.name, f.size
FROM funcs f
LEFT JOIN function_tag_mappings m
ON m.func_addr = f.addr AND m.tag_name = 'progress:annotated'
WHERE m.func_addr IS NULL
ORDER BY f.size DESC
LIMIT 30;
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
12 skills in this plugin
/dataQuery strings, bytes, data items, memory blocks, and relocations through ghidrasql./ghidrasql:re-sourcefrom ghidrasql
npx claudepluginhub 0xeb/ghidrasql-skills --plugin ghidrasqlOther plugins' skills for the same job