SDK Reference

* Hex-Rays Decompiler project
* Copyright (c) 2007-2019 by Hex-Rays, [email protected]
* Sample plugin for Hex-Rays Decompiler.
* It dumps all user-defined information about the current
* function to the messages window. Namely, it displays:
* - user defined label names
* - user defined indented comments
* - user defined number formats
* - user defined local variable names, types, comments
#include <hexrays.hpp>
// Hex-Rays API pointer
hexdsp_t *hexdsp = NULL;
// Initialize the plugin.
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);
void idaapi term(void)
static void print_location(qstring *buf, const vdloc_t &vdloc)
// we do not have the width info handy, so try 1 and sizeof(int)
// this is not quite correct, but we just need to print something
print_vdloc(buf, vdloc, 1);
if ( buf->empty() )
print_vdloc(buf, vdloc, inf_get_cc_size_i());
if ( buf->empty() )
*buf = "?";
bool idaapi run(size_t)
func_t *pfn = get_func(get_screen_ea());
if ( pfn == NULL )
warning("AUTOHIDE NONE\nPlease move the cursor into a function");
return true;
ea_t entry_ea = pfn->start_ea;
msg("Dump of user-defined information for function at %a\n", entry_ea);
// Display user defined labels.
user_labels_t *labels = restore_user_labels(entry_ea);
if ( labels != NULL )
msg("------- %" FMT_Z " user defined labels\n", user_labels_size(labels));
for ( p=user_labels_begin(labels);
p != user_labels_end(labels);
int org_label = user_labels_first(p);
qstring &name = user_labels_second(p);
msg("Label %d: %s\n", org_label, name.c_str());
// Display user defined comments
user_cmts_t *cmts = restore_user_cmts(entry_ea);
if ( cmts != NULL )
msg("------- %" FMT_Z " user defined comments\n", user_cmts_size(cmts));
for ( p=user_cmts_begin(cmts);
p != user_cmts_end(cmts);
const treeloc_t &tl = user_cmts_first(p);
msg("Comment at %a, preciser %x:\n%s\n\n", tl.ea, tl.itp, cmt.c_str());
// Display user defined citem iflags
user_iflags_t *iflags = restore_user_iflags(entry_ea);
if ( iflags != NULL )
msg("------- %" FMT_Z " user defined citem iflags\n", user_iflags_size(iflags));
for ( p=user_iflags_begin(iflags);
p != user_iflags_end(iflags);
int f = user_iflags_second(p);
msg("%a(%d): %08X", cl.ea, cl.op, f);
if ( f & CIT_COLLAPSED )
// Display user defined number formats
user_numforms_t *numforms = restore_user_numforms(entry_ea);
if ( numforms != NULL )
msg("------- %" FMT_Z " user defined number formats\n", user_numforms_size(numforms));
for ( p=user_numforms_begin(numforms);
p != user_numforms_end(numforms);
msg("Number format at %a, operand %d: %s",
ol.ea, ol.opnum, (nf.props & NF_NEGATE) != 0 ? "negated " : "");
if ( nf.is_enum() )
msg("enum %s (serial %d)\n", nf.type_name.c_str(), nf.serial);
else if ( nf.is_char() )
else if ( nf.is_stroff() )
msg("struct offset %s\n", nf.type_name.c_str());
msg("number base=%d\n", get_radix(nf.flags, ol.opnum));
// Display user-defined local variable information
if ( restore_user_lvar_settings(&lvinf, entry_ea) )
qstring buf;
msg("------- User defined local variable information\n");
lvar_saved_infos_t::const_iterator ptr = lvinf.lvvec.begin();
lvar_saved_infos_t::const_iterator end = lvinf.lvvec.end();
while ( ptr != end )
const lvar_saved_info_t &lv = *ptr++;
msg("Lvar defined at %a ", lv.ll.defea);
const vdloc_t &vdloc = lv.ll.location;
print_location(&buf, vdloc);
msg("%s", buf.c_str());
if ( lv.is_kept() )
msg(" Preserved info about deleted variable\n");
if ( lv.is_forced_lvar() )
msg(" Forced variable\n");
if ( ! )
msg(" Name: %s\n",;
if ( !lv.type.empty() )
qstring out;
msg(" Type: %s\n", out.c_str());
if ( !lv.cmt.empty() )
msg(" Comment: %s\n", lv.cmt.c_str());
msg("\n------- Variable mappings\n");
lvar_mapping_t &lm = lvinf.lmaps;
for ( lvar_mapping_t::iterator p=lm.begin(); p != lm.end(); ++p )
print_location(&buf, p->first.location);
msg("MAP LVAR %s ->", buf.c_str());
print_location(&buf, p->second.location);
msg(" %s\n", buf.c_str());
return true;
static const char comment[] = "Sample plugin4 for Hex-Rays decompiler";
plugin_t PLUGIN =
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
"Hex-Rays Dump User Info", // the preferred short name of the plugin
"" // the preferred hotkey to run the plugin
user_numforms_iterator_t user_numforms_next(user_numforms_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:8180
Iterator class for user_numforms_t.
Definition: hexrays.dox:33
ea_t defea
Definition address.
Definition: hexrays.hpp:1119
Iterator class for user_cmts_t.
Definition: hexrays.dox:36
bool init_hexrays_plugin(int flags=0)
Initialize your plugin for hex-rays decompiler.
Definition: hexrays.hpp:8140
Ctree item comment.
Definition: hexrays.hpp:5702
qstring cmt
Definition: hexrays.hpp:1399
user_cmts_iterator_t user_cmts_end(const user_cmts_t *map)
Get iterator pointing to the end of user_cmts_t.
Definition: hexrays.hpp:8501
flags_t flags
ida flags, which describe number radix, enum, etc
Definition: hexrays.hpp:789
user_labels_iterator_t user_labels_begin(const user_labels_t *map)
Get iterator pointing to the beginning of user_labels_t.
Definition: hexrays.hpp:8822
user_labels_iterator_t user_labels_next(user_labels_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:8840
size_t user_iflags_size(user_iflags_t *map)
Get size of user_iflags_t.
Definition: hexrays.hpp:8683
tinfo_t type
Definition: hexrays.hpp:1398
void user_cmts_free(user_cmts_t *map)
Delete user_cmts_t instance.
Definition: hexrays.hpp:8580
char props
properties: combination of NF_ bits (Number format property bits)
Definition: hexrays.hpp:791
user_cmts_iterator_t user_cmts_begin(const user_cmts_t *map)
Get iterator pointing to the beginning of user_cmts_t.
Definition: hexrays.hpp:8492
qstring & user_labels_second(user_labels_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:8864
user_labels_t * restore_user_labels(ea_t func_ea)
Restore user defined labels from the database.
Definition: hexrays.hpp:11436
Generic ctree element locator.
Definition: hexrays.hpp:5714
std::map< lvar_locator_t, lvar_locator_t > lvar_mapping_t
Local variable mapping (is used to merge variables)
Definition: hexrays.hpp:1452
#define NF_NEGATE
The user asked to negate the constant.
Definition: hexrays.hpp:798
user_labels_iterator_t user_labels_end(const user_labels_t *map)
Get iterator pointing to the end of user_labels_t.
Definition: hexrays.hpp:8831
All user-defined information about local variables.
Definition: hexrays.hpp:1455
lvar_locator_t ll
Variable locator.
Definition: hexrays.hpp:1396
Ctree location. Used to denote comment locations.
Definition: hexrays.hpp:5672
HexRays SDK header file.
Operand locator.
Definition: hexrays.hpp:770
qstring type_name
for stroffs: structure for offsetof() for enums: enum name
Definition: hexrays.hpp:804
number_format_t & user_numforms_second(user_numforms_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:8204
const char * get_hexrays_version(void)
Get decompiler version.
Definition: hexrays.hpp:10906
user_iflags_t * restore_user_iflags(ea_t func_ea)
Restore user defined citem iflags from the database.
Definition: hexrays.hpp:11460
uchar serial
for enums: constant serial number
Definition: hexrays.hpp:802
const operand_locator_t & user_numforms_first(user_numforms_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:8197
void term_hexrays_plugin(void)
Stop working with hex-rays decompiler.
Definition: hexrays.hpp:8147
Number representation.
Definition: hexrays.hpp:786
const treeloc_t & user_cmts_first(user_cmts_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:8527
user_cmts_t * restore_user_cmts(ea_t func_ea)
Restore user defined comments from the database.
Definition: hexrays.hpp:11448
void print_vdloc(qstring *vout, const vdloc_t &loc, int nbytes)
Print vdloc.
Definition: hexrays.hpp:9554
size_t user_numforms_size(user_numforms_t *map)
Get size of user_numforms_t.
Definition: hexrays.hpp:8243
User defined number formats.
Definition: hexrays.dox:44
user_iflags_iterator_t user_iflags_end(const user_iflags_t *map)
Get iterator pointing to the end of user_iflags_t.
Definition: hexrays.hpp:8611
User defined comments.
Definition: hexrays.dox:49
lvar_saved_infos_t lvvec
User-specified names, types, comments for lvars.
Definition: hexrays.hpp:1459
bool is_char(void) const
Is a character constant?
Definition: hexrays.hpp:824
ea_t ea
address of the original processor instruction
Definition: hexrays.hpp:776
user_numforms_t * restore_user_numforms(ea_t func_ea)
Restore user defined number formats from the database.
Definition: hexrays.hpp:11454
void * hexdsp_t(int code,...)
Hex-Rays decompiler dispatcher.
Definition: hexrays.hpp:6944
const citem_locator_t & user_iflags_first(user_iflags_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:8637
vdloc_t location
Variable location.
Definition: hexrays.hpp:1118
int32 & user_iflags_second(user_iflags_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:8644
size_t user_cmts_size(user_cmts_t *map)
Get size of user_cmts_t.
Definition: hexrays.hpp:8573
qstring name
Definition: hexrays.hpp:1397
display element in collapsed form
Definition: hexrays.hpp:6633
hexdsp_t * hexdsp
Pointer to Hex-Rays decompiler dispatcher.
lvar_mapping_t lmaps
Local variable mapping (used for merging variables)
Definition: hexrays.hpp:1462
const int & user_labels_first(user_labels_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:8857
user_iflags_iterator_t user_iflags_begin(const user_iflags_t *map)
Get iterator pointing to the beginning of user_iflags_t.
Definition: hexrays.hpp:8602
user_numforms_iterator_t user_numforms_begin(const user_numforms_t *map)
Get iterator pointing to the beginning of user_numforms_t.
Definition: hexrays.hpp:8162
citem_cmt_t & user_cmts_second(user_cmts_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:8534
ea_t ea
citem address
Definition: hexrays.hpp:5716
void user_labels_free(user_labels_t *map)
Delete user_labels_t instance.
Definition: hexrays.hpp:8910
int opnum
operand number in the instruction
Definition: hexrays.hpp:777
user_iflags_iterator_t user_iflags_next(user_iflags_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:8620
user_cmts_iterator_t user_cmts_next(user_cmts_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:8510
Saved user settings for local variables: name, type, comment.
Definition: hexrays.hpp:1394
void user_iflags_free(user_iflags_t *map)
Delete user_iflags_t instance.
Definition: hexrays.hpp:8690
User defined label names.
Definition: hexrays.dox:54
bool is_enum(void) const
Is a symbolic constant?
Definition: hexrays.hpp:822
Iterator class for user_labels_t.
Definition: hexrays.dox:39
size_t user_labels_size(user_labels_t *map)
Get size of user_labels_t.
Definition: hexrays.hpp:8903
ctype_t op
citem operation
Definition: hexrays.hpp:5717
void user_numforms_free(user_numforms_t *map)
Delete user_numforms_t instance.
Definition: hexrays.hpp:8250
bool is_stroff(void) const
Is a structure field offset?
Definition: hexrays.hpp:826
bool restore_user_lvar_settings(lvar_uservec_t *lvinf, ea_t func_ea)
Restore user defined local variable settings in the database.
Definition: hexrays.hpp:9632
user_numforms_iterator_t user_numforms_end(const user_numforms_t *map)
Get iterator pointing to the end of user_numforms_t.
Definition: hexrays.hpp:8171