huangcm
2024-12-18 9d29be7f7249789d6ffd0440067187a9f040c2cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <stdio.h>
#include <stdlib.h>
 
#include <capstone.h>
 
void print_string_hex(char *comment, unsigned char *str, size_t len);
 
void print_insn_detail_arm(csh handle, cs_insn *ins)
{
   cs_arm *arm;
   int i;
 
   // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
   if (ins->detail == NULL)
       return;
 
   arm = &(ins->detail->arm);
 
   if (arm->op_count)
       printf("\top_count: %u\n", arm->op_count);
 
   for (i = 0; i < arm->op_count; i++) {
       cs_arm_op *op = &(arm->operands[i]);
       switch((int)op->type) {
           default:
               break;
           case ARM_OP_REG:
               printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
               break;
           case ARM_OP_IMM:
               printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
               break;
           case ARM_OP_FP:
#if defined(_KERNEL_MODE)
               // Issue #681: Windows kernel does not support formatting float point
               printf("\t\toperands[%u].type: FP = <float_point_unsupported>\n", i);
#else
               printf("\t\toperands[%u].type: FP = %f\n", i, op->fp);
#endif
               break;
           case ARM_OP_MEM:
               printf("\t\toperands[%u].type: MEM\n", i);
               if (op->mem.base != X86_REG_INVALID)
                   printf("\t\t\toperands[%u].mem.base: REG = %s\n",
                           i, cs_reg_name(handle, op->mem.base));
               if (op->mem.index != X86_REG_INVALID)
                   printf("\t\t\toperands[%u].mem.index: REG = %s\n",
                           i, cs_reg_name(handle, op->mem.index));
               if (op->mem.scale != 1)
                   printf("\t\t\toperands[%u].mem.scale: %u\n", i, op->mem.scale);
               if (op->mem.disp != 0)
                   printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
 
               break;
           case ARM_OP_PIMM:
               printf("\t\toperands[%u].type: P-IMM = %u\n", i, op->imm);
               break;
           case ARM_OP_CIMM:
               printf("\t\toperands[%u].type: C-IMM = %u\n", i, op->imm);
               break;
           case ARM_OP_SETEND:
               printf("\t\toperands[%u].type: SETEND = %s\n", i, op->setend == ARM_SETEND_BE? "be" : "le");
               break;
           case ARM_OP_SYSREG:
               printf("\t\toperands[%u].type: SYSREG = %u\n", i, op->reg);
               break;
       }
 
       if (op->shift.type != ARM_SFT_INVALID && op->shift.value) {
           if (op->shift.type < ARM_SFT_ASR_REG)
               // shift with constant value
               printf("\t\t\tShift: %u = %u\n", op->shift.type, op->shift.value);
           else
               // shift with register
               printf("\t\t\tShift: %u = %s\n", op->shift.type,
                       cs_reg_name(handle, op->shift.value));
       }
 
       if (op->vector_index != -1) {
           printf("\t\toperands[%u].vector_index = %u\n", i, op->vector_index);
       }
 
       if (op->subtracted)
           printf("\t\tSubtracted: True\n");
   }
 
   if (arm->cc != ARM_CC_AL && arm->cc != ARM_CC_INVALID)
       printf("\tCode condition: %u\n", arm->cc);
 
   if (arm->update_flags)
       printf("\tUpdate-flags: True\n");
 
   if (arm->writeback)
       printf("\tWrite-back: True\n");
 
   if (arm->cps_mode)
       printf("\tCPSI-mode: %u\n", arm->cps_mode);
 
   if (arm->cps_flag)
       printf("\tCPSI-flag: %u\n", arm->cps_flag);
 
   if (arm->vector_data)
       printf("\tVector-data: %u\n", arm->vector_data);
 
   if (arm->vector_size)
       printf("\tVector-size: %u\n", arm->vector_size);
 
   if (arm->usermode)
       printf("\tUser-mode: True\n");
 
   if (arm->mem_barrier)
       printf("\tMemory-barrier: %u\n", arm->mem_barrier);
}