From edbb6130459b993e04ffc534c5f9829271d861e3 Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Fri, 23 Jun 2017 18:18:11 -0400 Subject: [PATCH] Add basic binja viz plugin (#347) * Add basic binja plugin * Inline lnk * Better instructions --- scripts/binaryninja/README.md | 23 +++++++++++++++ scripts/binaryninja/viz.py | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 scripts/binaryninja/README.md create mode 100644 scripts/binaryninja/viz.py diff --git a/scripts/binaryninja/README.md b/scripts/binaryninja/README.md new file mode 100644 index 0000000..97f8086 --- /dev/null +++ b/scripts/binaryninja/README.md @@ -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') +``` diff --git a/scripts/binaryninja/viz.py b/scripts/binaryninja/viz.py new file mode 100644 index 0000000..3d7ffe1 --- /dev/null +++ b/scripts/binaryninja/viz.py @@ -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) +