Module: Evoasm::X64
- Defined in:
- lib/evoasm/x64.rb,
lib/evoasm/x64/operand.rb,
lib/evoasm/x64/cpu_state.rb,
lib/evoasm/x64/parameters.rb,
lib/evoasm/x64/instruction.rb
Defined Under Namespace
Classes: BasicParameters, CPUState, Instruction, Operand, Parameters
Class Method Summary collapse
-
.disassemble(assembly, address = nil) ⇒ String
Disassembles x86-64 machine code.
-
.emit_stack_frame(abi = :sysv, buffer) ⇒ void
Emits a stack frame for the given ABI.
-
.encode(instruction_name, parameters, buffer = nil, basic: false) ⇒ String?
Encodes a x86-64 machine instruction.
-
.features ⇒ Array<Symbol>
The list of supported CPU features (obtained via CPUID).
- .id ⇒ Object
-
.instruction(instruction_name) ⇒ Instruction
Gives an Instruction object for the given instruction name.
-
.instruction_names(*reg_types, operand_types: [:reg, :rm, :imm], useless: false, basic: true, features: nil) ⇒ Array<Symbol>
Gives a list of instructions.
-
.registers ⇒ Array<Symbol>
A list of available registers.
Class Method Details
.disassemble(assembly, address = nil) ⇒ String
Disassembles x86-64 machine code
18 19 20 |
# File 'lib/evoasm/x64.rb', line 18 def disassemble(assembly, address = nil) Evoasm::Capstone.disassemble_x64 assembly, address end |
.emit_stack_frame(abi = :sysv, buffer) ⇒ void
This method returns an undefined value.
Emits a stack frame for the given ABI
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/evoasm/x64.rb', line 64 def emit_stack_frame(abi = :sysv, buffer) unless Libevoasm.x64_emit_func_prolog abi, buffer raise Error.last end yield unless Libevoasm.x64_emit_func_epilog abi, buffer raise Error.last end end |
.encode(instruction_name, parameters, buffer = nil, basic: false) ⇒ String?
Encodes a x86-64 machine instruction
28 29 30 |
# File 'lib/evoasm/x64.rb', line 28 def encode(instruction_name, parameters, buffer = nil, basic: false) instruction(instruction_name).encode parameters, buffer, basic: basic end |
.features ⇒ Array<Symbol>
Returns the list of supported CPU features (obtained via CPUID)
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/evoasm/x64.rb', line 38 def features feature_enum_type = Libevoasm.enum_type(:x64_feature) arch_info = Libevoasm.get_arch_info :x64 features_as_flags = Libevoasm.arch_info_get_features arch_info feature_enum_type.symbol_map.each_with_object({}) do |(k, v), features| next if k == :none supported = (features_as_flags & (1 << v)) != 0 features[k] = supported end end |
.id ⇒ Object
49 50 51 |
# File 'lib/evoasm/x64.rb', line 49 def id :x64 end |
.instruction(instruction_name) ⇒ Instruction
Gives an Instruction object for the given instruction name.
56 57 58 |
# File 'lib/evoasm/x64.rb', line 56 def instruction(instruction_name) Instruction.new Libevoasm.x64_get_inst(instruction_name), instruction_name end |
.instruction_names(*reg_types, operand_types: [:reg, :rm, :imm], useless: false, basic: true, features: nil) ⇒ Array<Symbol>
Gives a list of instructions
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/evoasm/x64.rb', line 83 def instruction_names(*reg_types, operand_types: [:reg, :rm, :imm], useless: false, basic: true, features: nil) inst_id_enum_type = Libevoasm.enum_type(:x64_inst_id) feature_enum_type = Libevoasm.enum_type(:x64_feature) insts_flags_enum_type = Libevoasm.enum_type(:x64_insts_flags) op_type_enum_type = Libevoasm.enum_type(:x64_operand_type) reg_type_enum_type = Libevoasm.enum_type(:x64_reg_type) flags = [] flags << :include_useless if useless flags << :only_basic if basic flags_as_flags = insts_flags_enum_type.flags flags, shift: false features_as_flags = if features.nil? arch_info = Libevoasm.get_arch_info :x64 Libevoasm.arch_info_get_features arch_info else feature_enum_type.flags features, shift: true end op_types_as_flags = op_type_enum_type.flags operand_types, shift: true reg_types_as_flags = reg_type_enum_type.flags reg_types, shift: true n_insts = inst_id_enum_type[:none] array = FFI::MemoryPointer.new :int, n_insts len = Libevoasm.x64_get_insts(flags_as_flags, features_as_flags, op_types_as_flags, reg_types_as_flags, array) instruction_ids = array.read_array_of_type(:int, :read_int, len) instruction_ids.map { |e| inst_id_enum_type[e] } end |
.registers ⇒ Array<Symbol>
Returns a list of available registers
33 34 35 |
# File 'lib/evoasm/x64.rb', line 33 def registers Libevoasm.enum_type(:x64_reg_id).symbols[0..-2] end |