YUHANG TANG | 08da0c0 | 2016-10-14 20:47:29 +0800 | [diff] [blame] | 1 | /* Capstone Disassembler Engine */ |
| 2 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */ |
| 3 | |
Nguyen Anh Quynh | 2897a80 | 2016-10-21 17:03:27 +0800 | [diff] [blame] | 4 | #include <inttypes.h> |
YUHANG TANG | 08da0c0 | 2016-10-14 20:47:29 +0800 | [diff] [blame] | 5 | #include <stdio.h> |
| 6 | |
Nguyen Anh Quynh | 2897a80 | 2016-10-21 17:03:27 +0800 | [diff] [blame] | 7 | #include <capstone/capstone.h> |
YUHANG TANG | 08da0c0 | 2016-10-14 20:47:29 +0800 | [diff] [blame] | 8 | |
Nguyen Anh Quynh | 32238dc | 2016-10-21 16:42:47 +0800 | [diff] [blame] | 9 | void print_string_hex(char *comment, unsigned char *str, size_t len); |
YUHANG TANG | 08da0c0 | 2016-10-14 20:47:29 +0800 | [diff] [blame] | 10 | |
| 11 | static const char* get_bc_name(int bc) |
| 12 | { |
Nguyen Anh Quynh | 32238dc | 2016-10-21 16:42:47 +0800 | [diff] [blame] | 13 | 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 TANG | 08da0c0 | 2016-10-14 20:47:29 +0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void print_insn_detail_ppc(csh handle, cs_insn *ins) |
| 41 | { |
Nguyen Anh Quynh | 32238dc | 2016-10-21 16:42:47 +0800 | [diff] [blame] | 42 | 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 Quynh | 2897a80 | 2016-10-21 17:03:27 +0800 | [diff] [blame] | 62 | printf("\t\toperands[%u].type: IMM = 0x%"PRIx64"\n", i, op->imm); |
Nguyen Anh Quynh | 32238dc | 2016-10-21 16:42:47 +0800 | [diff] [blame] | 63 | 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 TANG | 08da0c0 | 2016-10-14 20:47:29 +0800 | [diff] [blame] | 90 | } |