binsync / libbs

A library for writing plugins in any decompiler: includes API lifting, common data formatting, and GUI abstraction!
BSD 2-Clause "Simplified" License
71 stars 6 forks source link

Fix Ghidra Function Header Parameter Name and Typing for Stack Variables #36

Open Flipout50 opened 8 months ago

Flipout50 commented 8 months ago

https://github.com/binsync/libbs/blob/7928b24511eb82dd52f06fb1f9fc52e98bc2735a/libbs/decompilers/ghidra/interface.py#L355C32-L355C40

The code under this TODO currenty updates the parameter name and type if that parameter is being passed through a register. If you try to change the parameter for a stack var argument, like the second parameter of entry() in the fauxware test binary, the change will not go through. Below is some example libbs code that demonstrates the problem:

func_addr = deci.art_lifter.lift_addr(0x400580)
entry = deci.functions[func_addr]
func_args = entry.header.args
func_args[0].name = "new_name_1"
func_args[0].type = "int"
func_args[0].size = 4  
func_args[1].name = "new_name_2"
func_args[1].type = "double"
func_args[1].size = 8
deci.functions[func_addr] = entry
print(deci.functions[func_addr].header.args)
print(func_args)

When running the above with the DecompilerInterface connected to Ghidra with the fauxware binary loaded, you should see that the first parameter, the one passed by register, updates fine but the second one, a stack var, remains unchanged.