hexrays_sample4.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 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
* The plugin loads information from the database without decompiling anything.
*
*/
#include <hexrays.hpp>
//--------------------------------------------------------------------------
struct plugin_ctx_t : public plugmod_t
{
~plugin_ctx_t()
{
}
virtual bool idaapi run(size_t) override;
};
//--------------------------------------------------------------------------
{
buf->qclear();
// 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 plugin_ctx_t::run(size_t)
{
func_t *pfn = get_func(get_screen_ea());
if ( pfn == nullptr )
{
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.
if ( labels != nullptr )
{
p != user_labels_end(labels);
p=user_labels_next(p) )
{
qstring &name = user_labels_second(p);
msg("Label %d: %s\n", org_label, name.c_str());
}
user_labels_free(labels);
}
// Display user defined comments
if ( cmts != nullptr )
{
p != user_cmts_end(cmts);
p=user_cmts_next(p) )
{
}
user_cmts_free(cmts);
}
// Display user defined citem iflags
user_iflags_t *iflags = restore_user_iflags(entry_ea);
if ( iflags != nullptr )
{
p != user_iflags_end(iflags);
p=user_iflags_next(p) )
{
msg(" CIT_COLLAPSED");
msg("\n");
}
user_iflags_free(iflags);
}
// Display user defined number formats
if ( numforms != nullptr )
{
p != user_numforms_end(numforms);
p=user_numforms_next(p) )
{
msg("Number format at %a, operand %d: %s",
{
}
{
msg("char\n");
}
{
msg("struct offset %s\n", nf.type_name.c_str());
}
else
{
}
}
user_numforms_free(numforms);
}
// Display user-defined local variable information
lvar_uservec_t lvinf;
{
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 )
{
print_location(&buf, vdloc);
msg("%s", buf.c_str());
msg(" Preserved info about deleted variable\n");
msg(" Split variable\n");
msg(" Name: %s\n", lv.name.c_str());
{
qstring out;
lv.type.print(&out);
msg(" Type: %s\n", out.c_str());
}
msg(" Comment: %s\n", lv.cmt.c_str());
}
msg("\n------- Variable mappings\n");
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;
}
//--------------------------------------------------------------------------
// Initialize the plugin.
static plugmod_t *idaapi init()
{
return nullptr; // no decompiler
msg("Hex-rays version %s has been detected, %s ready to use\n",
hxver, PLUGIN.wanted_name);
return new plugin_ctx_t;
}
//--------------------------------------------------------------------------
static const char comment[] = "Sample plugin4 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
"Hex-Rays Dump User Info", // the preferred short name of the plugin
nullptr, // the preferred hotkey to run the plugin
};
Definition: hexrays.hpp:1083
HexRays SDK header file.
operand_locator_t const & user_numforms_first(user_numforms_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:8624
size_t user_numforms_size(user_numforms_t *map)
Get size of user_numforms_t.
Definition: hexrays.hpp:8704
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:8992
bool init_hexrays_plugin(int flags=0)
Check that your plugin is compatible with hex-rays decompiler.
Definition: hexrays.hpp:8601
user_iflags_iterator_t user_iflags_next(user_iflags_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:9110
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:8656
void print_vdloc(qstring *vout, const vdloc_t &loc, int nbytes)
Print vdloc.
Definition: hexrays.hpp:10006
std::map< lvar_locator_t, lvar_locator_t > lvar_mapping_t
Local variable mapping (is used to merge variables)
Definition: hexrays.hpp:1485
user_numforms_iterator_t user_numforms_next(user_numforms_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:8674
int32 & user_iflags_second(user_iflags_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:9067
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:9310
int const & user_labels_first(user_labels_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:9278
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:8983
user_cmts_iterator_t user_cmts_next(user_cmts_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:9001
user_iflags_t * restore_user_iflags(ea_t func_ea)
Restore user defined citem iflags from the database.
Definition: hexrays.hpp:12107
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:8665
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:10084
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:9319
void user_numforms_free(user_numforms_t *map)
Delete user_numforms_t instance.
Definition: hexrays.hpp:8711
number_format_t & user_numforms_second(user_numforms_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:8631
citem_cmt_t & user_cmts_second(user_cmts_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:8958
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:9092
user_numforms_t * restore_user_numforms(ea_t func_ea)
Restore user defined number formats from the database.
Definition: hexrays.hpp:12101
citem_locator_t const & user_iflags_first(user_iflags_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:9060
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:9101
treeloc_t const & user_cmts_first(user_cmts_iterator_t p)
Get reference to the current map key.
Definition: hexrays.hpp:8951
user_labels_t * restore_user_labels(ea_t func_ea)
Restore user defined labels from the database.
Definition: hexrays.hpp:12083
user_cmts_t * restore_user_cmts(ea_t func_ea)
Restore user defined comments from the database.
Definition: hexrays.hpp:12095
user_labels_iterator_t user_labels_next(user_labels_iterator_t p)
Move to the next element.
Definition: hexrays.hpp:9328
qstring & user_labels_second(user_labels_iterator_t p)
Get reference to the current map value.
Definition: hexrays.hpp:9285
Saved user settings for local variables: name, type, comment.
Definition: hexrays.hpp:1425
lvar_saved_infos_t lvvec
User-specified names, types, comments for lvars.
Definition: hexrays.hpp:1492
qstring type_name
for stroffs: structure for offsetof() for enums: enum name
Definition: hexrays.hpp:798
char props
properties: combination of NF_ bits (Number format property bits)
Definition: hexrays.hpp:783
Definition: hexrays.hpp:9052