class Rex::Poly::Machine::Solution
A class to hold a solution for a Rex::Poly::Machine
problem.
Attributes
offset[R]
Public Class Methods
new()
click to toggle source
# File lib/rex/poly/machine/machine.rb, line 264 def initialize @permutations = ::Array.new @reg_state = ::Array.new @offset = 0 end
Public Instance Methods
buffer()
click to toggle source
Render the final buffer.
# File lib/rex/poly/machine/machine.rb, line 309 def buffer previous_offset = nil count = 0 # perform an N-pass fixup for offsets... while( true ) do # If we cant get the offsets fixed within a fixed ammount of tries we return # nil to indicate failure and keep searching for a solution that will work. if( count > 64 ) return nil end # Reset the solution offset so as to update it for this pass @offset = 0 # perform a single pass to ensure we are using the correct offset values @permutations.each do | permutation | permutation.offset = @offset # Note: calling render() can throw both UndefinedPermutation and UnallowedPermutation exceptions, # however as we assume we only ever return the buffer once a final solution has been generated # we should never have either of those exceptions thrown. permutation.render @offset += permutation.length end # If we have generated two consecutive passes which are the same length we can stop fixing up the offsets. if( not previous_offset.nil? and @offset == previous_offset ) break end count +=1 previous_offset = @offset end # now a final pass to render the solution into the raw buffer raw = '' @permutations.each do | permutation | #$stderr.puts "#{permutation.name} - #{ "0x%08X (%d)" % [ permutation.offset, permutation.length] } " raw << permutation.render end return raw end
pop()
click to toggle source
Pop off the last permutaion and register/variables state from this solution.
# File lib/rex/poly/machine/machine.rb, line 297 def pop reg_available, reg_consumed, variables = @reg_state.pop permutation = @permutations.pop permutation.active = false permutation.offset = 0 @offset -= permutation.length return permutation, reg_available, reg_consumed, variables end
push( permutation, reg_available, reg_consumed, variables )
click to toggle source
Push a new permutation onto this solutions permutations list and save the associated register/variables state
# File lib/rex/poly/machine/machine.rb, line 286 def push( permutation, reg_available, reg_consumed, variables ) permutation.active = true permutation.offset = @offset @offset += permutation.length @permutations.push( permutation ) @reg_state.push( [ [].concat(reg_available), [].concat(reg_consumed), {}.merge(variables) ] ) end
reset()
click to toggle source
Reset this solution to an empty state.
# File lib/rex/poly/machine/machine.rb, line 273 def reset @offset = 0 @permutations.each do | permutation | permutation.active = false permutation.offset = 0 end @permutations.clear @reg_state.clear end