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