def renamed(self, ea, new_name, local_name): if LOG_IDP_EVENTS: self.debug_event("Renamed at 0x%08x with' %s'" % (ea, new_name)) if idaapi.is_member_id(ea): # this is a member id : hook already present (struc_member_renamed) pass elif idaapi.get_struc(ea) is not None: # this is a struc id : hook already present (struc_renamed) pass elif idaapi.get_enum_idx(ea) != idc.BADADDR: # this is an enum id : hook already present (enum_renamed) BUT NOT CALLED # (IDA BUG) hooks.idb.enum_renamed(ea) elif idaapi.get_enum_idx( idaapi.get_enum_member_enum(ea)) != idc.BADADDR: # this is an enum member id enum_id = idaapi.get_enum_member_enum(ea) hooks.idb.enum_member_renamed(enum_id, ea) else: self.pre_hook() # when we rename stackframe member, ea is member id # this case is supported by struc_member_renamed event try: old_name = hooks.current_rename_infos[ea] del hooks.current_rename_infos[ea] except KeyError: old_name = None hooks.ida.rename(ea, new_name, old_name=old_name) return hooks.idp.ev_rename(ea, new_name)
def list(**type): '''List all of the enumerations within the database that match the keyword specified by `type`.''' res = [item for item in iterate(**type)] maxindex = max(builtins.map(idaapi.get_enum_idx, res) if res else [1]) maxname = max( builtins.map(utils.fcompose(idaapi.get_enum_name, len), res ) if res else [0]) maxsize = max(builtins.map(size, res) if res else [0]) cindex = math.ceil(math.log(maxindex or 1) / math.log(10)) try: cmask = max( builtins.map( utils.fcompose( mask, utils.fcondition(utils.fpartial(operator.eq, 0)) (utils.fconstant(1), utils.fidentity), math. log, functools.partial(operator.mul, 1.0 / math.log(8)), math.ceil), res ) if res else [database.config.bits() / 4.0]) except: cmask = 0 for item in res: name = idaapi.get_enum_name(item) six.print_( u"[{:{:d}d}] {:>{:d}s} & {:<{:d}x} ({:d} members){:s}".format( idaapi.get_enum_idx(item), int(cindex), utils.string.of(name), maxname, mask(item), int(cmask), len(builtins.list(members(item))), u" // {:s}".format(comment(item)) if comment(item) else '')) return
def by(**type): """Search through all the enumerations within the database and return the first result. like = glob match regex = regular expression index = particular index identifier or id = internal id number """ searchstring = ', '.join("{:s}={!r}".format(k, v) for k, v in type.iteritems()) res = __builtin__.list(iterate(**type)) if len(res) > 1: map(logging.info, ("[{:d}] {:s} & {:#x} ({:d} members){:s}".format( idaapi.get_enum_idx(n), idaapi.get_enum_name(n), mask(n), len(__builtin__.list(members(n))), " // {:s}".format(comment(n)) if comment(n) else '') for i, n in enumerate(res))) logging.warn( "{:s}.search({:s}) : Found {:d} matching results, returning the first one." .format(__name__, searchstring, len(res))) res = next(iter(res), None) if res is None: raise LookupError( "{:s}.search({:s}) : Found 0 matching results.".format( __name__, searchstring)) return res
def list(**type): '''List all of the enumerations within the database that match the keyword specified by `type`.''' res = [item for item in iterate(**type)] maxindex = max(builtins.map(idaapi.get_enum_idx, res) if res else [1]) maxname = max( builtins.map(utils.fcompose(idaapi.get_enum_name, len), res ) if res else [0]) maxsize = max(builtins.map(size, res) if res else [0]) cindex = math.floor(1 + math.log(maxindex or 1) / math.log(10)) try: cmask = max(len("{:x}".format(mask(item))) for item in res) if res else database.config.bits() / 4.0 except Exception: cmask = 0 for item in res: name = idaapi.get_enum_name(item) six.print_( u"{:<{:d}s} {:>{:d}s} & {:<#{:d}x} ({:d} members){:s}".format( "[{:d}]".format(idaapi.get_enum_idx(item)), 2 + math.trunc(cindex), utils.string.of(name), maxname, mask(item), 2 + math.trunc(cmask), len(builtins.list(members(item))), u" // {:s}".format(comment(item)) if comment(item) else '')) return
def list(**type): """List all the enumerations within the database. Search type can be identified by providing a named argument. like = glob match regex = regular expression index = particular index identifier = particular id number pred = function predicate """ res = __builtin__.list(iterate(**type)) maxindex = max(__builtin__.map(idaapi.get_enum_idx, res)) maxname = max( __builtin__.map(utils.compose(idaapi.get_enum_name, len), res)) maxsize = max(__builtin__.map(size, res)) cindex = math.ceil(math.log(maxindex or 1) / math.log(10)) cmask = max( __builtin__.map( utils.compose(mask, math.log, functools.partial(operator.mul, 1.0 / math.log(16)), math.ceil), res) or [database.config.bits() / 4.0]) for n in res: print("[{:{:d}d}] {:>{:d}s} & {:#<{:d}x} ({:d} members){:s}".format( idaapi.get_enum_idx(n), int(cindex), idaapi.get_enum_name(n), maxname, mask(n), int(cmask), len(__builtin__.list(members(n))), " // {:s}".format(comment(n)) if comment(n) else '')) return
def rename(self, ea, new_name): """ This function only records information about the element *before* it is renamed """ if idaapi.is_member_id(ea): name = idaapi.get_member_fullname(ea) elif idaapi.get_struc(ea) is not None: name = idaapi.get_struc_name(ea) elif idaapi.get_enum_idx(ea) != idc.BADADDR: name = idaapi.get_enum_name(ea) elif idaapi.get_enum_idx(idaapi.get_enum_member_enum(ea)) != idc.BADADDR: # this is an enum member id enum_id = idaapi.get_enum_member_enum(ea) name = idaapi.get_enum_name(enum_id) + "." + idaapi.get_enum_member_name(ea) else: name = idc.Name(ea) hooks.current_rename_infos[ea] = name return 0
def by(**type): '''Return the identifier for the first enumeration matching the keyword specified by `type`.''' searchstring = utils.string.kwargs(type) res = builtins.list(iterate(**type)) if len(res) > 1: map(logging.info, (u"[{:d}] {:s} & {:#x} ({:d} members){:s}".format(idaapi.get_enum_idx(n), idaapi.get_enum_name(n), mask(n), len(builtins.list(members(n))), u" // {:s}".format(comment(n)) if comment(n) else '') for i,n in enumerate(res))) logging.warn(u"{:s}.search({:s}) : Found {:d} matching results. Returning the first enumeration {:#x}.".format(__name__, searchstring, len(res), res[0])) res = next(iter(res), None) if res is None: raise E.SearchResultsError(u"{:s}.search({:s}) : Found 0 matching results.".format(__name__, searchstring)) return res
def list(**type): '''List all of the enumerations within the database that match the keyword specified by `type`.''' res = builtins.list(iterate(**type)) maxindex = max(builtins.map(idaapi.get_enum_idx, res) or [1]) maxname = max(builtins.map(utils.fcompose(idaapi.get_enum_name, len), res) or [0]) maxsize = max(builtins.map(size, res) or [0]) cindex = math.ceil(math.log(maxindex or 1)/math.log(10)) try: cmask = max(builtins.map(utils.fcompose(mask, utils.fcondition(utils.fpartial(operator.eq, 0))(utils.fconstant(1), utils.fidentity), math.log, functools.partial(operator.mul, 1.0/math.log(8)), math.ceil), res) or [database.config.bits()/4.0]) except: cmask = 0 for n in res: name = idaapi.get_enum_name(n) six.print_(u"[{:{:d}d}] {:>{:d}s} & {:<{:d}x} ({:d} members){:s}".format(idaapi.get_enum_idx(n), int(cindex), utils.string.of(name), maxname, mask(n), int(cmask), len(builtins.list(members(n))), u" // {:s}".format(comment(n)) if comment(n) else '')) return
def by(**type): '''Return the identifier for the first enumeration matching the keyword specified by `type`.''' searchstring = utils.string.kwargs(type) listable = [item for item in iterate(**type)] if len(listable) > 1: messages = (u"[{:d}] {:s} & {:#x} ({:d} members){:s}".format( idaapi.get_enum_idx(item), idaapi.get_enum_name(item), mask(item), len(builtins.list(members(item))), u" // {:s}".format(comment(item)) if comment(item) else '') for i, item in enumerate(listable)) [logging.info(msg) for msg in messages] logging.warning( u"{:s}.search({:s}) : Found {:d} matching results. Returning the first enumeration {:#x}." .format(__name__, searchstring, len(listable), listable[0])) iterable = (item for item in listable) res = next(iterable, None) if res is None: raise E.SearchResultsError( u"{:s}.search({:s}) : Found 0 matching results.".format( __name__, searchstring)) return res
def gather_enum_info(ea, n): id = idaapi.get_enum_id(ea, n)[0] serial = idaapi.get_enum_idx(id) return id, serial