blob: ccea4b71bcd58381bb7984088bb1d6b9333524ac [file] [log] [blame]
YUHANG TANG08da0c02016-10-14 20:47:29 +08001/* Capstone Disassembler Engine */
2/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
3
Nguyen Anh Quynh2897a802016-10-21 17:03:27 +08004#include <inttypes.h>
YUHANG TANG08da0c02016-10-14 20:47:29 +08005#include <stdio.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
11static const char* get_bc_name(int bc)
12{
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080013 switch(bc) {
14 default:
15 case PPC_BC_INVALID:
16 return ("invalid");
17 case PPC_BC_LT:
18 return ("lt");
19 case PPC_BC_LE:
20 return ("le");
21 case PPC_BC_EQ:
22 return ("eq");
23 case PPC_BC_GE:
24 return ("ge");
25 case PPC_BC_GT:
26 return ("gt");
27 case PPC_BC_NE:
28 return ("ne");
29 case PPC_BC_UN:
30 return ("un");
31 case PPC_BC_NU:
32 return ("nu");
33 case PPC_BC_SO:
34 return ("so");
35 case PPC_BC_NS:
36 return ("ns");
37 }
YUHANG TANG08da0c02016-10-14 20:47:29 +080038}
39
40void print_insn_detail_ppc(csh handle, cs_insn *ins)
41{
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080042 cs_ppc *ppc;
43 int i;
44
45 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
46 if (ins->detail == NULL)
47 return;
48
49 ppc = &(ins->detail->ppc);
50 if (ppc->op_count)
51 printf("\top_count: %u\n", ppc->op_count);
52
53 for (i = 0; i < ppc->op_count; i++) {
54 cs_ppc_op *op = &(ppc->operands[i]);
55 switch((int)op->type) {
56 default:
57 break;
58 case PPC_OP_REG:
59 printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
60 break;
61 case PPC_OP_IMM:
Nguyen Anh Quynh2897a802016-10-21 17:03:27 +080062 printf("\t\toperands[%u].type: IMM = 0x%"PRIx64"\n", i, op->imm);
Nguyen Anh Quynh32238dc2016-10-21 16:42:47 +080063 break;
64 case PPC_OP_MEM:
65 printf("\t\toperands[%u].type: MEM\n", i);
66 if (op->mem.base != PPC_REG_INVALID)
67 printf("\t\t\toperands[%u].mem.base: REG = %s\n",
68 i, cs_reg_name(handle, op->mem.base));
69 if (op->mem.disp != 0)
70 printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
71
72 break;
73 case PPC_OP_CRX:
74 printf("\t\toperands[%u].type: CRX\n", i);
75 printf("\t\t\toperands[%u].crx.scale: %d\n", i, op->crx.scale);
76 printf("\t\t\toperands[%u].crx.reg: %s\n", i, cs_reg_name(handle, op->crx.reg));
77 printf("\t\t\toperands[%u].crx.cond: %s\n", i, get_bc_name(op->crx.cond));
78 break;
79 }
80 }
81
82 if (ppc->bc != 0)
83 printf("\tBranch code: %u\n", ppc->bc);
84
85 if (ppc->bh != 0)
86 printf("\tBranch hint: %u\n", ppc->bh);
87
88 if (ppc->update_cr0)
89 printf("\tUpdate-CR0: True\n");
YUHANG TANG08da0c02016-10-14 20:47:29 +080090}