1

I'd like to be able to create and change global variables at addresses with IDA Python: if variable doesn't exist, create it, if it exists, change it, set its name, undefine it.

For structs, there's idc.add_struc, idc.add_struc_member, idc.set_member_type, idc.set_member_name, idc.del_struc, idc.del_struc_member.

There's idc.set_name to set a name at address and ida_bytes.get_flags function to get flags, but I can't find a respective function such as set_flags or set_type to change global variable type at address. So to set variable type to dword, I'd do something like ida_bytes.set_flags(0x14001D01C, ida_bytes.dword_flag()), and to set it to structure type, I'd like to do something like ida_bytes.set_flags(0x14001D01C, ida_bytes.stru_flag(), ida_struct.get_struc_id("MyStructName"))

I scrolled through idaapi, ida_bytes, idc, ida_struct and ida_typeinf documentation. I also searched for set_, _flag, _type and other in the search box on the hex-rays documentation website, and also manually with Ctrl+F in the pages for namespaces above, but couldn't find functions to set flags at address.

1 Answer 1

2

The methods I was looking for are:

To get the name of the variable at address, use idc.get_name.

To get the type of the variable at address, first retreive the flags with ida_bytes.get_flags. Then to get its actual type you can use functions, such as idc.is_byte to determine if it's a byte, or idc.is_struct to determine if it's a struct. Then, if it's a struct, to determine specific type of a struct, use idaapi.get_opinfo(struct_id_buffer, ea, 0, flags)(example).

For structs, there's idc.add_struc, idc.add_struc_member, idc.set_member_type, idc.set_member_name, idc.del_struc, idc.del_struc_member.

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.