4

I have functions

foo_0(...,_ v0,...)
foo_1(...,_ v1,...)
...

And, for each (foo_x, _ v_x) pair, I would like to change the type of v_x in the declaration to ANIMAL *, where ANIMAL is a local type.

I recycled some code from this question, as follow:

from idaapi import *

tif = tinfo_t()
get_tinfo2(ea, tif)

funcdata = func_type_data_t()
tif.get_func_details(funcdata)

After this I was stuck, as funcdata[i].type is a tinfo_t object which I could not find a way to create/modify easily.

My last resort would be to use GuessType/GetType and modify the string before SetType, but this might be a tad complicated since some arguments are pointers to functions themselves.

Any suggestions would be most welcome!

4

This worked for me (checks might be needed on guess_tinfo and get_func_details)

tif = idaapi.tinfo_t()
ida_typeinf.guess_tinfo(ea,tif)                     
funcdata = idaapi.func_type_data_t()
tif.get_func_details(funcdata)
tif2 = idaapi.tinfo_t()
tif2.get_named_type(idaapi.get_idati(),"ANIMAL")       #tif2 = ANIMAL
tif3 = tinfo_t()
tif3.create_ptr(tif2)                                  #tif3 = ANIMAL *
funcdata[argnum].type = tif3                           #replace corresponding argument
function_tinfo = idaapi.tinfo_t()
function_tinfo.create_func(funcdata)
idaapi.apply_tinfo2(ea, function_tinfo, idaapi.TINFO_DEFINITE)
| improve this answer | |

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.