vds19

summary: add a custom microcode instruction optimization rule

description:

Installs a custom microcode instruction optimization rule, to transform:

x | ~x

into

-1

To see this plugin in action please use be_ornot_be.idb

level: advanced

Classes

subinsn_optimizer_t

sample_optimizer_t

my_plugin_t

Base class for all scripted plugins.

Functions

PLUGIN_ENTRY()

Module Contents

class vds19.subinsn_optimizer_t(_mba: mba_t = None, _blk: mblock_t = None, _topins: minsn_t = None)

Bases: ida_hexrays.minsn_visitor_t

cnt = 0
visit_minsn()
class vds19.sample_optimizer_t

Bases: ida_hexrays.optinsn_t

func(blk, ins, optflags)

Optimize an instruction.

Parameters:
  • blk – current basic block. maybe nullptr, which means that the instruction must be optimized without context

  • ins – instruction to optimize; it is always a top-level instruction. the callback may not delete the instruction but may convert it into nop (see mblock_t::make_nop). to optimize sub-instructions, visit them using minsn_visitor_t. sub-instructions may not be converted into nop but can be converted to “mov x,x”. for example: add x,0,x => mov x,x this callback may change other instructions in the block, but should do this with care, e.g. to no break the propagation algorithm if called with OPTI_NO_LDXOPT.

  • optflags – combination of optimization flags bits

Returns:

number of changes made to the instruction. if after this call the instruction’s use/def lists have changed, you must mark the block level lists as dirty (see mark_lists_dirty)

class vds19.my_plugin_t

Bases: ida_idaapi.plugin_t

Base class for all scripted plugins.

flags = 16
wanted_name = 'optimize x|~x'
wanted_hotkey = ''
comment = ''
help = ''
init()
term()
run(arg)
vds19.PLUGIN_ENTRY()