| 1 | /* Capstone Disassembly Engine */ |
| 2 | /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */ |
| 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 | #include "include/capstone/capstone.h" |
| 12 | #endif |
| 13 | #include "cs_priv.h" |
| 14 | #include "Mapping.h" |
| 15 | |
| 16 | // threshold number, so above this number will be printed in hexa mode |
| 17 | #define HEX_THRESHOLD 9 |
| 18 | |
| 19 | // count number of positive members in a list. |
| 20 | // NOTE: list must be guaranteed to end in 0 |
| 21 | unsigned int count_positive(const uint16_t *list); |
| 22 | unsigned int count_positive8(const unsigned char *list); |
| 23 | |
| 24 | #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0])) |
| 25 | #define MATRIX_SIZE(a) (sizeof(a[0])/sizeof(a[0][0])) |
| 26 | |
| 27 | char *cs_strdup(const char *str); |
| 28 | |
| 29 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) |
| 30 | |
| 31 | // we need this since Windows doesn't have snprintf() |
| 32 | int cs_snprintf(char *buffer, size_t size, const char *fmt, ...); |
| 33 | |
| 34 | #define CS_AC_IGNORE (1 << 7) |
| 35 | |
| 36 | // check if an id is existent in an array |
| 37 | bool arr_exist8(unsigned char *arr, unsigned char max, unsigned int id); |
| 38 | |
| 39 | bool arr_exist(uint16_t *arr, unsigned char max, unsigned int id); |
| 40 | |
| 41 | struct IndexType { |
| 42 | uint16_t encoding; |
| 43 | unsigned index; |
| 44 | }; |
| 45 | |
| 46 | // binary search for encoding in IndexType array |
| 47 | // return -1 if not found, or index if found |
| 48 | unsigned int binsearch_IndexTypeEncoding(const struct IndexType *index, size_t size, uint16_t encoding); |
| 49 | |
| 50 | uint16_t readBytes16(MCInst *MI, const uint8_t *Bytes); |
| 51 | uint32_t readBytes32(MCInst *MI, const uint8_t *Bytes); |
| 52 | |
| 53 | #endif |
| 54 |