Logo Idapython

Idapython

Tổ chức
allthingsida
idapython

Execute IDAPython via idasql, and query idasql from IDAPython with import idasql. Use when SQL surfaces are insufficient and direct IDA SDK access is needed via Python snippets or scripts, or when a script or plugin inside IDA needs SQL over the open database.

Tổng quan

Nhà phát hànhallthingsida
Kho mãidasql-skills
Tên kỹ năngidapython
Sao
50
Bản fork
10
Tệp đi kèm
1
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 1 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được allthingsida công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Idapython trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/allthingsida/idasql-skills/tree/main/plugins/idasql/skills/idapython
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/allthingsida/idasql-skills.git /tmp/idasql-skills
mkdir -p .claude/skills
cp -r /tmp/idasql-skills/plugins/idasql/skills/idapython .claude/skills/idapython
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Idapython trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Idapython ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Idapython không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.


Python Execution SQL Functions

FunctionDescription
idapython_snippet(code[, sandbox])Execute Python snippet and return captured output text
idapython_file(path[, sandbox])Execute Python file and return captured output text

Runtime Guard

Python execution is disabled by default. Enable it with:

sql
UPDATE runtime_settings SET value='1' WHERE key='enable_idapython';

Captured print output is unbounded by default. To bound a runaway or very chatty snippet (so it can't exhaust memory / the response), set an optional byte cap; 0 restores unbounded:

sql
UPDATE runtime_settings SET value='65536' WHERE key='idapython_output_max';  -- cap at 64 KiB
UPDATE runtime_settings SET value='0'     WHERE key='idapython_output_max';  -- unbounded (default)

Output past the cap is dropped with a ...[idapython output truncated at N bytes]... marker.

To confirm the current values of enable_idapython and idapython_output_max, query SELECT * FROM runtime_settings WHERE scope = 'idasql'. The table is the canonical writable runtime-control surface: read it with SELECT, and change settable value cells with an exact-key UPDATE. Use SELECT * FROM runtime_settings to include shared controls. See the connect skill.

Examples

sql
SELECT idapython_snippet('print("hello from idapython")');
SELECT idapython_file('C:/temp/script.py');
SELECT idapython_snippet('counter = globals().get("counter", 0) + 1; print(counter)', 'alpha');

Notes

  • Disabled by default until enable_idapython is enabled through runtime_settings
  • Python exceptions propagate as SQL errors
  • sandbox isolates/persists Python globals by sandbox key

Three Python Contexts (Important)

  • Host-side Python client (outside IDA): use requests.post(.../query, data=sql) to send SQL over HTTP. The body may be one statement or a semicolon-separated script; every response uses the canonical results[] envelope (a single statement is an array of one — read results[i].rows). Use this for loops, bulk updates, and automation orchestration. See connect skill HTTP client patterns.
  • IDAPython via SQL (inside IDA): use idapython_snippet() / idapython_file() when you need direct IDA SDK APIs in-process.
  • SQL from IDAPython (inside IDA): import idasql in the IDA console, a script, a plugin, or a snippet queries the open database in-process (below). Never call the HTTP server from Python running inside IDA: the request waits for IDA's main thread, which is busy running that Python, and the call deadlocks.

Example contrast:

python
# Host-side Python (outside IDA): sends SQL over HTTP
import requests
requests.post("http://127.0.0.1:8080/query", data="SELECT COUNT(*) FROM funcs")
sql
-- IDAPython (inside IDA): executes Python in IDA runtime
SELECT idapython_snippet('import idaapi; print(idaapi.get_kernel_version())');

Sandbox Behavior

Each sandbox key creates an isolated Python namespace:

  • Variables set in one sandbox are not visible in another
  • The same sandbox key reuses its namespace across calls (state persists within a session)
  • Without a sandbox key, code runs in the default global namespace

Error Propagation

When a Python script raises an exception, it propagates as a SQL error:

sql
-- This will return an error: "NameError: name 'undefined_var' is not defined"
SELECT idapython_snippet('print(undefined_var)');

Calling idasql from Python (import idasql)

Python that runs inside IDA (the console, a script or plugin, idapython_snippet) can query the open database directly. idasql injects a small idasql module through IDAPython; idasql itself does not link Python, and without IDAPython nothing changes.

python
import idasql
idasql.available()                                  # True when an idasql engine is loaded
n = idasql.scalar("SELECT COUNT(*) FROM funcs")     # first cell of the first row, typed, or None
r = idasql.query("SELECT addr, name, size FROM funcs WHERE size > ? ORDER BY size DESC", 100)
for f in r:                                         # Row = tuple with attribute access
    print(hex(f.addr), f.name, f.size)
r.columns, r.rows, r.warnings, r.elapsed_ms, r.timed_out, r.partial
r.dicts()                                           # list of dicts
idasql.rows("SELECT * FROM segments")               # query(...).dicts()
idasql.query("SELECT ? + ?", [40, 2])               # one list/tuple = the parameter sequence
results = idasql.script("SELECT 1; SELECT 2 AS two") # several statements: one Result each
try:
    idasql.query("SELECT * FROM no_such_table")
except idasql.Error as e:
    print(e.message, e.sql)
ValuePython type
INTEGERint (addresses come back as numbers)
REALfloat
TEXTstr (embedded NULs kept)
BLOBbytes
NULLNone

Parameters (?) are bound by SQLite, never formatted into the SQL: a quote in a name is data. Python int, float, str, bytes, bool and None are accepted; integers up to 2^64-1 are passed as their signed 64-bit value (how SQL holds high addresses).

Rules:

  • Main thread only. In the GUI a call from another Python thread is forwarded to IDA's main thread and waits for it. Under idalib (idasql CLI, --http, --mcp) nothing services such a request, so it fails at once with idasql.Error instead of hanging.
  • SQL -> Python -> SQL works. Inside idapython_snippet, import idasql queries the same database; the inner query shares the outer statement's deadline and cancellation.
  • Python -> SQL -> Python is refused. idapython_snippet / idapython_file inside SQL issued through idasql fail with a clear error: IDAPython is not re-entrant from there.
  • Writes are writes. Changes made through idasql are visible to every later query, roll back with checkpoints (see the annotations skill), and count as writes for the checkpoint redo guard.
  • Settings follow transactions. UPDATE runtime_settings from Python under a read-only statement takes effect at once; under a statement that writes, or inside BEGIN, when that commits.
  • Lifetime. When the database closes or the plugin unloads, a kept idasql.query raises idasql.Error. A different module already imported as idasql is never replaced (the bridge module carries _idasql_bridge_version).

Inside a snippet:

sql
UPDATE runtime_settings SET value='1' WHERE key='enable_idapython';
SELECT idapython_snippet('
import idasql
big = idasql.query("SELECT addr, name FROM funcs WHERE size > ? ORDER BY size DESC LIMIT 5", 64)
for f in big:
    print(hex(f.addr), f.name)
');

When to Use IDAPython vs SQL

Use CaseBest ToolWhy
Query/filter/aggregate dataSQLJOINs, CTEs, GROUP BY, window functions — SQL is purpose-built for this
Cross-table analysisSQLJOINing funcs, xrefs, strings, ctree is natural in SQL
Reporting and countingSQLCOUNT, SUM, AVG, GROUP_CONCAT — no Python loop needed
Complex algorithmsIDAPythonGraph algorithms, custom pattern matching, ML pipelines
IDA SDK APIs not in idasqlIDAPythonSome IDA SDK features aren't exposed as SQL tables/functions
UI automationIDAPythonOpening views, navigating cursor, triggering IDA actions
Existing scriptsIDAPythonReuse existing .py scripts without rewriting in SQL

General rule: Start with SQL. If you find yourself wanting nested loops, recursive algorithms, or IDA APIs that aren't exposed via idasql, reach for idapython_snippet() as a bridge.


Practical Use Cases

Run a custom analysis script

sql
-- Enable Python execution first
UPDATE runtime_settings SET value='1' WHERE key='enable_idapython';

-- Run a script that collects custom metrics
-- (in SQL this one is SELECT COUNT(*) FROM funcs WHERE flags & 4; prefer SQL when it can)
SELECT idapython_snippet('
import idautils, idc
count = 0
for func_addr in idautils.Functions():
    if idc.get_func_attr(func_addr, idc.FUNCATTR_FLAGS) & 0x4:  # FUNC_LIB
        count += 1
print(f"Library functions: {count}")
');

Access IDA SDK APIs not exposed through idasql

sql
-- Example: get processor-specific register names
SELECT idapython_snippet('
import ida_idp
for i in range(ida_idp.ph_get_regnames().__len__()):
    name = ida_idp.ph_get_regnames()[i]
    if name:
        print(f"{i}: {name}")
');

Bridge pattern: Python produces JSON, SQL processes it

When you need Python's power for extraction but SQL's power for analysis (inside a Python script, import idasql does the same without the JSON round trip):

sql
-- Python extracts data as JSON
SELECT idapython_snippet('
import json, idautils, idc
result = []
for addr in idautils.Functions():
    flags = idc.get_func_attr(addr, idc.FUNCATTR_FLAGS)
    if flags & 0x4:  # FUNC_LIB
        result.append({"addr": addr, "name": idc.get_func_name(addr)})
print(json.dumps(result))
');

-- Then process the JSON output in SQL using json_each()
-- (copy the output from above into the query)

See Also

  • Check the relevant SQL skill first (disassembly, decompiler, types, data, xrefs, annotations, debugger) — fall through to IDAPython only when no SQL surface exists for the task.
  • functions — the SQL function catalog; verify a scalar/helper doesn't already exist before scripting.

Tệp đi kèm

Mô hình đọc các tệp này khi cần trong lúc kỹ năng được tải. Các tệp được cung cấp ở dạng có thể đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Idapython làm được gì?

Execute IDAPython via idasql, and query idasql from IDAPython with import idasql. Use when SQL surfaces are insufficient and direct IDA SDK access is needed via Python snippets or scripts, or when a script or plugin inside IDA needs SQL over the open database.

Vì sao nên dùng Idapython trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Idapython là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Idapython trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/allthingsida/idasql-skills/tree/main/plugins/idasql/skills/idapython. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Idapython?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Idapython với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Idapython với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Idapython có miễn phí không?

Kỹ năng này được allthingsida phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇