0

Is there any way to change the calling convention programmatically? I found some C++ code in this repo but wasn't able to successfully update it to 6.8.

static bool idaapi convert_to_usercall(void *ud)
{
    vdui_t &vu = *(vdui_t *)ud;
    if (!vu.cfunc)
        return false;
    if ( vu.cfunc->entry_ea == BADADDR )
        return false;
    tinfo_t type;
    qtype fields;       
    if (!vu.cfunc->get_func_type(type, fields))
        return false;
    func_type_info_t fti;
    int a = build_funcarg_info(idati, type.c_str(), fields.c_str(), &fti, 0);
    if (!convert_cc_to_special(fti))
        return false;
    fields.clear();
    type.clear();
    build_func_type(&type, &fields, fti);
    if ( !apply_tinfo(idati, vu.cfunc->entry_ea, type.c_str(), fields.c_str(), 1) )
        return false;
    vu.refresh_view(true);
    return true;
}

The code seems to use apis that are now deprecated or changed up. Does anybody know a way to fix up this code or some other approach.

Any help would be appreciated, whether it is C++ or Python.

1

SetType? An example in Python could be this:

SetType(func_ea, "int x(int arg1, char *arg2);")
| improve this answer | |
  • Thanks for the response, but isn't there a way to set the calling convention explicitly? I want this task to be automated so I don't know know the function signature – ImCodezz Jul 25 '16 at 0:59
  • What I usually do is GetType, modify the returned prototype to set the __cdecl/__thiscall/__whatever calling conventiong and then issue a SetType call with the new string. – joxeankoret Jul 25 '16 at 19:53
0

Ok, I found a solution in Python and it should work the same in C++. For anyone interested, here's the code. It changes the calling convention from __usercall to __fastcall:

old_func_type = idaapi.tinfo_t()
cfunc.get_func_type(old_func_type)

fi = idaapi.func_type_data_t()
if old_func_type.get_func_details(fi):
    if (fi.cc == idaapi.CM_CC_SPECIAL) or (fi.cc == idaapi.CM_CC_SPECIALE) or (fi.cc == idaapi.CM_CC_SPECIALP):
        fi.cc = idaapi.CM_CC_FASTCALL

        new_func_type = idaapi.tinfo_t()
        new_func_type.create_func(fi)

        idaapi.apply_tinfo2(ea, new_func_type, 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.