6 #include <caml/mlvalues.h>
7 #include <caml/memory.h>
8 #include <caml/alloc.h>
11 #include "capstone/capstone.h"
13 #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0]))
31 CAMLlocal5(
list, cons, rec_insn, array,
tmp);
32 CAMLlocal4(arch_info, op_info_val, tmp2, tmp3);
42 for (j =
c; j > 0; j--) {
43 unsigned int lcount,
i;
44 cons = caml_alloc(2, 0);
46 rec_insn = caml_alloc(10, 0);
47 Store_field(rec_insn, 0, Val_int(insn[j-1].
id));
48 Store_field(rec_insn, 1, Val_int(insn[j-1].address));
49 Store_field(rec_insn, 2, Val_int(insn[j-1].
size));
52 lcount = insn[j-1].size;
54 array = caml_alloc(lcount, 0);
55 for (
i = 0;
i < lcount;
i++) {
56 Store_field(array,
i, Val_int(insn[j-1].
bytes[
i]));
60 Store_field(rec_insn, 3, array);
62 Store_field(rec_insn, 4, caml_copy_string(insn[j-1].
mnemonic));
63 Store_field(rec_insn, 5, caml_copy_string(insn[j-1].op_str));
67 lcount = (insn[j-1]).
detail->regs_read_count;
69 array = caml_alloc(lcount, 0);
70 for (
i = 0;
i < lcount;
i++) {
71 Store_field(array,
i, Val_int(insn[j-1].
detail->regs_read[
i]));
77 Store_field(rec_insn, 6, array);
80 lcount = (insn[j-1]).
detail->regs_write_count;
82 array = caml_alloc(lcount, 0);
83 for (
i = 0;
i < lcount;
i++) {
84 Store_field(array,
i, Val_int(insn[j-1].
detail->regs_write[
i]));
90 Store_field(rec_insn, 7, array);
93 lcount = (insn[j-1]).
detail->groups_count;
95 array = caml_alloc(lcount, 0);
96 for (
i = 0;
i < lcount;
i++) {
97 Store_field(array,
i, Val_int(insn[j-1].
detail->groups[
i]));
103 Store_field(rec_insn, 8, array);
108 arch_info = caml_alloc(1, 0);
110 op_info_val = caml_alloc(10, 0);
111 Store_field(op_info_val, 0, Val_bool(insn[j-1].
detail->arm.usermode));
112 Store_field(op_info_val, 1, Val_int(insn[j-1].
detail->arm.vector_size));
113 Store_field(op_info_val, 2, Val_int(insn[j-1].
detail->arm.vector_data));
114 Store_field(op_info_val, 3, Val_int(insn[j-1].
detail->arm.cps_mode));
115 Store_field(op_info_val, 4, Val_int(insn[j-1].
detail->arm.cps_flag));
116 Store_field(op_info_val, 5, Val_int(insn[j-1].
detail->arm.cc));
117 Store_field(op_info_val, 6, Val_bool(insn[j-1].
detail->arm.update_flags));
118 Store_field(op_info_val, 7, Val_bool(insn[j-1].
detail->arm.writeback));
119 Store_field(op_info_val, 8, Val_int(insn[j-1].
detail->arm.mem_barrier));
121 lcount = insn[j-1].detail->arm.op_count;
123 array = caml_alloc(lcount, 0);
124 for (
i = 0;
i < lcount;
i++) {
125 tmp2 = caml_alloc(6, 0);
126 switch(insn[j-1].
detail->arm.operands[
i].type) {
129 tmp = caml_alloc(1, 1);
130 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm.operands[
i].reg));
133 tmp = caml_alloc(1, 2);
134 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm.operands[
i].imm));
137 tmp = caml_alloc(1, 3);
138 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm.operands[
i].imm));
141 tmp = caml_alloc(1, 4);
142 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm.operands[
i].imm));
145 tmp = caml_alloc(1, 5);
146 Store_field(
tmp, 0, caml_copy_double(insn[j-1].
detail->arm.operands[
i].fp));
149 tmp = caml_alloc(1, 6);
150 tmp3 = caml_alloc(5, 0);
151 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->arm.operands[
i].mem.base));
152 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->arm.operands[
i].mem.index));
153 Store_field(tmp3, 2, Val_int(insn[j-1].
detail->arm.operands[
i].mem.scale));
154 Store_field(tmp3, 3, Val_int(insn[j-1].
detail->arm.operands[
i].mem.disp));
155 Store_field(tmp3, 4, Val_int(insn[j-1].
detail->arm.operands[
i].mem.lshift));
156 Store_field(
tmp, 0, tmp3);
159 tmp = caml_alloc(1, 7);
160 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm.operands[
i].setend));
164 tmp3 = caml_alloc(2, 0);
165 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->arm.operands[
i].shift.type));
166 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->arm.operands[
i].shift.value));
167 Store_field(tmp2, 0, Val_int(insn[j-1].
detail->arm.operands[
i].vector_index));
168 Store_field(tmp2, 1, tmp3);
169 Store_field(tmp2, 2,
tmp);
170 Store_field(tmp2, 3, Val_bool(insn[j-1].
detail->arm.operands[
i].subtracted));
171 Store_field(tmp2, 4, Val_int(insn[j-1].
detail->arm.operands[
i].access));
172 Store_field(tmp2, 5, Val_int(insn[j-1].
detail->arm.operands[
i].neon_lane));
173 Store_field(array,
i, tmp2);
178 Store_field(op_info_val, 9, array);
181 Store_field(arch_info, 0, op_info_val);
183 Store_field(rec_insn, 9, arch_info);
187 arch_info = caml_alloc(1, 1);
189 op_info_val = caml_alloc(4, 0);
190 Store_field(op_info_val, 0, Val_int(insn[j-1].
detail->arm64.cc));
191 Store_field(op_info_val, 1, Val_bool(insn[j-1].
detail->arm64.update_flags));
192 Store_field(op_info_val, 2, Val_bool(insn[j-1].
detail->arm64.writeback));
194 lcount = insn[j-1].detail->arm64.op_count;
196 array = caml_alloc(lcount, 0);
197 for (
i = 0;
i < lcount;
i++) {
198 tmp2 = caml_alloc(6, 0);
199 switch(insn[j-1].
detail->arm64.operands[
i].type) {
201 tmp = caml_alloc(1, 1);
202 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].reg));
205 tmp = caml_alloc(1, 2);
206 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].imm));
209 tmp = caml_alloc(1, 3);
210 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].imm));
213 tmp = caml_alloc(1, 4);
214 Store_field(
tmp, 0, caml_copy_double(insn[j-1].
detail->arm64.operands[
i].fp));
217 tmp = caml_alloc(1, 5);
218 tmp3 = caml_alloc(3, 0);
219 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].mem.base));
220 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->arm64.operands[
i].mem.index));
221 Store_field(tmp3, 2, Val_int(insn[j-1].
detail->arm64.operands[
i].mem.disp));
222 Store_field(
tmp, 0, tmp3);
225 tmp = caml_alloc(1, 6);
226 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].reg));
229 tmp = caml_alloc(1, 7);
230 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].reg));
233 tmp = caml_alloc(1, 8);
234 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].pstate));
237 tmp = caml_alloc(1, 9);
238 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].sys));
241 tmp = caml_alloc(1, 10);
242 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].prefetch));
245 tmp = caml_alloc(1, 11);
246 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].barrier));
250 tmp3 = caml_alloc(2, 0);
251 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].shift.type));
252 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->arm64.operands[
i].shift.value));
254 Store_field(tmp2, 0, Val_int(insn[j-1].
detail->arm64.operands[
i].vector_index));
255 Store_field(tmp2, 1, Val_int(insn[j-1].
detail->arm64.operands[
i].vas));
256 Store_field(tmp2, 2, Val_int(insn[j-1].
detail->arm64.operands[
i].vess));
257 Store_field(tmp2, 3, tmp3);
258 Store_field(tmp2, 4, Val_int(insn[j-1].
detail->arm64.operands[
i].ext));
259 Store_field(tmp2, 5,
tmp);
261 Store_field(array,
i, tmp2);
266 Store_field(op_info_val, 3, array);
269 Store_field(arch_info, 0, op_info_val);
271 Store_field(rec_insn, 9, arch_info);
275 arch_info = caml_alloc(1, 2);
277 op_info_val = caml_alloc(1, 0);
279 lcount = insn[j-1].detail->mips.op_count;
281 array = caml_alloc(lcount, 0);
282 for (
i = 0;
i < lcount;
i++) {
283 tmp2 = caml_alloc(1, 0);
284 switch(insn[j-1].
detail->mips.operands[
i].type) {
286 tmp = caml_alloc(1, 1);
287 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->mips.operands[
i].reg));
290 tmp = caml_alloc(1, 2);
291 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->mips.operands[
i].imm));
294 tmp = caml_alloc(1, 3);
295 tmp3 = caml_alloc(2, 0);
296 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->mips.operands[
i].mem.base));
297 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->mips.operands[
i].mem.disp));
298 Store_field(
tmp, 0, tmp3);
302 Store_field(tmp2, 0,
tmp);
303 Store_field(array,
i, tmp2);
308 Store_field(op_info_val, 0, array);
311 Store_field(arch_info, 0, op_info_val);
313 Store_field(rec_insn, 9, arch_info);
317 arch_info = caml_alloc(1, 3);
319 op_info_val = caml_alloc(17, 0);
324 array = caml_alloc(lcount, 0);
325 for (
i = 0;
i < lcount;
i++) {
326 Store_field(array,
i, Val_int(insn[j-1].
detail->x86.prefix[
i]));
330 Store_field(op_info_val, 0, array);
335 array = caml_alloc(lcount, 0);
336 for (
i = 0;
i < lcount;
i++) {
337 Store_field(array,
i, Val_int(insn[j-1].
detail->x86.opcode[
i]));
341 Store_field(op_info_val, 1, array);
343 Store_field(op_info_val, 2, Val_int(insn[j-1].
detail->x86.rex));
345 Store_field(op_info_val, 3, Val_int(insn[j-1].
detail->x86.addr_size));
347 Store_field(op_info_val, 4, Val_int(insn[j-1].
detail->x86.modrm));
349 Store_field(op_info_val, 5, Val_int(insn[j-1].
detail->x86.sib));
351 Store_field(op_info_val, 6, Val_int(insn[j-1].
detail->x86.disp));
353 Store_field(op_info_val, 7, Val_int(insn[j-1].
detail->x86.sib_index));
355 Store_field(op_info_val, 8, Val_int(insn[j-1].
detail->x86.sib_scale));
357 Store_field(op_info_val, 9, Val_int(insn[j-1].
detail->x86.sib_base));
359 Store_field(op_info_val, 10, Val_int(insn[j-1].
detail->x86.xop_cc));
360 Store_field(op_info_val, 11, Val_int(insn[j-1].
detail->x86.sse_cc));
361 Store_field(op_info_val, 12, Val_int(insn[j-1].
detail->x86.avx_cc));
362 Store_field(op_info_val, 13, Val_int(insn[j-1].
detail->x86.avx_sae));
363 Store_field(op_info_val, 14, Val_int(insn[j-1].
detail->x86.avx_rm));
364 Store_field(op_info_val, 15, Val_int(insn[j-1].
detail->x86.eflags));
366 lcount = insn[j-1].detail->x86.op_count;
368 array = caml_alloc(lcount, 0);
369 for (
i = 0;
i < lcount;
i++) {
370 switch(insn[j-1].
detail->x86.operands[
i].type) {
372 tmp = caml_alloc(1, 1);
373 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->x86.operands[
i].reg));
376 tmp = caml_alloc(1, 2);
377 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->x86.operands[
i].imm));
380 tmp = caml_alloc(1, 3);
381 tmp2 = caml_alloc(5, 0);
382 Store_field(tmp2, 0, Val_int(insn[j-1].
detail->x86.operands[
i].mem.segment));
383 Store_field(tmp2, 1, Val_int(insn[j-1].
detail->x86.operands[
i].mem.base));
384 Store_field(tmp2, 2, Val_int(insn[j-1].
detail->x86.operands[
i].mem.index));
385 Store_field(tmp2, 3, Val_int(insn[j-1].
detail->x86.operands[
i].mem.scale));
386 Store_field(tmp2, 4, Val_int(insn[j-1].
detail->x86.operands[
i].mem.disp));
388 Store_field(
tmp, 0, tmp2);
391 tmp = caml_alloc(1, 0);
395 tmp2 = caml_alloc(5, 0);
396 Store_field(tmp2, 0,
tmp);
397 Store_field(tmp2, 1, Val_int(insn[j-1].
detail->x86.operands[
i].size));
398 Store_field(tmp2, 2, Val_int(insn[j-1].
detail->x86.operands[
i].access));
399 Store_field(tmp2, 3, Val_int(insn[j-1].
detail->x86.operands[
i].avx_bcast));
400 Store_field(tmp2, 4, Val_int(insn[j-1].
detail->x86.operands[
i].avx_zero_opmask));
401 Store_field(array,
i, tmp2);
405 Store_field(op_info_val, 16, array);
408 Store_field(arch_info, 0, op_info_val);
410 Store_field(rec_insn, 9, arch_info);
414 arch_info = caml_alloc(1, 4);
416 op_info_val = caml_alloc(4, 0);
418 Store_field(op_info_val, 0, Val_int(insn[j-1].
detail->ppc.bc));
419 Store_field(op_info_val, 1, Val_int(insn[j-1].
detail->ppc.bh));
420 Store_field(op_info_val, 2, Val_bool(insn[j-1].
detail->ppc.update_cr0));
422 lcount = insn[j-1].detail->ppc.op_count;
424 array = caml_alloc(lcount, 0);
425 for (
i = 0;
i < lcount;
i++) {
426 tmp2 = caml_alloc(1, 0);
427 switch(insn[j-1].
detail->ppc.operands[
i].type) {
429 tmp = caml_alloc(1, 1);
430 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->ppc.operands[
i].reg));
433 tmp = caml_alloc(1, 2);
434 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->ppc.operands[
i].imm));
437 tmp = caml_alloc(1, 3);
438 tmp3 = caml_alloc(2, 0);
439 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->ppc.operands[
i].mem.base));
440 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->ppc.operands[
i].mem.disp));
441 Store_field(
tmp, 0, tmp3);
444 tmp = caml_alloc(1, 4);
445 tmp3 = caml_alloc(3, 0);
446 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->ppc.operands[
i].crx.scale));
447 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->ppc.operands[
i].crx.reg));
448 Store_field(tmp3, 2, Val_int(insn[j-1].
detail->ppc.operands[
i].crx.cond));
449 Store_field(
tmp, 0, tmp3);
453 Store_field(tmp2, 0,
tmp);
454 Store_field(array,
i, tmp2);
459 Store_field(op_info_val, 3, array);
462 Store_field(arch_info, 0, op_info_val);
464 Store_field(rec_insn, 9, arch_info);
469 arch_info = caml_alloc(1, 5);
471 op_info_val = caml_alloc(3, 0);
473 Store_field(op_info_val, 0, Val_int(insn[j-1].
detail->sparc.cc));
474 Store_field(op_info_val, 1, Val_int(insn[j-1].
detail->sparc.hint));
476 lcount = insn[j-1].detail->sparc.op_count;
478 array = caml_alloc(lcount, 0);
479 for (
i = 0;
i < lcount;
i++) {
480 tmp2 = caml_alloc(1, 0);
481 switch(insn[j-1].
detail->sparc.operands[
i].type) {
483 tmp = caml_alloc(1, 1);
484 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->sparc.operands[
i].reg));
487 tmp = caml_alloc(1, 2);
488 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->sparc.operands[
i].imm));
491 tmp = caml_alloc(1, 3);
492 tmp3 = caml_alloc(3, 0);
493 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->sparc.operands[
i].mem.base));
494 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->sparc.operands[
i].mem.index));
495 Store_field(tmp3, 2, Val_int(insn[j-1].
detail->sparc.operands[
i].mem.disp));
496 Store_field(
tmp, 0, tmp3);
500 Store_field(tmp2, 0,
tmp);
501 Store_field(array,
i, tmp2);
506 Store_field(op_info_val, 2, array);
509 Store_field(arch_info, 0, op_info_val);
511 Store_field(rec_insn, 9, arch_info);
516 arch_info = caml_alloc(1, 6);
518 op_info_val = caml_alloc(2, 0);
520 Store_field(op_info_val, 0, Val_int(insn[j-1].
detail->sysz.cc));
522 lcount = insn[j-1].detail->sysz.op_count;
524 array = caml_alloc(lcount, 0);
525 for (
i = 0;
i < lcount;
i++) {
526 tmp2 = caml_alloc(1, 0);
527 switch(insn[j-1].
detail->sysz.operands[
i].type) {
529 tmp = caml_alloc(1, 1);
530 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->sysz.operands[
i].reg));
533 tmp = caml_alloc(1, 2);
534 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->sysz.operands[
i].reg));
537 tmp = caml_alloc(1, 3);
538 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->sysz.operands[
i].imm));
541 tmp = caml_alloc(1, 4);
542 tmp3 = caml_alloc(4, 0);
543 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->sysz.operands[
i].mem.base));
544 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->sysz.operands[
i].mem.index));
545 Store_field(tmp3, 2, caml_copy_int64(insn[j-1].
detail->sysz.operands[
i].mem.length));
546 Store_field(tmp3, 3, caml_copy_int64(insn[j-1].
detail->sysz.operands[
i].mem.disp));
547 Store_field(
tmp, 0, tmp3);
551 Store_field(tmp2, 0,
tmp);
552 Store_field(array,
i, tmp2);
557 Store_field(op_info_val, 1, array);
560 Store_field(arch_info, 0, op_info_val);
562 Store_field(rec_insn, 9, arch_info);
567 arch_info = caml_alloc(1, 7);
569 op_info_val = caml_alloc(1, 0);
571 lcount = insn[j-1].detail->xcore.op_count;
573 array = caml_alloc(lcount, 0);
574 for (
i = 0;
i < lcount;
i++) {
575 tmp2 = caml_alloc(1, 0);
576 switch(insn[j-1].
detail->xcore.operands[
i].type) {
578 tmp = caml_alloc(1, 1);
579 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->xcore.operands[
i].reg));
582 tmp = caml_alloc(1, 2);
583 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->xcore.operands[
i].imm));
586 tmp = caml_alloc(1, 3);
587 tmp3 = caml_alloc(4, 0);
588 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->xcore.operands[
i].mem.base));
589 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->xcore.operands[
i].mem.index));
590 Store_field(tmp3, 2, caml_copy_int64(insn[j-1].
detail->xcore.operands[
i].mem.disp));
591 Store_field(tmp3, 3, caml_copy_int64(insn[j-1].
detail->xcore.operands[
i].mem.direct));
592 Store_field(
tmp, 0, tmp3);
596 Store_field(tmp2, 0,
tmp);
597 Store_field(array,
i, tmp2);
602 Store_field(op_info_val, 0, array);
605 Store_field(arch_info, 0, op_info_val);
607 Store_field(rec_insn, 9, arch_info);
612 arch_info = caml_alloc(1, 8);
614 op_info_val = caml_alloc(2, 0);
615 Store_field(op_info_val, 0, Val_int(insn[j-1].
detail->m680x.flags));
617 lcount = insn[j-1].detail->m680x.op_count;
619 array = caml_alloc(lcount, 0);
620 for (
i = 0;
i < lcount;
i++) {
621 tmp2 = caml_alloc(3, 0);
622 switch(insn[j-1].
detail->m680x.operands[
i].type) {
624 tmp = caml_alloc(1, 1);
625 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->m680x.operands[
i].imm));
628 tmp = caml_alloc(1, 2);
629 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->m680x.operands[
i].reg));
632 tmp = caml_alloc(1, 3);
633 tmp3 = caml_alloc(7, 0);
634 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->m680x.operands[
i].idx.base_reg));
635 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->m680x.operands[
i].idx.offset_reg));
636 Store_field(tmp3, 2, Val_int(insn[j-1].
detail->m680x.operands[
i].idx.offset));
637 Store_field(tmp3, 3, Val_int(insn[j-1].
detail->m680x.operands[
i].idx.offset_addr));
638 Store_field(tmp3, 4, Val_int(insn[j-1].
detail->m680x.operands[
i].idx.offset_bits));
639 Store_field(tmp3, 5, Val_int(insn[j-1].
detail->m680x.operands[
i].idx.inc_dec));
640 Store_field(tmp3, 6, Val_int(insn[j-1].
detail->m680x.operands[
i].idx.flags));
641 Store_field(
tmp, 0, tmp3);
644 tmp = caml_alloc(1, 4);
645 tmp3 = caml_alloc(2, 0);
646 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->m680x.operands[
i].rel.address));
647 Store_field(tmp3, 1, Val_int(insn[j-1].
detail->m680x.operands[
i].rel.offset));
648 Store_field(
tmp, 0, tmp3);
651 tmp = caml_alloc(1, 5);
652 tmp3 = caml_alloc(2, 0);
653 Store_field(tmp3, 0, Val_int(insn[j-1].
detail->m680x.operands[
i].ext.address));
654 Store_field(tmp3, 1, Val_bool(insn[j-1].
detail->m680x.operands[
i].ext.indirect));
655 Store_field(
tmp, 0, tmp3);
658 tmp = caml_alloc(1, 6);
659 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->m680x.operands[
i].direct_addr));
662 tmp = caml_alloc(1, 7);
663 Store_field(
tmp, 0, Val_int(insn[j-1].
detail->m680x.operands[
i].const_val));
667 Store_field(tmp2, 0,
tmp);
668 Store_field(tmp2, 1, Val_int(insn[j-1].
detail->m680x.operands[
i].size));
669 Store_field(tmp2, 2, Val_int(insn[j-1].
detail->m680x.operands[
i].access));
670 Store_field(array,
i, tmp2);
675 Store_field(op_info_val, 1, array);
678 Store_field(arch_info, 0, op_info_val);
680 Store_field(rec_insn, 9, arch_info);
688 Store_field(cons, 0, rec_insn);
689 Store_field(cons, 1,
list);
702 CAMLparam5(_arch, _mode, _code, _addr, _count);
709 size_t count, code_len;
711 switch (Int_val(_arch)) {
746 caml_invalid_argument(
"Invalid arch");
747 return Val_emptylist;
750 while (_mode != Val_emptylist) {
752 switch (Int_val(
head)) {
835 caml_invalid_argument(
"Invalid mode");
836 return Val_emptylist;
838 _mode =
Field(_mode, 1);
843 return Val_emptylist;
847 code_len = caml_string_length(_code);
848 addr = Int64_val(_addr);
849 count = Int64_val(_count);
856 CAMLparam5(_arch, _handle, _code, _addr, _count);
862 handle = Int64_val(_handle);
864 arch = Int_val(_arch);
866 code_len = caml_string_length(_code);
867 addr = Int64_val(_addr);
868 count = Int64_val(_count);
875 CAMLparam2(_arch, _mode);
881 list = Val_emptylist;
883 switch (Int_val(_arch)) {
918 caml_invalid_argument(
"Invalid arch");
919 return Val_emptylist;
923 while (_mode != Val_emptylist) {
925 switch (Int_val(
head)) {
1008 caml_invalid_argument(
"Invalid mode");
1009 return Val_emptylist;
1011 _mode =
Field(_mode, 1);
1015 CAMLreturn(Val_int(0));
1018 result = caml_alloc(1, 0);
1019 Store_field(result, 0, caml_copy_int64(
handle));
1025 CAMLparam3(_handle, _opt, _value);
1029 switch (Int_val(_opt)) {
1049 caml_invalid_argument(
"Invalid option");
1053 err =
cs_option(Int64_val(_handle), opt, Int64_val(_value));
1055 CAMLreturn(Val_int(
err));
1062 caml_invalid_argument(
"invalid reg_id");
1066 return caml_copy_string(
name);
1073 caml_invalid_argument(
"invalid insn_id");
1077 return caml_copy_string(
name);
1084 caml_invalid_argument(
"invalid insn_id");
1088 return caml_copy_string(
name);
1099 CAMLparam1(_handle);
1102 h = Int64_val(_handle);
static mcore_handle handle
@ ARM64_OP_FP
= CS_OP_FP (Floating-Point operand).
@ ARM64_OP_PSTATE
PState operand.
@ ARM64_OP_BARRIER
Memory barrier operand (ISB/DMB/DSB instructions).
@ ARM64_OP_REG
= CS_OP_REG (Register operand).
@ ARM64_OP_PREFETCH
Prefetch operand (PRFM).
@ ARM64_OP_MEM
= CS_OP_MEM (Memory operand).
@ ARM64_OP_SYS
SYS operand for IC/DC/AT/TLBI instructions.
@ ARM64_OP_REG_MRS
MRS register operand.
@ ARM64_OP_CIMM
C-Immediate.
@ ARM64_OP_IMM
= CS_OP_IMM (Immediate operand).
@ ARM64_OP_REG_MSR
MSR register operand.
@ ARM_OP_IMM
= CS_OP_IMM (Immediate operand).
@ ARM_OP_REG
= CS_OP_REG (Register operand).
@ ARM_OP_CIMM
C-Immediate (coprocessor registers)
@ ARM_OP_SETEND
operand for SETEND instruction
@ ARM_OP_PIMM
P-Immediate (coprocessor registers)
@ ARM_OP_MEM
= CS_OP_MEM (Memory operand).
@ ARM_OP_FP
= CS_OP_FP (Floating-Point operand).
@ ARM_OP_SYSREG
MSR/MRS special register operand.
cs_arch
Architecture type.
@ CS_ARCH_ARM64
ARM-64, also called AArch64.
@ CS_ARCH_SPARC
Sparc architecture.
@ CS_ARCH_XCORE
XCore architecture.
@ CS_ARCH_M68K
68K architecture
@ CS_ARCH_X86
X86 architecture (including x86 & x86-64)
@ CS_ARCH_M680X
680X architecture
@ CS_ARCH_ARM
ARM architecture (including Thumb, Thumb-2)
@ CS_ARCH_MIPS
Mips architecture.
@ CS_ARCH_SYSZ
SystemZ architecture.
@ CS_ARCH_TMS320C64X
TMS320C64x architecture.
@ CS_ARCH_PPC
PowerPC architecture.
@ CS_MODE_M680X_6811
M680X Motorola/Freescale/NXP 68HC11 mode.
@ CS_MODE_M680X_6805
M680X Motorola/Freescale 6805 mode.
@ CS_MODE_MCLASS
ARM's Cortex-M series.
@ CS_MODE_M680X_HCS08
M680X Freescale/NXP HCS08 mode.
@ CS_MODE_64
64-bit mode (X86, PPC)
@ CS_MODE_MIPS64
Mips64 ISA (Mips)
@ CS_MODE_M680X_6309
M680X Hitachi 6309 mode.
@ CS_MODE_32
32-bit mode (X86)
@ CS_MODE_V8
ARMv8 A32 encodings for ARM.
@ CS_MODE_MICRO
MicroMips mode (MIPS)
@ CS_MODE_M680X_CPU12
used on M68HC12/HCS12
@ CS_MODE_MIPS3
Mips III ISA.
@ CS_MODE_M680X_6301
M680X Hitachi 6301,6303 mode.
@ CS_MODE_MIPS32
Mips32 ISA (Mips)
@ CS_MODE_MIPS32R6
Mips32r6 ISA.
@ CS_MODE_M680X_6801
M680X Motorola 6801,6803 mode.
@ CS_MODE_BIG_ENDIAN
big-endian mode
@ CS_MODE_16
16-bit mode (X86)
@ CS_MODE_V9
SparcV9 mode (Sparc)
@ CS_MODE_THUMB
ARM's Thumb mode, including Thumb-2.
@ CS_MODE_M680X_6800
M680X Motorola 6800,6802 mode.
@ CS_MODE_M680X_6808
M680X Motorola/Freescale/NXP 68HC08 mode.
@ CS_MODE_QPX
Quad Processing eXtensions mode (PPC)
@ CS_MODE_LITTLE_ENDIAN
little-endian mode (default mode)
@ CS_MODE_MIPS2
Mips II ISA.
@ CS_MODE_M680X_6809
M680X Motorola 6809 mode.
cs_opt_type
Runtime option for the disassembled engine.
@ CS_OPT_SKIPDATA_SETUP
Setup user-defined function for SKIPDATA option.
@ CS_OPT_MEM
User-defined dynamic memory related functions.
@ CS_OPT_MODE
Change engine's mode at run-time.
@ CS_OPT_DETAIL
Break down instruction structure into details.
@ CS_OPT_SYNTAX
Assembly output syntax.
@ CS_OPT_SKIPDATA
Skip data when disassembling. Then engine is in SKIPDATA mode.
@ SYSZ_OP_MEM
= CS_OP_MEM (Memory operand).
@ SYSZ_OP_IMM
= CS_OP_IMM (Immediate operand).
@ SYSZ_OP_ACREG
Access register operand.
@ SYSZ_OP_REG
= CS_OP_REG (Register operand).
@ X86_OP_IMM
= CS_OP_IMM (Immediate operand).
@ X86_OP_REG
= CS_OP_REG (Register operand).
@ X86_OP_MEM
= CS_OP_MEM (Memory operand).
@ XCORE_OP_REG
= CS_OP_REG (Register operand).
@ XCORE_OP_IMM
= CS_OP_IMM (Immediate operand).
@ XCORE_OP_MEM
= CS_OP_MEM (Memory operand).
struct java_field_t Field
CAPSTONE_EXPORT unsigned int CAPSTONE_API cs_version(int *major, int *minor)
CAPSTONE_EXPORT size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
CAPSTONE_EXPORT const char *CAPSTONE_API cs_group_name(csh ud, unsigned int group)
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
CAPSTONE_EXPORT const char *CAPSTONE_API cs_insn_name(csh ud, unsigned int insn)
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static void list(RzEgg *egg)
@ M680X_OP_EXTENDED
= Extended addressing operand.
@ M680X_OP_INDEXED
= Indexed addressing operand.
@ M680X_OP_CONSTANT
Used e.g. for a bit index or page number.
@ M680X_OP_IMMEDIATE
= Immediate operand.
@ M680X_OP_REGISTER
= Register operand.
@ M680X_OP_RELATIVE
= Relative addressing operand.
@ M680X_OP_DIRECT
= Direct addressing operand.
CAMLprim value ocaml_cs_disasm_internal(value _arch, value _handle, value _code, value _addr, value _count)
CAMLprim value ocaml_instruction_name(value _handle, value _insn)
static unsigned int list_count(uint8_t *list, unsigned int max)
CAMLprim value ocaml_group_name(value _handle, value _insn)
CAMLprim value _cs_disasm(cs_arch arch, csh handle, const uint8_t *code, size_t code_len, uint64_t addr, size_t count)
CAMLprim value ocaml_open(value _arch, value _mode)
CAMLprim value ocaml_close(value _handle)
CAMLprim value ocaml_cs_disasm(value _arch, value _mode, value _code, value _addr, value _count)
CAMLprim value ocaml_register_name(value _handle, value _reg)
CAMLprim value ocaml_option(value _handle, value _opt, value _value)
CAMLprim value ocaml_version(void)
@ MIPS_OP_REG
= CS_OP_REG (Register operand).
@ MIPS_OP_IMM
= CS_OP_IMM (Immediate operand).
@ MIPS_OP_MEM
= CS_OP_MEM (Memory operand).
@ PPC_OP_REG
= CS_OP_REG (Register operand).
@ PPC_OP_IMM
= CS_OP_IMM (Immediate operand).
@ PPC_OP_MEM
= CS_OP_MEM (Memory operand).
@ PPC_OP_CRX
Condition Register field.
@ SPARC_OP_MEM
= CS_OP_MEM (Memory operand).
@ SPARC_OP_IMM
= CS_OP_IMM (Immediate operand).
@ SPARC_OP_REG
= CS_OP_REG (Register operand).
if(dbg->bits==RZ_SYS_BITS_64)