1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include <capstone/capstone.h>
5
6 void print_string_hex(char *comment, unsigned char *str, size_t len);
7
get_am_name(mos65xx_address_mode mode)8 static const char *get_am_name(mos65xx_address_mode mode)
9 {
10 switch(mode) {
11 default:
12 case MOS65XX_AM_NONE:
13 return "No address mode";
14 case MOS65XX_AM_IMP:
15 return "implied addressing (no addressing mode)";
16 case MOS65XX_AM_ACC:
17 return "accumulator addressing";
18 case MOS65XX_AM_ABS:
19 return "absolute addressing";
20 case MOS65XX_AM_ZP:
21 return "zeropage addressing";
22 case MOS65XX_AM_IMM:
23 return "8 Bit immediate value";
24 case MOS65XX_AM_ABSX:
25 return "indexed absolute addressing by the X index register";
26 case MOS65XX_AM_ABSY:
27 return "indexed absolute addressing by the Y index register";
28 case MOS65XX_AM_INDX:
29 return "indexed indirect addressing by the X index register";
30 case MOS65XX_AM_INDY:
31 return "indirect indexed addressing by the Y index register";
32 case MOS65XX_AM_ZPX:
33 return "indexed zeropage addressing by the X index register";
34 case MOS65XX_AM_ZPY:
35 return "indexed zeropage addressing by the Y index register";
36 case MOS65XX_AM_REL:
37 return "relative addressing used by branches";
38 case MOS65XX_AM_IND:
39 return "absolute indirect addressing";
40 }
41 }
42
43
print_insn_detail_mos65xx(csh handle,cs_insn * ins)44 void print_insn_detail_mos65xx(csh handle, cs_insn *ins)
45 {
46 int i;
47 cs_mos65xx *mos65xx;
48
49 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
50 if (ins->detail == NULL)
51 return;
52
53 mos65xx = &(ins->detail->mos65xx);
54 printf("\taddress mode: %s\n", get_am_name(mos65xx->am));
55 printf("\tmodifies flags: %s\n", mos65xx->modifies_flags ? "true": "false");
56
57 if (mos65xx->op_count)
58 printf("\top_count: %u\n", mos65xx->op_count);
59
60 for (i = 0; i < mos65xx->op_count; i++) {
61 cs_mos65xx_op *op = &(mos65xx->operands[i]);
62 switch((int)op->type) {
63 default:
64 break;
65 case MOS65XX_OP_REG:
66 printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
67 break;
68 case MOS65XX_OP_IMM:
69 printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
70 break;
71 case MOS65XX_OP_MEM:
72 printf("\t\toperands[%u].type: MEM = 0x%x\n", i, op->mem);
73 break;
74 }
75 }
76 }
77