/bnsql:connectfrom bnsql
Connect to Binary Ninja databases and bootstrap sessions. Use when starting analysis, routing to other skills, or setting up CLI/HTTP/MCP connections.
Ships in bnsql. 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.
bnsql --help)bnsql vX.Y.Z - SQL interface for Binary Ninja
Usage:
bnsql <file> Interactive mode
bnsql <file> -c <query> Execute query and exit
bnsql <file> -f <file.sql> Execute SQL file
bnsql <file> --http [port] Start HTTP REST server (default: 8080)
bnsql <file> --mcp [port] Start MCP server (default: 9998)
<file> is a Binary Ninja database (.bndb) OR a raw binary
(.exe/.dll/firmware/etc.). Raw binaries trigger fresh BN analysis;
the resulting .bndb is auto-saved next to the source on clean exit.
Options:
-s, --source <path> Binary Ninja database (.bndb) OR raw binary
(.exe/.dll/firmware/etc.) — raw binaries trigger
fresh BN analysis (auto-saved next to source)
-c, --command <sql> SQL query to execute
-f, --file <path> SQL file to execute
-i, --interactive Interactive SQL mode (default)
--http [port] Start HTTP REST server (default: 8080)
--mcp [port] Start MCP server for Claude Desktop, etc. (default: 9998)
--bind <addr> Bind address for server (default: 127.0.0.1)
--token <token> Auth token for HTTP/MCP mode
-q, --quiet Suppress banner
-h, --help Show this help
-v, --version Show version
Examples:
bnsql sample.bndb -c "SELECT name, size FROM funcs LIMIT 10"
bnsql sample.bndb --http 8080
bnsql sample.exe --http 8080 # raw PE: BN auto-analyzes, then serves SQL
bnsql firmware.bin -c "SELECT COUNT(*) FROM funcs"
Key takeaway: bnsql <file> (and the equivalent -s <file>) accepts either
an existing Binary Ninja database or a raw binary. No manual
binaryninja --headless pre-step is needed — point bnsql straight at the
.exe/.dll/firmware/etc. and Binary Ninja creates the database on first
open. The resulting .bndb is auto-saved next to the source on clean exit.
Use these commands first to avoid guessing behavior or schema:
# Query a Binary Ninja database
bnsql sample.bndb -c "SELECT * FROM binary"
bnsql sample.bndb -c "SELECT * FROM binary; SELECT COUNT(*) FROM funcs;"
# Interactive REPL
bnsql sample.bndb
# Long-lived HTTP server for iterative analysis
bnsql sample.bndb --http 8080
# Raw binary (.exe/.dll/firmware/etc.) — BN auto-analyzes on first open
bnsql sample.exe --http 8080
bnsql sample.exe -c "SELECT * FROM binary"
# Query over HTTP
curl -X POST http://127.0.0.1:8080/query --data-binary "SELECT name, size FROM funcs LIMIT 5"
Critical guardrails:
.bndb) or a raw binary (.exe, .dll, firmware blob, etc.)
— raw binaries trigger fresh BN analysis and the resulting .bndb is
auto-saved next to the source on clean exit. Do not pre-build a .bndb
with binaryninja --headless; bnsql raw.exe does it in one shot.set_name, set_comment, type edits,
bookmarks, pseudocode comments, patches) are applied in-memory only. Call
SELECT save(); to persist to
disk before exiting. This is the explicit-save model introduced in v0.0.9..schema <table>PRAGMA table_xinfo(<table>); (or PRAGMA table_info(<table>);)SELECT * FROM binary;.Everything above is the CLI. One surface exists only inside a running Binary Ninja GUI, because it needs a live UI:
get_ui_context_json() — what the user is looking at (see the ui-context skill)bnsql_python() / bnsql_python_file() work in every runtime — headless
CLI/--http/--mcp and the GUI plugin alike (see the python skill). The GUI
plugin remains the route when you specifically want Python against the analyst's
live GUI session.
To reach them, the analyst starts the server from Binary Ninja's Plugins → BNSQL
menu, then you query it over HTTP exactly as you would a CLI server:
| Menu command | Effect |
|---|---|
Run SQL Query... | one-off query in a dialog |
Show Tables | list the surface |
Start HTTP Server... | prompts for port or host:port |
Stop HTTP Server / HTTP Server Status | lifecycle |
The prompt accepts a bare port (8080 → loopback) or host:port
(0.0.0.0:8080, 192.168.1.50:8080, [::1]:8080). Binding off-loopback
prompts for an auth token and, if left empty, requires confirming an
unauthenticated exposure — that endpoint can execute Python once enable_python
is on, so an open bind is remote code execution on the analyst's workstation. When
a token is set, send it as Authorization: Bearer <token> (or X-XSQL-Token).
Note the CLI cannot attach to a running GUI server — there is no --url
option. Use curl or any HTTP client against /query.
Check what a given endpoint supports before relying on it:
SELECT value FROM runtime_settings WHERE key = 'enable_python'; -- the gate
and GET /status reports python_available — whether a scripting provider exists
at all. The two are independent: enable_python: true with
python_available: false means the process environment is broken (typically a
copied binaryninjacore.dll beside the executable splitting the provider
registry — see the python skill), not that headless lacks Python.
Canonical table/view formats live in references/schema-catalog.md.
pragma_table_list + pragma_table_xinfo).Manual refresh:
SELECT schema, name, type, ncol FROM pragma_table_list WHERE schema='main' ORDER BY type, name;PRAGMA table_xinfo(<surface>);Use this exact startup flow before deep analysis:
bnsql <file>, --http, or --mcp). The file can
be an existing .bndb or a raw binary — never pre-build a .bndb with
binaryninja --headless; let bnsql raw.exe do it.SELECT * FROM binary;
SELECT COUNT(*) AS funcs FROM funcs;
SELECT COUNT(*) AS xrefs FROM xrefs;
SELECT COUNT(*) AS strings FROM strings;
SELECT * FROM capabilities;
PRAGMA table_xinfo(funcs);
PRAGMA table_xinfo(xrefs);
Never skip steps 2-5 when the user prompt is broad or ambiguous.
These contracts apply across all bnsql skills and should be treated as one shared agent behavior model.
SELECT) before writes (INSERT/UPDATE/DELETE).addr, func_addr, from_addr, to_addr).types, type_members,
func_signatures, patches, capabilities, runtime_settings)..schema or PRAGMA table_xinfo(...) before issuing
uncertain queries.funcs, segments, names, comments, bookmarks, hlil_vars,
pseudocode, types*, patches, and the set_name/set_comment UDFs are
applied in-memory but not
written to disk until SELECT save(); is called.save() when the user expects the change to
survive after exit.hlil_vars name/type rename/retype reflects in the same session (the
write's commit flushes analysis once) — the next SELECT shows it with no
decompile(addr, ..., refresh=1); a batch rename in one UPDATE flushes once..bndb backing), some writes apply lossily or not at all even
after save() — the .bndb-backed session is the durable path. A successful
mutation on a raw-binary session emits a warning steering you to a .bndb.
For lossless, durable edits, open/save a .bndb (SELECT save(); creates one
next to the input) and re-run the edit there.xrefs, instructions, pseudocode,
hlil_vars, hlil_calls) by key columns (func_addr).func_addr = X unless explicitly asked for
broad scans.callers / callees pre-computed views over func_start(addr)
/ func_at(addr) UDFs in bulk xref queries — UDFs call the BN API once per
row.no such table/column: introspect schema and retry.capabilities for
whether the surface is available in this binary view._main, 2851 bytes"); show supporting
rows only when they help the user verify; don't dump full tables unprompted;
never surface data fetched only as an intermediate reasoning step./query response is a JSON envelope
({success, results:[{columns,rows,…}]}). Consume it directly and render in
your reply. Do not pipe responses through python/jq to pre-render a
table — that discards the success/elapsed_ms/error fields and makes you
reason over a lossy view. The CLI (-c/-f) already prints a table. Reserve
jq/python for extracting a value to feed a later query. (For direct
terminal/pipe use the server can emit ?format=text|csv|tsv; as an agent,
consume json.)Use this deterministic mapping for initial routing:
| User intent | Primary skill | Typical first query |
|---|---|---|
| "what does this binary do?" / triage | analysis | SELECT * FROM entries; |
| disassembly, segments, instructions | disassembly | SELECT * FROM funcs LIMIT 20; |
| xrefs/callers/callees/import dependencies | xrefs | SELECT * FROM callers WHERE callee_addr = ...; |
strings/bytes/pattern search (byte_search) | data | SELECT * FROM strings LIMIT 20; |
| decompile/pseudocode/hlil variables/calls | decompiler | SELECT decompile(0x...); |
| comments/renames/retyping/save | annotations | SELECT ... FROM funcs WHERE addr = ...; |
| type creation/struct/enum/member work | types | SELECT * FROM types LIMIT 20; |
| SQL function lookup/signature recall | functions | SELECT name FROM pragma_function_list; |
| runtime knobs / pragma surface / timeouts | connect | SELECT key, value FROM runtime_settings; |
| what's on screen / current view / selection ("here", "this") | ui-context | SELECT get_ui_context_json(); |
| run Python / custom algorithm / BN API not in a table | python | SELECT bnsql_python('...'); |
When prompts span domains, execute in this order:
connectxrefs + decompiler + annotations)Database orientation surface for quick session metadata. binary is a
key/value (EAV) table — three columns key, value, type (type ∈ {string, hex, bool, int}), one row per metadata item; the shape and canonical key names
are shared across the tool family, and the summary row is emitted first so
SELECT * FROM binary shows the digest up top. The keys are: summary,
tool_name (bnsql), tool_version (build version), processor, filetype,
image_base, entry_point, min_addr, max_addr, is_64bit, bits,
endianness, filename, platform (bnsql extra).
min_addr is the first valid/lowest mapped view address (GetStart), max_addr
the end virtual address (GetEnd), and image_base the image base of the main
input file (GetImageBase) — three distinct values (the image base is not the
min address and not the entry point). Use SELECT value FROM binary WHERE key = 'entry_point' to read a single field.
SELECT * FROM binary;
SELECT value FROM binary WHERE key = 'entry_point';
For canonical schema and owner mapping, see references/schema-catalog.md.
Live table of runtime knobs — columns key, value, type, scope,
kind (value/action) and settable (1 only when UPDATE is accepted), one
live row per runtime key. Its value column is writable: change a value
via UPDATE runtime_settings SET value='<v>' WHERE key='<key>' (INSERT/DELETE and
read-only keys are rejected with a capability-scoped error). The two timeout-stack
verbs stay pragmas (PRAGMA bnsql.timeout_push = <ms> /
PRAGMA bnsql.timeout_pop). Keys: query_timeout_ms, queue_admission_timeout_ms,
max_queue, hints_enabled, enable_python, python_output_max,
timeout_stack_depth, max_timeout_stack_depth, timeout_push, timeout_pop.
SELECT key, value, type, scope, kind, settable FROM runtime_settings;
UPDATE runtime_settings SET value='60000' WHERE key='query_timeout_ms'; -- then re-select to see it tracked
Binary Ninja is a modern reverse engineering platform. It analyzes compiled binaries (executables, DLLs, firmware) and produces:
BNSQL exposes all this analysis data through SQL virtual tables, enabling:
Everything in a binary has an address — a memory location where code or
data lives. BNSQL exposes addresses as SQLite INTEGERs (signed 64-bit). Use
hex(addr) or printf('0x%X', addr) for display; both print the unsigned form.
SELECT hex(addr) AS addr, name FROM funcs WHERE size > 1000;
High addresses (>= 2^63), e.g. kernel images at 0xFFFFF800...: SQL holds
them as negative INTEGERs, so ORDER BY addr lists them first. Write them as hex
literals (0xFFFFF80000100000) or the negative decimal, never as a decimal
= 2^63 (SQLite makes that a REAL, which matches nothing).
addr >= <high hex>also includes every low address; the high half alone isaddr BETWEEN <high hex> AND -1. Details: the disassembly and data skills.
Binary Ninja groups code into functions with:
addr — Where the function beginsname — Assigned or auto-generated name (e.g. main, sub_401000)size — Total bytes in the functionFor single-address disassembly (code or data), prefer disasm(addr) over
function-scoped queries.
Binary analysis is about understanding relationships:
from_addr → to_addr represents "address X references address Y"Use table: xrefs(from_addr, to_addr, type, is_code, from_func).
The from_func column is pre-computed (no UDF call per row) — use it for
bulk call-graph queries instead of func_start(from_addr).
Memory is divided into segments with different purposes. For a typical PE:
.text — Executable code.data — Initialized global data.rdata — Read-only data (strings, constants).bss — Uninitialized dataUse table: segments.
Within a function, basic blocks are straight-line code sequences:
Use table: blocks(start_addr, end_addr, func_addr).
Binary Ninja's HLIL (High Level IL) is the closest thing to C-like pseudocode in BN:
pseudocode table — full-function decompiled texthlil_vars — local variables detected by HLILhlil_calls — call sites discovered in HLILCore decompiler surfaces:
decompile(addr) — Returns the entire function as one text block.
Use this first when the user asks to "decompile", "show pseudocode", or
"explain function logic".decompile(addr, limit) — Limit-aware variant; useful when survey-decompiling
many functions.pseudocode table — for line-level filtering by func_addr / addr.hlil_vars — local variable rename / type / comment updates.hlil_calls — call-site analysis.Some tables have optimized filters that use efficient BN API:
| Table | Optimized Filter | Without Filter |
|---|---|---|
instructions | func_addr = X | O(all instructions) — SLOW |
blocks | func_addr = X | O(all blocks) |
xrefs | to_addr = X or from_addr = X | O(all xrefs) |
pseudocode | func_addr = X | Materializes ALL functions |
hlil_vars | func_addr = X | Materializes ALL functions |
hlil_calls | func_addr = X or LIMIT | Lazy: LIMIT/bounded decompiles a few; full scan decompiles all |
_hlil_ast | func_addr = X or LIMIT | Lazy (expert table); same as hlil_calls |
Filter pseudocode/hlil_vars by func_addr (they materialize the whole binary). hlil_calls/_hlil_ast stream lazily, so a bounded LIMIT is also cheap.
-- SLOW: One BN API call per row (8000+ for medium binaries)
SELECT func_start(from_addr), to_addr FROM xrefs WHERE is_code = 1;
-- FAST: Pure SQL using pre-computed view
SELECT func_addr, callee_addr FROM callees;
The callers and callees views compute function boundaries once at startup,
not per row. Use them for any bulk call-graph analysis.
pseudocode, hlil_vars,
hlil_calls) may be empty or unavailable depending on the BN tier. Check
capabilities.pseudocode/hlil_vars decompile every
function (slow — prefer func_addr). hlil_calls/_hlil_ast stream lazily,
so an unbounded full scan is still heavy but a LIMIT/bounded query is cheap.save(): Mutations succeed but disappear on exit. Always pair a
mutation with SELECT save(); if persistence is required.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub 0xeb/bnsql-skills --plugin bnsqlOther plugins' skills for the same job
11 skills in this plugin
/analysisBNSQL analysis workflows: triage, security audit, crypto/network detection, multi-table queries./annotationsEdit Binary Ninja databases: comments, renames, types, patches. Mutations require SELECT save() to persist (explicit-save model, v0.0.9+)./dataQuery Binary Ninja strings, bytes, and binary patterns. Use the byte_search table for fast byte-pattern search./decompilerDecompile Binary Ninja functions via HLIL: pseudocode text, local variables, call sites. Always filter by func_addr.