diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-04-30 13:44:56 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-04-30 13:44:56 (GMT) |
commit | cf981a295153f12efdbe50d7bef54f13385d443c (patch) | |
tree | 6a4a2e9ab4d4e0548cf8d687c6d50fdfede2590b /python/ins_collect.py |
Provided some initial samples of Python bindings usage.
Diffstat (limited to 'python/ins_collect.py')
-rw-r--r-- | python/ins_collect.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/python/ins_collect.py b/python/ins_collect.py new file mode 100644 index 0000000..f48a49e --- /dev/null +++ b/python/ins_collect.py @@ -0,0 +1,80 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import sys +import pychrysalide +from pychrysalide.analysis.contents import FileContent +from pychrysalide.format.elf import ElfFormat +from pychrysalide.analysis import LoadedBinary + + +if len(sys.argv) != 2: + print('Usage: %s <elf binary>' % sys.argv[0]) + sys.exit(1) + + +# Load the provided binary + +cnt = FileContent(sys.argv[1]) + +fmt = ElfFormat(cnt) + +binary = LoadedBinary(fmt) + +binary.analyze_and_wait() + + +# Compute some stats + +ins_count = 0 + +opsize_0 = 0 +opsize_1 = 0 + +srcsz_0 = 0 +srcsz_1 = 0 + +destsz_0 = 0 +destsz_1 = 0 + +for ins in binary.processor.instrs: + + ins_count += 1 + + size = len(ins.operands) + + if size == 0: + opsize_0 += 1 + + elif size == 1: + opsize_1 += 1 + + size = len(ins.sources) + + if size == 0: + srcsz_0 += 1 + + elif size == 1: + srcsz_1 += 1 + + size = len(ins.destinations) + + if size == 0: + destsz_0 += 1 + + elif size == 1: + destsz_1 += 1 + + +# Display the results + +print('=== Collected %d instructions ===' % ins_count) + +print('No operand: %u' % opsize_0) +print('One operand: %u' % opsize_1) + +print('No source: %u' % srcsz_0) +print('One source: %u' % srcsz_1) + +print('No destination: %u' % destsz_0) +print('One destination: %u' % destsz_1) |