static bool inited = false;
static const char nodename[] = "$ hexrays inverted-if";
static netnode node;
static eavec_t inverted_ifs;
#define ACTION_NAME "sample3:invertif"
static void do_invert_if(
cinsn_t *i)
{
delete notcond;
}
static void add_inverted_if(ea_t ea)
{
eavec_t::iterator p = inverted_ifs.find(ea);
if ( p != inverted_ifs.end() )
inverted_ifs.erase(p);
else
inverted_ifs.push_back(ea);
eavec_t copy = inverted_ifs;
for ( int i=0; i < copy.size(); i++ )
copy[i] = ea2node(copy[i]);
node.setblob(copy.begin(), copy.size()*sizeof(ea_t), 0, 'I');
}
{
{
return i;
}
{
{
ea_t ea;
if_finder_t(ea_t e)
{
{
found = i;
return 1;
}
return 0;
}
};
if ( iff.apply_to(&vu.
cfunc->body, NULL) )
return iff.found;
}
return NULL;
}
static void convert_marked_ifs(
cfunc_t *cfunc)
{
{
{
do_invert_if(i);
return 0;
}
};
if_inverter_t ifi;
ifi.apply_to(&cfunc->
body, NULL);
}
{
switch ( event )
{
{
TPopupMenu *popup = va_arg(va, TPopupMenu *);
if ( find_if_statement(vu) != NULL )
attach_action_to_popup(widget, popup, ACTION_NAME);
}
break;
if ( !inverted_ifs.empty() )
{
convert_marked_ifs(cfunc);
}
break;
default:
break;
}
return 0;
}
struct invert_if_ah_t : public action_handler_t
{
virtual int idaapi activate(action_activation_ctx_t *ctx)
{
cinsn_t *i = find_if_statement(vu);
do_invert_if(i);
return 1;
}
virtual action_state_t idaapi update(action_update_ctx_t *ctx)
{
if ( vu == NULL )
return AST_DISABLE_FOR_WIDGET;
return find_if_statement(*vu) == NULL ? AST_DISABLE : AST_ENABLE;
}
};
static invert_if_ah_t invert_if_ah;
static const action_desc_t invert_if_action =
ACTION_DESC_LITERAL(
ACTION_NAME,
"Invert if-statement",
&invert_if_ah,
NULL,
NULL,
-1
);
int idaapi init(void)
{
return PLUGIN_SKIP;
if ( !node.create(nodename) )
{
size_t n;
void *blob = node.getblob(NULL, &n, 0, 'I');
if ( blob != NULL )
{
inverted_ifs.clear();
inverted_ifs.inject((ea_t *)blob, n / sizeof(ea_t));
for ( int i=0; i < inverted_ifs.size(); i++ )
inverted_ifs[i] = node2ea(inverted_ifs[i]);
}
}
msg("Hex-rays version %s has been detected, %s ready to use\n", hxver, PLUGIN.wanted_name);
register_action(invert_if_action);
inited = true;
return PLUGIN_KEEP;
}
void idaapi term(void)
{
if ( inited )
{
}
}
bool idaapi run(size_t)
{
return false;
}
static char comment[] = "Sample3 plugin for Hex-Rays decompiler";
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
PLUGIN_HIDE,
init,
term,
run,
comment,
"",
"Hex-Rays if-inverter",
""
};