• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Capstone Disassembly Engine */
2 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
3 
4 #ifndef CS_UTILS_H
5 #define CS_UTILS_H
6 
7 #if defined(CAPSTONE_HAS_OSXKERNEL)
8 #include <libkern/libkern.h>
9 #else
10 #include <stddef.h>
11 #endif
12 #include "include/capstone.h"
13 #include "cs_priv.h"
14 
15 // threshold number, so above this number will be printed in hexa mode
16 #define HEX_THRESHOLD 9
17 
18 // map instruction to its characteristics
19 typedef struct insn_map {
20 	unsigned short id;
21 	unsigned short mapid;
22 #ifndef CAPSTONE_DIET
23 	unsigned char regs_use[12]; // list of implicit registers used by this instruction
24 	unsigned char regs_mod[20]; // list of implicit registers modified by this instruction
25 	unsigned char groups[8]; // list of group this instruction belong to
26 	bool branch;	// branch instruction?
27 	bool indirect_branch;	// indirect branch instruction?
28 #endif
29 } insn_map;
30 
31 // look for @id in @m, given its size in @max. first time call will update @cache.
32 // return 0 if not found
33 unsigned short insn_find(insn_map *m, unsigned int max, unsigned int id, unsigned short **cache);
34 
35 // map id to string
36 typedef struct name_map {
37 	unsigned int id;
38 	char *name;
39 } name_map;
40 
41 // map a name to its ID
42 // return 0 if not found
43 int name2id(name_map* map, int max, const char *name);
44 
45 // count number of positive members in a list.
46 // NOTE: list must be guaranteed to end in 0
47 unsigned int count_positive(unsigned char *list);
48 
49 #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0]))
50 
51 char *cs_strdup(const char *str);
52 
53 #define MIN(x, y) ((x) < (y) ? (x) : (y))
54 
55 // we need this since Windows doesnt have snprintf()
56 int cs_snprintf(char *buffer, size_t size, const char *fmt, ...);
57 
58 #endif
59 
60