def func(self, blk, ins): ret_val = self.optimize(ins, blk) # This callback doesn't seem to get called for subinstructions of # conditional branches. So, if we're dealing with a conditional branch, # manually optimize the condition expression if (is_mcode_jcond(ins.opcode) or \ is_mcode_set(ins.opcode)) and \ ins.l.t == mop_d: # In order to optimize the jcc condition, we actually need a different # structure than optinsn_t: in particular, we need a minsn_visitor_t. # This local structure declaration just passes the calls to # minsn_visitor_t::visit_minsn onto the Optimize function in this # optinsn_t object. class blah_t(minsn_visitor_t): def __init__(self, oco): minsn_visitor_t.__init__(self) self.oco = oco def visit_minsn(self): try: return self.oco.optimize(self.curins, self.blk) except: import traceback traceback.print_exc() raise # Optimize all subinstructions of the JCC conditional ret_val += ins.for_all_insns(blah_t(self)) # If any optimizations were performed... if ret_val: # ... inform the user ... hexrays_util.report_debug("ObfCompilerOptimizer: replaced by %s" % hexrays_util.mcode_t_to_string(ins)) _optimize(blk, ins) # I got an INTERR if I optimized jcc conditionals without marking the lists dirty. blk.mark_lists_dirty() blk.mba.verify(True) return ret_val
def report_debug(self, msg): hexrays_util.report_debug(msg)