smart-patch-binja
Skill715 starsChanged 5 days agoMITView on GitHub
Patch binary code in Binary Ninja using natural language — read, assemble, write, verify
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- llms.txtllms.txt
- webpage/llms.txtllms.txt
- binja-scriptingSkill
- ctfSkill
- deobfuscationSkill
- driver-analysisSkill
- generic-reSkill
- ida-scriptingSkill
- linux-malwareSkill
- malware-analysisSkill
- modifySkill
- smart-patch-idaSkill
- vuln-auditSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
Ensure the new instructions fit within the original byte boundaries.
- Distinctive: line 21
If new instructions are shorter, the remaining bytes MUST be filled with NOPs.
- Distinctive: line 22
Verify branch targets and relative offsets are correct for the patch address.
- Distinctive: line 54
NOP padding is mandatory: If new instructions are shorter, fill remaining bytes with NOPs.
- Very specific: line 57
Revert on failure: If verification shows the patch didn't work: bv.write(addr, original_bytes) then bv.update_analysis_and_wait().
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
- Read the target function's disassembly (
read_function_disassembly) and decompiled pseudocode /get_ilat HLIL level to understand its current behavior. - Identify which specific instructions implement the behavior the user wants to change. Use
get_instruction_infoto get exact byte sizes and encodings for the target instructions. - Back up the original bytes before patching. Use
read_bytesat the target address for the instruction length, and print them so the user has a record:Original bytes at 0x{addr:x}: {hex_bytes} - 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.
- Patch using
execute_pythonwith 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") - 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. - 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...") - Annotate each patched address with
set_commentexplaining what was changed and why.
Safety Rules
- In-memory only.
bv.write()modifies the in-memory BinaryView immediately. The.bndbfile 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)thenbv.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, 0xa → cmp eax, 0x14.
Removing a check entirely
NOP out the comparison and conditional jump instructions using nop_instructions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

