Class: Evoasm::X64::Instruction
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- Evoasm::X64::Instruction
- Defined in:
- lib/evoasm/x64/instruction.rb
Overview
Represents an x86-64 instruction
Defined Under Namespace
Classes: Parameter
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
The instruction's name.
Instance Method Summary collapse
-
#basic? ⇒ Bool
Returns whether this instruction is encodable with the basic encoder.
-
#encode(parameters, buffer = nil, basic: false) ⇒ void
Encodes the instruciton with the given parameters.
-
#mnemonic ⇒ String
Gives the preferred instruction mnemonic.
-
#mnemonics ⇒ Array<String>
Gives a list of instruction mnemonics.
-
#operand(index) ⇒ Operand
Gives the operand at the specified index.
-
#operands ⇒ Array<Operand>
Gives the instruction's operands.
-
#parameters ⇒ Array<Instruction::Parameter>
Gives this instruction's parameters.
Methods inherited from FFI::Pointer
Instance Attribute Details
#name ⇒ Symbol (readonly)
Returns the instruction's name
16 17 18 |
# File 'lib/evoasm/x64/instruction.rb', line 16 def name @name end |
Instance Method Details
#basic? ⇒ Bool
Returns whether this instruction is encodable with the basic encoder
63 64 65 |
# File 'lib/evoasm/x64/instruction.rb', line 63 def basic? Libevoasm.x64_inst_is_basic(self) end |
#encode(parameters, buffer = nil, basic: false) ⇒ void
This method returns an undefined value.
Encodes the instruciton with the given parameters
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/evoasm/x64/instruction.rb', line 72 def encode(parameters, buffer = nil, basic: false) if basic && !basic? raise ArgumentError, 'instruction does not support basic mode' end buf_ref = Libevoasm.buf_ref_alloc if buffer Libevoasm.buf_to_buf_ref buffer, buf_ref else data = FFI::MemoryPointer.new :uint8, 32 len_ptr = FFI::MemoryPointer.new :size_t, 1 Libevoasm.buf_ref_init buf_ref, data, len_ptr end parameters = Parameters.for(parameters, basic: basic) success = if basic Libevoasm.x64_inst_enc_basic self, parameters, buf_ref else Libevoasm.x64_inst_enc self, parameters, buf_ref end Libevoasm.buf_ref_free buf_ref if success unless buffer len = len_ptr.read_size_t data.read_string len end else raise Error.last end end |
#mnemonic ⇒ String
Gives the preferred instruction mnemonic
33 34 35 |
# File 'lib/evoasm/x64/instruction.rb', line 33 def mnemonic mnemonics.first end |
#mnemonics ⇒ Array<String>
Gives a list of instruction mnemonics
26 27 28 |
# File 'lib/evoasm/x64/instruction.rb', line 26 def mnemonics Libevoasm.x64_inst_get_mnem(self).split('/') end |
#operand(index) ⇒ Operand
Gives the operand at the specified index
39 40 41 |
# File 'lib/evoasm/x64/instruction.rb', line 39 def operand(index) Operand.new Libevoasm.x64_inst_get_operand(self, index), self end |
#operands ⇒ Array<Operand>
Gives the instruction's operands
45 46 47 48 49 50 |
# File 'lib/evoasm/x64/instruction.rb', line 45 def operands n_operands = Libevoasm.x64_inst_get_n_operands self Array.new(n_operands) do |index| operand index end end |
#parameters ⇒ Array<Instruction::Parameter>
Gives this instruction's parameters
54 55 56 57 58 59 |
# File 'lib/evoasm/x64/instruction.rb', line 54 def parameters n_params = Libevoasm.x64_inst_get_n_params self Array.new(n_params) do |param_index| Parameter.new Libevoasm.x64_inst_get_param(self, param_index) end end |