Agent Skillsbuzzer-re/Rikugan › Smart Patch (Binary Ninja)

Smart Patch (Binary Ninja)

GitHub

基于自然语言在 Binary Ninja 中精准修补二进制代码。流程涵盖读取反汇编、识别指令、备份原字节、规划最小化补丁(含 NOP 填充)、执行写入及反编译验证,确保修改安全且符合预期。

rikugan/skills/builtins/smart-patch-binja/SKILL.md buzzer-re/Rikugan

Trigger Scenarios

用户请求修改二进制文件中的特定行为或逻辑 需要绕过安全检查或修复漏洞的二进制补丁操作 调用 /modify 命令进行逆向工程任务

Install

npx skills add buzzer-re/Rikugan --skill Smart Patch (Binary Ninja) -g -y
More Options

Non-standard path

npx skills add https://github.com/buzzer-re/Rikugan/tree/main/rikugan/skills/builtins/smart-patch-binja -g -y

Use without installing

npx skills use buzzer-re/Rikugan@Smart Patch (Binary Ninja)

指定 Agent (Claude Code)

npx skills add buzzer-re/Rikugan --skill Smart Patch (Binary Ninja) -a claude-code -g -y

安装 repo 全部 skill

npx skills add buzzer-re/Rikugan --all -g -y

预览 repo 内 skill

npx skills add buzzer-re/Rikugan --list

SKILL.md

Frontmatter
{
    "name": "Smart Patch (Binary Ninja)",
    "tags": [
        "patching",
        "assembly",
        "binary",
        "binja"
    ],
    "author": "Rikugan",
    "version": 2,
    "description": "Patch binary code in Binary Ninja using natural language — read, assemble, write, verify",
    "allowed_tools": [
        "read_disassembly",
        "read_function_disassembly",
        "get_instruction_info",
        "decompile_function",
        "get_il",
        "read_bytes",
        "execute_python",
        "redecompile_function",
        "nop_instructions",
        "set_comment",
        "exploration_report"
    ]
}

Task: Apply targeted binary patches in Binary Ninja based on the user's natural language description. Analyze the function, identify the minimal set of instructions to change, assemble new instructions, write them, and verify the result.

Workflow

  1. Read the target function's disassembly (read_function_disassembly) and decompiled pseudocode / get_il at HLIL level to understand its current behavior.

  2. Identify which specific instructions implement the behavior the user wants to change. Use get_instruction_info to get exact byte sizes and encodings for the target instructions.

  3. Back up the original bytes before patching. Use read_bytes at the target address for the instruction length, and print them so the user has a record:

    Original bytes at 0x{addr:x}: {hex_bytes}
    
  4. Plan the minimal patch:

    • Determine what new instruction(s) achieve the desired behavior.
    • Ensure the new instructions fit within the original byte boundaries.
    • If new instructions are shorter, the remaining bytes MUST be filled with NOPs.
    • Verify branch targets and relative offsets are correct for the patch address.
  5. Patch using execute_python with Binary Ninja's assembler and writer:

    # Assemble new instruction at the correct address
    new_bytes = bv.arch.assemble("jg 0x401300", 0x401248)
    original_size = 6  # from get_instruction_info
    
    # NOP padding if shorter
    if len(new_bytes) < original_size:
        nop = bv.arch.assemble("nop", 0)
        new_bytes += nop * (original_size - len(new_bytes))
    
    bv.write(0x401248, new_bytes)
    bv.update_analysis_and_wait()
    print(f"Patched {len(new_bytes)} bytes at 0x401248")
    
  6. Verify with redecompile_function — confirm the HLIL output reflects the desired behavior change. If it doesn't match, revert by writing back the original bytes and try a different approach.

  7. Report — If called from /modify, you MUST call:

    exploration_report(category="patch_result", address=..., summary="Patched X: old → new", original_hex="...", new_hex="...", evidence="redecompile confirms...")
    
  8. Annotate each patched address with set_comment explaining what was changed and why.

Safety Rules

  • In-memory only. bv.write() modifies the in-memory BinaryView immediately. The .bndb file is only updated when the user does: File → Save or File → Save As.
  • When called from /modify, do NOT call bv.save() — the Phase 4 save gate handles this.
  • Never exceed original boundaries. New instructions must not be larger than the instructions they replace.
  • NOP padding is mandatory. If new instructions are shorter, fill remaining bytes with NOPs.
  • Always back up first. Print original bytes before writing any patch.
  • Always verify after. Redecompile and confirm the change matches the user's intent.
  • Revert on failure. If verification shows the patch didn't work: bv.write(addr, original_bytes) then bv.update_analysis_and_wait().
  • Minimal changes only. Patch the fewest bytes possible.

NOP via IL

For single-instruction NOPs, prefer nop_instructions — it patches at the IL layer and triggers re-analysis. This is safer than execute_python for simple NOP operations because it handles alignment automatically.

Common Patch Patterns

Changing a conditional branch

Replace jl with jg, je with jne, etc. Same instruction size, just a different opcode byte.

Inverting a condition

Change test eax, eax + je to test eax, eax + jne, or patch the comparison operand.

Forcing a branch (always/never taken)

Replace conditional jump with jmp (always) or NOP out the jump (never).

Changing an immediate operand

Reassemble the instruction with a new immediate value, e.g., cmp eax, 0xacmp eax, 0x14.

Removing a check entirely

NOP out the comparison and conditional jump instructions using nop_instructions.

Version History

  • ee3951d Current 2026-07-25 11:01

Same Skill Collection

rikugan/skills/builtins/binja-scripting/SKILL.md
rikugan/skills/builtins/ctf/SKILL.md
rikugan/skills/builtins/deobfuscation/SKILL.md
rikugan/skills/builtins/driver-analysis/SKILL.md
rikugan/skills/builtins/generic-re/SKILL.md
rikugan/skills/builtins/ida-scripting/SKILL.md
rikugan/skills/builtins/linux-malware/SKILL.md
rikugan/skills/builtins/malware-analysis/SKILL.md
rikugan/skills/builtins/modify/SKILL.md
rikugan/skills/builtins/smart-patch-ida/SKILL.md
rikugan/skills/builtins/vuln-audit/SKILL.md

Metadata

Files
0
Version
ee3951d
Hash
fd2ce12a
Indexed
2026-07-25 11:01

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-22 03:51
浙ICP备14020137号-1 $mapa de visitantes$