1

I am trying to write an IDAPython script that renames some local variables (in the disassembly window) according to some logic, unfortunately I am unable/failing to use the API to do so...

In my searches I found that set_member_name should be used since the stack frame is treated like a structure from IDA's POV, but again the documentation is not clear about how I can name a variable in a certain stack frame (or any structure for that matter)...

I will appreciate any help.

2
  • Can you precise if this is for the disassembly window or for the pseudocode window (decompiler)?
    – vmallet
    Commented Jul 12, 2022 at 19:39
  • For Disassembly. Commented Jul 13, 2022 at 8:44

2 Answers 2

2

I managed to write a function that is doing what I was looking for... sharing my code below:

def rename_stack_variable(func_addr, var_name, new_var_name):
    func = idaapi.get_func(func_addr)
    frame = idaapi.get_frame(func)

    offset = 0x0

    for i in range(0, len(list(frame.members))):
        if var_name == get_member_name(frame.id, offset):
            break
        offset = i * 4

    set_member_name(frame.id, offset, new_var_name)
1
  • ** a small comment on my code above is that I assumed that all the stack variables are 4 bytes, which is not necessarily true but worked on my case, so if you/someone has a better solution I would be happy to hear :) Commented Jul 14, 2022 at 14:54
-2
    my_rename <- function(df, varname) {
  varname <- ensym(varname)
  
  df %>% 
    rename(!!varname := cyl) %>% 
    group_by(!!varname) %>%
    summarize(mean_mpg = mean(mpg))
}

my_rename(mtcars, cylinder)

# A tibble: 3 x 2
  cylinder mean_mpg
     <dbl>    <dbl>
1        4     26.7
2        6     19.7
3        8     15.1

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.