Class: Pwnlib::Shellcraft::Registers::Register
- Inherits:
-
Object
- Object
- Pwnlib::Shellcraft::Registers::Register
- Defined in:
- lib/pwnlib/shellcraft/registers.rb
Overview
class Register, currently only supports i386 and amd64.
Instance Attribute Summary collapse
-
#bigger ⇒ Object
readonly
Returns the value of attribute bigger.
-
#ff00 ⇒ Object
readonly
Returns the value of attribute ff00.
-
#is64bit ⇒ Object
readonly
Returns the value of attribute is64bit.
-
#name ⇒ String
readonly
Register’s name.
-
#native32 ⇒ Object
readonly
Returns the value of attribute native32.
-
#native64 ⇒ Object
readonly
Returns the value of attribute native64.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#sizes ⇒ Object
readonly
Returns the value of attribute sizes.
-
#smaller ⇒ Object
readonly
Returns the value of attribute smaller.
-
#xor ⇒ Object
readonly
Returns the value of attribute xor.
Instance Method Summary collapse
- #bits ⇒ Object
- #bytes ⇒ Object
- #fits(value) ⇒ Object
-
#initialize(name, size) ⇒ Register
constructor
Instantiate a Register object.
- #inspect ⇒ Object
- #to_s ⇒ Object
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.
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
#bigger ⇒ Object (readonly)
Returns the value of attribute bigger.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def bigger @bigger end |
#ff00 ⇒ Object (readonly)
Returns the value of attribute ff00.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def ff00 @ff00 end |
#is64bit ⇒ Object (readonly)
Returns the value of attribute is64bit.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def is64bit @is64bit end |
#name ⇒ String (readonly)
Returns Register’s name.
36 37 38 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 36 def name @name end |
#native32 ⇒ Object (readonly)
Returns the value of attribute native32.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def native32 @native32 end |
#native64 ⇒ Object (readonly)
Returns the value of attribute native64.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def native64 @native64 end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def size @size end |
#sizes ⇒ Object (readonly)
Returns the value of attribute sizes.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def sizes @sizes end |
#smaller ⇒ Object (readonly)
Returns the value of attribute smaller.
37 38 39 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 37 def smaller @smaller end |
#xor ⇒ Object (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
#bits ⇒ Object
72 73 74 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 72 def bits size end |
#bytes ⇒ Object
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 |
#inspect ⇒ Object
88 89 90 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 88 def inspect format('Register(%s)', name) end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/pwnlib/shellcraft/registers.rb', line 84 def to_s name end |