Trigger Intents
Use this skill when user asks for:
- Function/segment/instruction inspection
- Call-site or control-flow analysis from disassembly
- Operand formatting and low-level code structure
- Raw byte/instruction-level evidence
Route to:
- for AST/pseudocode semantics
- for relationship-heavy caller/callee workflows
- for patching/breakpoint actions
Do This First (Warm-Start Sequence)
sql
-- 1) Orientation
SELECT * FROM welcome;
-- 2) Segment map
SELECT name, printf('0x%X', start_ea) AS start_ea, printf('0x%X', end_ea) AS end_ea, perm
FROM segments
ORDER BY start_ea;
-- 3) Largest functions (triage anchors)
SELECT name, printf('0x%X', address) AS addr, size
FROM funcs
ORDER BY size DESC
LIMIT 20;
Interpretation guidance:
- Start from executable segments and largest/highly connected functions.
- Use constraints early when querying instruction-heavy surfaces.
Failure and Recovery
- Slow queries on /:
- Missing expected symbol names:
- Pivot to address-based workflows and enrich via updates later.
- Ambiguous control-flow behavior:
- Cross-check with and then escalate to .
Handoff Patterns
- -> for relation expansion.
- -> for semantic interpretation.
- -> for patch/breakpoint execution.
Entity Tables
funcs
All detected functions in the binary with prototype information.
| Column | Type | Description |
|---|
| INT | Function start address |
| TEXT | Function name |
| INT | Function size in bytes |
| INT | Function end address |
| INT | Function flags |
Prototype columns (populated when type info available):
| Column | Type | Description |
|---|
| TEXT | Return type string (e.g., "int", "void *") |
| INT | 1 if return type is pointer |
| INT | 1 if return type is exactly int |
| INT | 1 if return type is int-like (int, long, DWORD, BOOL) |
| INT | 1 if return type is void |
| INT | Number of function arguments |
| TEXT | Calling convention (cdecl, stdcall, fastcall, etc.) |
sql
-- 10 largest functions
SELECT name, size FROM funcs ORDER BY size DESC LIMIT 10;
-- Functions starting with "sub_" (auto-named, not analyzed)
SELECT name, printf('0x%X', address) as addr FROM funcs WHERE name LIKE 'sub_%';
-- Functions returning integers with 3+ arguments
SELECT name, return_type, arg_count FROM funcs
WHERE return_is_integral = 1 AND arg_count >= 3;
Write operations:
sql
-- Create a function
INSERT INTO funcs (address) VALUES (0x401000);
-- Rename a function
UPDATE funcs SET name = 'my_func' WHERE address = 0x401000;
-- Delete a function
DELETE FROM funcs WHERE address = 0x401000;
segments
Memory segments. Supports INSERT, UPDATE (
,
,
), and DELETE.
| Column | Type | RW | Description |
|---|
| INT | R | Segment start |
| INT | R | Segment end |
| TEXT | RW | Segment name (.text, .data, etc.) |
| TEXT | RW | Segment class (CODE, DATA) |
| INT | RW | Permissions (R=4, W=2, X=1) |
sql
-- Find executable segments
SELECT name, printf('0x%X', start_ea) as start FROM segments WHERE perm & 1 = 1;
-- Rename a segment
UPDATE segments SET name = '.mytext' WHERE start_ea = 0x401000;
names
All named locations (functions, labels, data). Supports INSERT, UPDATE, and DELETE.
| Column | Type | RW | Description |
|---|
| INT | R | Address |
| TEXT | RW | Name |
sql
-- Create/set a name
INSERT INTO names (address, name) VALUES (0x401000, 'my_symbol');
-- Rename
UPDATE names SET name = 'my_symbol_renamed' WHERE address = 0x401000;
entries
Entry points (exports, program entry, tls callbacks, etc.).
| Column | Type | Description |
|---|
| INT | Export ordinal |
| INT | Entry address |
| TEXT | Entry name |
Instruction Tables
instructions
is the disassembly table. For scalar disassembly text at a specific EA, use
.
Use
or
when you explicitly need a function/range listing.
Decoded instructions support DELETE (converts instruction to unexplored bytes) and operand representation updates via
.
is the fast path (function-item iterator). Without it, the table scans all code heads.
| Column | Type | Description |
|---|
| INT | Instruction address |
| INT | Containing function |
| INT | Instruction type (architecture-specific) |
| TEXT | Instruction mnemonic |
| INT | Instruction size |
| TEXT | Operand text () |
| TEXT | Full disassembly line |
operand0_class..operand7_class
| TEXT | Operand class: , , , , ... |
operand0_repr_kind..operand7_repr_kind
| TEXT | Current representation: , , |
operand0_repr_type_name..operand7_repr_type_name
| TEXT | Enum name or stroff path |
operand0_format_spec..operand7_format_spec
| TEXT (RW) | Apply/clear representation for a specific operand |
sql
-- Instruction profile of a function (FAST)
SELECT mnemonic, COUNT(*) as count
FROM instructions WHERE func_addr = 0x401330
GROUP BY mnemonic ORDER BY count DESC;
-- Find all call instructions in a function
SELECT address, disasm FROM instructions
WHERE func_addr = 0x401000 AND mnemonic = 'call';
-- Apply enum representation to operand 1
UPDATE instructions
SET operand1_format_spec = 'enum:MY_ENUM'
WHERE address = 0x401020;
-- Clear representation back to plain
UPDATE instructions
SET operand1_format_spec = 'clear'
WHERE address = 0x401020;
instruction_operands
One row per decoded non-void operand. Use this table for operand type/value details and for joinable replacements of old operand/decode helper functions.
| Column | Type | Description |
|---|
| INT | Instruction address |
| INT | Containing function |
| INT | Operand index |
| TEXT | Operand text |
| INT | IDA operand type code |
| TEXT | Operand type name (, , , ...) |
| INT | Operand dtype |
| INT | Register number when applicable |
| INT | Referenced address/displacement when applicable |
| INT | Raw operand value |
| INT | Best-effort scalar operand value |
sql
SELECT opnum, text, type_name, value
FROM instruction_operands
WHERE address = 0x401000
ORDER BY opnum;
SELECT i.address, i.itype, i.mnemonic, o.opnum, o.text, o.type_name, o.value
FROM instructions i
LEFT JOIN instruction_operands o
ON o.address = i.address AND o.func_addr = 0x401000
WHERE i.func_addr = 0x401000
ORDER BY i.address, o.opnum;
Performance: decodes one instruction;
uses O(function_size) iteration. Without one of these constraints, it scans the entire database.
disasm_calls
All call instructions with resolved targets.
| Column | Type | Description |
|---|
| INT | Function containing the call |
| INT | Call instruction address |
| INT | Target address (0 if unknown) |
| TEXT | Target name |
sql
-- Functions that call malloc
SELECT DISTINCT (SELECT name FROM funcs WHERE func_addr >= address AND func_addr < end_ea LIMIT 1) as caller
FROM disasm_calls WHERE callee_name LIKE '%malloc%';
blocks
Basic blocks within functions.
Use constraint for performance.
| Column | Type | Description |
|---|
| INT | Containing function |
| INT | Block start |
| INT | Block end |
| INT | Block size |
sql
-- Blocks in a specific function (FAST - uses constraint pushdown)
SELECT * FROM blocks WHERE func_ea = 0x401000;
-- Functions with most basic blocks
SELECT (SELECT name FROM funcs WHERE func_ea >= address AND func_ea < end_ea LIMIT 1) as name, COUNT(*) as blocks
FROM blocks GROUP BY func_ea ORDER BY blocks DESC LIMIT 10;
cfg_edges
Control flow graph edges between basic blocks.
Always use (filter_eq pushdown, O(blocks in function)).
| Column | Type | Description |
|---|
| INT | Containing function |
| INT | Source block address |
| INT | Target block address |
| TEXT | (single-successor or fallback label), / (generic first/second arms for a two-way branch; labels follow successor order, not taken/fallthrough semantics) |
sql
-- Get CFG structure
SELECT * FROM cfg_edges WHERE func_ea = 0x401000;
-- Find branch points (conditional blocks)
SELECT from_block, COUNT(*) as succ_count
FROM cfg_edges WHERE func_ea = 0x401000
GROUP BY from_block HAVING succ_count > 1;
-- Find merge points (blocks with multiple predecessors)
SELECT to_block, COUNT(*) as pred_count
FROM cfg_edges WHERE func_ea = 0x401000
GROUP BY to_block HAVING pred_count > 1;
-- Function complexity ranking: combine CFG, loops, and call metrics
SELECT f.name, f.size,
(SELECT COUNT(*)
FROM (
SELECT ce.from_block
FROM cfg_edges ce
WHERE ce.func_ea = f.address
GROUP BY ce.from_block
HAVING COUNT(*) > 1
) branch_blocks) as branch_sites,
(SELECT COUNT(*) FROM disasm_loops dl WHERE dl.func_addr = f.address) as loops,
(SELECT COUNT(*) FROM disasm_calls dc WHERE dc.func_addr = f.address) as calls_made
FROM funcs f
WHERE f.size > 32
ORDER BY branch_sites DESC
LIMIT 20;
function_chunks
Cached table with one row per function chunk. Aggregate by
when you
need function-level span or density metrics.
| Column | Type | Description |
|---|
| INT | Function address |
| INT | Chunk start address |
| INT | Chunk end address |
| INT | Number of blocks in chunk |
| INT | Total size of chunk |
sql
SELECT * FROM function_chunks WHERE func_addr = 0x401000;
SQL Functions -- Disassembly
| Function | Description |
|---|
| Canonical listing line for containing head (works for code/data) |
| Canonical listing line with +/- neighboring heads |
| Single disassembly line at address |
| Next N instructions from address (count-based) |
| All disassembly lines in address range [start, end) |
| Full disassembly of function containing address |
| Create instruction at address (returns 1/0) |
make_code_range(start, end)
| Create instructions in range, returns created count |
Disassembly Examples
sql
-- Canonical single-EA disassembly (safe for code or data)
SELECT disasm_at(0x401000);
-- Canonical context window (+/- 2 heads)
SELECT disasm_at(0x401000, 2);
-- Full function disassembly (resolves boundaries via get_func)
SELECT disasm_func(address) FROM funcs WHERE name = '_main';
-- Disassemble a specific address range
SELECT disasm_range(0x401000, 0x401100);
-- Sliding window: next 5 instructions from an address
SELECT disasm(0x401000, 5);
SQL Functions -- Names & Functions
Use table lookups for address and containing-function metadata. Resolve symbol names to integer EAs before using these patterns.
| Pattern | Description |
|---|
SELECT name FROM names WHERE address = :ea LIMIT 1
| Name at address |
SELECT name FROM funcs WHERE :ea >= address AND :ea < end_ea LIMIT 1
| Function containing address |
SELECT address FROM funcs WHERE :ea >= address AND :ea < end_ea LIMIT 1
| Start of containing function |
SELECT end_ea FROM funcs WHERE :ea >= address AND :ea < end_ea LIMIT 1
| End of containing function |
Function count and index lookup are table-driven:
sql
SELECT COUNT(*) AS function_count FROM funcs;
SELECT address FROM funcs WHERE rowid = 0;
SQL Functions -- Navigation
Use
ordering for defined-item navigation and SQLite formatting functions for display strings. Address equality/range filters are optimized;
or
is consumed for next/previous-item lookups.
sql
SELECT address
FROM heads
WHERE address > 0x401000
ORDER BY address
LIMIT 1;
SELECT address
FROM heads
WHERE address < 0x401000
ORDER BY address DESC
LIMIT 1;
SELECT printf('0x%llx', address) AS address_hex
FROM heads
LIMIT 10;
Segment lookup is table-driven:
sql
SELECT name
FROM segments
WHERE 0x401000 >= start_ea
AND 0x401000 < end_ea
LIMIT 1;
SQL Functions -- Item Analysis
Use
for item classification, size, and raw flags:
sql
SELECT address, size, type, flags, disasm
FROM heads
WHERE address = 0x401000;
SQL Functions -- Instruction Details
Use
and
for decoded instruction facts:
sql
SELECT address, itype, mnemonic
FROM instructions
WHERE func_addr = 0x401000
LIMIT 10;
SELECT opnum, text, type_code, type_name, value
FROM instruction_operands
WHERE address = 0x401000
ORDER BY opnum;
SELECT i.address, i.itype, i.mnemonic, i.size, o.opnum, o.text, o.type_name, o.value
FROM instructions i
LEFT JOIN instruction_operands o
ON o.address = i.address AND o.address = 0x401000
WHERE i.address = 0x401000
ORDER BY o.opnum;
SQL Functions -- File Generation
| Function | Description |
|---|
| Generate full-database listing output (LST) |
SQL Functions -- Graph Generation
| Function | Description |
|---|
| Generate CFG as DOT graph string |
gen_cfg_dot_file(addr, path)
| Write CFG DOT to file |
| Generate database schema as DOT |
sql
-- Get CFG for a function as DOT format
SELECT gen_cfg_dot(0x401000);
Performance Rules
| Table | Architecture | Key Constraint | Notes |
|---|
| Index-Based | none needed | O(1) per row via -- always fast |
| Iterator | | Function-item iterator (fast) vs full code-head scan (slow) |
| Iterator | | Constraint pushdown: iterates blocks of one function |
| Iterator | | filter_eq pushdown: O(blocks in function) |
| Generator | | Lazy streaming, respects LIMIT |
| Generator | , address range | Consumes for next/previous navigation; broad scans can still be large |
| Iterator | , | Address lookup decodes one instruction; function lookup iterates one function |
| Index-Based | none needed | Small table, always fast |
| Iterator | none needed | Iterates IDA's name list |
Key rules:
- is always fast -- no constraint needed.
- without scans every code head -- use for per-function queries.
- without iterates all functions' flowcharts -- always constrain.
- is often large. Use for item facts and address range plus
ORDER BY address [DESC] LIMIT 1
for navigation.
Cost model:
funcs (full scan) -> O(number of functions), typically ~1000s, fast
instructions WHERE func_addr -> O(function_size / avg_insn_size)
instructions (no constraint) -> O(total_code_heads), potentially 100K+
blocks WHERE func_ea -> O(block_count_in_func), fast
cfg_edges WHERE func_ea -> O(block_count_in_func), fast
disasm_calls WHERE func_addr -> O(instructions_in_func), streaming
heads WHERE address -> O(1) IDA head check
heads next/prev LIMIT 1 -> O(distance to next/previous defined head)
instruction_operands address -> O(operands in one instruction)
instruction_operands func -> O(operands in one function)
Additional Resources
- For advanced CTE patterns and instruction lifecycle playbooks: references/disassembly-examples.md
- For additional table schemas (fchunks, heads, bytes, signatures, problems, fixups, etc.): references/disassembly-tables.md