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.



915
916
917
918
919
920
921
922
# File 'lib/wilson.rb', line 915

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.



903
904
905
# File 'lib/wilson.rb', line 903

def id
  @id
end

#indexObject

Returns the value of attribute index.



903
904
905
# File 'lib/wilson.rb', line 903

def index
  @index
end

#isAssemblerOffset=(value) ⇒ Object (writeonly)

FIX



905
906
907
# File 'lib/wilson.rb', line 905

def isAssemblerOffset=(value)
  @isAssemblerOffset = value
end

#offsetObject

Returns the value of attribute offset.



904
905
906
# File 'lib/wilson.rb', line 904

def offset
  @offset
end

Class Method Details

.on_id_offset(machine, id, offset) ⇒ Object



907
908
909
910
911
912
913
# File 'lib/wilson.rb', line 907

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



937
938
939
940
941
942
943
944
# File 'lib/wilson.rb', line 937

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)


946
947
948
# File 'lib/wilson.rb', line 946

def address?
  true
end

#bitsObject



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

def bits
  super || self.machine.bits
end

#mObject



984
985
986
# File 'lib/wilson.rb', line 984

def m
  self
end

#offset?Boolean

Returns:

  • (Boolean)


950
951
952
# File 'lib/wilson.rb', line 950

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

#push_mod_rm_on(spareRegister, stream) ⇒ Object



954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'lib/wilson.rb', line 954

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