JusticeRage / Gepetto

IDA plugin which queries uses language models to speed up reverse-engineering
GNU General Public License v3.0
2.87k stars 263 forks source link

the rename button does not work #14

Closed mishatsht closed 1 year ago

JusticeRage commented 1 year ago

Please provide details for this bug. The rename button seems to be working for everyone else. Share any log message appearing in IDA's output window, or maybe the IDB in which the problem appears. Without any information, I will be unable to reproduce the bug and have no option but to close this issue.

JusticeRage commented 1 year ago

Closing due to lack of information.

FBLeee commented 1 year ago

可以增加下列代码即可修复

def rename_lvar(ea, src, dst):
    def make_unique_name(name, taken):
        if name not in taken:
            return name
        fmt = "%s_%%i" % name
        for i in range(3, 1024):
            tmpName = fmt % i
            if tmpName not in taken:
                return tmpName
        return "i_give_up"

    #  if you want to use an existing view:
    #      widget = ida_kernwin.find_widget('Pseudocode-Y')
    #      vu = ida_hexrays.get_widget_vdui(widget)
    func = idaapi.get_func(ea)
    if func:
        ea = func.start_ea
        vu = idaapi.open_pseudocode(ea, 0)
        names = [n.name for n in vu.cfunc.lvars]
        if dst in names:
            dst = make_unique_name(dst, names)
        lvars = [n for n in vu.cfunc.lvars if n.name == src]
        if len(lvars) == 1:
            print("renaming {} to {}".format(lvars[0].name, dst))
            vu.rename_lvar(lvars[0], dst, 1)
            # how to close the view without a widget object?
            #     idautils.close_pseudocode (nope)
            #     ida_kerwin.close_widget   (nope)
        else:
            print("couldn't find var {}".format(src))
JusticeRage commented 1 year ago

I appreciate the fix, but I still don't understand what the problem is... Could anyone clarify what the bug is and how to trigger it?

FBLeee commented 1 year ago

I appreciate the fix, but I still don't understand what the problem is... Could anyone clarify what the bug is and how to trigger it?

There is a problem with this code(line 200). The rename_lvar of ida_hexrays does not work. Is it caused by different IDA versions?

  for n in names:
         if ida_hexrays.rename_lvar(function_addr, n, names[n]):
             replaced.append(n)