diff options
| author | Rusty Wagner <rusty@vector35.com> | 2016-05-17 23:35:52 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2016-05-17 23:36:33 -0400 |
| commit | 3c9ce9e4b3a3e31df64924df0117e7360afb7a46 (patch) | |
| tree | 643aefabc42b567eaa567983ca2fd7a9a3a4735e /python/examples | |
| parent | cef6e55ba5aa55bfd2e168df7ac0e477e8dceffc (diff) | |
| parent | 399568bbb0c88b2aa3919ac3552483a9dd8f01ab (diff) | |
Merge branch 'iterators' of https://github.com/withzombies/binaryninja-api into dev
Diffstat (limited to 'python/examples')
| -rw-r--r-- | python/examples/instruction-iterator.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/python/examples/instruction-iterator.py b/python/examples/instruction-iterator.py new file mode 100644 index 00000000..7b03b095 --- /dev/null +++ b/python/examples/instruction-iterator.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import sys +try: + import binaryninja +except ImportError: + sys.path.append("/Applications/Binary Ninja.app/Contents/Resources/python/") + import binaryninja +import time + +if sys.platform.lower().startswith("linux"): + bintype="ELF" +elif sys.platform.lower() == "darwin": + bintype="Mach-O" +else: + raise Exception, "%s is not supported on this plugin" % sys.platform + +if len(sys.argv) > 1: + target = sys.argv[1] +else: + target = "/bin/ls" + +bv = binaryninja.BinaryViewType[bintype].open(target) +bv.update_analysis() + +"""Until update_analysis_and_wait is complete, sleep is necessary as the analysis is multi-threaded.""" +time.sleep(1) + +print "-------- %s --------" % target +print "START: 0x%x" % bv.start +print "ENTRY: 0x%x" % bv.entry_point +print "ARCH: %s" % bv.arch.name +print "\n-------- Function List --------" + +""" print all the functions, their basic blocks, and their il instructions """ +for func in bv.functions: + print repr(func) + for block in func.low_level_il: + print "\t{0}".format(block) + + for insn in block: + print "\t\t{0}".format(insn) + + +""" print all the functions, their basic blocks, and their mc instructions """ +for func in bv.functions: + print repr(func) + for block in func: + print "\t{0}".format(block) + + for insn in block: + print "\t\t{0}".format(insn) |
