Class: Rex::Poly::LogicalRegister

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/poly/register.rb

Overview

This class represents a register that is used in the context of one or more logical blocks. The register number is assigned on demand or is statically specified if passed in to the constructor.

Direct Known Subclasses

X86

Defined Under Namespace

Classes: X86

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, regnum = nil) ⇒ LogicalRegister

Initializes the register’s name and number, if assigned. If a register number is specified, the instance will be assumed to have a statically assigned register number. The name is meant to be used as a symbolic variable name, such as ‘counter’ or ‘key’.



31
32
33
34
35
# File 'lib/rex/poly/register.rb', line 31

def initialize(name, regnum = nil)
  @name   = name
  @regnum = regnum
  @static = (regnum) ? true : false
end

Instance Attribute Details

#nameObject (readonly)

Returns the variable (friendly) name for the register that was passed to the constructor.



70
71
72
# File 'lib/rex/poly/register.rb', line 70

def name
  @name
end

Class Method Details

.regnum_setObject

This class method is meant to return an array of register numbers that can be used to pool from. Architecture specific classes must implement this method on their own.



21
22
23
# File 'lib/rex/poly/register.rb', line 21

def self.regnum_set
  nil
end

Instance Method Details

#regnumObject

Returns the register number that has currently been assigned. If no register number is assigned, an InvalidRegisterError exception is raised. This exception can be used to assign the LogicalRegister instance a register number on demand.

Raises:



60
61
62
63
64
# File 'lib/rex/poly/register.rb', line 60

def regnum
  raise InvalidRegisterError.new(self), "Register has not been assigned" if (@regnum == nil)

  @regnum
end

#regnum=(val) ⇒ Object

Sets the register number to the value specified. If the register number is declared static, a RuntimeError exception is raised.

Raises:



48
49
50
51
52
# File 'lib/rex/poly/register.rb', line 48

def regnum=(val)
  raise RuntimeError, "Attempted to assign regnum to static register" if (static?)

  @regnum = val
end

#static?Boolean

Returns true if the register number should be assumed static.

Returns:

  • (Boolean)


40
41
42
# File 'lib/rex/poly/register.rb', line 40

def static?
  @static
end