Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 1 | /* Capstone Disassembler Engine */ |
| 2 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */ |
| 3 | |
| 4 | #ifndef __CS_UTILS_H__ |
| 5 | #define __CS_UTILS_H__ |
| 6 | |
| 7 | #include <stdbool.h> |
| 8 | |
| 9 | typedef struct Pair { |
| 10 | char *str; |
| 11 | unsigned num; |
| 12 | } Pair; |
| 13 | |
| 14 | // map instruction to its characteristics |
| 15 | typedef struct insn_map { |
| 16 | unsigned int id; |
| 17 | unsigned int mapid; |
| 18 | unsigned int regs_use[32]; // list of implicit registers used by this instruction |
| 19 | unsigned int regs_mod[32]; // list of implicit registers modified by this instruction |
| 20 | unsigned int groups[8]; // list of group this instruction belong to |
| 21 | bool branch; // branch instruction? |
| 22 | bool indirect_branch; // indirect branch instruction? |
| 23 | } insn_map; |
| 24 | |
| 25 | bool str_in_list(char **list, char *s); |
| 26 | |
Nguyen Anh Quynh | ad61c49 | 2013-11-30 16:23:31 +0800 | [diff] [blame] | 27 | // binary searching in @m, given its size in @max, and @id |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 28 | int insn_find(insn_map *m, unsigned int max, unsigned int id); |
| 29 | |
| 30 | // map id to string |
| 31 | typedef struct name_map { |
| 32 | unsigned int id; |
| 33 | char *name; |
| 34 | } name_map; |
| 35 | |
| 36 | // map a name to its ID |
| 37 | // return 0 if not found |
| 38 | int name2id(name_map* map, int max, char *name); |
| 39 | |
| 40 | // reverse mapid to id |
| 41 | // return 0 if not found |
| 42 | unsigned int insn_reverse_id(insn_map *insns, unsigned int max, unsigned int id); |
| 43 | |
| 44 | #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0])) |
| 45 | |
| 46 | #endif |
| 47 | |