#!/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 ' % 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)