Latest available version: IDA and decompilers v8.4.240320sp1 see all releases
Hex-Rays logo State-of-the-art binary code analysis tools
email icon
hexrays_sample1.cpp
/*
* Hex-Rays Decompiler project
* Copyright (c) 2007-2024 by Hex-Rays, support@hex-rays.com
* ALL RIGHTS RESERVED.
*
* Sample plugin for Hex-Rays Decompiler.
* It decompiles the current function and prints it in the message window
*
*/
#include <hexrays.hpp>
//--------------------------------------------------------------------------
struct plugin_ctx_t : public plugmod_t
{
~plugin_ctx_t()
{
}
virtual bool idaapi run(size_t) override;
};
//--------------------------------------------------------------------------
static plugmod_t *idaapi init()
{
return nullptr; // 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 new plugin_ctx_t;
}
//--------------------------------------------------------------------------
bool idaapi plugin_ctx_t::run(size_t)
{
func_t *pfn = get_func(get_screen_ea());
if ( pfn == nullptr )
{
warning("Please position the cursor within a function");
return true;
}
cfuncptr_t cfunc = decompile(pfn, &hf, DECOMP_WARNINGS);
if ( cfunc == nullptr )
{
warning("#error \"%a: %s", hf.errea, hf.desc().c_str());
return true;
}
msg("%a: successfully decompiled\n", pfn->start_ea);
const strvec_t &sv = cfunc->get_pseudocode();
for ( int i=0; i < sv.size(); i++ )
{
qstring buf;
tag_remove(&buf, sv[i].line);
msg("%s\n", buf.c_str());
}
return true;
}
//--------------------------------------------------------------------------
static char comment[] = "Sample1 plugin for Hex-Rays decompiler";
//--------------------------------------------------------------------------
//
// PLUGIN DESCRIPTION BLOCK
//
//--------------------------------------------------------------------------
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
PLUGIN_MULTI, // The plugin can work with multiple idbs in parallel
init, // initialize
nullptr,
nullptr,
comment, // long comment about the plugin
nullptr, // multiline help about the plugin
"Decompile & Print", // the preferred short name of the plugin
nullptr, // the preferred hotkey to run the plugin
};
Vector of colored strings.
Definition: hexrays.dox:64
#define DECOMP_WARNINGS
display warnings in the output window
Definition: hexrays.hpp:7142
HexRays SDK header file.
bool init_hexrays_plugin(int flags=0)
Check that your plugin is compatible with hex-rays decompiler.
Definition: hexrays.hpp:8601
cfuncptr_t decompile(const mba_ranges_t &mbr, hexrays_failure_t *hf=nullptr, int decomp_flags=0)
Decompile a snippet or a function.
Definition: hexrays.hpp:12313
void term_hexrays_plugin()
Stop working with hex-rays decompiler.
Definition: hexrays.hpp:8609
const char * get_hexrays_version()
Get decompiler version.
Definition: hexrays.hpp:11511
Exception object: decompiler failure information.
Definition: hexrays.hpp:5442
ea_t errea
associated address
Definition: hexrays.hpp:5444