Exporting IDA function for IDC Script Usage

Sometimes you want to specify additional options or to call internal function of IDA plugin that you wrote. You can use “set_idc_func” API to achive this. Here’s a sample skeleton code that is showing how to make a custom function that idc script can call.
char *OutputFilename;
static const char SendDiassemblyInfoArgs[]={VT_STR,0 };
static error_t idaapi SendDiassemblyInfo(value_t *argv,value_t *res)
{
msg("%s is called with arg0=%s\n",argv[0].str);
OutputFilename=strdup(argv[0].str);
run(2);
res->num=1;
return eOk;
}

int idaapi init(void)
{
if ( inf.filetype == f_ELF ) return PLUGIN_SKIP;

set_idc_func("SendDiassemblyInfo",SendDiassemblyInfo,SendDiassemblyInfoArgs);
return PLUGIN_KEEP;
}

void idaapi term(void)
{
set_idc_func("SendDiassemblyInfo",NULL,NULL);
}
From idc script, you can call the defined function as if it’s a built-in API like following.
static main()
{
RunPlugin("DarunGrim2",1);
SendDiassemblyInfo("disassembly.info");
Exit(0);
}
Simple!
Advertisements