Skip to content

P1: Code/data repair (define function|code|data, undefine)#209

Closed
mahaloz wants to merge 1 commit into
feat/cli-searchfrom
feat/cli-define-undefine
Closed

P1: Code/data repair (define function|code|data, undefine)#209
mahaloz wants to merge 1 commit into
feat/cli-searchfrom
feat/cli-define-undefine

Conversation

@mahaloz

@mahaloz mahaloz commented Jul 17, 2026

Copy link
Copy Markdown
Member

What & why

Auto-analysis misses functions and mislabels code/data — routine on obfuscated or hand-written binaries. This adds the repair primitives IDALib exposes.

New capabilities

  • decompiler define function|code|data <addr> and decompiler undefine <addr>.
  • Interface define_function/define_code/define_data/undefine (base raises NotImplementedError) with per-backend implementations:
    Backend define function define code define data undefine
    IDA add_func create_insn create_data/SetType del_func+del_items
    Ghidra createFunction disassemble createData removeFunction+clearListing
    Binary Ninja create_user_function (via function) define_user_data_var remove_user_function
    angr
  • undefine removes a function if one starts at the address, then clears the requested span.

Example

$ decompiler undefine 0x664 --size 137     # clear authenticate
undefined: True
$ decompiler define code 0x664
$ decompiler define function 0x664          # re-create it
defined: function
success: True
$ decompiler define data 0x4040 --type int

Tests

test_undefine_and_define_function (round-trip: define function reporting success is the strong signal that undefine truly removed the function — add_func/createFunction only succeed when none is there) and test_define_data.

  • IDA: pass. Ghidra: pass. angr: asserts the unsupported (exit 2) path.

Note: list_functions uses the light-artifact path, which lags IDA's del_func by a query (while get_func is immediately consistent), so the test verifies via the define-success signal rather than the transient list state.


Sixth PR in the IDALib-parity series. Based on feat/cli-search (#208).

🤖 Generated with Claude Code

https://claude.ai/code/session_01HfZHdprXg38re1XyKxzGg5

Important for obfuscated binaries and incorrect auto-analysis.

- New `decompiler define function|code|data` and `decompiler undefine`.
- Interface define_function/define_code/define_data/undefine (base raises
  NotImplementedError) with per-backend implementations:
  - IDA: ida_funcs.add_func/del_func, idc.create_insn, ida_bytes
    create_data/del_items.
  - Ghidra: FlatProgramAPI.createFunction/disassemble/createData +
    FunctionManager.removeFunction + clearListing (transactional).
  - Binary Ninja: create_user_function/remove_user_function/
    define_user_data_var (best-effort).
  - angr: unsupported (CFG-based; no define/undefine primitives).
- undefine removes a function if one starts at the address, then clears
  the requested span.
- Client proxies + tests: undefine->define round-trip on a real function
  (define reporting success proves undefine removed it) and define data.
  IDA + Ghidra full pass; angr asserts the unsupported (exit 2) path.
- SKILL.md / docs updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HfZHdprXg38re1XyKxzGg5
@mahaloz

mahaloz commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Integrated into main as commit 99f15a7. The stack got tangled when the bottom PRs (#204/#205) were squash-merged (#205 landed on feat/cli-persistence instead of main), so I reconciled by cherry-picking the whole series onto main linearly. The exact reviewed content of this PR is on main — closing this stacked PR as its changes are shipped.

@mahaloz
mahaloz deleted the feat/cli-define-undefine branch July 17, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant