def get_ea(): while True: ea = yaunit.get_next_function() for eai in idautils.FuncItems(ea): flags = idaapi.get_flags_novalue(eai) if idaapi.isNum1(flags) and not idaapi.isEnum(flags, 1): return eai
def yatest_reference_views(self): addr = yaunit.get_next_function() f = idaapi.get_flags_novalue(addr) while not idaapi.isNum1(f) and not idaapi.isOff(f, 1): addr += idc.ItemSize(addr) f = idaapi.get_flags_novalue(addr) self.assertTrue(idaapi.set_offset(addr, self.operand, self.reference_addr)) yaunit.save('reference_view_addr', addr)
def get_function_sid_without_del(self, in_stack, local_size=1, count_from_first_var=False): if not in_stack: return 'create_struct_complex', idc.AddStrucEx(0, 'create_struct_complex', 0) ea = yaunit.get_next_function(lambda ea : yaunit.has_locals(ea, local_size, count_from_first_var)) frame = idaapi.get_frame(ea) self.assertNotEqual(frame, None) offset = idc.GetFirstMember(frame.id) return ea, frame.id
def find_operand_addr(self): while True: addr = yaunit.get_next_function() self.assertNotEqual(addr, idaapi.BADADDR) for ea in idautils.FuncItems(addr): flags = idaapi.get_flags_novalue(ea) if idaapi.isNum1(flags): return ea
def yatest_bookmarks(self): logger.info("yatest_bookmarks") addrs = [] for i in range(0, 3): addr = yaunit.get_next_function() logger.info("yatest_bookmarks:0x%08X : %d", addr, i) idc.MarkPosition(addr, 1, 1, 1, i+1, 'bookmark_%d' % i) addrs.append(addr) yaunit.save('bookmarks', addrs)
def get_address_for_operand(self, offset, op): def has_reg_item(ea): items = list(idautils.FuncItems(ea)) if offset >= len(items): return False return idc.GetOpType(items[offset], op) == idc.o_reg ea = yaunit.get_next_function(has_reg_item) return list(idautils.FuncItems(ea))[offset]
def yatest_function_flags(self): addrs = [] for i, k in enumerate(flag_types): addr = yaunit.get_next_function() flags = idc.GetFunctionFlags(addr) self.assertNotEqual(flags, -1) self.assertEqual(idc.SetFunctionFlags(addr, flags | k), 1) addrs.append(addr) yaunit.save('function_flags', addrs)
def get_func_item(offset): def get_item_(ea): items = list(idautils.FuncItems(ea)) return offset < len(items) predicate = get_item_ if offset else None ea = yaunit.get_next_function(predicate) if not offset: return ea return list(idautils.FuncItems(ea))[offset]
def yatest_function_local_vars(self): addr = yaunit.get_next_function(yaunit.has_locals) frame = idaapi.get_frame(addr) offset = 0 frame_size = idaapi.get_struc_size(frame.id) while offset < frame_size: if idc.SetMemberName(frame.id, offset, 'local_var'): break offset += 1 yaunit.save('function_with_local_vars', addr)
def yatest_reference_views(self): eas = [] for (operand, is_num, reference) in tests: ea = yaunit.get_next_function() f = idaapi.get_flags_novalue(ea) while not is_num(f) and not idaapi.isOff(f, operand): ea += idc.ItemSize(ea) f = idaapi.get_flags_novalue(ea) self.assertTrue(idaapi.set_offset(ea, operand, reference)) eas.append(ea) yaunit.save('reference_views', eas)
def get_function_sid(self, in_stack, local_size=1): if not in_stack: return 'create_struct_complex', idc.AddStrucEx(0, 'create_struct_complex', 0) ea = yaunit.get_next_function(lambda ea : yaunit.has_locals(ea, local_size)) frame = idaapi.get_frame(ea) self.assertNotEqual(frame, None) offset = idc.GetFirstMember(frame.id) while offset != idaapi.BADADDR: idc.DelStrucMember(frame.id, offset) offset = idc.GetFirstMember(frame.id) return ea, frame.id
def yatest_hiddenareas(self): logger.info("yatest_hiddenarea") addrs = [] for i in range(0, 3): addr = yaunit.get_next_function() logger.info("yatest_hiddenarea:0x%08X : %d", addr, i) ea2 = idaapi.nextaddr(addr) idaapi.add_hidden_area(addr, ea2, "yatest_hiddenarea_%x" % addr, "header", "footer", 0) addrs.append(addr) yaunit.save('hiddenarea', addrs)
def yatest_function_name(self): addr = yaunit.get_next_function() self.assertTrue( idc.MakeNameEx(addr, 'some_new_function_name', idc.SN_PUBLIC)) yaunit.save('function_name', addr)