capstone
1/* Capstone Disassembler Engine */
2/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
3
4#include <stdio.h>
5#include <stdlib.h>
6
7#include <capstone/capstone.h>
8#include "cstool.h"
9
10void print_insn_detail_mips(csh handle, cs_insn *ins)
11{
12int i;
13cs_mips *mips;
14
15// detail can be NULL on "data" instruction if SKIPDATA option is turned ON
16if (ins->detail == NULL)
17return;
18
19mips = &(ins->detail->mips);
20if (mips->op_count)
21printf("\top_count: %u\n", mips->op_count);
22
23for (i = 0; i < mips->op_count; i++) {
24cs_mips_op *op = &(mips->operands[i]);
25switch((int)op->type) {
26default:
27break;
28case MIPS_OP_REG:
29printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
30break;
31case MIPS_OP_IMM:
32printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
33break;
34case MIPS_OP_MEM:
35printf("\t\toperands[%u].type: MEM\n", i);
36if (op->mem.base != MIPS_REG_INVALID)
37printf("\t\t\toperands[%u].mem.base: REG = %s\n",
38i, cs_reg_name(handle, op->mem.base));
39if (op->mem.disp != 0)
40printf("\t\t\toperands[%u].mem.disp: 0x%" PRIx64 "\n", i, op->mem.disp);
41
42break;
43}
44
45}
46}
47