我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用idc.MakeNameEx()。
def _rename_functions(self): '''Rename functions.''' print "IPL: Started to rename functions..." failed = 0 total = 0 for function in idautils.Functions(): total += 1 pdb_mangled_name = self.PDBLookup.lookup(function, True) if not pdb_mangled_name: failed += 1 print "IPL: Failed to find symbol for function: 0x{:08x}".format(function) continue _, mangled_function_name = pdb_mangled_name.split('!') # https://www.hex-rays.com/products/ida/support/idadoc/203.shtml idc.MakeNameEx(function, mangled_function_name, idc.SN_AUTO | idc.SN_NOCHECK) print "IPL: Total {} functions, {} failed to rename.".format(total, failed)
def sample_dest(): global src_data if src_data is None: print "run the src_data = ... first" return src_hashes = {} for i in src_data.split("|"): z = i.split(":") if len(z) < 2: continue if src_hashes.has_key(z[1]): src_hashes[z[1]] = "baadf00d" else: src_hashes[z[1]] = z[0] dst_hashes = {} for addr in idautils.Functions(idc.MinEA(),idc.MaxEA()): fname = idc.GetFunctionName(addr) z = calc_hash(addr) if dst_hashes.has_key(z): dst_hashes[z] = "baadf00d" else: dst_hashes[z] = addr c = 0 for tmp in dst_hashes: if dst_hashes[tmp] == "baadf00d": continue if src_hashes.has_key(tmp): if src_hashes[tmp] != "baadf00d": idc.MakeNameEx(dst_hashes[tmp],"SHARED_"+src_hashes[tmp], SN_NOWARN) c = c+1 print "%d subs have been renamed" % (c) return
def do_rename(l): splitted = l.split() straddr = splitted[0] strname = splitted[1].replace("\r", "").replace("\n", "") if straddr.find(":") != -1: #assuming form segment:offset #removing segment, offset should be unique, if it isn't so, we should handle it differently straddr = straddr.split(":")[1] eaaddr = int(straddr, 16) idc.MakeCode(eaaddr) idc.MakeFunction(eaaddr) idc.MakeNameEx(int(straddr, 16), strname, idc.SN_NOWARN)
def makeNameAndStructure(self, api, suffix=None): if suffix is not None: named = idc.MakeNameEx(api[0], str(api[3] + "_{}".format(suffix)), 256) else: named = idc.MakeNameEx(api[0], str(api[3]), 256) self.makeDQWord(api) return named
def loadmap(self): total = 0 count = 0 for line in self.sym_file: total+=1 sm = re.search("[\d]+:([\dA-F]+)[\s]+([\S]+)", line) if sm and not re.search("_([\dA-F]{8})", line): if idc.MakeNameEx(self.base + int(sm.group(1), 16), sm.group(2), idc.SN_NOCHECK | idc.SN_NOWARN) == 0: print "set symble name %s:%s failed" % (sm.group(1), sm.group(2)) continue count += 1 print "total %d applied %d symbols" % (total,count)
def make_name(addr, export_name): """ Appends a number if a given name exists """ ret = idc.MakeNameEx(addr, export_name, idc.SN_PUBLIC | idc.SN_NOWARN) i = 0 while ret == 0 and i < 1000: new_name = "%s_%d" % (export_name, i) ret = idc.MakeNameEx(addr, new_name, idc.SN_PUBLIC | idc.SN_NOWARN) i += 1 if ret == 0: print "[!] could not set name %s at 0x%X" % (export_name, addr)