hexrays_sample1.cpp
#include <hexrays.hpp>
hexdsp_t *hexdsp = NULL;
static bool inited = false;
int idaapi init(void)
{
if ( !init_hexrays_plugin() )
return PLUGIN_SKIP;
const char *hxver = get_hexrays_version();
msg("Hex-rays version %s has been detected, %s ready to use\n", hxver, PLUGIN.wanted_name);
inited = true;
return PLUGIN_KEEP;
}
void idaapi term(void)
{
if ( inited )
term_hexrays_plugin();
}
void idaapi run(int)
{
func_t *pfn = get_func(get_screen_ea());
if ( pfn == NULL )
{
warning("Please position the cursor within a function");
return;
}
hexrays_failure_t hf;
cfunc_t *cfunc = decompile(pfn, &hf);
if ( cfunc == NULL )
{
warning("#error \"%a: %s", hf.errea, hf.desc().c_str());
return;
}
msg("%a: successfully decompiled\n", pfn->startEA);
qstring bodytext;
qstring_printer_t sp(cfunc, bodytext, false);
cfunc->print_func(sp);
msg("%s\n", bodytext.c_str());
delete cfunc;
}
static char comment[] = "Sample1 plugin for Hex-Rays decompiler";
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
0,
init,
term,
run,
comment,
"",
"Decompile & Print",
""
};