node/lib/metasm/metasm/main.rb
# a check to see if an Expr is the composition of two rotations (rol eax, 4 ; rol eax, 6 => rol eax, 10)
# this is a bit too ugly to stay in the main reduce_rec body.
a check to see if an Expr is the composition of two rotations (rol eax, 4 ; rol eax, 6 => rol eax, 10)
this is a bit too ugly to stay in the main reduce_rec body.
a check to see if an Expr is the composition of two rotations ( rol eax 4 ; rol eax 6 = > rol eax 10 ) this is a bit too ugly to stay in the main reduce_rec body .
def reduce_rec_composerol(e, mask)
		m = Expression[['var', :sh_op, 'amt'], :|, ['var', :inv_sh_op, 'inv_amt']]
		if vars = e.match(m, 'var', :sh_op, 'amt', :inv_sh_op, 'inv_amt') and vars[:sh_op] == {:>> => :<<, :<< => :>>}[vars[:inv_sh_op]] and
		   ((vars['amt'].kind_of?(::Integer) and  vars['inv_amt'].kind_of?(::Integer) and ampl = vars['amt'] + vars['inv_amt']) or
		    (vars['amt'].kind_of? Expression and vars['amt'].op == :% and vars['amt'].rexpr.kind_of?(::Integer) and
		     vars['inv_amt'].kind_of? Expression and vars['inv_amt'].op == :% and vars['amt'].rexpr == vars['inv_amt'].rexpr and ampl = vars['amt'].rexpr)) and
		   mask == (1<<ampl)-1 and vars['var'].kind_of? Expression and	
		   vars['var'].op == :& and vars['var'].rexpr == mask and
		  ivars = vars['var'].lexpr.match(m, 'var', :sh_op, 'amt', :inv_sh_op, 'inv_amt') and ivars[:sh_op] == {:>> => :<<, :<< => :>>}[ivars[:inv_sh_op]] and
		   ((ivars['amt'].kind_of?(::Integer) and  ivars['inv_amt'].kind_of?(::Integer) and ampl = ivars['amt'] + ivars['inv_amt']) or
		    (ivars['amt'].kind_of? Expression and ivars['amt'].op == :% and ivars['amt'].rexpr.kind_of?(::Integer) and
		     ivars['inv_amt'].kind_of? Expression and ivars['inv_amt'].op == :% and ivars['amt'].rexpr == ivars['inv_amt'].rexpr and ampl = ivars['amt'].rexpr))
			if ivars[:sh_op] != vars[:sh_op]
				ivars[:sh_op], ivars[:inv_sh_op] = ivars[:inv_sh_op], ivars[:sh_op]
				ivars['amt'],  ivars['inv_amt']  = ivars['inv_amt'],  ivars['amt']
			end
			amt = Expression[[vars['amt'], :+, ivars['amt']], :%, ampl]
			invamt = Expression[[vars['inv_amt'], :+, ivars['inv_amt']], :%, ampl]
			Expression[[[[ivars['var'], :&, mask], vars[:sh_op], amt], :|, [[ivars['var'], :&, mask], vars[:inv_sh_op], invamt]], :&, mask].reduce_rec
		else
			Expression[e, :&, mask]
		end
	end
def reduce_rec_composerol ( e , mask ) m = Expression [ [ 'var' , :sh_op , 'amt' ] , :| , [ 'var' , :inv_sh_op , 'inv_amt' ] ] if vars = e . match ( m , 'var' , :sh_op , 'amt' , :inv_sh_op , 'inv_amt' ) and vars [ :sh_op ] == { :>> => :<< , :<< => :>> } [ vars [ :inv_sh_op ] ] and ( ( vars [ 'amt' ] . kind_of? ( :: Integer ) and vars [ 'inv_amt' ] . kind_of? ( :: Integer ) and ampl = vars [ 'amt' ] + vars [ 'inv_amt' ] ) or ( vars [ 'amt' ] . kind_of? Expression and vars [ 'amt' ] . op == :% and vars [ 'amt' ] . rexpr . kind_of? ( :: Integer ) and vars [ 'inv_amt' ] . kind_of? Expression and vars [ 'inv_amt' ] . op == :% and vars [ 'amt' ] . rexpr == vars [ 'inv_amt' ] . rexpr and ampl = vars [ 'amt' ] . rexpr ) ) and mask == ( 1 << ampl ) - 1 and vars [ 'var' ] . kind_of? Expression and vars [ 'var' ] . op == :& and vars [ 'var' ] . rexpr == mask and ivars = vars [ 'var' ] . lexpr . match ( m , 'var' , :sh_op , 'amt' , :inv_sh_op , 'inv_amt' ) and ivars [ :sh_op ] == { :>> => :<< , :<< => :>> } [ ivars [ :inv_sh_op ] ] and ( ( ivars [ 'amt' ] . kind_of? ( :: Integer ) and ivars [ 'inv_amt' ] . kind_of? ( :: Integer ) and ampl = ivars [ 'amt' ] + ivars [ 'inv_amt' ] ) or ( ivars [ 'amt' ] . kind_of? Expression and ivars [ 'amt' ] . op == :% and ivars [ 'amt' ] . rexpr . kind_of? ( :: Integer ) and ivars [ 'inv_amt' ] . kind_of? Expression and ivars [ 'inv_amt' ] . op == :% and ivars [ 'amt' ] . rexpr == ivars [ 'inv_amt' ] . rexpr and ampl = ivars [ 'amt' ] . rexpr ) ) if ivars [ :sh_op ] != vars [ :sh_op ] ivars [ :sh_op ] , ivars [ :inv_sh_op ] = ivars [ :inv_sh_op ] , ivars [ :sh_op ] ivars [ 'amt' ] , ivars [ 'inv_amt' ] = ivars [ 'inv_amt' ] , ivars [ 'amt' ] end amt = Expression [ [ vars [ 'amt' ] , :+ , ivars [ 'amt' ] ] , :% , ampl ] invamt = Expression [ [ vars [ 'inv_amt' ] , :+ , ivars [ 'inv_amt' ] ] , :% , ampl ] Expression [ [ [ [ ivars [ 'var' ] , :& , mask ] , vars [ :sh_op ] , amt ] , :| , [ [ ivars [ 'var' ] , :& , mask ] , vars [ :inv_sh_op ] , invamt ] ] , :& , mask ] . reduce_rec else Expression [ e , :& , mask ] end end
a check to see if an Expr is the composition of two rotations (rol eax, 4 ; rol eax, 6 => rol eax, 10)
this is a bit too ugly to stay in the main reduce_rec body.
a check to see if an Expr is the composition of two rotations ( rol eax 4 ; rol eax 6 = > rol eax 10 ) this is a bit too ugly to stay in the main reduce_rec body .
# it's a rotation # ensure the rotations are the same orientation
e
mask