blob: 1edf16eee575c20f646449f66cd2638c2b1f305b [file] [log] [blame]
YUHANG TANG08da0c02016-10-14 20:47:29 +08001/* Capstone Disassembler Engine */
2/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
3
4#include <stdio.h>
5#include <stdlib.h>
6
Nguyen Anh Quynh2897a802016-10-21 17:03:27 +08007#include <capstone/capstone.h>
YUHANG TANG08da0c02016-10-14 20:47:29 +08008
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +08009void print_string_hex(char *comment, unsigned char *str, size_t len);
YUHANG TANG08da0c02016-10-14 20:47:29 +080010
11void print_insn_detail_mips(csh handle, cs_insn *ins)
12{
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080013 int i;
14 cs_mips *mips;
YUHANG TANG9bc14c12016-10-28 15:32:50 +080015
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080016 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
17 if (ins->detail == NULL)
18 return;
YUHANG TANG9bc14c12016-10-28 15:32:50 +080019
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080020 mips = &(ins->detail->mips);
21 if (mips->op_count)
22 printf("\top_count: %u\n", mips->op_count);
YUHANG TANG9bc14c12016-10-28 15:32:50 +080023
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080024 for (i = 0; i < mips->op_count; i++) {
25 cs_mips_op *op = &(mips->operands[i]);
26 switch((int)op->type) {
27 default:
28 break;
29 case MIPS_OP_REG:
30 printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
31 break;
32 case MIPS_OP_IMM:
33 printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
34 break;
35 case MIPS_OP_MEM:
36 printf("\t\toperands[%u].type: MEM\n", i);
YUHANG TANGbe3f8672016-10-27 12:12:59 +080037 if (op->mem.base != MIPS_REG_INVALID)
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080038 printf("\t\t\toperands[%u].mem.base: REG = %s\n",
YUHANG TANGbe3f8672016-10-27 12:12:59 +080039 i, cs_reg_name(handle, op->mem.base));
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080040 if (op->mem.disp != 0)
41 printf("\t\t\toperands[%u].mem.disp: 0x%" PRIx64 "\n", i, op->mem.disp);
YUHANG TANG9bc14c12016-10-28 15:32:50 +080042
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080043 break;
44 }
YUHANG TANG9bc14c12016-10-28 15:32:50 +080045
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080046 }
YUHANG TANG08da0c02016-10-14 20:47:29 +080047}