Rizin
unix-like reverse engineering framework and cli tools
cstool_arm.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <capstone/capstone.h>

Go to the source code of this file.

Functions

void print_string_hex (char *comment, unsigned char *str, size_t len)
 
void print_insn_detail_arm (csh handle, cs_insn *ins)
 

Function Documentation

◆ print_insn_detail_arm()

void print_insn_detail_arm ( csh  handle,
cs_insn *  ins 
)

Definition at line 8 of file cstool_arm.c.

9 {
10  cs_arm *arm;
11  int i;
12  cs_regs regs_read, regs_write;
13  uint8_t regs_read_count, regs_write_count;
14 
15  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
16  if (ins->detail == NULL)
17  return;
18 
19  arm = &(ins->detail->arm);
20 
21  if (arm->op_count)
22  printf("\top_count: %u\n", arm->op_count);
23 
24  for (i = 0; i < arm->op_count; i++) {
25  cs_arm_op *op = &(arm->operands[i]);
26  switch((int)op->type) {
27  default:
28  break;
29  case ARM_OP_REG:
30  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
31  break;
32  case ARM_OP_IMM:
33  printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
34  break;
35  case ARM_OP_FP:
36 #if defined(_KERNEL_MODE)
37  // Issue #681: Windows kernel does not support formatting float point
38  printf("\t\toperands[%u].type: FP = <float_point_unsupported>\n", i);
39 #else
40  printf("\t\toperands[%u].type: FP = %f\n", i, op->fp);
41 #endif
42  break;
43  case ARM_OP_MEM:
44  printf("\t\toperands[%u].type: MEM\n", i);
45  if (op->mem.base != ARM_REG_INVALID)
46  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
47  i, cs_reg_name(handle, op->mem.base));
48  if (op->mem.index != ARM_REG_INVALID)
49  printf("\t\t\toperands[%u].mem.index: REG = %s\n",
50  i, cs_reg_name(handle, op->mem.index));
51  if (op->mem.scale != 1)
52  printf("\t\t\toperands[%u].mem.scale: %d\n", i, op->mem.scale);
53  if (op->mem.disp != 0)
54  printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
55  if (op->mem.lshift != 0)
56  printf("\t\t\toperands[%u].mem.lshift: 0x%x\n", i, op->mem.lshift);
57 
58  break;
59  case ARM_OP_PIMM:
60  printf("\t\toperands[%u].type: P-IMM = %u\n", i, op->imm);
61  break;
62  case ARM_OP_CIMM:
63  printf("\t\toperands[%u].type: C-IMM = %u\n", i, op->imm);
64  break;
65  case ARM_OP_SETEND:
66  printf("\t\toperands[%u].type: SETEND = %s\n", i, op->setend == ARM_SETEND_BE? "be" : "le");
67  break;
68  case ARM_OP_SYSREG:
69  printf("\t\toperands[%u].type: SYSREG = %u\n", i, op->reg);
70  break;
71  }
72 
73  if (op->neon_lane != -1) {
74  printf("\t\toperands[%u].neon_lane = %u\n", i, op->neon_lane);
75  }
76 
77  switch(op->access) {
78  default:
79  break;
80  case CS_AC_READ:
81  printf("\t\toperands[%u].access: READ\n", i);
82  break;
83  case CS_AC_WRITE:
84  printf("\t\toperands[%u].access: WRITE\n", i);
85  break;
86  case CS_AC_READ | CS_AC_WRITE:
87  printf("\t\toperands[%u].access: READ | WRITE\n", i);
88  break;
89  }
90 
91  if (op->shift.type != ARM_SFT_INVALID && op->shift.value) {
92  if (op->shift.type < ARM_SFT_ASR_REG)
93  // shift with constant value
94  printf("\t\t\tShift: %u = %u\n", op->shift.type, op->shift.value);
95  else
96  // shift with register
97  printf("\t\t\tShift: %u = %s\n", op->shift.type,
98  cs_reg_name(handle, op->shift.value));
99  }
100 
101  if (op->vector_index != -1) {
102  printf("\t\toperands[%u].vector_index = %u\n", i, op->vector_index);
103  }
104 
105  if (op->subtracted)
106  printf("\t\tSubtracted: True\n");
107  }
108 
109  if (arm->cc != ARM_CC_AL && arm->cc != ARM_CC_INVALID)
110  printf("\tCode condition: %u\n", arm->cc);
111 
112  if (arm->update_flags)
113  printf("\tUpdate-flags: True\n");
114 
115  if (arm->writeback)
116  printf("\tWrite-back: True\n");
117 
118  if (arm->cps_mode)
119  printf("\tCPSI-mode: %u\n", arm->cps_mode);
120 
121  if (arm->cps_flag)
122  printf("\tCPSI-flag: %u\n", arm->cps_flag);
123 
124  if (arm->vector_data)
125  printf("\tVector-data: %u\n", arm->vector_data);
126 
127  if (arm->vector_size)
128  printf("\tVector-size: %u\n", arm->vector_size);
129 
130  if (arm->usermode)
131  printf("\tUser-mode: True\n");
132 
133  if (arm->mem_barrier)
134  printf("\tMemory-barrier: %u\n", arm->mem_barrier);
135 
136  // Print out all registers accessed by this instruction (either implicit or explicit)
137  if (!cs_regs_access(handle, ins,
138  regs_read, &regs_read_count,
139  regs_write, &regs_write_count)) {
140  if (regs_read_count) {
141  printf("\tRegisters read:");
142  for(i = 0; i < regs_read_count; i++) {
143  printf(" %s", cs_reg_name(handle, regs_read[i]));
144  }
145  printf("\n");
146  }
147 
148  if (regs_write_count) {
149  printf("\tRegisters modified:");
150  for(i = 0; i < regs_write_count; i++) {
151  printf(" %s", cs_reg_name(handle, regs_write[i]));
152  }
153  printf("\n");
154  }
155  }
156 }
lzma_index ** i
Definition: index.h:629
static mcore_handle handle
Definition: asm_mcore.c:8
@ ARM_SFT_INVALID
Definition: arm.h:19
@ ARM_SFT_ASR_REG
shift with register
Definition: arm.h:25
@ ARM_SETEND_BE
BE operand.
Definition: arm.h:176
@ ARM_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: arm.h:164
@ ARM_OP_REG
= CS_OP_REG (Register operand).
Definition: arm.h:163
@ ARM_OP_CIMM
C-Immediate (coprocessor registers)
Definition: arm.h:167
@ ARM_OP_SETEND
operand for SETEND instruction
Definition: arm.h:169
@ ARM_OP_PIMM
P-Immediate (coprocessor registers)
Definition: arm.h:168
@ ARM_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: arm.h:165
@ ARM_OP_FP
= CS_OP_FP (Floating-Point operand).
Definition: arm.h:166
@ ARM_OP_SYSREG
MSR/MRS special register operand.
Definition: arm.h:170
@ ARM_CC_AL
Always (unconditional) Always (unconditional)
Definition: arm.h:49
@ ARM_CC_INVALID
Definition: arm.h:34
@ ARM_REG_INVALID
Definition: arm.h:253
@ CS_AC_READ
Operand read from memory or register.
Definition: capstone.h:204
@ CS_AC_WRITE
Operand write to memory or register.
Definition: capstone.h:205
#define NULL
Definition: cris-opc.c:27
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_regs_access(csh ud, const cs_insn *insn, cs_regs regs_read, uint8_t *regs_read_count, cs_regs regs_write, uint8_t *regs_write_count)
Definition: cs.c:1504
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1154
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
unsigned char uint8_t
Definition: sftypes.h:31
Instruction operand.
Definition: arm.h:391
Instruction structure.
Definition: arm.h:424
Definition: dis.c:32

References ARM_CC_AL, ARM_CC_INVALID, ARM_OP_CIMM, ARM_OP_FP, ARM_OP_IMM, ARM_OP_MEM, ARM_OP_PIMM, ARM_OP_REG, ARM_OP_SETEND, ARM_OP_SYSREG, ARM_REG_INVALID, ARM_SETEND_BE, ARM_SFT_ASR_REG, ARM_SFT_INVALID, CS_AC_READ, CS_AC_WRITE, cs_reg_name(), cs_regs_access(), handle, i, NULL, and printf().

Referenced by print_details().

◆ print_string_hex()

void print_string_hex ( char *  comment,
unsigned char *  str,
size_t  len 
)