1 /* Capstone testing regression */
2 /* By Do Minh Tuan <tuanit96@gmail.com>, 02-2019 */
3
4
5 #include "factory.h"
6
get_am_name(mos65xx_address_mode mode)7 static const char *get_am_name(mos65xx_address_mode mode)
8 {
9 switch(mode) {
10 default:
11 case MOS65XX_AM_NONE:
12 return "No address mode";
13 case MOS65XX_AM_IMP:
14 return "implied addressing (no addressing mode)";
15 case MOS65XX_AM_ACC:
16 return "accumulator addressing";
17 case MOS65XX_AM_ABS:
18 return "absolute addressing";
19 case MOS65XX_AM_ZP:
20 return "zeropage addressing";
21 case MOS65XX_AM_IMM:
22 return "8 Bit immediate value";
23 case MOS65XX_AM_ABSX:
24 return "indexed absolute addressing by the X index register";
25 case MOS65XX_AM_ABSY:
26 return "indexed absolute addressing by the Y index register";
27 case MOS65XX_AM_INDX:
28 return "indexed indirect addressing by the X index register";
29 case MOS65XX_AM_INDY:
30 return "indirect indexed addressing by the Y index register";
31 case MOS65XX_AM_ZPX:
32 return "indexed zeropage addressing by the X index register";
33 case MOS65XX_AM_ZPY:
34 return "indexed zeropage addressing by the Y index register";
35 case MOS65XX_AM_REL:
36 return "relative addressing used by branches";
37 case MOS65XX_AM_IND:
38 return "absolute indirect addressing";
39 }
40 }
41
42
get_detail_mos65xx(csh * handle,cs_mode mode,cs_insn * ins)43 char *get_detail_mos65xx(csh *handle, cs_mode mode, cs_insn *ins)
44 {
45 int i;
46 cs_mos65xx *mos65xx;
47 char *result;
48
49 result = (char *)malloc(sizeof(char));
50 result[0] = '\0';
51
52 if (ins->detail == NULL)
53 return result;
54
55 mos65xx = &(ins->detail->mos65xx);
56 add_str(&result, " ; address mode: %s", get_am_name(mos65xx->am));
57 add_str(&result, " ; modifies flags: %s", mos65xx->modifies_flags ? "true": "false");
58
59 if (mos65xx->op_count)
60 add_str(&result, " ; op_count: %u", mos65xx->op_count);
61
62 for (i = 0; i < mos65xx->op_count; i++) {
63 cs_mos65xx_op *op = &(mos65xx->operands[i]);
64 switch((int)op->type) {
65 default:
66 break;
67 case MOS65XX_OP_REG:
68 add_str(&result, " ; operands[%u].type: REG = %s", i, cs_reg_name(*handle, op->reg));
69 break;
70 case MOS65XX_OP_IMM:
71 add_str(&result, " ; operands[%u].type: IMM = 0x%x", i, op->imm);
72 break;
73 case MOS65XX_OP_MEM:
74 add_str(&result, " ; operands[%u].type: MEM = 0x%x", i, op->mem);
75 break;
76 }
77 }
78 return result;
79 }
80