Class: Evoasm::X64::Operand
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- Evoasm::X64::Operand
- Defined in:
- lib/evoasm/x64/operand.rb
Overview
Represents a formal instruction operand
Constant Summary
- INVALID_IMMEDIATE =
-1
Instance Attribute Summary collapse
-
#instruction ⇒ X64::Instruction
readonly
The instruction this operand belongs to.
Instance Method Summary collapse
-
#explicit? ⇒ Boolean
Returns whether this operand is explicit.
-
#immediate ⇒ Integer?
Returns the operand's immediate (e.g. if implicit) if available.
-
#implicit? ⇒ Boolean
Returns whether this operand is implicit.
- #index ⇒ Object
-
#index_register_size ⇒ Integer?
Returns the operand's index register size (e.g. in VSIB instructions).
- #inspect(parameters = nil) ⇒ Object
-
#maybe_written? ⇒ Boolean
Returns whether this operand is possibliy written (e.g. in a conditional move instruction).
-
#memory_size ⇒ Integer?
Returns the operand's memory size (e.g. in R/M instructions).
-
#mnemonic? ⇒ Boolean
Returns whether this operand is part of the instruction mnemonic.
-
#parameter ⇒ X64::Parameter
Gives the parameter affecting this operand.
-
#read? ⇒ Boolean
Returns whether this operand is read.
-
#register(parameters = nil) ⇒ Symbol?
Returns the operand's register (e.g. if implicit) if available.
-
#register_size ⇒ Integer?
Returns the operand's register size.
-
#register_type ⇒ Symbol?
Returns the operand's register type (e.g. if implicit) if available.
-
#size ⇒ Integer
Gives the operand's size.
-
#type ⇒ :rm, ...
Returns the operand type.
-
#word(mode, parameters = nil, mask: false) ⇒ Symbol
Gives the operand's word.
- #word_mask(mode, parameters = nil) ⇒ Object
-
#written? ⇒ Boolean
Returns whether this operand is written.
Methods inherited from FFI::Pointer
Instance Attribute Details
#instruction ⇒ X64::Instruction (readonly)
Returns the instruction this operand belongs to
9 10 11 |
# File 'lib/evoasm/x64/operand.rb', line 9 def instruction @instruction end |
Instance Method Details
#explicit? ⇒ Boolean
Returns whether this operand is explicit
62 63 64 |
# File 'lib/evoasm/x64/operand.rb', line 62 def explicit? !implicit? end |
#immediate ⇒ Integer?
Returns the operand's immediate (e.g. if implicit) if available
100 101 102 103 104 105 106 107 |
# File 'lib/evoasm/x64/operand.rb', line 100 def immediate if type == :imm imm = Libevoasm.x64_operand_get_imm self imm == INVALID_IMMEDIATE ? nil : imm else nil end end |
#implicit? ⇒ Boolean
Returns whether this operand is implicit
44 45 46 |
# File 'lib/evoasm/x64/operand.rb', line 44 def implicit? Libevoasm.x64_operand_is_implicit self end |
#index ⇒ Object
153 154 155 156 157 |
# File 'lib/evoasm/x64/operand.rb', line 153 def index index = Libevoasm.x64_inst_get_operand_idx @instruction, self return nil if index == -1 index end |
#index_register_size ⇒ Integer?
Returns the operand's index register size (e.g. in VSIB instructions)
171 172 173 174 175 176 177 |
# File 'lib/evoasm/x64/operand.rb', line 171 def index_register_size if type == :vsib convert_size Libevoasm.x64_operand_get_index_reg_size(self) else nil end end |
#inspect(parameters = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/evoasm/x64/operand.rb', line 48 def inspect(parameters = nil) info = case type when :reg, :rm "#{register_type}:#{register parameters}" when :imm "imm:#{immediate}" when :mem 'mem' end "#<#{self.class.inspect} #{index} #{info}>" end |
#maybe_written? ⇒ Boolean
Returns whether this operand is possibliy written (e.g. in a conditional move instruction)
34 35 36 |
# File 'lib/evoasm/x64/operand.rb', line 34 def maybe_written? Libevoasm.x64_operand_is_maybe_written self end |
#memory_size ⇒ Integer?
Returns the operand's memory size (e.g. in R/M instructions)
181 182 183 184 185 186 187 |
# File 'lib/evoasm/x64/operand.rb', line 181 def memory_size if type == :rm || type == :mem || type == :vsib convert_size Libevoasm.x64_operand_get_mem_size(self) else nil end end |
#mnemonic? ⇒ Boolean
Returns whether this operand is part of the instruction mnemonic
39 40 41 |
# File 'lib/evoasm/x64/operand.rb', line 39 def mnemonic? Libevoasm.x64_operand_is_mnem self end |
#parameter ⇒ X64::Parameter
Gives the parameter affecting this operand
19 20 21 |
# File 'lib/evoasm/x64/operand.rb', line 19 def parameter @instruction.parameters[Libevoasm.x64_operand_get_param_idx self] end |
#read? ⇒ Boolean
Returns whether this operand is read
24 25 26 |
# File 'lib/evoasm/x64/operand.rb', line 24 def read? Libevoasm.x64_operand_is_read self end |
#register(parameters = nil) ⇒ Symbol?
Returns the operand's register (e.g. if implicit) if available
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/evoasm/x64/operand.rb', line 74 def register(parameters = nil) if type == :rm || type == :reg reg_id = Libevoasm.x64_operand_get_reg_id self if reg_id == :none if parameters parameter_name = parameter&.name if parameter_name parameters[parameter_name] else nil end else nil end else reg_id end else nil end end |
#register_size ⇒ Integer?
Returns the operand's register size
161 162 163 164 165 166 167 |
# File 'lib/evoasm/x64/operand.rb', line 161 def register_size if type == :rm || type == :reg convert_size Libevoasm.x64_operand_get_reg_size(self) else nil end end |
#register_type ⇒ Symbol?
Returns the operand's register type (e.g. if implicit) if available
111 112 113 114 115 116 117 118 |
# File 'lib/evoasm/x64/operand.rb', line 111 def register_type if type == :rm || type == :reg reg_type = Libevoasm.x64_operand_get_reg_type self reg_type == :none ? nil : reg_type else nil end end |
#size ⇒ Integer
Gives the operand's size
122 123 124 |
# File 'lib/evoasm/x64/operand.rb', line 122 def size convert_size Libevoasm.x64_operand_get_size(self) end |
#type ⇒ :rm, ...
Returns the operand type
68 69 70 |
# File 'lib/evoasm/x64/operand.rb', line 68 def type Libevoasm.x64_operand_get_type self end |
#word(mode, parameters = nil, mask: false) ⇒ Symbol
Gives the operand's word
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/evoasm/x64/operand.rb', line 130 def word(mode, parameters = nil, mask: false) word = Libevoasm.x64_operand_get_word(self, @instruction, parameters, mode == :read) if word && mask mask = Bitmap.new 512 Libevoasm.x64_operand_word_get_mask(word, mask) mask else word end end |
#word_mask(mode, parameters = nil) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/evoasm/x64/operand.rb', line 141 def word_mask(mode, parameters = nil) word = Libevoasm.x64_operand_get_word(self, @instruction, parameters, mode == :read) if word && word != :none #mask = Bitmap.new 512 mask = FFI::MemoryPointer.new :uint64, 8 Libevoasm.x64_operand_word_get_mask(word, mask) mask.read_array_of_uint64 8 else nil end end |
#written? ⇒ Boolean
Returns whether this operand is written
29 30 31 |
# File 'lib/evoasm/x64/operand.rb', line 29 def written? Libevoasm.x64_operand_is_written self end |