def dump(): ret = [] for struct_idx, struct_id, struct_name in idautils.Structs(): struct = ida_struct.get_struc(struct_id) members = [{'offset': offset, 'name': name, 'size': size} for offset, name, size in idautils.StructMembers(struct_id)] # Find all xrefs to any members of this struct. xrefs = [] for offset, name, size in idautils.StructMembers(struct_id): member = ida_struct.get_member_by_name(struct, name) if member is not None: for xref in idautils.XrefsTo(member.id): d = { 'from': xref.frm, 'type': xref.type, } # Get offset base if it's an offset xref. if xref.type == 1: d['offset'] = ida_offset.get_offbase(xref.frm, 1) xrefs.append(d) ret.append({ 'idx': struct_idx, 'name': struct_name, 'members': members, 'xrefs': xrefs, }) return ret
def structs(): _structs = {} for struct_item in idautils.Structs(): idx, sid, name = struct_item[:] sptr = ida_struct.get_struc(sid) size = ida_struct.get_struc_size(sptr) _structs[name] = Struct(name, size, {}) return _structs
def get_structs(): """Get structures from IDA database """ structs = {} for idx, sid, name in idautils.Structs(): struct = ida_struct.get_struc(sid) structs[name] = {} structs[name]["size"] = idc.GetStrucSize(sid) structs[name]["members"] = get_struct_members(struct, sid) return structs
def get_all_structures(): """ Returns a dictionary of {address -> (normal comment, repeated comment, anterior lines list, posterior lines list) }. """ structures = {} for _, sid, name in idautils.Structs(): struct = ida_struct.get_struc(sid) struct_def = psida_common.get_struct_def(struct.ordinal) structures[name] = struct_def return structures
def start_upload(self): log('upload_action').info("Data upload started") # TODO: Is this too slow? should we move this to perform_upload? or into a # generator? self.instances = set( (FunctionInstance, f) for f in idautils.Functions()) self.instances.add( (UniversalInstance, (s[0] for s in idautils.Structs()))) self.ui.increase_maximum(len(self.instances)) self.timer.timeout.connect(self.perform_upload) self.timer.start(0)
def get_structs(): """ Get structures from IDA database :return: Dict containing structure info """ structs = OrderedDict() for idx, sid, name in idautils.Structs(): struct = ida_struct.get_struc(sid) structs[name] = {} structs[name]['size'] = ida_struct.get_struc_size(struct) structs[name]['members'] = get_struct_members(struct, sid) return structs
def walk_struct_members(): for (idx, sid, name) in idautils.Structs(): s = idaapi.get_struc(sid) for (offset, name, size) in idautils.StructMembers(sid): m = idaapi.get_member(s, offset) yield m.id
def all_struct_members(): for struct in idautils.Structs(): print struct members = idautils.StructMembers(struct[1]) for member in members: yield struct[2], member[0], member[1], member[2]
while bmask != idaapi.BADADDR: for v, m in get_enums(bmask): yield v, m bmask = idc.GetNextBmask(eid, bmask) # iterate on regular constants for v, m in get_enums(-1): yield v, m for idx in range(0, idaapi.get_enum_qty()): num_enums += 1 eid = idaapi.getn_enum(idx) for (value, bmask) in walk_enum(eid): num_enum_members += 1 for (idx, sid, name) in idautils.Structs(): num_structs += 1 for (offset, name, size) in idautils.StructMembers(sid): num_struct_members += 1 print "blocks", num_blocks print "binaries", num_binaries print "codes", num_codes print "datas", num_datas print "enum_members", num_enum_members print "enums", num_enums print "functions", num_functions print "segment_chunks", num_segment_chunks print "segments", num_segments print "stackframe_members", num_stackframe_members print "stackframes", num_stackframes
def Structs(self): """All structures definitions in the IDB :type: [:class:`midap.struct.StructDef`]""" return [idastruct.StructDef(s[1]) for s in idautils.Structs()]