blob: ee1b981646c51be8821248eb2f241cd332d0fb41 [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_PRIV_H
5#define CS_PRIV_H
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08006
7#include <capstone.h>
8
9#include "MCInst.h"
10#include "SStream.h"
11
12typedef 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 Quynh4d3e8522013-12-14 10:45:09 +080016typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080017
pancakef0e4eed2013-12-11 22:14:42 +010018typedef 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 Quynh26ee41a2013-11-27 12:11:31 +080019
pancakef0e4eed2013-12-11 22:14:42 +010020typedef const char *(*GetName_t)(csh handle, unsigned int reg);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080021
Nguyen Anh Quynh1acfd0b2014-01-06 10:56:59 +080022typedef void (*GetID_t)(cs_struct *h, cs_insn *insn, unsigned int id);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080023
Nguyen Anh Quynh7772d852014-01-21 11:49:25 +080024typedef bool (*CheckCombineInsn_t)(cs_struct *h, cs_insn *insn);
25
26typedef void (*CombineInsn_t)(cs_struct *h, cs_insn *insn, cs_insn *prev);
27
Nguyen Anh Quynh7c7a8bc2013-12-02 13:16:44 +080028// for ARM only
29typedef struct ARM_ITStatus {
30 unsigned char ITStates[128]; // FIXME
31 unsigned int size;
32} ARM_ITStatus;
33
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080034struct cs_struct {
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080035 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 Quynh3eb9ac92013-11-27 15:24:47 +080046 cs_err errnum;
Nguyen Anh Quynh7c7a8bc2013-12-02 13:16:44 +080047 ARM_ITStatus ITBlock; // for Arm only
Nguyen Anh Quynha209e672013-12-14 00:23:41 +080048 cs_opt_value detail;
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080049 int syntax; // asm syntax for simple printer such as PPC
Nguyen Anh Quynh19b0de32013-12-31 22:40:04 +080050 bool doing_mem; // handling memory operand in InstPrinter code
Nguyen Anh Quynh1acfd0b2014-01-06 10:56:59 +080051 unsigned short *insn_cache; // index caching for mapping.c
Nguyen Anh Quynh7772d852014-01-21 11:49:25 +080052 CheckCombineInsn_t check_combine;
53 CombineInsn_t combine;
54 uint8_t prev_prefix; // save previous prefix for combining instructions - X86 only.
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080055};
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080056
Nguyen Anh Quynh07552822013-12-22 11:13:07 +080057#define MAX_ARCH 8
Nguyen Anh Quynhf1851802013-12-21 12:16:47 +080058
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080059// constructor initialization for all archs
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080060extern cs_err (*arch_init[MAX_ARCH]) (cs_struct *);
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080061
62// support cs_option() for all archs
63extern cs_err (*arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
Nguyen Anh Quynhf1851802013-12-21 12:16:47 +080064
Nguyen Anh Quynhb2654062014-01-03 17:08:58 +080065// deinitialized functions: to be called when cs_close() is called
66extern void (*arch_destroy[MAX_ARCH]) (cs_struct*);
67
Nguyen Anh Quynh39a42ed2013-12-22 10:40:58 +080068extern unsigned int all_arch;
Nguyen Anh Quynhf1851802013-12-21 12:16:47 +080069
Nguyen Anh Quynha8eb7a52014-01-11 12:55:31 +080070extern cs_malloc_t cs_mem_malloc;
71extern cs_calloc_t cs_mem_calloc;
72extern cs_realloc_t cs_mem_realloc;
73extern cs_free_t cs_mem_free;
Nguyen Anh Quynhedeeb042014-01-15 20:44:03 +080074extern cs_vsnprintf_t cs_vsnprintf;
Nguyen Anh Quynhc7404072014-01-05 11:35:47 +080075
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080076#endif