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;
}
|