hexrays_sample13.cpp
/*
* Hex-Rays Decompiler project
* Copyright (c) 2007-2019 by Hex-Rays, [email protected]
* ALL RIGHTS RESERVED.
*
* Sample plugin for Hex-Rays Decompiler.
* It generates microcode for selection and dumps it to the output window.
*/
#include <hexrays.hpp>
#include <frame.hpp>
// Hex-Rays API pointer
hexdsp_t *hexdsp = NULL;
//--------------------------------------------------------------------------
int idaapi init(void)
{
return PLUGIN_SKIP; // no decompiler
const char *hxver = get_hexrays_version();
msg("Hex-rays version %s has been detected, %s ready to use\n", hxver, PLUGIN.wanted_name);
return PLUGIN_KEEP;
}
//--------------------------------------------------------------------------
void idaapi term(void)
{
if ( hexdsp != NULL )
}
//--------------------------------------------------------------------------
bool idaapi run(size_t)
{
ea_t ea1, ea2;
if ( !read_range_selection(NULL, &ea1, &ea2) )
{
warning("Please select a range of addresses to analyze");
return true;
}
flags_t F = get_flags(ea1);
if ( !is_code(F) )
{
warning("The selected range must start with an instruction");
return true;
}
// generate microcode
mbr.ranges.push_back(range_t(ea1, ea2));
mbl_array_t *mba = gen_microcode(mbr, &hf, NULL, DECOMP_WARNINGS);
if ( mba == NULL )
{
warning("%a: %s", hf.errea, hf.desc().c_str());
return true;
}
msg("Successfully generated microcode for %a..%a\n", ea1, ea2);
mba->print(vp);
// We must explicitly delete the microcode array
delete mba;
return true;
}
//--------------------------------------------------------------------------
static const char comment[] = "Sample13 plugin for Hex-Rays decompiler";
//--------------------------------------------------------------------------
//
// PLUGIN DESCRIPTION BLOCK
//
//--------------------------------------------------------------------------
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
0, // plugin flags
init, // initialize
term, // terminate. this pointer may be NULL.
run, // invoke plugin
comment, // long comment about the plugin
// it could appear in the status line
// or as a hint
"", // multiline help about the plugin
"Dump microcode for selected range", // the preferred short name of the plugin
"" // the preferred hotkey to run the plugin
};
void print(vd_printer_t &vp) const
Print microcode to any destination.
Definition: hexrays.hpp:10768
bool init_hexrays_plugin(int flags=0)
Initialize your plugin for hex-rays decompiler.
Definition: hexrays.hpp:8140
Micro block array (internal representation of the decompiled code).
Definition: hexrays.dox:62
rangevec_t ranges
empty ? function_mode : snippet mode
Definition: hexrays.hpp:4182
HexRays SDK header file.
const char * get_hexrays_version(void)
Get decompiler version.
Definition: hexrays.hpp:10906
void term_hexrays_plugin(void)
Stop working with hex-rays decompiler.
Definition: hexrays.hpp:8147
#define DECOMP_WARNINGS
display warnings in the output window
Definition: hexrays.hpp:6809
Exception object: decompiler failure information.
Definition: hexrays.hpp:5112
mbl_array_t * gen_microcode(const mba_ranges_t &mbr, hexrays_failure_t *hf, const mlist_t *retlist=NULL, int flags=0, mba_maturity_t reqmat=MMAT_GLBOPT3)
Generate microcode of an arbitrary code snippet.
Definition: hexrays.hpp:11636
void * hexdsp_t(int code,...)
Hex-Rays decompiler dispatcher.
Definition: hexrays.hpp:6944
Base helper class to convert binary data structures into text.
Definition: hexrays.hpp:844
hexdsp_t * hexdsp
Pointer to Hex-Rays decompiler dispatcher.
Ranges to decompile. Either a function or an explicit vector of ranges.
Definition: hexrays.hpp:4179
ea_t errea
associated address
Definition: hexrays.hpp:5115