Created
February 12, 2024 23:29
-
-
Save alexander-hanel/10264b06e73f19c68fd1f0b853a21513 to your computer and use it in GitHub Desktop.
A hackish way to extract arguments passed to a function from hex-rays decompiler output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import idautils | |
ea = 0x000000140013188 | |
name = ida_name.get_ea_name(ea) | |
print("found") | |
# get xrefs to function | |
xrefs = [x for x in idautils.CodeRefsTo(ea, 0)] | |
for func in xrefs: | |
args = [] | |
cfunc = idaapi.decompile(func) | |
sv = cfunc.get_pseudocode() | |
comment_len = ida_name.get_ea_name(func) | |
comment_flag = False | |
c = 1 | |
for index, sline in enumerate(sv): | |
tt = idaapi.tag_remove(sline.line) | |
if name in tt and comment_flag != True: | |
args.append(tt.rstrip().lstrip()) | |
comment_flag = True | |
continue | |
# print lines | |
if comment_flag: | |
if ";" in tt: | |
break | |
args.append(tt.rstrip().lstrip()) | |
print(hex(func), args) |
Hi @52617365, my version uses the hex-rays decompiler to extract the arguments. I always forget Hex-Rays API usage. Yes, your example will work but I would exercise caution when relying on idaapi.get_arg_addrs
to extract function arguments. It works well on 64-bit functions that use standard calling conventions but it can fail on other calling conventions or functions that don’t have their types defined. I have had to write a couple of backtracing functions to deal with idaapi.get_arg_addrs
failing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, this is how I get arguments passed into a function call.