Class: Evoasm::X64::CPUState
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- Evoasm::X64::CPUState
- Defined in:
- lib/evoasm/x64/cpu_state.rb
Overview
Represents the CPU state (i.e. a snapshot of all registers) at a specific moment in time.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](register, word = :none) ⇒ Array<Integer>
Obtain the value of a register.
-
#[]=(register, data) ⇒ void
Sets the value of a register.
-
#clone ⇒ CPUState
Clone this CPU state object.
-
#emit_load(buffer) ⇒ void
Emits machine code to load (set) the current CPU state to the state of this object.
-
#emit_store(buffer) ⇒ void
Emits machine code to store (save) the current CPU state into this object.
-
#initialize(flags = [:rflags]) ⇒ CPUState
constructor
A new instance of CPUState.
- #rflags_flag(flag) ⇒ Object
-
#to_h ⇒ Hash
Converts this object into a hash.
Constructor Details
#initialize(flags = [:rflags]) ⇒ CPUState
Returns a new instance of CPUState
16 17 18 19 20 |
# File 'lib/evoasm/x64/cpu_state.rb', line 16 def initialize(flags = [:rflags]) ptr = Libevoasm.x64_cpu_state_alloc Libevoasm.x64_cpu_state_init ptr, Libevoasm.enum_type(:x64_cpu_state_flags).flags(flags, shift: false) super(ptr) end |
Class Method Details
.random ⇒ Object
22 23 24 25 26 27 |
# File 'lib/evoasm/x64/cpu_state.rb', line 22 def self.random cpu_state = new Libevoasm.x64_cpu_state_rand cpu_state, PRNG.default cpu_state end |
Instance Method Details
#[](register, word = :none) ⇒ Array<Integer>
Obtain the value of a register
45 46 47 48 49 |
# File 'lib/evoasm/x64/cpu_state.rb', line 45 def [](register, word = :none) data_ptr = FFI::MemoryPointer.new :uint64, 16 data_len = Libevoasm.x64_cpu_state_get self, register, word, data_ptr, 16 data_ptr.read_array_of_uint64 data_len end |
#[]=(register, data) ⇒ void
This method returns an undefined value.
Sets the value of a register
34 35 36 37 38 39 |
# File 'lib/evoasm/x64/cpu_state.rb', line 34 def []=(register, data) data = Array(data) ptr = FFI::MemoryPointer.new :uint64, data.size ptr.write_array_of_uint64 data Libevoasm.x64_cpu_state_set self, register, ptr, data.size end |
#clone ⇒ CPUState
Clone this CPU state object
53 54 55 56 57 58 |
# File 'lib/evoasm/x64/cpu_state.rb', line 53 def clone cloned_cpu_state = self.class.new Libevoasm.x64_cpu_state_clone self, cloned_cpu_state cloned_cpu_state end |
#emit_load(buffer) ⇒ void
This method returns an undefined value.
Emits machine code to load (set) the current CPU state to the state of this object
100 101 102 103 104 |
# File 'lib/evoasm/x64/cpu_state.rb', line 100 def emit_load(buffer) unless Libevoasm.x64_cpu_state_emit_load self, buffer raise Error.last end end |
#emit_store(buffer) ⇒ void
This method returns an undefined value.
Emits machine code to store (save) the current CPU state into this object
89 90 91 92 93 |
# File 'lib/evoasm/x64/cpu_state.rb', line 89 def emit_store(buffer) unless Libevoasm.x64_cpu_state_emit_store self, buffer raise Error.last end end |
#rflags_flag(flag) ⇒ Object
80 81 82 |
# File 'lib/evoasm/x64/cpu_state.rb', line 80 def rflags_flag(flag) Libevoasm.x64_cpu_state_get_rflags_flag self, flag end |
#to_h ⇒ Hash
Converts this object into a hash
74 75 76 77 78 |
# File 'lib/evoasm/x64/cpu_state.rb', line 74 def to_h X64.registers.each_with_object({}) do |register, hash| hash[register] = self[register] end end |