Class: Wilson::Address

Inherits:
Operand show all
Defined in:
lib/wilson.rb

Overview

Address is a memory address in one of the following example forms:

eax, ebx + ecx, eax + 5, 23545, edx + eax + 2312

Instance Attribute Summary collapse

Attributes inherited from Operand

#machine

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operand

#instructionFromMessage, #method_missing, on, #operand?

Constructor Details

#initialize(isAssemblerOffset = nil, bits = nil, id = nil) ⇒ Address

Returns a new instance of Address.



858
859
860
861
862
863
864
865
# File 'lib/wilson.rb', line 858

def initialize isAssemblerOffset = nil, bits = nil, id = nil
  super(bits)

  self.isAssemblerOffset = isAssemblerOffset
  self.id = id

  self.index = self.offset = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Wilson::Operand

Instance Attribute Details

#idObject

Returns the value of attribute id.



846
847
848
# File 'lib/wilson.rb', line 846

def id
  @id
end

#indexObject

Returns the value of attribute index.



846
847
848
# File 'lib/wilson.rb', line 846

def index
  @index
end

#isAssemblerOffset=(value) ⇒ Object (writeonly)

FIX



848
849
850
# File 'lib/wilson.rb', line 848

def isAssemblerOffset=(value)
  @isAssemblerOffset = value
end

#offsetObject

Returns the value of attribute offset.



847
848
849
# File 'lib/wilson.rb', line 847

def offset
  @offset
end

Class Method Details

.on_id_offset(machine, id, offset) ⇒ Object



850
851
852
853
854
855
856
# File 'lib/wilson.rb', line 850

def self.on_id_offset machine, id, offset
  address         = self.new
  address.machine = machine
  address.id      = id
  address.offset  = offset
  address
end

Instance Method Details

#+(o) ⇒ Object

TODO: this seems totally and completely wrong



880
881
882
883
884
885
886
887
# File 'lib/wilson.rb', line 880

def + o # TODO: this seems totally and completely wrong
  if o.register? then
    self.index = o
  else
    self.offset = o
  end
  self
end

#address?Boolean

Returns:

  • (Boolean)


889
890
891
# File 'lib/wilson.rb', line 889

def address?
  true
end

#bitsObject



867
868
869
# File 'lib/wilson.rb', line 867

def bits
  super || self.machine.bits
end

#mObject



927
928
929
# File 'lib/wilson.rb', line 927

def m
  self
end

#offset?Boolean

Returns:

  • (Boolean)


893
894
895
# File 'lib/wilson.rb', line 893

def offset?
  @isAssemblerOffset.nil? ? id.nil? : @isAssemblerOffset
end

#push_mod_rm_on(spareRegister, stream) ⇒ Object



897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
# File 'lib/wilson.rb', line 897

def push_mod_rm_on spareRegister, stream
  if id.nil? then
    stream << (0b00000101 + (spareRegister.id << 3))
    return stream.push_D(offset)
  end

  modrm = case offset
          when 0 then
            0b00000000
          when 1..255 then
            0b01000000
          else
            0b10000000
          end

  if index.nil? then
    modrm += (spareRegister.id << 3)
  else
    stream << (0b00000100 + (spareRegister.id << 3))
    modrm += (index.id << 3)
  end

  stream << modrm + id

  return self if offset == 0
  return stream.push_B(offset) if offset < 256

  stream.push_D offset
end