blob: cc41dc301361fd161e3a99621839361499d5f7bb [file] [log] [blame]
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08001/* Capstone Disassembler Engine */
2/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
3
Nguyen Anh Quynhae3649f2014-01-02 13:15:07 +08004#ifndef CS_UTILS_H
5#define CS_UTILS_H
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08006
Nguyen Anh Quynh24bf0d92014-01-05 11:19:04 +08007#include "include/capstone.h"
Nguyen Anh Quynhc7404072014-01-05 11:35:47 +08008#include "cs_priv.h"
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08009
Nguyen Anh Quynh462f2912013-12-11 17:35:27 +080010// threshold number, so above this number will be printed in hexa mode
11#define HEX_THRESHOLD 9
12
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080013// map instruction to its characteristics
14typedef struct insn_map {
Nguyen Anh Quynhf4af98c2014-01-01 00:02:42 +080015 unsigned short id;
16 unsigned short mapid;
Nguyen Anh Quynhfc83a432014-02-22 23:26:27 +080017#ifndef CAPSTONE_DIET
Nguyen Anh Quynh18103e42013-12-20 17:35:15 +080018 unsigned char regs_use[12]; // list of implicit registers used by this instruction
19 unsigned char regs_mod[20]; // list of implicit registers modified by this instruction
20 unsigned char groups[8]; // list of group this instruction belong to
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080021 bool branch; // branch instruction?
22 bool indirect_branch; // indirect branch instruction?
Nguyen Anh Quynhfc83a432014-02-22 23:26:27 +080023#endif
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080024} insn_map;
25
Nguyen Anh Quynhbed90912013-12-13 18:28:38 +080026// return the position of a string in a list of strings
27// or -1 if given string is not in the list
28int str_in_list(char **list, char *s);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080029
Nguyen Anh Quynhb2654062014-01-03 17:08:58 +080030// look for @id in @m, given its size in @max. first time call will update @cache.
31// return 0 if not found
32unsigned short insn_find(insn_map *m, unsigned int max, unsigned int id, unsigned short **cache);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080033
34// map id to string
35typedef struct name_map {
36 unsigned int id;
37 char *name;
38} name_map;
39
40// map a name to its ID
41// return 0 if not found
pancakef0e4eed2013-12-11 22:14:42 +010042int name2id(name_map* map, int max, const char *name);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080043
Nguyen Anh Quynhf35e2ad2013-12-03 11:10:26 +080044// count number of positive members in a list.
45// NOTE: list must be guaranteed to end in 0
Nguyen Anh Quynh18103e42013-12-20 17:35:15 +080046unsigned int count_positive(unsigned char *list);
Nguyen Anh Quynhf35e2ad2013-12-03 11:10:26 +080047
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080048#define ARR_SIZE(a) (sizeof(a)/sizeof(a[0]))
49
Nguyen Anh Quynha9ffb442014-01-15 18:27:01 +080050char *cs_strdup(const char *str);
51
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080052#endif
53