I'm using ida 6.8 SDK and i have an problem with saving changed variables names,

I used many functions like set_reg_name(C++), setMemberName(in python), they change the name but not permanently, after pressing refresh , or reopening ida, the variables have old names.

What function is used when u press "N" Rename Iyvar, and were to get info on correct way of saving changed variable names ?

  • As far as I remember there was save_user_lvar_settings for hex rays variables in ida 6.8. I'd suggest to search this function on github - this will probably give you some examples.
    – w s
    Commented Apr 22, 2018 at 10:06
  • @ws seems a common problem ? the thing is that when i'm trying to use user_lvar_visitor_t ulv;( instead of old lvar_uservec_t lvinf; ) i get error that can't create example of abstract class . And i can't find any valid source, can u point me to correct sources ?
    – LighFusion
    Commented Apr 22, 2018 at 11:53
  • Unfortunately the only source I know about that should work is related to IDA 7.1 and resides here :github.com/IDArlingTeam/IDArling/blob/master/idarling/core/…
    – w s
    Commented Apr 22, 2018 at 12:55
  • @ws and that's for python ? i can't make lvinf = ida_hexrays.lvar_uservec_t() the same in C++ ; Also i have found this function - bool __fastcall hexapi rename_lvar(lvar_t *v, const char *name, bool is_user_name); in comments it says //This function permanently renames a local variable. , but how to access it ? i get error not found when i try to use it
    – LighFusion
    Commented Apr 22, 2018 at 13:06
  • @ws huh finnaly after 2 days of searching, thx to these github.com/REhints/HexRaysCodeXplorer/blob/… guys ! the solutions i to get pointer from pseudo code, and apply vu.rename_lvar(&lvars.at(i), "var_permaNamed", true); Ands thats it! it renames permamently, thanks anyway ,
    – LighFusion
    Commented Apr 22, 2018 at 13:45

3 Answers 3


Solution is very simple:

  1. get pointer to pseudoview

    vdui_t * vuu= open_pseudocode(func->startEA, 0);

  2. Get Pointer to variables

    lvars_t& lvars = *pFunction->get_lvars();

  3. Simply rename variable

    vuu->rename_lvar(&lvars.at(i), "permanamed", true);

last bool flag in rename_lvar func, operate if renaming is permanent or not .

p.s. Its kind'a bad solution as it require opening pseudo view, but i didn't find any other way to do it permanently , or similiar, working function that set's flag like in rename_lvar func .

  • I'm having difficulty getting this to work in Python. The function "vuu.rename_lvar" returns true, and I"m using lvars from cfunc.lvars or cfunc.get_lvars(). however, if I use the pop up from vuu.ui_rename_lvar it contains the name that I've attempted to rename it to! so something is happening. Commented Oct 21, 2019 at 16:35
  • figured it out, if you get your cfunc_t a different way (such as get_func(ea) then it doesn't work! must get it through the vuu object. Commented Oct 21, 2019 at 17:42

Excellent work @LighFusion and @bravosierra99. Since I ended up here after looking for the Python solution, I'll paste it for anybody else.

widget = ida_kernwin.find_widget('Pseudocode-Y') 
vu = ida_hexrays.get_widget_vdui(widget) 
vu.rename_lvar(vu.cfunc.lvars[2], "pModelInfo", 1)

@Igor Skochinsky -- I just think it would just be common decency to make source or documentation available regarding how the existing basic [context] menu functionality works, so people have something to build on. I can't count the number of times I've been unable to fully replicate some basic inbuilt menu option, watching scripts constantly fail when I can manually perform the operation and it works perfectly.

Here's a more complete example:

def rename_lvar(src, dst, ea):
    #  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)
        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)
            print("couldn't find var {}".format(src))

It's better to do this directly, without using the user-interface class vdui_t. Here's a small function you can call to set the name of a local variable, assuming you already have the lvar_t object you want to rename:

def SetLvarName(func_ea,lvar,name):
    lsi = ida_hexrays.lvar_saved_info_t()
    lsi.ll = lvar
    lsi.name = name
    ida_hexrays.modify_user_lvar_info(func_ea, ida_hexrays.MLI_NAME, lsi)

Here's a little harness I wrote to ensure it works. It decompiles some function in my database, finds the lvar_t named "v35", and renames it to "vNewName".

def GetCfunc(ea):
    f = idaapi.get_func(ea)
    if f is None:
        return None

    # Decompile the function.
    cfunc = None
        cfunc = idaapi.decompile(f)
        return cfunc

cfunc = GetCfunc(0x61FE5DDE)
if cfunc:
    mba = cfunc.mba
    for idx in xrange(mba.vars.size()):
        var = mba.vars[idx]
        if var.name == "v35":

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.