Class: Pwnlib::Shellcraft::Registers::Register

Inherits:
Object
  • Object
show all
Defined in:
lib/pwnlib/shellcraft/registers.rb

Overview

class Register, currently only supports i386 and amd64.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, size) ⇒ Register

Instantiate a Pwnlib::Shellcraft::Registers::Register object.

Create a register by its name and size (in bits) for fetching other information. For example, for register ‘ax’, #bigger contains ‘rax’ and ‘eax’.

Normally you don’t need to create any Pwnlib::Shellcraft::Registers::Register object, use Pwnlib::Shellcraft::Registers.get_register to get register by name.

Examples:

Register.new('rax', 64)
Register.new('bx', 16)

Parameters:

  • name (String)

    Register’s name.

  • size (Integer)

    Register size in bits.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pwnlib/shellcraft/registers.rb', line 54

def initialize(name, size)
  @name = name
  @size = size
  X86_ORDERED.each do |row|
    next unless row.include?(name)

    @bigger = row[0, row.index(name)]
    @smaller = row[(row.index(name) + 1)..-1]
    @native64 = row[0]
    @native32 = row[1]
    @sizes = row.each_with_object({}).with_index { |(r, h), i| h[64 >> i] = r }
    @xor = @sizes[[size, 32].min]
    break
  end
  @ff00 = "#{name[1]}h" if @size >= 32 && @name.end_with?('x')
  @is64bit = true if @name.start_with?('r')
end

Instance Attribute Details

#biggerObject (readonly)

Returns the value of attribute bigger.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def bigger
  @bigger
end

#ff00Object (readonly)

Returns the value of attribute ff00.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def ff00
  @ff00
end

#is64bitObject (readonly)

Returns the value of attribute is64bit.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def is64bit
  @is64bit
end

#nameString (readonly)

Returns Register’s name.

Returns:

  • (String)

    Register’s name.



36
37
38
# File 'lib/pwnlib/shellcraft/registers.rb', line 36

def name
  @name
end

#native32Object (readonly)

Returns the value of attribute native32.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def native32
  @native32
end

#native64Object (readonly)

Returns the value of attribute native64.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def native64
  @native64
end

#sizeObject (readonly)

Returns the value of attribute size.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def size
  @size
end

#sizesObject (readonly)

Returns the value of attribute sizes.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def sizes
  @sizes
end

#smallerObject (readonly)

Returns the value of attribute smaller.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def smaller
  @smaller
end

#xorObject (readonly)

Returns the value of attribute xor.



37
38
39
# File 'lib/pwnlib/shellcraft/registers.rb', line 37

def xor
  @xor
end

Instance Method Details

#bitsObject



72
73
74
# File 'lib/pwnlib/shellcraft/registers.rb', line 72

def bits
  size
end

#bytesObject



76
77
78
# File 'lib/pwnlib/shellcraft/registers.rb', line 76

def bytes
  bits / 8
end

#fits(value) ⇒ Object



80
81
82
# File 'lib/pwnlib/shellcraft/registers.rb', line 80

def fits(value)
  size >= Registers.bits_required(value)
end

#inspectObject



88
89
90
# File 'lib/pwnlib/shellcraft/registers.rb', line 88

def inspect
  format('Register(%s)', name)
end

#to_sObject



84
85
86
# File 'lib/pwnlib/shellcraft/registers.rb', line 84

def to_s
  name
end