Rizin
unix-like reverse engineering framework and cli tools
cstool.c File Reference
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "getopt.h"
#include <capstone/capstone.h>

Go to the source code of this file.

Functions

void print_insn_detail_x86 (csh ud, cs_mode mode, cs_insn *ins)
 
void print_insn_detail_arm (csh handle, cs_insn *ins)
 
void print_insn_detail_arm64 (csh handle, cs_insn *ins)
 
void print_insn_detail_mips (csh handle, cs_insn *ins)
 
void print_insn_detail_ppc (csh handle, cs_insn *ins)
 
void print_insn_detail_sparc (csh handle, cs_insn *ins)
 
void print_insn_detail_sysz (csh handle, cs_insn *ins)
 
void print_insn_detail_xcore (csh handle, cs_insn *ins)
 
void print_insn_detail_m68k (csh handle, cs_insn *ins)
 
void print_insn_detail_tms320c64x (csh handle, cs_insn *ins)
 
void print_insn_detail_m680x (csh handle, cs_insn *ins)
 
void print_insn_detail_evm (csh handle, cs_insn *ins)
 
static void print_details (csh handle, cs_arch arch, cs_mode md, cs_insn *ins)
 
void print_string_hex (const char *comment, unsigned char *str, size_t len)
 
static uint8_t char_to_hexnum (char c)
 
static uint8_tpreprocess (char *code, size_t *size)
 
static void usage (char *prog)
 
int main (int argc, char **argv)
 

Variables

struct {
   const char *   name
 
   cs_arch   arch
 
   cs_mode   mode
 
all_archs []
 

Function Documentation

◆ char_to_hexnum()

static uint8_t char_to_hexnum ( char  c)
static

Definition at line 104 of file cstool.c.

105 {
106  if (c >= '0' && c <= '9') {
107  return (uint8_t)(c - '0');
108  }
109 
110  if (c >= 'a' && c <= 'f') {
111  return (uint8_t)(10 + c - 'a');
112  }
113 
114  // c >= 'A' && c <= 'F'
115  return (uint8_t)(10 + c - 'A');
116 }
unsigned char uint8_t
Definition: sftypes.h:31
#define c(i)
Definition: sha256.c:43

References c.

Referenced by preprocess().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 297 of file cstool.c.

298 {
299  int i, c;
300  csh handle;
301  char *mode;
302  uint8_t *assembly;
303  size_t count, size;
304  uint64_t address = 0LL;
305  cs_insn *insn;
306  cs_err err;
307  cs_mode md;
309  bool detail_flag = false;
310  bool unsigned_flag = false;
311  bool skipdata = false;
312  int args_left;
313 
314  while ((c = getopt (argc, argv, "sudhv")) != -1) {
315  switch (c) {
316  case 's':
317  skipdata = true;
318  break;
319  case 'u':
320  unsigned_flag = true;
321  break;
322  case 'd':
323  detail_flag = true;
324  break;
325  case 'v':
326  printf("Cstool for Capstone Disassembler Engine v%u.%u.%u\n", CS_VERSION_MAJOR, CS_VERSION_MINOR, CS_VERSION_EXTRA);
327 
328  printf("Capstone build: ");
329  if (cs_support(CS_ARCH_X86)) {
330  printf("x86=1 ");
331  }
332 
333  if (cs_support(CS_ARCH_ARM)) {
334  printf("arm=1 ");
335  }
336 
337  if (cs_support(CS_ARCH_ARM64)) {
338  printf("arm64=1 ");
339  }
340 
341  if (cs_support(CS_ARCH_MIPS)) {
342  printf("mips=1 ");
343  }
344 
345  if (cs_support(CS_ARCH_PPC)) {
346  printf("ppc=1 ");
347  }
348 
349  if (cs_support(CS_ARCH_SPARC)) {
350  printf("sparc=1 ");
351  }
352 
353  if (cs_support(CS_ARCH_SYSZ)) {
354  printf("sysz=1 ");
355  }
356 
357  if (cs_support(CS_ARCH_XCORE)) {
358  printf("xcore=1 ");
359  }
360 
361  if (cs_support(CS_ARCH_M68K)) {
362  printf("m68k=1 ");
363  }
364 
366  printf("tms320c64x=1 ");
367  }
368 
369  if (cs_support(CS_ARCH_M680X)) {
370  printf("m680x=1 ");
371  }
372 
373  if (cs_support(CS_ARCH_EVM)) {
374  printf("evm=1 ");
375  }
376 
378  printf("diet=1 ");
379  }
380 
382  printf("x86_reduce=1 ");
383  }
384 
385  printf("\n");
386  return 0;
387  case 'h':
388  usage(argv[0]);
389  return 0;
390  default:
391  usage(argv[0]);
392  return -1;
393  }
394  }
395 
396  args_left = argc - optind;
397  if (args_left < 2 || args_left > 3) {
398  usage(argv[0]);
399  return -1;
400  }
401 
402  mode = argv[optind];
403  assembly = preprocess(argv[optind + 1], &size);
404  if (!assembly) {
405  usage(argv[0]);
406  return -1;
407  }
408 
409  if (args_left == 3) {
410  char *temp, *src = argv[optind + 2];
411  address = strtoull(src, &temp, 16);
412  if (temp == src || *temp != '\0' || errno == ERANGE) {
413  printf("ERROR: invalid address argument, quit!\n");
414  return -2;
415  }
416  }
417 
418  for (i = 0; all_archs[i].name; i++) {
419  if (!strcmp(all_archs[i].name, mode)) {
420  arch = all_archs[i].arch;
422  if (!err) {
423  md = all_archs[i].mode;
424  if (strstr (mode, "att")) {
426  }
427 
428  // turn on SKIPDATA mode
429  if (skipdata)
431  }
432  break;
433  }
434  }
435 
436  if (arch == CS_ARCH_ALL) {
437  printf("ERROR: Invalid <arch+mode>: \"%s\", quit!\n", mode);
438  usage(argv[0]);
439  return -1;
440  }
441 
442  if (err) {
443  printf("ERROR: Failed on cs_open(), quit!\n");
444  usage(argv[0]);
445  return -1;
446  }
447 
448  if (detail_flag) {
450  }
451 
452  if (unsigned_flag) {
454  }
455 
456  count = cs_disasm(handle, assembly, size, address, 0, &insn);
457  if (count > 0) {
458  size_t i;
459 
460  for (i = 0; i < count; i++) {
461  int j;
462 
463  printf("%2"PRIx64" ", insn[i].address);
464  for (j = 0; j < insn[i].size; j++) {
465  if (j > 0)
466  putchar(' ');
467  printf("%02x", insn[i].bytes[j]);
468  }
469  // X86 and s390 instruction sizes are variable.
470  // align assembly instruction after the opcode
471  if (arch == CS_ARCH_X86) {
472  for (; j < 16; j++) {
473  printf(" ");
474  }
475  } else if (arch == CS_ARCH_SYSZ) {
476  for (; j < 6; j++) {
477  printf(" ");
478  }
479  }
480 
481  printf(" %s\t%s\n", insn[i].mnemonic, insn[i].op_str);
482 
483  if (detail_flag) {
484  print_details(handle, arch, md, &insn[i]);
485  }
486  }
487 
488  cs_free(insn, count);
489  } else {
490  printf("ERROR: invalid assembly code\n");
491  return(-4);
492  }
493 
494  cs_close(&handle);
495  free(assembly);
496 
497  return 0;
498 }
lzma_index ** i
Definition: index.h:629
lzma_index * src
Definition: index.h:567
static bool err
Definition: armass.c:435
static ut8 bytes[32]
Definition: asm_arc.c:23
static mcore_handle handle
Definition: asm_mcore.c:8
int getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.h:20
int optind
Definition: getopt.h:6
#define CS_VERSION_EXTRA
Definition: capstone.h:61
cs_arch
Architecture type.
Definition: capstone.h:74
@ CS_ARCH_ARM64
ARM-64, also called AArch64.
Definition: capstone.h:76
@ CS_ARCH_SPARC
Sparc architecture.
Definition: capstone.h:80
@ CS_ARCH_XCORE
XCore architecture.
Definition: capstone.h:82
@ CS_ARCH_M68K
68K architecture
Definition: capstone.h:83
@ CS_ARCH_X86
X86 architecture (including x86 & x86-64)
Definition: capstone.h:78
@ CS_ARCH_ALL
Definition: capstone.h:88
@ CS_ARCH_M680X
680X architecture
Definition: capstone.h:85
@ CS_ARCH_ARM
ARM architecture (including Thumb, Thumb-2)
Definition: capstone.h:75
@ CS_ARCH_MIPS
Mips architecture.
Definition: capstone.h:77
@ CS_ARCH_SYSZ
SystemZ architecture.
Definition: capstone.h:81
@ CS_ARCH_TMS320C64X
TMS320C64x architecture.
Definition: capstone.h:84
@ CS_ARCH_EVM
Ethereum architecture.
Definition: capstone.h:86
@ CS_ARCH_PPC
PowerPC architecture.
Definition: capstone.h:79
#define CS_SUPPORT_X86_REDUCE
Definition: capstone.h:99
cs_mode
Mode type.
Definition: capstone.h:102
#define CS_VERSION_MAJOR
Definition: capstone.h:59
@ CS_OPT_UNSIGNED
print immediate operands in unsigned form
Definition: capstone.h:177
@ CS_OPT_DETAIL
Break down instruction structure into details.
Definition: capstone.h:171
@ CS_OPT_SYNTAX
Assembly output syntax.
Definition: capstone.h:170
@ CS_OPT_SKIPDATA
Skip data when disassembling. Then engine is in SKIPDATA mode.
Definition: capstone.h:174
size_t csh
Definition: capstone.h:71
@ CS_OPT_SYNTAX_ATT
X86 ATT asm syntax (CS_OPT_SYNTAX).
Definition: capstone.h:186
@ CS_OPT_ON
Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
Definition: capstone.h:183
#define CS_SUPPORT_DIET
Definition: capstone.h:94
#define CS_VERSION_MINOR
Definition: capstone.h:60
CAPSTONE_EXPORT bool CAPSTONE_API cs_support(int query)
Definition: cs.c:368
CAPSTONE_EXPORT size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
Definition: cs.c:798
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: cs.c:453
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
Definition: cs.c:1017
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
Definition: cs.c:501
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
Definition: cs.c:646
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
cs_mode mode
Definition: cstool.c:14
static struct @340 all_archs[]
static void print_details(csh handle, cs_arch arch, cs_mode md, cs_insn *ins)
Definition: cstool.c:240
static void usage(char *prog)
Definition: cstool.c:147
cs_arch arch
Definition: cstool.c:13
static uint8_t * preprocess(char *code, size_t *size)
Definition: cstool.c:120
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define ERANGE
Definition: sftypes.h:144
unsigned long uint64_t
Definition: sftypes.h:28
Definition: z80asm.h:102
#define PRIx64
Definition: sysdefs.h:94
mnemonic
Definition: z80asm.h:48

References all_archs, arch, argv, bytes, c, count, CS_ARCH_ALL, CS_ARCH_ARM, CS_ARCH_ARM64, CS_ARCH_EVM, CS_ARCH_M680X, CS_ARCH_M68K, CS_ARCH_MIPS, CS_ARCH_PPC, CS_ARCH_SPARC, CS_ARCH_SYSZ, CS_ARCH_TMS320C64X, CS_ARCH_X86, CS_ARCH_XCORE, cs_close(), cs_disasm(), cs_free(), cs_open(), CS_OPT_DETAIL, CS_OPT_ON, CS_OPT_SKIPDATA, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT, CS_OPT_UNSIGNED, cs_option(), cs_support(), CS_SUPPORT_DIET, CS_SUPPORT_X86_REDUCE, CS_VERSION_EXTRA, CS_VERSION_MAJOR, CS_VERSION_MINOR, ERANGE, err, free(), getopt(), handle, i, benchmark::md, mode, optind, preprocess(), print_details(), printf(), PRIx64, src, and usage().

◆ preprocess()

static uint8_t* preprocess ( char *  code,
size_t size 
)
static

Definition at line 120 of file cstool.c.

121 {
122  size_t i = 0, j = 0;
123  uint8_t high, low;
124  uint8_t *result;
125 
126  if (strlen(code) == 0)
127  return NULL;
128 
129  result = (uint8_t *)malloc(strlen(code));
130  if (result != NULL) {
131  while (code[i] != '\0') {
132  if (isxdigit(code[i]) && isxdigit(code[i+1])) {
133  high = 16 * char_to_hexnum(code[i]);
134  low = char_to_hexnum(code[i+1]);
135  result[j] = high + low;
136  i++;
137  j++;
138  }
139  i++;
140  }
141  *size = j;
142  }
143 
144  return result;
145 }
#define NULL
Definition: cris-opc.c:27
static uint8_t char_to_hexnum(char c)
Definition: cstool.c:104
void * malloc(size_t size)
Definition: malloc.c:123
#define isxdigit(c)
Definition: safe-ctype.h:145
Definition: inftree9.h:24

References char_to_hexnum(), i, isxdigit, malloc(), and NULL.

Referenced by main().

◆ print_details()

static void print_details ( csh  handle,
cs_arch  arch,
cs_mode  md,
cs_insn *  ins 
)
static

Definition at line 240 of file cstool.c.

241 {
242  printf("\tID: %u (%s)\n", ins->id, cs_insn_name(handle, ins->id));
243 
244  switch(arch) {
245  case CS_ARCH_X86:
247  break;
248  case CS_ARCH_ARM:
250  break;
251  case CS_ARCH_ARM64:
253  break;
254  case CS_ARCH_MIPS:
256  break;
257  case CS_ARCH_PPC:
259  break;
260  case CS_ARCH_SPARC:
262  break;
263  case CS_ARCH_SYSZ:
265  break;
266  case CS_ARCH_XCORE:
268  break;
269  case CS_ARCH_M68K:
271  break;
272  case CS_ARCH_TMS320C64X:
274  break;
275  case CS_ARCH_M680X:
277  break;
278  case CS_ARCH_EVM:
280  break;
281  default: break;
282  }
283 
284  if (ins->detail->groups_count) {
285  int j;
286 
287  printf("\tGroups: ");
288  for(j = 0; j < ins->detail->groups_count; j++) {
289  printf("%s ", cs_group_name(handle, ins->detail->groups[j]));
290  }
291  printf("\n");
292  }
293 
294  printf("\n");
295 }
CAPSTONE_EXPORT const char *CAPSTONE_API cs_group_name(csh ud, unsigned int group)
Definition: cs.c:1178
CAPSTONE_EXPORT const char *CAPSTONE_API cs_insn_name(csh ud, unsigned int insn)
Definition: cs.c:1166
void print_insn_detail_xcore(csh handle, cs_insn *ins)
Definition: cstool_xcore.c:9
void print_insn_detail_arm64(csh handle, cs_insn *ins)
Definition: cstool_arm64.c:11
void print_insn_detail_tms320c64x(csh handle, cs_insn *ins)
void print_insn_detail_arm(csh handle, cs_insn *ins)
Definition: cstool_arm.c:8
void print_insn_detail_sysz(csh handle, cs_insn *ins)
void print_insn_detail_x86(csh ud, cs_mode mode, cs_insn *ins)
Definition: cstool_x86.c:180
void print_insn_detail_mips(csh handle, cs_insn *ins)
Definition: cstool_mips.c:11
void print_insn_detail_m68k(csh handle, cs_insn *ins)
Definition: cstool_m68k.c:61
void print_insn_detail_ppc(csh handle, cs_insn *ins)
Definition: cstool_ppc.c:39
void print_insn_detail_evm(csh handle, cs_insn *ins)
Definition: cstool_evm.c:8
void print_insn_detail_sparc(csh handle, cs_insn *ins)
Definition: cstool_sparc.c:10
void print_insn_detail_m680x(csh handle, cs_insn *ins)
Definition: cstool_m680x.c:45

References arch, CS_ARCH_ARM, CS_ARCH_ARM64, CS_ARCH_EVM, CS_ARCH_M680X, CS_ARCH_M68K, CS_ARCH_MIPS, CS_ARCH_PPC, CS_ARCH_SPARC, CS_ARCH_SYSZ, CS_ARCH_TMS320C64X, CS_ARCH_X86, CS_ARCH_XCORE, cs_group_name(), cs_insn_name(), handle, benchmark::md, print_insn_detail_arm(), print_insn_detail_arm64(), print_insn_detail_evm(), print_insn_detail_m680x(), print_insn_detail_m68k(), print_insn_detail_mips(), print_insn_detail_ppc(), print_insn_detail_sparc(), print_insn_detail_sysz(), print_insn_detail_tms320c64x(), print_insn_detail_x86(), print_insn_detail_xcore(), and printf().

Referenced by main().

◆ 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 }
@ 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
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
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_insn_detail_arm64()

void print_insn_detail_arm64 ( csh  handle,
cs_insn *  ins 
)

Definition at line 11 of file cstool_arm64.c.

12 {
13  cs_arm64 *arm64;
14  int i;
15  cs_regs regs_read, regs_write;
16  uint8_t regs_read_count, regs_write_count;
18 
19  // detail can be NULL if SKIPDATA option is turned ON
20  if (ins->detail == NULL)
21  return;
22 
23  arm64 = &(ins->detail->arm64);
24  if (arm64->op_count)
25  printf("\top_count: %u\n", arm64->op_count);
26 
27  for (i = 0; i < arm64->op_count; i++) {
28  cs_arm64_op *op = &(arm64->operands[i]);
29  switch(op->type) {
30  default:
31  break;
32  case ARM64_OP_REG:
33  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
34  break;
35  case ARM64_OP_IMM:
36  printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
37  break;
38  case ARM64_OP_FP:
39 #if defined(_KERNEL_MODE)
40  // Issue #681: Windows kernel does not support formatting float point
41  printf("\t\toperands[%u].type: FP = <float_point_unsupported>\n", i);
42 #else
43  printf("\t\toperands[%u].type: FP = %f\n", i, op->fp);
44 #endif
45  break;
46  case ARM64_OP_MEM:
47  printf("\t\toperands[%u].type: MEM\n", i);
48  if (op->mem.base != ARM64_REG_INVALID)
49  printf("\t\t\toperands[%u].mem.base: REG = %s\n", i, cs_reg_name(handle, op->mem.base));
50  if (op->mem.index != ARM64_REG_INVALID)
51  printf("\t\t\toperands[%u].mem.index: REG = %s\n", i, cs_reg_name(handle, op->mem.index));
52  if (op->mem.disp != 0)
53  printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
54 
55  break;
56  case ARM64_OP_CIMM:
57  printf("\t\toperands[%u].type: C-IMM = %u\n", i, (int)op->imm);
58  break;
59  case ARM64_OP_REG_MRS:
60  printf("\t\toperands[%u].type: REG_MRS = 0x%x\n", i, op->reg);
61  break;
62  case ARM64_OP_REG_MSR:
63  printf("\t\toperands[%u].type: REG_MSR = 0x%x\n", i, op->reg);
64  break;
65  case ARM64_OP_PSTATE:
66  printf("\t\toperands[%u].type: PSTATE = 0x%x\n", i, op->pstate);
67  break;
68  case ARM64_OP_SYS:
69  printf("\t\toperands[%u].type: SYS = 0x%x\n", i, op->sys);
70  break;
71  case ARM64_OP_PREFETCH:
72  printf("\t\toperands[%u].type: PREFETCH = 0x%x\n", i, op->prefetch);
73  break;
74  case ARM64_OP_BARRIER:
75  printf("\t\toperands[%u].type: BARRIER = 0x%x\n", i, op->barrier);
76  break;
77  }
78 
79  access = op->access;
80  switch(access) {
81  default:
82  break;
83  case CS_AC_READ:
84  printf("\t\toperands[%u].access: READ\n", i);
85  break;
86  case CS_AC_WRITE:
87  printf("\t\toperands[%u].access: WRITE\n", i);
88  break;
89  case CS_AC_READ | CS_AC_WRITE:
90  printf("\t\toperands[%u].access: READ | WRITE\n", i);
91  break;
92  }
93 
94  if (op->shift.type != ARM64_SFT_INVALID &&
95  op->shift.value)
96  printf("\t\t\tShift: type = %u, value = %u\n",
97  op->shift.type, op->shift.value);
98 
99  if (op->ext != ARM64_EXT_INVALID)
100  printf("\t\t\tExt: %u\n", op->ext);
101 
102  if (op->vas != ARM64_VAS_INVALID)
103  printf("\t\t\tVector Arrangement Specifier: 0x%x\n", op->vas);
104 
105  if (op->vess != ARM64_VESS_INVALID)
106  printf("\t\t\tVector Element Size Specifier: %u\n", op->vess);
107 
108  if (op->vector_index != -1)
109  printf("\t\t\tVector Index: %u\n", op->vector_index);
110  }
111 
112  if (arm64->update_flags)
113  printf("\tUpdate-flags: True\n");
114 
115  if (arm64->writeback)
116  printf("\tWrite-back: True\n");
117 
118  if (arm64->cc)
119  printf("\tCode-condition: %u\n", arm64->cc);
120 
121  // Print out all registers accessed by this instruction (either implicit or explicit)
122  if (!cs_regs_access(handle, ins,
123  regs_read, &regs_read_count,
124  regs_write, &regs_write_count)) {
125  if (regs_read_count) {
126  printf("\tRegisters read:");
127  for(i = 0; i < regs_read_count; i++) {
128  printf(" %s", cs_reg_name(handle, regs_read[i]));
129  }
130  printf("\n");
131  }
132 
133  if (regs_write_count) {
134  printf("\tRegisters modified:");
135  for(i = 0; i < regs_write_count; i++) {
136  printf(" %s", cs_reg_name(handle, regs_write[i]));
137  }
138  printf("\n");
139  }
140  }
141 }
@ ARM64_VESS_INVALID
Definition: arm64.h:208
@ ARM64_OP_FP
= CS_OP_FP (Floating-Point operand).
Definition: arm64.h:238
@ ARM64_OP_PSTATE
PState operand.
Definition: arm64.h:242
@ ARM64_OP_BARRIER
Memory barrier operand (ISB/DMB/DSB instructions).
Definition: arm64.h:245
@ ARM64_OP_REG
= CS_OP_REG (Register operand).
Definition: arm64.h:235
@ ARM64_OP_PREFETCH
Prefetch operand (PRFM).
Definition: arm64.h:244
@ ARM64_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: arm64.h:237
@ ARM64_OP_SYS
SYS operand for IC/DC/AT/TLBI instructions.
Definition: arm64.h:243
@ ARM64_OP_REG_MRS
MRS register operand.
Definition: arm64.h:240
@ ARM64_OP_CIMM
C-Immediate.
Definition: arm64.h:239
@ ARM64_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: arm64.h:236
@ ARM64_OP_REG_MSR
MSR register operand.
Definition: arm64.h:241
@ ARM64_VAS_INVALID
Definition: arm64.h:194
@ ARM64_SFT_INVALID
Definition: arm64.h:19
@ ARM64_REG_INVALID
Definition: arm64.h:348
@ ARM64_EXT_INVALID
Definition: arm64.h:29
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause access
Definition: sflib.h:64
Instruction operand.
Definition: arm64.h:630
Instruction structure.
Definition: arm64.h:658

References access, ARM64_EXT_INVALID, ARM64_OP_BARRIER, ARM64_OP_CIMM, ARM64_OP_FP, ARM64_OP_IMM, ARM64_OP_MEM, ARM64_OP_PREFETCH, ARM64_OP_PSTATE, ARM64_OP_REG, ARM64_OP_REG_MRS, ARM64_OP_REG_MSR, ARM64_OP_SYS, ARM64_REG_INVALID, ARM64_SFT_INVALID, ARM64_VAS_INVALID, ARM64_VESS_INVALID, CS_AC_READ, CS_AC_WRITE, cs_reg_name(), cs_regs_access(), handle, i, NULL, printf(), and PRIx64.

Referenced by print_details().

◆ print_insn_detail_evm()

void print_insn_detail_evm ( csh  handle,
cs_insn *  ins 
)

Definition at line 8 of file cstool_evm.c.

9 {
10  cs_evm *evm;
11 
12  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
13  if (ins->detail == NULL)
14  return;
15 
16  evm = &(ins->detail->evm);
17 
18  if (evm->pop)
19  printf("\tPop: %u\n", evm->pop);
20 
21  if (evm->push)
22  printf("\tPush: %u\n", evm->push);
23 
24  if (evm->fee)
25  printf("\tGas fee: %u\n", evm->fee);
26 }
Instruction structure.
Definition: evm.h:18
unsigned int fee
gas fee for the instruction
Definition: evm.h:21
unsigned char push
number of items pushed into the stack
Definition: evm.h:20
unsigned char pop
number of items popped from the stack
Definition: evm.h:19

References cs_evm::fee, NULL, cs_evm::pop, printf(), and cs_evm::push.

Referenced by print_details().

◆ print_insn_detail_m680x()

void print_insn_detail_m680x ( csh  handle,
cs_insn *  ins 
)

Definition at line 45 of file cstool_m680x.c.

46 {
47  cs_detail *detail = insn->detail;
48  cs_m680x *m680x = NULL;
49  int i;
50 
51  // detail can be NULL on "data" instruction if SKIPDATA option is
52  // turned ON
53  if (detail == NULL)
54  return;
55 
56  m680x = &detail->m680x;
57 
58  if (m680x->op_count)
59  printf("\top_count: %u\n", m680x->op_count);
60 
61  for (i = 0; i < m680x->op_count; i++) {
62  cs_m680x_op *op = &(m680x->operands[i]);
63  const char *comment;
64 
65  switch ((int)op->type) {
66  default:
67  break;
68 
69  case M680X_OP_REGISTER:
70  comment = "";
71 
72  if ((i == 0 && m680x->flags & M680X_FIRST_OP_IN_MNEM) ||
73  (i == 1 && m680x->flags &
75  comment = " (in mnemonic)";
76 
77  printf("\t\toperands[%u].type: REGISTER = %s%s\n", i,
78  cs_reg_name(handle, op->reg), comment);
79  break;
80 
81  case M680X_OP_CONSTANT:
82  printf("\t\toperands[%u].type: CONSTANT = %u\n", i,
83  op->const_val);
84  break;
85 
86  case M680X_OP_IMMEDIATE:
87  printf("\t\toperands[%u].type: IMMEDIATE = #%d\n", i,
88  op->imm);
89  break;
90 
91  case M680X_OP_DIRECT:
92  printf("\t\toperands[%u].type: DIRECT = 0x%02x\n", i,
93  op->direct_addr);
94  break;
95 
96  case M680X_OP_EXTENDED:
97  printf("\t\toperands[%u].type: EXTENDED %s = 0x%04x\n",
98  i, op->ext.indirect ? "INDIRECT" : "",
99  op->ext.address);
100  break;
101 
102  case M680X_OP_RELATIVE:
103  printf("\t\toperands[%u].type: RELATIVE = 0x%04x\n", i,
104  op->rel.address);
105  break;
106 
107  case M680X_OP_INDEXED:
108  printf("\t\toperands[%u].type: INDEXED%s\n", i,
109  (op->idx.flags & M680X_IDX_INDIRECT) ?
110  " INDIRECT" : "");
111 
112  if (op->idx.base_reg != M680X_REG_INVALID)
113  printf("\t\t\tbase register: %s\n",
114  cs_reg_name(handle, op->idx.base_reg));
115 
116  if (op->idx.offset_reg != M680X_REG_INVALID)
117  printf("\t\t\toffset register: %s\n",
118  cs_reg_name(handle, op->idx.offset_reg));
119 
120  if ((op->idx.offset_bits != 0) &&
121  (op->idx.offset_reg == M680X_REG_INVALID) &&
122  !op->idx.inc_dec) {
123  printf("\t\t\toffset: %d\n", op->idx.offset);
124 
125  if (op->idx.base_reg == M680X_REG_PC)
126  printf("\t\t\toffset address: 0x%x\n",
127  op->idx.offset_addr);
128 
129  printf("\t\t\toffset bits: %u\n",
130  op->idx.offset_bits);
131  }
132 
133  if (op->idx.inc_dec) {
134  const char *post_pre = op->idx.flags &
135  M680X_IDX_POST_INC_DEC ? "post" : "pre";
136  const char *inc_dec = (op->idx.inc_dec > 0) ?
137  "increment" : "decrement";
138 
139  printf("\t\t\t%s %s: %d\n", post_pre, inc_dec,
140  abs(op->idx.inc_dec));
141  }
142 
143  break;
144  }
145 
146  if (op->size != 0)
147  printf("\t\t\tsize: %u\n", op->size);
148 
149  if (op->access != CS_AC_INVALID)
150  printf("\t\t\taccess: %s\n", s_access[op->access]);
151  }
152 
154 }
@ CS_AC_INVALID
Uninitialized/invalid access type.
Definition: capstone.h:203
static const char * s_access[]
Definition: cstool_m680x.c:9
void print_read_write_regs(csh handle, cs_detail *detail)
Definition: cstool_m680x.c:13
#define M680X_IDX_INDIRECT
Definition: m680x.h:76
#define M680X_FIRST_OP_IN_MNEM
Definition: m680x.h:159
@ M680X_REG_INVALID
Definition: m680x.h:21
@ M680X_REG_PC
M6800/1/2/3/9, M6301/9.
Definition: m680x.h:46
#define M680X_IDX_POST_INC_DEC
Definition: m680x.h:78
@ M680X_OP_EXTENDED
= Extended addressing operand.
Definition: m680x.h:60
@ M680X_OP_INDEXED
= Indexed addressing operand.
Definition: m680x.h:59
@ M680X_OP_CONSTANT
Used e.g. for a bit index or page number.
Definition: m680x.h:63
@ M680X_OP_IMMEDIATE
= Immediate operand.
Definition: m680x.h:58
@ M680X_OP_REGISTER
= Register operand.
Definition: m680x.h:57
@ M680X_OP_RELATIVE
= Relative addressing operand.
Definition: m680x.h:62
@ M680X_OP_DIRECT
= Direct addressing operand.
Definition: m680x.h:61
#define M680X_SECOND_OP_IN_MNEM
Definition: m680x.h:162
Instruction operand.
Definition: m680x.h:114
The M680X instruction and it's operands.
Definition: m680x.h:165
uint8_t flags
See: M680X instruction flags.
Definition: m680x.h:166
cs_m680x_op operands[M680X_OPERAND_COUNT]
operands for this insn.
Definition: m680x.h:168
uint8_t op_count
number of operands for the instruction or 0
Definition: m680x.h:167

References CS_AC_INVALID, cs_reg_name(), cs_m680x::flags, handle, i, M680X_FIRST_OP_IN_MNEM, M680X_IDX_INDIRECT, M680X_IDX_POST_INC_DEC, M680X_OP_CONSTANT, M680X_OP_DIRECT, M680X_OP_EXTENDED, M680X_OP_IMMEDIATE, M680X_OP_INDEXED, M680X_OP_REGISTER, M680X_OP_RELATIVE, M680X_REG_INVALID, M680X_REG_PC, M680X_SECOND_OP_IN_MNEM, NULL, cs_m680x::op_count, cs_m680x::operands, print_read_write_regs(), printf(), and s_access.

Referenced by print_details().

◆ print_insn_detail_m68k()

void print_insn_detail_m68k ( csh  handle,
cs_insn *  ins 
)

Definition at line 61 of file cstool_m68k.c.

62 {
63  cs_m68k* m68k;
64  cs_detail* detail;
65  int i;
66 
67  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
68  if (ins->detail == NULL)
69  return;
70 
71  detail = ins->detail;
72  m68k = &detail->m68k;
73  if (m68k->op_count)
74  printf("\top_count: %u\n", m68k->op_count);
75 
77 
78  printf("\tgroups_count: %u\n", detail->groups_count);
79 
80  for (i = 0; i < m68k->op_count; i++) {
81  cs_m68k_op* op = &(m68k->operands[i]);
82 
83  switch((int)op->type) {
84  default:
85  break;
86  case M68K_OP_REG:
87  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
88  break;
89  case M68K_OP_IMM:
90  printf("\t\toperands[%u].type: IMM = 0x%x\n", i, (int)op->imm);
91  break;
92  case M68K_OP_MEM:
93  printf("\t\toperands[%u].type: MEM\n", i);
94  if (op->mem.base_reg != M68K_REG_INVALID)
95  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
96  i, cs_reg_name(handle, op->mem.base_reg));
97  if (op->mem.index_reg != M68K_REG_INVALID) {
98  printf("\t\t\toperands[%u].mem.index: REG = %s\n",
99  i, cs_reg_name(handle, op->mem.index_reg));
100  printf("\t\t\toperands[%u].mem.index: size = %c\n",
101  i, op->mem.index_size ? 'l' : 'w');
102  }
103  if (op->mem.disp != 0)
104  printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
105  if (op->mem.scale != 0)
106  printf("\t\t\toperands[%u].mem.scale: %d\n", i, op->mem.scale);
107 
108  printf("\t\taddress mode: %s\n", s_addressing_modes[op->address_mode]);
109  break;
110  case M68K_OP_FP_SINGLE:
111  printf("\t\toperands[%u].type: FP_SINGLE\n", i);
112  printf("\t\t\toperands[%u].simm: %f\n", i, op->simm);
113  break;
114  case M68K_OP_FP_DOUBLE:
115  printf("\t\toperands[%u].type: FP_DOUBLE\n", i);
116  printf("\t\t\toperands[%u].dimm: %lf\n", i, op->dimm);
117  break;
118  }
119  }
120 }
static const char * s_addressing_modes[]
Definition: cstool_m68k.c:14
static void print_read_write_regs(cs_detail *detail, csh handle)
Definition: cstool_m68k.c:44
@ M68K_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: m68k.h:115
@ M68K_OP_FP_SINGLE
single precision Floating-Point operand
Definition: m68k.h:117
@ M68K_OP_FP_DOUBLE
double precision Floating-Point operand
Definition: m68k.h:118
@ M68K_OP_REG
= CS_OP_REG (Register operand).
Definition: m68k.h:114
@ M68K_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: m68k.h:116
@ M68K_REG_INVALID
Definition: m68k.h:21
Instruction operand.
Definition: m68k.h:160
The M68K instruction and it's operands.
Definition: m68k.h:210

References cs_reg_name(), test_evm::detail, handle, i, M68K_OP_FP_DOUBLE, M68K_OP_FP_SINGLE, M68K_OP_IMM, M68K_OP_MEM, M68K_OP_REG, M68K_REG_INVALID, NULL, print_read_write_regs(), printf(), and s_addressing_modes.

Referenced by print_details().

◆ print_insn_detail_mips()

void print_insn_detail_mips ( csh  handle,
cs_insn *  ins 
)

Definition at line 11 of file cstool_mips.c.

12 {
13  int i;
14  cs_mips *mips;
15 
16  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
17  if (ins->detail == NULL)
18  return;
19 
20  mips = &(ins->detail->mips);
21  if (mips->op_count)
22  printf("\top_count: %u\n", mips->op_count);
23 
24  for (i = 0; i < mips->op_count; i++) {
25  cs_mips_op *op = &(mips->operands[i]);
26  switch((int)op->type) {
27  default:
28  break;
29  case MIPS_OP_REG:
30  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
31  break;
32  case MIPS_OP_IMM:
33  printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
34  break;
35  case MIPS_OP_MEM:
36  printf("\t\toperands[%u].type: MEM\n", i);
37  if (op->mem.base != MIPS_REG_INVALID)
38  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
39  i, cs_reg_name(handle, op->mem.base));
40  if (op->mem.disp != 0)
41  printf("\t\t\toperands[%u].mem.disp: 0x%" PRIx64 "\n", i, op->mem.disp);
42 
43  break;
44  }
45 
46  }
47 }
Instruction operand.
Definition: mips.h:240
Instruction structure.
Definition: mips.h:250
@ MIPS_OP_REG
= CS_OP_REG (Register operand).
Definition: mips.h:24
@ MIPS_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: mips.h:25
@ MIPS_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: mips.h:26
@ MIPS_REG_INVALID
Definition: mips.h:31

References cs_reg_name(), handle, i, MIPS_OP_IMM, MIPS_OP_MEM, MIPS_OP_REG, MIPS_REG_INVALID, NULL, printf(), and PRIx64.

Referenced by print_details().

◆ print_insn_detail_ppc()

void print_insn_detail_ppc ( csh  handle,
cs_insn *  ins 
)

Definition at line 39 of file cstool_ppc.c.

40 {
41  cs_ppc *ppc;
42  int i;
43 
44  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
45  if (ins->detail == NULL)
46  return;
47 
48  ppc = &(ins->detail->ppc);
49  if (ppc->op_count)
50  printf("\top_count: %u\n", ppc->op_count);
51 
52  for (i = 0; i < ppc->op_count; i++) {
53  cs_ppc_op *op = &(ppc->operands[i]);
54  switch((int)op->type) {
55  default:
56  break;
57  case PPC_OP_REG:
58  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
59  break;
60  case PPC_OP_IMM:
61  printf("\t\toperands[%u].type: IMM = 0x%"PRIx64"\n", i, op->imm);
62  break;
63  case PPC_OP_MEM:
64  printf("\t\toperands[%u].type: MEM\n", i);
65  if (op->mem.base != PPC_REG_INVALID)
66  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
67  i, cs_reg_name(handle, op->mem.base));
68  if (op->mem.disp != 0)
69  printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
70 
71  break;
72  case PPC_OP_CRX:
73  printf("\t\toperands[%u].type: CRX\n", i);
74  printf("\t\t\toperands[%u].crx.scale: %d\n", i, op->crx.scale);
75  printf("\t\t\toperands[%u].crx.reg: %s\n", i, cs_reg_name(handle, op->crx.reg));
76  printf("\t\t\toperands[%u].crx.cond: %s\n", i, get_bc_name(op->crx.cond));
77  break;
78  }
79  }
80 
81  if (ppc->bc != 0)
82  printf("\tBranch code: %u\n", ppc->bc);
83 
84  if (ppc->bh != 0)
85  printf("\tBranch hint: %u\n", ppc->bh);
86 
87  if (ppc->update_cr0)
88  printf("\tUpdate-CR0: True\n");
89 }
static const char * get_bc_name(int bc)
Definition: cstool_ppc.c:10
Instruction operand.
Definition: ppc.h:283
Instruction structure.
Definition: ppc.h:294
@ PPC_OP_REG
= CS_OP_REG (Register operand).
Definition: ppc.h:44
@ PPC_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: ppc.h:45
@ PPC_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: ppc.h:46
@ PPC_OP_CRX
Condition Register field.
Definition: ppc.h:47
@ PPC_REG_INVALID
Definition: ppc.h:52

References cs_reg_name(), get_bc_name(), handle, i, NULL, PPC_OP_CRX, PPC_OP_IMM, PPC_OP_MEM, PPC_OP_REG, PPC_REG_INVALID, printf(), and PRIx64.

Referenced by print_details().

◆ print_insn_detail_sparc()

void print_insn_detail_sparc ( csh  handle,
cs_insn *  ins 
)

Definition at line 10 of file cstool_sparc.c.

11 {
12  cs_sparc *sparc;
13  int i;
14 
15  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
16  if (ins->detail == NULL)
17  return;
18 
19  sparc = &(ins->detail->sparc);
20  if (sparc->op_count)
21  printf("\top_count: %u\n", sparc->op_count);
22 
23  for (i = 0; i < sparc->op_count; i++) {
24  cs_sparc_op *op = &(sparc->operands[i]);
25  switch((int)op->type) {
26  default:
27  break;
28  case SPARC_OP_REG:
29  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
30  break;
31  case SPARC_OP_IMM:
32  printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
33  break;
34  case SPARC_OP_MEM:
35  printf("\t\toperands[%u].type: MEM\n", i);
36  if (op->mem.base != X86_REG_INVALID)
37  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
38  i, cs_reg_name(handle, op->mem.base));
39  if (op->mem.index != X86_REG_INVALID)
40  printf("\t\t\toperands[%u].mem.index: REG = %s\n",
41  i, cs_reg_name(handle, op->mem.index));
42  if (op->mem.disp != 0)
43  printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
44 
45  break;
46  }
47  }
48 
49  if (sparc->cc != 0)
50  printf("\tCode condition: %u\n", sparc->cc);
51 
52  if (sparc->hint != 0)
53  printf("\tHint code: %u\n", sparc->hint);
54 }
@ X86_REG_INVALID
Definition: x86.h:20
Instruction operand.
Definition: sparc.h:189
Instruction structure.
Definition: sparc.h:199
@ SPARC_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: sparc.h:74
@ SPARC_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: sparc.h:73
@ SPARC_OP_REG
= CS_OP_REG (Register operand).
Definition: sparc.h:72

References cs_reg_name(), handle, i, NULL, printf(), PRIx64, SPARC_OP_IMM, SPARC_OP_MEM, SPARC_OP_REG, and X86_REG_INVALID.

Referenced by print_details().

◆ print_insn_detail_sysz()

void print_insn_detail_sysz ( csh  handle,
cs_insn *  ins 
)

Definition at line 10 of file cstool_systemz.c.

11 {
12  cs_sysz *sysz;
13  int i;
14 
15  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
16  if (ins->detail == NULL)
17  return;
18 
19  sysz = &(ins->detail->sysz);
20  if (sysz->op_count)
21  printf("\top_count: %u\n", sysz->op_count);
22 
23  for (i = 0; i < sysz->op_count; i++) {
24  cs_sysz_op *op = &(sysz->operands[i]);
25  switch((int)op->type) {
26  default:
27  break;
28  case SYSZ_OP_REG:
29  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
30  break;
31  case SYSZ_OP_ACREG:
32  printf("\t\toperands[%u].type: ACREG = %u\n", i, op->reg);
33  break;
34  case SYSZ_OP_IMM:
35  printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
36  break;
37  case SYSZ_OP_MEM:
38  printf("\t\toperands[%u].type: MEM\n", i);
39  if (op->mem.base != SYSZ_REG_INVALID)
40  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
41  i, cs_reg_name(handle, op->mem.base));
42  if (op->mem.index != SYSZ_REG_INVALID)
43  printf("\t\t\toperands[%u].mem.index: REG = %s\n",
44  i, cs_reg_name(handle, op->mem.index));
45  if (op->mem.length != 0)
46  printf("\t\t\toperands[%u].mem.length: 0x%" PRIx64 "\n", i, op->mem.length);
47  if (op->mem.disp != 0)
48  printf("\t\t\toperands[%u].mem.disp: 0x%" PRIx64 "\n", i, op->mem.disp);
49 
50  break;
51  }
52  }
53 
54  if (sysz->cc != 0)
55  printf("\tCode condition: %u\n", sysz->cc);
56 }
@ SYSZ_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: systemz.h:42
@ SYSZ_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: systemz.h:41
@ SYSZ_OP_ACREG
Access register operand.
Definition: systemz.h:43
@ SYSZ_OP_REG
= CS_OP_REG (Register operand).
Definition: systemz.h:40
@ SYSZ_REG_INVALID
Definition: systemz.h:48
Instruction operand.
Definition: systemz.h:101
sysz_cc cc
Definition: systemz.h:112
cs_sysz_op operands[6]
operands for this instruction.
Definition: systemz.h:116
uint8_t op_count
Definition: systemz.h:115

References cs_sysz::cc, cs_reg_name(), handle, i, NULL, cs_sysz::op_count, cs_sysz::operands, printf(), PRIx64, SYSZ_OP_ACREG, SYSZ_OP_IMM, SYSZ_OP_MEM, SYSZ_OP_REG, and SYSZ_REG_INVALID.

Referenced by print_details().

◆ print_insn_detail_tms320c64x()

void print_insn_detail_tms320c64x ( csh  handle,
cs_insn *  ins 
)

Definition at line 9 of file cstool_tms320c64x.c.

10 {
11  cs_tms320c64x *tms320c64x;
12  int i;
13 
14  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
15  if (ins->detail == NULL)
16  return;
17 
18  tms320c64x = &(ins->detail->tms320c64x);
19  if (tms320c64x->op_count)
20  printf("\top_count: %u\n", tms320c64x->op_count);
21 
22  for (i = 0; i < tms320c64x->op_count; i++) {
23  cs_tms320c64x_op *op = &(tms320c64x->operands[i]);
24  switch((int)op->type) {
25  default:
26  break;
27  case TMS320C64X_OP_REG:
28  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
29  break;
30  case TMS320C64X_OP_IMM:
31  printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
32  break;
33  case TMS320C64X_OP_MEM:
34  printf("\t\toperands[%u].type: MEM\n", i);
35  if (op->mem.base != TMS320C64X_REG_INVALID)
36  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
37  i, cs_reg_name(handle, op->mem.base));
38  printf("\t\t\toperands[%u].mem.disptype: ", i);
39  if(op->mem.disptype == TMS320C64X_MEM_DISP_INVALID) {
40  printf("Invalid\n");
41  printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
42  }
43  if(op->mem.disptype == TMS320C64X_MEM_DISP_CONSTANT) {
44  printf("Constant\n");
45  printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
46  }
47  if(op->mem.disptype == TMS320C64X_MEM_DISP_REGISTER) {
48  printf("Register\n");
49  printf("\t\t\toperands[%u].mem.disp: %s\n", i, cs_reg_name(handle, op->mem.disp));
50  }
51  printf("\t\t\toperands[%u].mem.unit: %u\n", i, op->mem.unit);
52  printf("\t\t\toperands[%u].mem.direction: ", i);
53  if(op->mem.direction == TMS320C64X_MEM_DIR_INVALID)
54  printf("Invalid\n");
55  if(op->mem.direction == TMS320C64X_MEM_DIR_FW)
56  printf("Forward\n");
57  if(op->mem.direction == TMS320C64X_MEM_DIR_BW)
58  printf("Backward\n");
59  printf("\t\t\toperands[%u].mem.modify: ", i);
60  if(op->mem.modify == TMS320C64X_MEM_MOD_INVALID)
61  printf("Invalid\n");
62  if(op->mem.modify == TMS320C64X_MEM_MOD_NO)
63  printf("No\n");
64  if(op->mem.modify == TMS320C64X_MEM_MOD_PRE)
65  printf("Pre\n");
66  if(op->mem.modify == TMS320C64X_MEM_MOD_POST)
67  printf("Post\n");
68  printf("\t\t\toperands[%u].mem.scaled: %u\n", i, op->mem.scaled);
69 
70  break;
72  printf("\t\toperands[%u].type: REGPAIR = %s:%s\n", i, cs_reg_name(handle, op->reg + 1), cs_reg_name(handle, op->reg));
73  break;
74  }
75  }
76 
77  printf("\tFunctional unit: ");
78  switch(tms320c64x->funit.unit) {
79  case TMS320C64X_FUNIT_D:
80  printf("D%u\n", tms320c64x->funit.side);
81  break;
82  case TMS320C64X_FUNIT_L:
83  printf("L%u\n", tms320c64x->funit.side);
84  break;
85  case TMS320C64X_FUNIT_M:
86  printf("M%u\n", tms320c64x->funit.side);
87  break;
88  case TMS320C64X_FUNIT_S:
89  printf("S%u\n", tms320c64x->funit.side);
90  break;
92  printf("No Functional Unit\n");
93  break;
94  default:
95  printf("Unknown (Unit %u, Side %u)\n", tms320c64x->funit.unit, tms320c64x->funit.side);
96  break;
97  }
98  if(tms320c64x->funit.crosspath == 1)
99  printf("\tCrosspath: 1\n");
100 
101  if(tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
102  printf("\tCondition: [%c%s]\n", (tms320c64x->condition.zero == 1) ? '!' : ' ', cs_reg_name(handle, tms320c64x->condition.reg));
103  printf("\tParallel: %s\n", (tms320c64x->parallel == 1) ? "true" : "false");
104 
105  printf("\n");
106 }
cs_tms320c64x_op operands[8]
operands for this instruction.
Definition: tms320c64x.h:66
struct cs_tms320c64x::@364 funit
unsigned int unit
Definition: tms320c64x.h:72
unsigned int parallel
Definition: tms320c64x.h:76
unsigned int crosspath
Definition: tms320c64x.h:74
unsigned int reg
Definition: tms320c64x.h:68
uint8_t op_count
Definition: tms320c64x.h:65
struct cs_tms320c64x::@363 condition
unsigned int zero
Definition: tms320c64x.h:69
unsigned int side
Definition: tms320c64x.h:73
@ TMS320C64X_FUNIT_NO
Definition: tms320c64x.h:351
@ TMS320C64X_FUNIT_L
Definition: tms320c64x.h:348
@ TMS320C64X_FUNIT_D
Definition: tms320c64x.h:347
@ TMS320C64X_FUNIT_S
Definition: tms320c64x.h:350
@ TMS320C64X_FUNIT_M
Definition: tms320c64x.h:349
@ TMS320C64X_MEM_DISP_INVALID
Definition: tms320c64x.h:27
@ TMS320C64X_MEM_DISP_CONSTANT
Definition: tms320c64x.h:28
@ TMS320C64X_MEM_DISP_REGISTER
Definition: tms320c64x.h:29
@ TMS320C64X_REG_INVALID
Definition: tms320c64x.h:80
@ TMS320C64X_MEM_DIR_FW
Definition: tms320c64x.h:34
@ TMS320C64X_MEM_DIR_BW
Definition: tms320c64x.h:35
@ TMS320C64X_MEM_DIR_INVALID
Definition: tms320c64x.h:33
@ TMS320C64X_MEM_MOD_POST
Definition: tms320c64x.h:42
@ TMS320C64X_MEM_MOD_INVALID
Definition: tms320c64x.h:39
@ TMS320C64X_MEM_MOD_NO
Definition: tms320c64x.h:40
@ TMS320C64X_MEM_MOD_PRE
Definition: tms320c64x.h:41
@ TMS320C64X_OP_REG
= CS_OP_REG (Register operand).
Definition: tms320c64x.h:20
@ TMS320C64X_OP_REGPAIR
Register pair for double word ops.
Definition: tms320c64x.h:23
@ TMS320C64X_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: tms320c64x.h:21
@ TMS320C64X_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: tms320c64x.h:22

References cs_tms320c64x::condition, cs_tms320c64x::crosspath, cs_reg_name(), cs_tms320c64x::funit, handle, i, NULL, cs_tms320c64x::op_count, cs_tms320c64x::operands, cs_tms320c64x::parallel, printf(), cs_tms320c64x::reg, cs_tms320c64x::side, TMS320C64X_FUNIT_D, TMS320C64X_FUNIT_L, TMS320C64X_FUNIT_M, TMS320C64X_FUNIT_NO, TMS320C64X_FUNIT_S, TMS320C64X_MEM_DIR_BW, TMS320C64X_MEM_DIR_FW, TMS320C64X_MEM_DIR_INVALID, TMS320C64X_MEM_DISP_CONSTANT, TMS320C64X_MEM_DISP_INVALID, TMS320C64X_MEM_DISP_REGISTER, TMS320C64X_MEM_MOD_INVALID, TMS320C64X_MEM_MOD_NO, TMS320C64X_MEM_MOD_POST, TMS320C64X_MEM_MOD_PRE, TMS320C64X_OP_IMM, TMS320C64X_OP_MEM, TMS320C64X_OP_REG, TMS320C64X_OP_REGPAIR, TMS320C64X_REG_INVALID, cs_tms320c64x::unit, and cs_tms320c64x::zero.

Referenced by print_details().

◆ print_insn_detail_x86()

void print_insn_detail_x86 ( csh  ud,
cs_mode  mode,
cs_insn *  ins 
)

Definition at line 180 of file cstool_x86.c.

181 {
182  int count, i;
183  cs_x86 *x86;
184  cs_regs regs_read, regs_write;
185  uint8_t regs_read_count, regs_write_count;
186 
187  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
188  if (ins->detail == NULL)
189  return;
190 
191  x86 = &(ins->detail->x86);
192 
193  print_string_hex("\tPrefix:", x86->prefix, 4);
194  print_string_hex("\tOpcode:", x86->opcode, 4);
195  printf("\trex: 0x%x\n", x86->rex);
196  printf("\taddr_size: %u\n", x86->addr_size);
197  printf("\tmodrm: 0x%x\n", x86->modrm);
198  printf("\tdisp: 0x%" PRIx64 "\n", x86->disp);
199 
200  // SIB is not available in 16-bit mode
201  if ((mode & CS_MODE_16) == 0) {
202  printf("\tsib: 0x%x\n", x86->sib);
203  if (x86->sib_base != X86_REG_INVALID)
204  printf("\t\tsib_base: %s\n", cs_reg_name(ud, x86->sib_base));
205  if (x86->sib_index != X86_REG_INVALID)
206  printf("\t\tsib_index: %s\n", cs_reg_name(ud, x86->sib_index));
207  if (x86->sib_scale != 0)
208  printf("\t\tsib_scale: %d\n", x86->sib_scale);
209  }
210 
211  // XOP code condition
212  if (x86->xop_cc != X86_XOP_CC_INVALID) {
213  printf("\txop_cc: %u\n", x86->xop_cc);
214  }
215 
216  // SSE code condition
217  if (x86->sse_cc != X86_SSE_CC_INVALID) {
218  printf("\tsse_cc: %u\n", x86->sse_cc);
219  }
220 
221  // AVX code condition
222  if (x86->avx_cc != X86_AVX_CC_INVALID) {
223  printf("\tavx_cc: %u\n", x86->avx_cc);
224  }
225 
226  // AVX Suppress All Exception
227  if (x86->avx_sae) {
228  printf("\tavx_sae: %u\n", x86->avx_sae);
229  }
230 
231  // AVX Rounding Mode
232  if (x86->avx_rm != X86_AVX_RM_INVALID) {
233  printf("\tavx_rm: %u\n", x86->avx_rm);
234  }
235 
236  // Print out all immediate operands
237  count = cs_op_count(ud, ins, X86_OP_IMM);
238  if (count > 0) {
239  printf("\timm_count: %u\n", count);
240  for (i = 1; i < count + 1; i++) {
241  int index = cs_op_index(ud, ins, X86_OP_IMM, i);
242  printf("\t\timms[%u]: 0x%" PRIx64 "\n", i, x86->operands[index].imm);
243  }
244  }
245 
246  if (x86->op_count)
247  printf("\top_count: %u\n", x86->op_count);
248 
249  // Print out all operands
250  for (i = 0; i < x86->op_count; i++) {
251  cs_x86_op *op = &(x86->operands[i]);
252 
253  switch((int)op->type) {
254  case X86_OP_REG:
255  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(ud, op->reg));
256  break;
257  case X86_OP_IMM:
258  printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
259  break;
260  case X86_OP_MEM:
261  printf("\t\toperands[%u].type: MEM\n", i);
262  if (op->mem.segment != X86_REG_INVALID)
263  printf("\t\t\toperands[%u].mem.segment: REG = %s\n", i, cs_reg_name(ud, op->mem.segment));
264  if (op->mem.base != X86_REG_INVALID)
265  printf("\t\t\toperands[%u].mem.base: REG = %s\n", i, cs_reg_name(ud, op->mem.base));
266  if (op->mem.index != X86_REG_INVALID)
267  printf("\t\t\toperands[%u].mem.index: REG = %s\n", i, cs_reg_name(ud, op->mem.index));
268  if (op->mem.scale != 1)
269  printf("\t\t\toperands[%u].mem.scale: %u\n", i, op->mem.scale);
270  if (op->mem.disp != 0)
271  printf("\t\t\toperands[%u].mem.disp: 0x%" PRIx64 "\n", i, op->mem.disp);
272  break;
273  default:
274  break;
275  }
276 
277  // AVX broadcast type
278  if (op->avx_bcast != X86_AVX_BCAST_INVALID)
279  printf("\t\toperands[%u].avx_bcast: %u\n", i, op->avx_bcast);
280 
281  // AVX zero opmask {z}
282  if (op->avx_zero_opmask != false)
283  printf("\t\toperands[%u].avx_zero_opmask: TRUE\n", i);
284 
285  printf("\t\toperands[%u].size: %u\n", i, op->size);
286 
287  switch(op->access) {
288  default:
289  break;
290  case CS_AC_READ:
291  printf("\t\toperands[%u].access: READ\n", i);
292  break;
293  case CS_AC_WRITE:
294  printf("\t\toperands[%u].access: WRITE\n", i);
295  break;
296  case CS_AC_READ | CS_AC_WRITE:
297  printf("\t\toperands[%u].access: READ | WRITE\n", i);
298  break;
299  }
300  }
301 
302  // Print out all registers accessed by this instruction (either implicit or explicit)
303  if (!cs_regs_access(ud, ins,
304  regs_read, &regs_read_count,
305  regs_write, &regs_write_count)) {
306  if (regs_read_count) {
307  printf("\tRegisters read:");
308  for(i = 0; i < regs_read_count; i++) {
309  printf(" %s", cs_reg_name(ud, regs_read[i]));
310  }
311  printf("\n");
312  }
313 
314  if (regs_write_count) {
315  printf("\tRegisters modified:");
316  for(i = 0; i < regs_write_count; i++) {
317  printf(" %s", cs_reg_name(ud, regs_write[i]));
318  }
319  printf("\n");
320  }
321  }
322 
323  if (x86->eflags || x86->fpu_flags) {
324  for(i = 0; i < ins->detail->groups_count; i++) {
325  if (ins->detail->groups[i] == X86_GRP_FPU) {
326  printf("\tFPU_FLAGS:");
327  for(i = 0; i <= 63; i++)
328  if (x86->fpu_flags & ((uint64_t)1 << i)) {
329  printf(" %s", get_fpu_flag_name((uint64_t)1 << i));
330  }
331  printf("\n");
332  break;
333  }
334  }
335 
336  if (i == ins->detail->groups_count) {
337  printf("\tEFLAGS:");
338  for(i = 0; i <= 63; i++)
339  if (x86->eflags & ((uint64_t)1 << i)) {
340  printf(" %s", get_eflag_name((uint64_t)1 << i));
341  }
342  printf("\n");
343  }
344  }
345 }
@ CS_MODE_16
16-bit mode (X86)
Definition: capstone.h:105
@ X86_AVX_BCAST_INVALID
Uninitialized.
Definition: x86.h:180
@ X86_AVX_RM_INVALID
Uninitialized.
Definition: x86.h:239
@ X86_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: x86.h:161
@ X86_OP_REG
= CS_OP_REG (Register operand).
Definition: x86.h:160
@ X86_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: x86.h:162
@ X86_XOP_CC_INVALID
Uninitialized.
Definition: x86.h:167
@ X86_GRP_FPU
Definition: x86.h:1963
@ X86_AVX_CC_INVALID
Uninitialized.
Definition: x86.h:202
@ X86_SSE_CC_INVALID
Uninitialized.
Definition: x86.h:189
CAPSTONE_EXPORT int CAPSTONE_API cs_op_count(csh ud, const cs_insn *insn, unsigned int op_type)
Definition: cs.c:1271
CAPSTONE_EXPORT int CAPSTONE_API cs_op_index(csh ud, const cs_insn *insn, unsigned int op_type, unsigned int post)
Definition: cs.c:1369
void print_string_hex(const char *comment, unsigned char *str, size_t len)
Definition: cstool.c:91
static const char * get_fpu_flag_name(uint64_t flag)
Definition: cstool_x86.c:132
static const char * get_eflag_name(uint64_t flag)
Definition: cstool_x86.c:10
Instruction operand.
Definition: x86.h:275
Instruction structure.
Definition: x86.h:312

References count, CS_AC_READ, CS_AC_WRITE, CS_MODE_16, cs_op_count(), cs_op_index(), cs_reg_name(), cs_regs_access(), get_eflag_name(), get_fpu_flag_name(), i, NULL, print_string_hex(), printf(), PRIx64, X86_AVX_BCAST_INVALID, X86_AVX_CC_INVALID, X86_AVX_RM_INVALID, X86_GRP_FPU, X86_OP_IMM, X86_OP_MEM, X86_OP_REG, X86_REG_INVALID, X86_SSE_CC_INVALID, and X86_XOP_CC_INVALID.

Referenced by print_details().

◆ print_insn_detail_xcore()

void print_insn_detail_xcore ( csh  handle,
cs_insn *  ins 
)

Definition at line 9 of file cstool_xcore.c.

10 {
11  cs_xcore *xcore;
12  int i;
13 
14  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
15  if (ins->detail == NULL)
16  return;
17 
18  xcore = &(ins->detail->xcore);
19  if (xcore->op_count)
20  printf("\top_count: %u\n", xcore->op_count);
21 
22  for (i = 0; i < xcore->op_count; i++) {
23  cs_xcore_op *op = &(xcore->operands[i]);
24  switch((int)op->type) {
25  default:
26  break;
27  case XCORE_OP_REG:
28  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
29  break;
30  case XCORE_OP_IMM:
31  printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
32  break;
33  case XCORE_OP_MEM:
34  printf("\t\toperands[%u].type: MEM\n", i);
35  if (op->mem.base != XCORE_REG_INVALID)
36  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
37  i, cs_reg_name(handle, op->mem.base));
38  if (op->mem.index != XCORE_REG_INVALID)
39  printf("\t\t\toperands[%u].mem.index: REG = %s\n",
40  i, cs_reg_name(handle, op->mem.index));
41  if (op->mem.disp != 0)
42  printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
43  if (op->mem.direct != 1)
44  printf("\t\t\toperands[%u].mem.direct: -1\n", i);
45 
46 
47  break;
48  }
49  }
50 
51  printf("\n");
52 }
@ XCORE_REG_INVALID
Definition: xcore.h:27
@ XCORE_OP_REG
= CS_OP_REG (Register operand).
Definition: xcore.h:20
@ XCORE_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: xcore.h:21
@ XCORE_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: xcore.h:22
Instruction operand.
Definition: xcore.h:75
Instruction structure.
Definition: xcore.h:85

References cs_reg_name(), handle, i, NULL, printf(), XCORE_OP_IMM, XCORE_OP_MEM, XCORE_OP_REG, and XCORE_REG_INVALID.

Referenced by print_details().

◆ print_string_hex()

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

Definition at line 91 of file cstool.c.

92 {
93  unsigned char *c;
94 
95  printf("%s", comment);
96  for (c = str; c < str + len; c++) {
97  printf("0x%02x ", *c & 0xff);
98  }
99 
100  printf("\n");
101 }
size_t len
Definition: 6502dis.c:15

References c, len, printf(), and cmd_descs_generate::str.

Referenced by test_x86::print_insn_detail(), and print_insn_detail_x86().

◆ usage()

static void usage ( char *  prog)
static

Definition at line 147 of file cstool.c.

148 {
149  printf("Cstool for Capstone Disassembler Engine v%u.%u.%u\n\n", CS_VERSION_MAJOR, CS_VERSION_MINOR, CS_VERSION_EXTRA);
150  printf("Syntax: %s [-d|-s|-u|-v] <arch+mode> <assembly-hexstring> [start-address-in-hex-format]\n", prog);
151  printf("\nThe following <arch+mode> options are supported:\n");
152 
153  if (cs_support(CS_ARCH_X86)) {
154  printf(" x16: 16-bit mode (X86)\n");
155  printf(" x32: 32-bit mode (X86)\n");
156  printf(" x64: 64-bit mode (X86)\n");
157  printf(" x16att: 16-bit mode (X86) syntax-att\n");
158  printf(" x32att: 32-bit mode (X86) syntax-att\n");
159  printf(" x64att: 64-bit mode (X86) syntax-att\n");
160  }
161 
162  if (cs_support(CS_ARCH_ARM)) {
163  printf(" arm: arm\n");
164  printf(" armbe: arm + big endian\n");
165  printf(" thumb: thumb mode\n");
166  printf(" thumbbe: thumb + big endian\n");
167  printf(" cortexm: thumb + cortex-m extensions\n");
168  printf(" armv8: arm v8\n");
169  printf(" thumbv8: thumb v8\n");
170  }
171 
172  if (cs_support(CS_ARCH_ARM64)) {
173  printf(" arm64: aarch64 mode\n");
174  printf(" arm64be: aarch64 + big endian\n");
175  }
176 
177  if (cs_support(CS_ARCH_MIPS)) {
178  printf(" mips: mips32 + little endian\n");
179  printf(" mipsbe: mips32 + big endian\n");
180  printf(" mips64: mips64 + little endian\n");
181  printf(" mips64be: mips64 + big endian\n");
182  }
183 
184  if (cs_support(CS_ARCH_PPC)) {
185  printf(" ppc32: ppc32 + little endian\n");
186  printf(" ppc32be: ppc32 + big endian\n");
187  printf(" ppc32qpx: ppc32 + qpx + little endian\n");
188  printf(" ppc32beqpx: ppc32 + qpx + big endian\n");
189  printf(" ppc64: ppc64 + little endian\n");
190  printf(" ppc64be: ppc64 + big endian\n");
191  printf(" ppc64qpx: ppc64 + qpx + little endian\n");
192  printf(" ppc64beqpx: ppc64 + qpx + big endian\n");
193  }
194 
195  if (cs_support(CS_ARCH_SPARC)) {
196  printf(" sparc: sparc\n");
197  }
198 
199  if (cs_support(CS_ARCH_SYSZ)) {
200  printf(" systemz: systemz (s390x)\n");
201  }
202 
203  if (cs_support(CS_ARCH_XCORE)) {
204  printf(" xcore: xcore\n");
205  }
206 
207  if (cs_support(CS_ARCH_M68K)) {
208  printf(" m68k: m68k + big endian\n");
209  printf(" m68k40: m68k_040\n");
210  }
211 
213  printf(" tms320c64x: TMS320C64x\n");
214  }
215 
216  if (cs_support(CS_ARCH_M680X)) {
217  printf(" m6800: M6800/2\n");
218  printf(" m6801: M6801/3\n");
219  printf(" m6805: M6805\n");
220  printf(" m6808: M68HC08\n");
221  printf(" m6809: M6809\n");
222  printf(" m6811: M68HC11\n");
223  printf(" cpu12: M68HC12/HCS12\n");
224  printf(" hd6301: HD6301/3\n");
225  printf(" hd6309: HD6309\n");
226  printf(" hcs08: HCS08\n");
227  }
228 
229  if (cs_support(CS_ARCH_EVM)) {
230  printf(" evm: Ethereum Virtual Machine\n");
231  }
232 
233  printf("\nExtra options:\n");
234  printf(" -d show detailed information of the instructions\n");
235  printf(" -s decode in SKIPDATA mode\n");
236  printf(" -u show immediates as unsigned\n");
237  printf(" -v show version & Capstone core build info\n\n");
238 }
char * prog
Definition: untgz.c:125

References CS_ARCH_ARM, CS_ARCH_ARM64, CS_ARCH_EVM, CS_ARCH_M680X, CS_ARCH_M68K, CS_ARCH_MIPS, CS_ARCH_PPC, CS_ARCH_SPARC, CS_ARCH_SYSZ, CS_ARCH_TMS320C64X, CS_ARCH_X86, CS_ARCH_XCORE, cs_support(), CS_VERSION_EXTRA, CS_VERSION_MAJOR, CS_VERSION_MINOR, printf(), and prog.

Referenced by main().

Variable Documentation

◆ 

struct { ... } all_archs[]

Referenced by main().

◆ arch

cs_arch arch

Definition at line 13 of file cstool.c.

Referenced by _cs_disasm(), _resolve_arch(), arch_destroys_dst(), arch_hint_acc_cb(), bs_open(), core_bin_file_print(), cpu_reload_needed(), create(), cs_fuzz_arch(), cs_open(), does_arch_destroys_dst(), ds_print_fcn_name(), ds_print_ptr(), entries(), extract(), extract_binobj(), gdbr_get_reg_profile(), gdbr_set_architecture(), get_cpu_mips(), get_dwarf_reg_name(), get_entrypoint(), info(), is_apple_target(), LLVMFuzzerTestOneInput(), main(), TestBasic::main(), ocaml_cs_disasm(), ocaml_cs_disasm_internal(), ocaml_open(), oneshot_buffer(), opiscall(), parse_asm_path(), print_arch_hint_cb(), print_assembly_output(), print_details(), rz_analysis_hint_get(), rz_analysis_hint_set_arch(), rz_analysis_hint_set_arch_handler(), rz_analysis_set_triplet(), rz_asm_setup(), rz_bin_arch_options_init(), rz_bin_file_find_by_arch_bits(), rz_bin_object_find_by_arch_bits(), rz_bin_pe_get_arch(), rz_bin_pe_is_big_endian(), rz_bin_select(), rz_bin_select_object(), rz_bin_te_get_arch(), rz_bin_use_arch(), rz_coff_supported_arch(), rz_core_analysis_esil(), rz_core_analysis_hint_print(), rz_core_analysis_search(), rz_core_analysis_sigdb_apply(), rz_core_arch_bits_at(), rz_core_asm_plugins_print(), rz_core_bin_apply_all_info(), rz_core_bin_load(), rz_core_bin_set_arch_bits(), rz_core_bin_update_arch_bits(), rz_core_egg_setup(), rz_core_flirt_arch_from_id(), rz_core_flirt_arch_from_name(), rz_core_rtr_gdb_run(), rz_core_search_rop(), rz_core_seek_arch_bits(), rz_core_set_asm_configs(), rz_debug_gdb_attach(), rz_debug_gdb_reg_profile(), rz_debug_qnx_attach(), rz_debug_qnx_reg_profile(), rz_debug_set_arch(), rz_egg_Cfile_armOrMips(), rz_egg_Cfile_parser(), rz_egg_Cfile_set_cEnv(), rz_egg_load_file(), rz_egg_setup(), rz_flirt_scan_handler(), rz_main_rz_asm(), rz_main_rz_bin(), rz_main_rz_gg(), rz_open_arch_bits_handler(), rz_platform_profiles_init(), rz_platform_target_index_init(), rz_sys_arch_id(), rz_sys_arch_match(), rz_sys_arch_str(), rz_syscall_setup(), rz_sysreg_set_arch(), rz_test_load_asm_test_file(), rz_type_db_init(), sections(), set_tmp_arch(), setab(), symbols(), syscall_reload_needed(), sysregs_reload_needed(), test(), update_asmcpu_options(), and xtr_metadata_match().

◆ mode

Definition at line 14 of file cstool.c.

Referenced by main().

◆ name

const char* name

Definition at line 12 of file cstool.c.