blob: 9b36ed9ad8fad167ba5411c8c7d870f2b96adc0d [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 Quynh18103e42013-12-20 17:35:15 +080017 unsigned char regs_use[12]; // list of implicit registers used by this instruction
18 unsigned char regs_mod[20]; // list of implicit registers modified by this instruction
19 unsigned char groups[8]; // list of group this instruction belong to
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080020 bool branch; // branch instruction?
21 bool indirect_branch; // indirect branch instruction?
22} insn_map;
23
Nguyen Anh Quynhbed90912013-12-13 18:28:38 +080024// return the position of a string in a list of strings
25// or -1 if given string is not in the list
26int str_in_list(char **list, char *s);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080027
Nguyen Anh Quynhb2654062014-01-03 17:08:58 +080028// look for @id in @m, given its size in @max. first time call will update @cache.
29// return 0 if not found
30unsigned short insn_find(insn_map *m, unsigned int max, unsigned int id, unsigned short **cache);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080031
32// map id to string
33typedef struct name_map {
34 unsigned int id;
35 char *name;
36} name_map;
37
38// map a name to its ID
39// return 0 if not found
pancakef0e4eed2013-12-11 22:14:42 +010040int name2id(name_map* map, int max, const char *name);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080041
42// reverse mapid to id
43// return 0 if not found
44unsigned int insn_reverse_id(insn_map *insns, unsigned int max, unsigned int id);
45
Nguyen Anh Quynhf35e2ad2013-12-03 11:10:26 +080046// count number of positive members in a list.
47// NOTE: list must be guaranteed to end in 0
Nguyen Anh Quynh18103e42013-12-20 17:35:15 +080048unsigned int count_positive(unsigned char *list);
Nguyen Anh Quynhf35e2ad2013-12-03 11:10:26 +080049
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080050#define ARR_SIZE(a) (sizeof(a)/sizeof(a[0]))
51
Nguyen Anh Quynha9ffb442014-01-15 18:27:01 +080052char *cs_strdup(const char *str);
53
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080054#endif
55