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.



934
935
936
937
938
939
940
941
# File 'lib/wilson.rb', line 934

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.



922
923
924
# File 'lib/wilson.rb', line 922

def id
  @id
end

#indexObject

Returns the value of attribute index.



922
923
924
# File 'lib/wilson.rb', line 922

def index
  @index
end

#isAssemblerOffset=(value) ⇒ Object (writeonly)

FIX



924
925
926
# File 'lib/wilson.rb', line 924

def isAssemblerOffset=(value)
  @isAssemblerOffset = value
end

#offsetObject

Returns the value of attribute offset.



923
924
925
# File 'lib/wilson.rb', line 923

def offset
  @offset
end

Class Method Details

.on_id_offset(machine, id, offset) ⇒ Object



926
927
928
929
930
931
932
# File 'lib/wilson.rb', line 926

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



956
957
958
959
960
961
962
963
# File 'lib/wilson.rb', line 956

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)


965
966
967
# File 'lib/wilson.rb', line 965

def address?
  true
end

#bitsObject



943
944
945
# File 'lib/wilson.rb', line 943

def bits
  super || self.machine.bits
end

#mObject



1003
1004
1005
# File 'lib/wilson.rb', line 1003

def m
  self
end

#offset?Boolean

Returns:

  • (Boolean)


969
970
971
# File 'lib/wilson.rb', line 969

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

#push_mod_rm_on(spareRegister, stream) ⇒ Object



973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
# File 'lib/wilson.rb', line 973

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