def add_enum(name=None, index=None, flags=idaapi.hex_flag(), bitfield=False): """Create a new enum. Args: name: Name of the enum to create. index: The index of the enum. Leave at default to append the enum as the last enum. flags: Enum type flags. bitfield: Is the enum a bitfield. Returns: An `Enum` object. """ if name is not None: with suppress(exceptions.EnumNotFound): _get_enum(name) raise exceptions.EnumAlreadyExists() if index is None or index < 0: index = idaapi.get_enum_qty() eid = idaapi.add_enum(index, name, flags) if eid == idaapi.BADADDR: raise exceptions.EnumCreationFailed( 'Failed creating enum "{}"'.format(name)) if bitfield: idaapi.set_enum_bf(eid, bitfield) return Enum(eid=eid)
def add_enum(name=None, index=None, flags=idaapi.hexflag(), bitfield=False): """Create a new enum. Args: name: Name of the enum to create. index: The index of the enum. Leave at default to append the enum as the last enum. flags: Enum type flags. bitfield: Is the enum a bitfield. Returns: An `Enum` object. """ if name is not None: with ignored(exceptions.EnumNotFound): _get_enum(name) raise exceptions.EnumAlreadyExists() if index is None or index < 0: index = idaapi.get_enum_qty() eid = idaapi.add_enum(index, name, flags) if eid == idaapi.BADADDR: raise exceptions.EnumCreationFailed('Failed creating enum "{}"'.format(name)) if bitfield: idaapi.set_enum_bf(eid, bitfield) return Enum(eid=eid)
def createEnum(self, enum): eid = idc.add_enum(-1, enum[0], 0x1100000) #what is this flag? idaapi.set_enum_bf(eid, 1) val = 0 mask = 0x1f idaapi.set_enum_width(eid, 1) for i in enum[1]: idc.add_enum_member(eid, i, val, mask) val += 1
def add_enum(name=None, index=idaapi.BADADDR, flags=idaapi.hexflag(), bitfield=False): """Create a new enum.""" if name is not None: with ignored(exceptions.EnumNotFound): _get_enum(name) raise exceptions.EnumAlreadyExists() eid = idaapi.add_enum(index, name, flags) if eid == idaapi.BADADDR: raise exceptions.EnumCreationFailed('Failed creating enum "{}"'.format(name)) if bitfield: idaapi.set_enum_bf(eid, bitfield) return Enum(eid=eid)
def make_enum(self, object_version, address): enum_name = object_version.get_name() object_id = object_version.get_id() # build flags bitfield = False flags = object_version.get_object_flags() if flags & 0x1 == 0x1: bitfield = True flags = flags & ~0x1 try: enum_width = object_version.get_size() except KeyError: enum_width = None # check if enum already exists enum_id = idc.GetEnum(enum_name) enum_xrefs_ids = object_version.get_xrefed_ids() logger.debug( "%s:%d : Check here that enum_xrefs_ids is a set(YaToolObjectId) and correctly used" % (__file__, inspect.currentframe().f_lineno)) if enum_id != idc.BADADDR: # enum already exists, deleting all members for (const_id, const_value, bmask) in YaToolIDATools.enum_member_iterate_all(enum_id): if bmask == idc.BADADDR: bmask = -1 const_name = idc.GetConstName(const_id) if (enum_name, const_name, const_value) not in self.enum_member_ids: idc.DelConstEx(enum_id, const_value, 0, bmask) elif self.hash_provider.get_enum_member_id( enum_id, enum_name, const_id, const_name, const_value) not in enum_xrefs_ids: logger.debug("deleting not found constant : %s/%s" % (enum_name, const_name)) idc.DelConstEx(enum_id, const_value, 0, bmask) """ if the enum "bitfield" state has changed : change it! We can't access the functions """ if idc.IsBitfield(enum_id) != bitfield: idaapi.set_enum_bf(enum_id, bitfield) else: # create enum # SetEnumFlag return "'module' object has no attribute 'set_enum_flag'". enum_id = idc.AddEnum(address, enum_name, flags) if enum_width is not None: idc.SetEnumWidth(enum_id, enum_width) if bitfield: idc.SetEnumBf(enum_id, 1) # process comment try: repeatable_headercomment = self.sanitize_comment_to_ascii( object_version.get_header_comment(True)) idc.SetEnumCmt(enum_id, repeatable_headercomment, 1) except KeyError: pass try: nonrepeatable_headercomment = self.sanitize_comment_to_ascii( object_version.get_header_comment(False)) idc.SetEnumCmt(enum_id, nonrepeatable_headercomment, 0) except KeyError: pass self.enum_ids[object_id] = enum_id self.hash_provider.put_hash_struc_or_enum(enum_id, object_id) logger.debug("adding enum id %s : '0x%.016X'" % (self.hash_provider.hash_to_string(object_id), enum_id))
def bitfield(self, value): success = idaapi.set_enum_bf(self.eid, value) if not success: raise exceptions.CantSetEnumBitfield()