Class: Keystone::Assembler

Inherits:
Object
  • Object
show all
Includes:
KeystoneBind
Defined in:
lib/keystone/keystone.rb

Instance Method Summary collapse

Constructor Details

#initialize(arch: KS_ARCH_ARM, mode: KS_MODE_ARM) ⇒ Assembler

Returns a new instance of Assembler.



46
47
48
49
50
51
52
# File 'lib/keystone/keystone.rb', line 46

def initialize(arch: KS_ARCH_ARM, mode: KS_MODE_ARM)

  FFI::MemoryPointer.new(:pointer,1) do |ptr|
    safe_call(:ks_open, arch, mode, ptr)
    @engine = FFI::AutoPointer.new(ptr.read_pointer, method(:ks_close))
  end
end

Instance Method Details

#assemble(asm_str, addr: 0) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/keystone/keystone.rb', line 54

def assemble(asm_str, addr: 0)
  encoding_ptr = FFI::MemoryPointer.new(:pointer)
  encoding_size = FFI::MemoryPointer.new(:size_t)
  stat_count = FFI::MemoryPointer.new(:size_t)
  safe_call(:ks_asm, @engine, asm_str, addr, encoding_ptr, encoding_size, stat_count)
  encoded_bytes = encoding_ptr.read_pointer.read_array_of_uint8(encoding_size.read_uint)
  ks_free(encoding_ptr.read_pointer)
  encoded_bytes.pack('C*')
end

#set_option(ks_opt_type, value) ⇒ Object



64
65
66
# File 'lib/keystone/keystone.rb', line 64

def set_option(ks_opt_type, value)
  safe_call(:ks_option, @engine, ks_opt_type, value)
end