def arm_guess_jump_table(mnemo, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool): ira = get_ira(mnemo, attrib) jra = ExprId('jra') jrb = ExprId('jrb') sp = asm_symbol_pool() ir_arch = ira(sp) ir_arch.add_bloc(cur_bloc) ir_blocs = ir_arch.blocs.values() for irb in ir_blocs: # print 'X'*40 # print irb pc_val = None # lr_val = None for exprs in irb.irs: for e in exprs: if e.dst == ir_arch.pc: pc_val = e.src # if e.dst == mnemo.regs.LR: # lr_val = e.src if pc_val is None: continue if not isinstance(pc_val, ExprMem): continue assert (pc_val.size == 32) print pc_val ad = pc_val.arg ad = expr_simp(ad) print ad res = MatchExpr(ad, jra + jrb, set([jra, jrb])) if res is False: raise NotImplementedError('not fully functional') print res if not isinstance(res[jrb], ExprInt): raise NotImplementedError('not fully functional') base_ad = int(res[jrb]) print base_ad addrs = set() i = -1 max_table_entry = 10000 max_diff_addr = 0x100000 # heuristic while i < max_table_entry: i += 1 try: ad = upck32(pool_bin.getbytes(base_ad + 4 * i, 4)) except: break if abs(ad - base_ad) > max_diff_addr: break addrs.add(ad) print[hex(x) for x in addrs] for ad in addrs: offsets_to_dis.add(ad) l = symbol_pool.getby_offset_create(ad) c = asm_constraint_to(l) cur_bloc.addto(c)
base_ad = int(res[jrb]) print base_ad addrs = set() i = -1 max_table_entry = 10000 max_diff_addr = 0x100000 # heuristic while i < max_table_entry: i += 1 try: ad = upck32(pool_bin.getbytes(base_ad + 4 * i, 4)) except: break if abs(ad - base_ad) > max_diff_addr: break addrs.add(ad) print [hex(x) for x in addrs] for ad in addrs: offsets_to_dis.add(ad) l = symbol_pool.getby_offset_create(ad) c = asm_constraint_to(l) cur_bloc.addto(c) guess_funcs = [] def guess_multi_cb( mnemo, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool): for f in guess_funcs: f(mnemo, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool)
blocks.add_node(my_block) assert len(blocks) == 3 assert blocks.label2block(first_block.label) == first_block assert blocks.label2block(my_block.label) == my_block ## Bad blocks assert len(list(blocks.get_bad_blocks())) == 0 assert len(list(blocks.get_bad_blocks_predecessors())) == 0 ### Add a bad block, not linked my_bad_block = asm_block_bad(asm_label("testlabel_bad")) blocks.add_node(my_bad_block) assert list(blocks.get_bad_blocks()) == [my_bad_block] assert len(list(blocks.get_bad_blocks_predecessors())) == 0 ### Link the bad block and update edges ### Indeed, a sub-element has been modified (bto from a block from blocks) my_block.bto.add(asm_constraint_to(my_bad_block.label)) blocks.rebuild_edges() assert list(blocks.get_bad_blocks_predecessors()) == [my_block] ### Test strict option my_block.bto.add(asm_constraint_to(my_block.label)) blocks.rebuild_edges() assert list(blocks.get_bad_blocks_predecessors(strict=False)) == [my_block] assert len(list(blocks.get_bad_blocks_predecessors(strict=True))) == 0 ## Sanity check blocks.sanity_check() ### Next on itself my_block_ni = asm_bloc(asm_label("testlabel_nextitself")) my_block_ni.bto.add(asm_constraint_next(my_block_ni.label)) blocks.add_node(my_block_ni) error_raised = False