Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## This script helps with renaming functions
- ## See the following link for more info
- ## Created by alexander.hanel@gmail.com
- from idaapi import *
- import idautils
- import idc
- import sys
- imports_list = []
- # The following two functions are used to get the import API names.
- # ret_list_of_imports() returns the api names in a list
- def imp_cb(ea, name, ord):
- global imports_list
- if not name:
- pass
- else:
- imports_list.append(name)
- return True
- def ret_list_of_imports():
- global imports_list
- nimps = idaapi.get_import_module_qty()
- for i in xrange(0,nimps):
- name = idaapi.get_import_module_name(i)
- if not name:
- pass
- idaapi.enum_import_names(i, imp_cb)
- return imports_list
- def graph_down(ea, graph = {}, path = set([])):
- # This function was borrowed from Carlos G. Prado. Check out his Milf-Plugin for IDA on Google Code.
- graph[ea] = list() # Create a new entry on the graph dictionary {node: [child1, child2, ...], ...}
- path.add(ea) # This is a set, therefore the add() method
- # Iterate through all function instructions and take only call instructions
- for x in [x for x in FuncItems(ea) if is_call_insn(x)]: # Take the call elements
- for xref in XrefsFrom(x, XREF_FAR):
- if not xref.iscode:
- continue
- if xref.to not in path: # Eliminates recursions
- graph[ea].append(xref.to)
- graph_down(xref.to, graph, path)
- return path
- def main():
- # Get function name as input.
- func_name = LocByName(AskStr("sub_0xxxxx", "Enter Function Name"))
- if func_name == 0xffffffff:
- Warning("[ERROR] Bad Function Name [ERROR]")
- return
- tag = AskStr("string", "Function Tag")
- if tag == None:
- Warning("[ERROR] Tag cannot be None [ERROR]")
- return
- list_imports = ret_list_of_imports()
- # graph down needs the address of the function passed.
- nodes_xref_down = graph_down(func_name,graph = {}, path = set([]))
- # graph_down returns the int address needs to be converted
- tmp = []
- tmp1 = ''
- for func in nodes_xref_down:
- tmp1 = GetFunctionName(func)
- if tmp1 != '':
- tmp.append(tmp1)
- nodes_xref_down = tmp
- # Remove the APIs from the xref list
- for xx in set(list_imports).intersection(set(nodes_xref_down)):
- nodes_xref_down.remove(xx)
- for rename in nodes_xref_down:
- func_addr = LocByName(rename)
- if tag not in rename:
- MakeNameEx(func_addr, str(tag) + str('_') + rename, SN_NOWARN)
- =============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement