Nguyen Anh Quynh | 6023ef7 | 2014-04-29 11:21:04 +0800 | [diff] [blame] | 1 | /* Capstone Disassembly Engine */ |
| 2 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */ |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 3 | |
Nguyen Anh Quynh | ae3649f | 2014-01-02 13:15:07 +0800 | [diff] [blame] | 4 | #ifndef CS_UTILS_H |
| 5 | #define CS_UTILS_H |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 6 | |
Nguyen Anh Quynh | cae09bf | 2014-06-17 14:58:39 +0800 | [diff] [blame] | 7 | #include <stddef.h> |
Nguyen Anh Quynh | 24bf0d9 | 2014-01-05 11:19:04 +0800 | [diff] [blame] | 8 | #include "include/capstone.h" |
Nguyen Anh Quynh | c740407 | 2014-01-05 11:35:47 +0800 | [diff] [blame] | 9 | #include "cs_priv.h" |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 10 | |
Nguyen Anh Quynh | 462f291 | 2013-12-11 17:35:27 +0800 | [diff] [blame] | 11 | // threshold number, so above this number will be printed in hexa mode |
| 12 | #define HEX_THRESHOLD 9 |
| 13 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 14 | // map instruction to its characteristics |
| 15 | typedef struct insn_map { |
Nguyen Anh Quynh | f4af98c | 2014-01-01 00:02:42 +0800 | [diff] [blame] | 16 | unsigned short id; |
| 17 | unsigned short mapid; |
Nguyen Anh Quynh | fc83a43 | 2014-02-22 23:26:27 +0800 | [diff] [blame] | 18 | #ifndef CAPSTONE_DIET |
Nguyen Anh Quynh | 18103e4 | 2013-12-20 17:35:15 +0800 | [diff] [blame] | 19 | unsigned char regs_use[12]; // list of implicit registers used by this instruction |
| 20 | unsigned char regs_mod[20]; // list of implicit registers modified by this instruction |
| 21 | unsigned char groups[8]; // list of group this instruction belong to |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 22 | bool branch; // branch instruction? |
| 23 | bool indirect_branch; // indirect branch instruction? |
Nguyen Anh Quynh | fc83a43 | 2014-02-22 23:26:27 +0800 | [diff] [blame] | 24 | #endif |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 25 | } insn_map; |
| 26 | |
Nguyen Anh Quynh | b265406 | 2014-01-03 17:08:58 +0800 | [diff] [blame] | 27 | // look for @id in @m, given its size in @max. first time call will update @cache. |
| 28 | // return 0 if not found |
| 29 | unsigned short insn_find(insn_map *m, unsigned int max, unsigned int id, unsigned short **cache); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 30 | |
| 31 | // map id to string |
| 32 | typedef struct name_map { |
| 33 | unsigned int id; |
| 34 | char *name; |
| 35 | } name_map; |
| 36 | |
| 37 | // map a name to its ID |
| 38 | // return 0 if not found |
pancake | f0e4eed | 2013-12-11 22:14:42 +0100 | [diff] [blame] | 39 | int name2id(name_map* map, int max, const char *name); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 40 | |
Nguyen Anh Quynh | f35e2ad | 2013-12-03 11:10:26 +0800 | [diff] [blame] | 41 | // count number of positive members in a list. |
| 42 | // NOTE: list must be guaranteed to end in 0 |
Nguyen Anh Quynh | 18103e4 | 2013-12-20 17:35:15 +0800 | [diff] [blame] | 43 | unsigned int count_positive(unsigned char *list); |
Nguyen Anh Quynh | f35e2ad | 2013-12-03 11:10:26 +0800 | [diff] [blame] | 44 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 45 | #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0])) |
| 46 | |
Nguyen Anh Quynh | a9ffb44 | 2014-01-15 18:27:01 +0800 | [diff] [blame] | 47 | char *cs_strdup(const char *str); |
| 48 | |
Nguyen Anh Quynh | a88c116 | 2014-04-27 13:38:04 +0800 | [diff] [blame] | 49 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) |
| 50 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 51 | #endif |
| 52 | |