This guide will go through how to make a custom architecture plugin in binaryninja for an example arch `CoolVM`, used in Patriot CTF 2022.
Warning: Obsidian code snippets do not look to nice when lines are very wide. All the code can also be found on GitHub ([thisusernameistaken/coolvm_binja (github.com)](https://github.com/thisusernameistaken/coolvm_binja))
# What is a VM
What is a VM https://www.jmeiners.com/lc3-vm/#s0:0
# Plugin Layout
- binja-vm
- `__init__.py`
- This is the code that is run when binja loads the plugin
- [[__init__]]
- [coolvm_binja/__init__.py at master · thisusernameistaken/coolvm_binja (github.com)](https://github.com/thisusernameistaken/coolvm_binja/blob/master/__init__.py)
- `view.py`
- This is the "loader", it takes the VM code and maps into a virtual address space
- [[BinaryView]]
- [coolvm_binja/view.py at master · thisusernameistaken/coolvm_binja (github.com)](https://github.com/thisusernameistaken/coolvm_binja/blob/master/view.py)
- `arch.py`
- This is the definition of the custom architecture (ie. Endianness/registers/...)
- [[Architecture Plugin]]
- [coolvm_binja/arch.py at master · thisusernameistaken/coolvm_binja (github.com)](https://github.com/thisusernameistaken/coolvm_binja/blob/master/arch.py)
- `disassembler.py`
- This defines each instruction in the arch
- [[Disassembler]]
- [coolvm_binja/disassembler.py at master · thisusernameistaken/coolvm_binja (github.com)](https://github.com/thisusernameistaken/coolvm_binja/blob/master/disassembler.py)
- `lifter.py`
- This defines the actual actions each instruction does
- [[Lifter]]
- [coolvm_binja/lifter.py at master · thisusernameistaken/coolvm_binja (github.com)](https://github.com/thisusernameistaken/coolvm_binja/blob/master/lifter.py)
For the example challenge, `CoolVM` (https://github.com/MasonCompetitiveCyber/PatriotCTF2022-Public/tree/main/RE/cool_vm_1), We can also implement a [[Workflow]] which will help make the decompilation a little more readable. [coolvm_binja/workflow.py at master · thisusernameistaken/coolvm_binja (github.com)](https://github.com/thisusernameistaken/coolvm_binja/blob/master/workflow.py)