Add basic binja viz plugin (#347)
* Add basic binja plugin * Inline lnk * Better instructions
This commit is contained in:
parent
e2c0414dca
commit
edbb613045
23
scripts/binaryninja/README.md
Normal file
23
scripts/binaryninja/README.md
Normal file
@ -0,0 +1,23 @@
|
||||
## Installation
|
||||
|
||||
- Symlink the desired plugin into the [plugin directory](https://github.com/Vector35/binaryninja-api/tree/dev/python/examples#loading-plugins)
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
$ ln -s $PWD/viz.py ~/Library/Application\ Support/Binary\ Ninja/plugins/
|
||||
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
- Run manticore on a binary
|
||||
- Open the binary in Binary Ninja
|
||||
- `import` it from the Binary Ninja Script Console, and call desired functions
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
>>> import viz
|
||||
>>> viz.viz(bv, '/mnt/hgfs/code/manticore/examples/linux/mcore_1vCAKM')
|
||||
```
|
||||
54
scripts/binaryninja/viz.py
Normal file
54
scripts/binaryninja/viz.py
Normal file
@ -0,0 +1,54 @@
|
||||
from binaryninja import *
|
||||
import os.path
|
||||
|
||||
blue = HighlightStandardColor.BlueHighlightColor
|
||||
black = HighlightStandardColor.BlackHighlightColor
|
||||
white = HighlightStandardColor.WhiteHighlightColor
|
||||
clear = HighlightStandardColor.NoHighlightColor
|
||||
|
||||
|
||||
MBASE = 0x0007fffffdb7000
|
||||
|
||||
|
||||
def viz(view, fname, base=0):
|
||||
"""
|
||||
Given a Manticore workspace, or trace file, highlight the basic blocks.
|
||||
"""
|
||||
fname = fname.replace('/mnt/hgfs', '~')
|
||||
fname = os.path.expanduser(fname)
|
||||
log_info('got: {}'.format(fname))
|
||||
if os.path.isdir(fname):
|
||||
for f in os.listdir(fname):
|
||||
if f.endswith('trace'):
|
||||
fullpath = os.path.join(fname, f)
|
||||
viz_trace(view, fullpath, base)
|
||||
else:
|
||||
viz_trace(view, fname, base)
|
||||
|
||||
|
||||
def viz_trace(view, fname, base=0):
|
||||
"""
|
||||
Given a Manticore trace file, highlight the basic blocks.
|
||||
"""
|
||||
with open(os.path.expanduser(fname)) as f:
|
||||
addrs = [int(x.strip(), 0) for x in f.readlines()]
|
||||
_viz_addrs(view, addrs, base, blue)
|
||||
|
||||
|
||||
def clear_all(view, fname, base=0):
|
||||
with open(os.path.expanduser(fname)) as f:
|
||||
addrs = [int(x.strip(), 0) for x in f.readlines()]
|
||||
_viz_addrs(view, addrs, base, white)
|
||||
|
||||
|
||||
def _viz_addrs(view, addrs, base, hl):
|
||||
for addr in addrs:
|
||||
if base:
|
||||
addr -= base
|
||||
_highlight_block(view, addr, hl)
|
||||
|
||||
def _highlight_block(view, addr, hl):
|
||||
blocks = view.get_basic_blocks_at(addr)
|
||||
for b in blocks:
|
||||
b.set_user_highlight(hl)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user