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 | |
Nguyen Anh Quynh | ae3649f | 2014-01-02 13:15:07 +0800 | [diff] [blame] | 4 | #ifndef CS_PRIV_H |
| 5 | #define CS_PRIV_H |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 6 | |
| 7 | #include <capstone.h> |
| 8 | |
| 9 | #include "MCInst.h" |
| 10 | #include "SStream.h" |
| 11 | |
| 12 | typedef void (*Printer_t)(MCInst *MI, SStream *OS, void *info); |
| 13 | |
| 14 | // function to be called after Printer_t |
| 15 | // this is the best time to gather insn's characteristics |
Nguyen Anh Quynh | 4d3e852 | 2013-12-14 10:45:09 +0800 | [diff] [blame] | 16 | typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 17 | |
pancake | f0e4eed | 2013-12-11 22:14:42 +0100 | [diff] [blame] | 18 | typedef bool (*Disasm_t)(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 19 | |
pancake | f0e4eed | 2013-12-11 22:14:42 +0100 | [diff] [blame] | 20 | typedef const char *(*GetName_t)(csh handle, unsigned int reg); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 21 | |
Nguyen Anh Quynh | 1acfd0b | 2014-01-06 10:56:59 +0800 | [diff] [blame] | 22 | typedef void (*GetID_t)(cs_struct *h, cs_insn *insn, unsigned int id); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 23 | |
Nguyen Anh Quynh | 7772d85 | 2014-01-21 11:49:25 +0800 | [diff] [blame] | 24 | typedef bool (*CheckCombineInsn_t)(cs_struct *h, cs_insn *insn); |
| 25 | |
| 26 | typedef void (*CombineInsn_t)(cs_struct *h, cs_insn *insn, cs_insn *prev); |
| 27 | |
Nguyen Anh Quynh | 7c7a8bc | 2013-12-02 13:16:44 +0800 | [diff] [blame] | 28 | // for ARM only |
| 29 | typedef struct ARM_ITStatus { |
| 30 | unsigned char ITStates[128]; // FIXME |
| 31 | unsigned int size; |
| 32 | } ARM_ITStatus; |
| 33 | |
Nguyen Anh Quynh | 42c6b1a | 2013-12-30 00:15:25 +0800 | [diff] [blame] | 34 | struct cs_struct { |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 35 | cs_arch arch; |
| 36 | cs_mode mode; |
| 37 | Printer_t printer; // asm printer |
| 38 | void *printer_info; // aux info for printer |
| 39 | Disasm_t disasm; // disassembler |
| 40 | void *getinsn_info; // auxiliary info for printer |
| 41 | bool big_endian; |
| 42 | GetName_t reg_name; |
| 43 | GetName_t insn_name; |
| 44 | GetID_t insn_id; |
| 45 | PostPrinter_t post_printer; |
Nguyen Anh Quynh | 3eb9ac9 | 2013-11-27 15:24:47 +0800 | [diff] [blame] | 46 | cs_err errnum; |
Nguyen Anh Quynh | 7c7a8bc | 2013-12-02 13:16:44 +0800 | [diff] [blame] | 47 | ARM_ITStatus ITBlock; // for Arm only |
Nguyen Anh Quynh | a209e67 | 2013-12-14 00:23:41 +0800 | [diff] [blame] | 48 | cs_opt_value detail; |
Nguyen Anh Quynh | 42c6b1a | 2013-12-30 00:15:25 +0800 | [diff] [blame] | 49 | int syntax; // asm syntax for simple printer such as PPC |
Nguyen Anh Quynh | 19b0de3 | 2013-12-31 22:40:04 +0800 | [diff] [blame] | 50 | bool doing_mem; // handling memory operand in InstPrinter code |
Nguyen Anh Quynh | 1acfd0b | 2014-01-06 10:56:59 +0800 | [diff] [blame] | 51 | unsigned short *insn_cache; // index caching for mapping.c |
Nguyen Anh Quynh | 7772d85 | 2014-01-21 11:49:25 +0800 | [diff] [blame] | 52 | CheckCombineInsn_t check_combine; |
| 53 | CombineInsn_t combine; |
| 54 | uint8_t prev_prefix; // save previous prefix for combining instructions - X86 only. |
Nguyen Anh Quynh | 42c6b1a | 2013-12-30 00:15:25 +0800 | [diff] [blame] | 55 | }; |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 56 | |
Nguyen Anh Quynh | 0755282 | 2013-12-22 11:13:07 +0800 | [diff] [blame] | 57 | #define MAX_ARCH 8 |
Nguyen Anh Quynh | f185180 | 2013-12-21 12:16:47 +0800 | [diff] [blame] | 58 | |
Nguyen Anh Quynh | d345839 | 2013-12-22 11:10:56 +0800 | [diff] [blame] | 59 | // constructor initialization for all archs |
Nguyen Anh Quynh | 42c6b1a | 2013-12-30 00:15:25 +0800 | [diff] [blame] | 60 | extern cs_err (*arch_init[MAX_ARCH]) (cs_struct *); |
Nguyen Anh Quynh | d345839 | 2013-12-22 11:10:56 +0800 | [diff] [blame] | 61 | |
| 62 | // support cs_option() for all archs |
| 63 | extern cs_err (*arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value); |
Nguyen Anh Quynh | f185180 | 2013-12-21 12:16:47 +0800 | [diff] [blame] | 64 | |
Nguyen Anh Quynh | b265406 | 2014-01-03 17:08:58 +0800 | [diff] [blame] | 65 | // deinitialized functions: to be called when cs_close() is called |
| 66 | extern void (*arch_destroy[MAX_ARCH]) (cs_struct*); |
| 67 | |
Nguyen Anh Quynh | 39a42ed | 2013-12-22 10:40:58 +0800 | [diff] [blame] | 68 | extern unsigned int all_arch; |
Nguyen Anh Quynh | f185180 | 2013-12-21 12:16:47 +0800 | [diff] [blame] | 69 | |
Nguyen Anh Quynh | a8eb7a5 | 2014-01-11 12:55:31 +0800 | [diff] [blame] | 70 | extern cs_malloc_t cs_mem_malloc; |
| 71 | extern cs_calloc_t cs_mem_calloc; |
| 72 | extern cs_realloc_t cs_mem_realloc; |
| 73 | extern cs_free_t cs_mem_free; |
Nguyen Anh Quynh | edeeb04 | 2014-01-15 20:44:03 +0800 | [diff] [blame] | 74 | extern cs_vsnprintf_t cs_vsnprintf; |
Nguyen Anh Quynh | c740407 | 2014-01-05 11:35:47 +0800 | [diff] [blame] | 75 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 76 | #endif |