Class: KeystoneEngine::Ks
- Inherits:
-
Object
- Object
- KeystoneEngine::Ks
- Defined in:
- lib/keystone_engine.rb
Instance Method Summary collapse
- #asm(instructions, address = 0) ⇒ Object
-
#initialize(arch, mode) ⇒ Ks
constructor
A new instance of Ks.
Constructor Details
#initialize(arch, mode) ⇒ Ks
Returns a new instance of Ks.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/keystone_engine.rb', line 50 def initialize(arch, mode) _ks = KsEnginePtr.new err = KeystoneEngine::ks_open(arch, mode, _ks) if err != KS_ERR_OK raise KsError, KeystoneEngine::ks_strerror(err).read_string end @ks = _ks[:value] ObjectSpace.define_finalizer(self, proc{ KeystoneEngine::ks_close(ks) }) end |
Instance Method Details
#asm(instructions, address = 0) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/keystone_engine.rb', line 61 def asm(instructions, address=0) inst = FFI::MemoryPointer.from_string(instructions) bytes = StringPtr.new size = IntPtr.new count = IntPtr.new err = KeystoneEngine::ks_asm(ks, inst, address, bytes, size, count) if err != KS_ERR_OK raise KsError, KeystoneEngine::ks_strerror(err).read_string end return [bytes[:value].read_string(size[:value]), count[:value]] end |