import pygrap
pattern = """
digraph getprocaddress_resolve {
"1" [cond="opcode is 'push'", getid="push1"]
"2" [cond="opcode is 'push' and arg1 is 'esi'", getid="push2"]
"3" [cond="opcode is 'call' and arg1 is 'edi'", getid="call"]
"4" [cond="opcode is 'mov' and arg2 is 'eax'", getid="mov"]
"1" -> "2" [childnumber=1]
"2" -> "3" [childnumber=1]
"3" -> "4" [childnumber=1]
}
"""
matches = pygrap.ida_match(pattern, print_matches=False)
if "getprocaddress_resolve" in matches:
for m in matches["getprocaddress_resolve"]:
push1_arg_str = m["push1"][0].info.arg1
push1_arg_int = pygrap.parse_first_immediate(push1_arg_str)
func_name = get_strlit_contents(push1_arg_int)
mov_arg1 = m["mov"][0].info.arg1
var_addr = pygrap.parse_first_indirect(mov_arg1)
MakeName(var_addr, func_name)
print "Function", func_name, "imported to", hex(var_addr), "- variable renamed."