7

IDA has this nifty habit that when it doesn't know what a special purpose register is, it just drops in the number of the register instead. While this is all well and fine, I'd like to be able to correct these items in my database. I know I can just adjust the [arch].cfg file; however, that applies the changes to ALL processors of that architecture, which isn't always the correct behavior. Instead, I'd like to only change the registers per database that I'm working on.

So I started down the IDAPython path and I can easily get the unnamed registers:

for r in range(220,240):
    uknName = get_reg_name(r,0)
    print("Got: '%s' for register %d ") % (unkName,r)
    if unkName is None:
        # I'd like to fix this but I can't
        # set_reg_name(r,<something I read from a file>)

Where I've run into issues is that I can't seem to find the IDAPython idc/idaapi/idautils function that I can use to rename the it. Do you know what the magic python sauce is that would allow me to rename these items? I've been trying to find something in the official docs here but haven't had any luck.

UPDATE: Equivalent Functionality

As mentioned below, this isn't "possible" with the IDA API (as is also noted in my original implied statement of "I read all of this and can't find a way to do it." The following code will provide you an equvilent bit of information ... but I've not found an efficient way to implement it so I just keep this snip-it around and hack it up as needed. It provides the same as the "RightClick->Rename" that you can use to rename a given register per function ... sadly, not a good way to do an entire database. Mucked up for x86 since it was the only image I had available:

ea = ScreenEA()
func = idaapi.get_func(ea)
regvar = idaapi.find_regvar(func, ea, "eax")
# print(var_dump(regvar))
# associated "rename variable" magic
idaapi.rename_regvar(func, idaapi.find_regvar(func, ea, "eax"), "asdfd")
  • I have a problem: the meaning of your answer is that rename the register name? such that: mov eax,ebx; when scripting it: it will be changed into mov asdfd,ebx? I think it will be changed same as before, but when I use it in my IDA 7.0 pro, It does not work. – byzero Apr 22 at 8:20
  • You've happened upon a problem nearly 5 years old. The meaning of the answer is exactly what is stated - it will rename the registers for that function. The IDA python API has additionally changed in 5 years time and is likely not the same as it once was, though I can't imagine it's much different to implement now. Additionally, if you're on a mac, you're probably getting rax instead of eax because it's 64bit. – Wyatt May 11 at 17:57
2

This cannot be done with either IDA C or IDA Python. There is no API function to rename a register. Check the docs: https://www.hex-rays.com/products/ida/support/idapython_docs/

  • Basically what we've found. I've updated with our "solution" but it's definitely not an ideal solution. – Wyatt Feb 25 '15 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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