def di(bin_s): ''' Disassemble some x86 assembly di(\x90A\x90) ''' bin = hexa_representation_to_bytes(bin_s) if bin == None: return 'An error occured' job_done, symbol_pool = set(), asmbloc.asm_symbol_pool() all_bloc = asmbloc.dis_bloc_all(x86_mn, bin_stream(bin), 0, job_done, symbol_pool) disassembly_dic = {} for i in all_bloc: for b in i.lines: # hmm ok, re-order the different instruction from each blocs disassembly_dic[b.offset] = b disass, offset = '', 0 for k in sorted(disassembly_dic.keys()): # add the label for the different blocs ; except for the main label if symbol_pool.getby_offset(k) and k != 0: disass += '%s: ' % symbol_pool.getby_offset(k).name disass += '%s ; ' % clean_assembly(str(disassembly_dic[k])) if disass == '': return 'No disassembly found.' return disass
def create_symbol_pool(self): dll_dyn_funcs = get_import_address_elf(self.E) self.symbol_pool = asmbloc.asm_symbol_pool() for (n, f), ads in list(dll_dyn_funcs.items()): for ad in ads: l = self.symbol_pool.getby_name_create("%s_%s" % (n, f)) l.offset = ad self.symbol_pool.s_offset[l.offset] = l
def create_symbol_pool(self): dll_dyn_funcs = get_import_address_elf(self.E) self.symbol_pool = asmbloc.asm_symbol_pool() for (n,f), ads in dll_dyn_funcs.items(): for ad in ads: l = self.symbol_pool.getby_name_create("%s_%s"%(n, f)) l.offset = ad self.symbol_pool.s_offset[l.offset] = l
def __disassembleMiasm(self, data, address, mn, dll_dyn_funcs): in_str = bin_stream(data) job_done = set() symbol_pool = asmbloc.asm_symbol_pool() for (n,f), ads in dll_dyn_funcs.items(): for ad in ads: l = symbol_pool.getby_name_create("%s_%s"%(n, f)) l.offset = ad symbol_pool.s_offset[l.offset] = l all_bloc = asmbloc.dis_bloc_all(mn, in_str, address, job_done, symbol_pool, follow_call = True, lines_wd = 60) lines = [] for bloc in all_bloc: lines.append(str(bloc)) return ('\n'.join(lines))