Class: Hatstone
- Inherits:
-
Object
- Object
- Hatstone
- Defined in:
- ext/hatstone/hatstone.c
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.new(arch, mode) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'ext/hatstone/hatstone.c', line 21
static VALUE
hatstone_open(VALUE klass, VALUE arch, VALUE mode)
{
csh * handle = calloc(sizeof(csh), 1);
if (CS_ERR_OK == cs_open(NUM2INT(arch), NUM2INT(mode), handle)) {
return TypedData_Wrap_Struct(klass, &handle_type, handle);
} else {
return Qnil;
}
}
|
Instance Method Details
#disasm(code_str, addr) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'ext/hatstone/hatstone.c', line 33
static VALUE
hatstone_disasm(VALUE self, VALUE code_str, VALUE addr)
{
csh * handle;
TypedData_Get_Struct(self, csh, &handle_type, handle);
size_t size = RSTRING_LEN(code_str);
const uint8_t * code = (uint8_t *)StringValuePtr(code_str);
uint64_t address = NUM2LONG(addr);
cs_insn * insn = cs_malloc(*handle);
VALUE list = rb_ary_new();
while (cs_disasm_iter(*handle, &code, &size, &address, insn)) {
VALUE vals = rb_ary_new_from_args(6,
INT2NUM(insn->id),
LONG2NUM(insn->address),
INT2NUM(insn->size),
rb_str_new((const char *)insn->bytes, insn->size),
rb_str_new2(insn->mnemonic),
rb_str_new2(insn->op_str));
rb_ary_push(list, rb_struct_alloc(cInsn, vals));
}
cs_free(insn, 1);
return list;
}
|