Class: Ronin::Code::ASM::MemoryOperand

Inherits:
Struct
  • Object
show all
Defined in:
lib/ronin/code/asm/memory_operand.rb

Overview

Represents a Memory Operand.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base = nil, offset = 0, index = nil, scale = 1, width = nil) ⇒ MemoryOperand

Creates a new Memory Operand.

Parameters:

  • base (Register, nil) (defaults to: nil)

    The base of the value.

  • offset (Integer) (defaults to: 0)

    The fixed offset to add to the base.

  • index (Register, nil) (defaults to: nil)

    The variable index to multiple by scale, then add to `base.

  • scale (Integer) (defaults to: 1)

    The scale to multiple index by.

  • width (Integer, nil) (defaults to: nil)

    The optional width of the memory operand.

Raises:

  • (TypeError)

    base or index was not a Register or nil.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ronin/code/asm/memory_operand.rb', line 54

def initialize(base=nil,offset=0,index=nil,scale=1,width=nil)
  unless (base.nil? || base.kind_of?(Register))
    raise(TypeError,"base must be a Register or nil")
  end

  unless offset.kind_of?(Integer)
    raise(TypeError,"offset must be an Integer")
  end

  unless (index.nil? || index.kind_of?(Register))
    raise(TypeError,"index must be a Register or nil")
  end

  unless scale.kind_of?(Integer)
    raise(TypeError,"scale must be an Integer")
  end

  if base
    width ||= base.width
  end

  super(base,offset,index,scale,width)
end

Instance Attribute Details

#baseObject

Returns the value of attribute base

Returns:

  • (Object)

    the current value of base



31
32
33
# File 'lib/ronin/code/asm/memory_operand.rb', line 31

def base
  @base
end

#indexObject

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



31
32
33
# File 'lib/ronin/code/asm/memory_operand.rb', line 31

def index
  @index
end

#offsetObject

Returns the value of attribute offset

Returns:

  • (Object)

    the current value of offset



31
32
33
# File 'lib/ronin/code/asm/memory_operand.rb', line 31

def offset
  @offset
end

#scaleObject

Returns the value of attribute scale

Returns:

  • (Object)

    the current value of scale



31
32
33
# File 'lib/ronin/code/asm/memory_operand.rb', line 31

def scale
  @scale
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



31
32
33
# File 'lib/ronin/code/asm/memory_operand.rb', line 31

def width
  @width
end

Instance Method Details

#+(offset) ⇒ MemoryOperand

Adds to the offset of the Memory Operand.

Parameters:

  • offset (Integer)

    The offset to add to the Memory Operand.

Returns:



87
88
89
90
91
92
93
94
95
# File 'lib/ronin/code/asm/memory_operand.rb', line 87

def +(offset)
  MemoryOperand.new(
    self.base,
    self.offset + offset,
    self.index,
    self.scale,
    self.width
  )
end

#-(offset) ⇒ MemoryOperand

Subtracts from the offset of the Memory Operand.

Parameters:

  • offset (Integer)

    The offset to subject from the Memory Operand.

Returns:



106
107
108
109
110
111
112
113
114
# File 'lib/ronin/code/asm/memory_operand.rb', line 106

def -(offset)
  MemoryOperand.new(
    self.base,
    self.offset - offset,
    self.index,
    self.scale,
    self.width
  )
end