blob: bb7cb0d40ede15fa3c1ae2bb20111edef616ada4 [file] [log] [blame]
Nguyen Anh Quynh6023ef72014-04-29 11:21:04 +08001/* Capstone Disassembly Engine */
Nguyen Anh Quynhbfcaba52015-03-04 17:45:23 +08002/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08003
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
pancake9c10ace2015-02-24 04:55:55 +01007#include <capstone/capstone.h>
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08008
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 Quynh64564812014-05-19 16:46:31 +080016typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem, MCInst *mci);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080017
Nguyen Anh Quynha5ffdc32014-05-07 08:25:24 +080018typedef 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
Nguyen Anh Quynh650f96c2014-07-08 08:59:27 +080020typedef const char *(*GetName_t)(csh handle, unsigned int id);
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 Quynh2ff665a2014-03-11 00:18:50 +080024// return register name, given register ID
25typedef char *(*GetRegisterName_t)(unsigned RegNo);
26
Nguyen Anh Quynhefffe782015-03-25 15:02:13 +080027// return registers accessed by instruction
28typedef void (*GetRegisterAccess_t)(const cs_insn *insn,
29 cs_regs regs_read, uint8_t *regs_read_count,
30 cs_regs regs_write, uint8_t *regs_write_count);
31
Nguyen Anh Quynh7c7a8bc2013-12-02 13:16:44 +080032// for ARM only
33typedef struct ARM_ITStatus {
Nguyen Anh Quynhab6cc882015-06-03 22:25:22 +080034 unsigned char ITStates[8];
Nguyen Anh Quynh7c7a8bc2013-12-02 13:16:44 +080035 unsigned int size;
36} ARM_ITStatus;
37
Nguyen Anh Quynh0b965452015-04-26 22:54:41 +080038// Customize mnemonic for instructions with alternative name.
39struct customized_mnem {
40 // ID of instruction to be customized.
41 unsigned int id;
42 // Customized instruction mnemonic.
Nguyen Anh Quynhde654dd2015-04-27 09:47:59 +080043 char mnemonic[CS_MNEMONIC_SIZE];
Nguyen Anh Quynh0b965452015-04-26 22:54:41 +080044};
45
46struct insn_mnem {
47 struct customized_mnem insn;
48 struct insn_mnem *next; // linked list of customized mnemonics
49};
50
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080051struct cs_struct {
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080052 cs_arch arch;
53 cs_mode mode;
54 Printer_t printer; // asm printer
55 void *printer_info; // aux info for printer
56 Disasm_t disasm; // disassembler
57 void *getinsn_info; // auxiliary info for printer
58 bool big_endian;
59 GetName_t reg_name;
60 GetName_t insn_name;
Nguyen Anh Quynh650f96c2014-07-08 08:59:27 +080061 GetName_t group_name;
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080062 GetID_t insn_id;
63 PostPrinter_t post_printer;
Nguyen Anh Quynh3eb9ac92013-11-27 15:24:47 +080064 cs_err errnum;
Nguyen Anh Quynh7c7a8bc2013-12-02 13:16:44 +080065 ARM_ITStatus ITBlock; // for Arm only
Nguyen Anh Quynh256090a2016-03-14 13:52:23 +080066 cs_opt_value detail, imm_unsigned;
Nguyen Anh Quynh2ff665a2014-03-11 00:18:50 +080067 int syntax; // asm syntax for simple printer such as ARM, Mips & PPC
Nguyen Anh Quynh19b0de32013-12-31 22:40:04 +080068 bool doing_mem; // handling memory operand in InstPrinter code
Nguyen Anh Quynh1acfd0b2014-01-06 10:56:59 +080069 unsigned short *insn_cache; // index caching for mapping.c
Nguyen Anh Quynh2ff665a2014-03-11 00:18:50 +080070 GetRegisterName_t get_regname;
Nguyen Anh Quynhd3ffe372014-04-09 23:49:30 +080071 bool skipdata; // set this to True if we skip data when disassembling
72 uint8_t skipdata_size; // how many bytes to skip
73 cs_opt_skipdata skipdata_setup; // user-defined skipdata setup
Nguyen Anh Quynh10850732014-06-18 12:16:24 +080074 uint8_t *regsize_map; // map to register size (x86-only for now)
Nguyen Anh Quynhefffe782015-03-25 15:02:13 +080075 GetRegisterAccess_t reg_access;
Nguyen Anh Quynh0b965452015-04-26 22:54:41 +080076 struct insn_mnem *mnem_list; // linked list of customized instruction mnemonic
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080077};
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080078
Daniel Collin2ee675c2015-08-03 18:45:08 +020079#define MAX_ARCH 9
Nguyen Anh Quynhf1851802013-12-21 12:16:47 +080080
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080081// constructor initialization for all archs
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080082extern cs_err (*arch_init[MAX_ARCH]) (cs_struct *);
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080083
84// support cs_option() for all archs
85extern cs_err (*arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
Nguyen Anh Quynhf1851802013-12-21 12:16:47 +080086
Nguyen Anh Quynh39a42ed2013-12-22 10:40:58 +080087extern unsigned int all_arch;
Nguyen Anh Quynhf1851802013-12-21 12:16:47 +080088
Nguyen Anh Quynha8eb7a52014-01-11 12:55:31 +080089extern cs_malloc_t cs_mem_malloc;
90extern cs_calloc_t cs_mem_calloc;
91extern cs_realloc_t cs_mem_realloc;
92extern cs_free_t cs_mem_free;
Nguyen Anh Quynhedeeb042014-01-15 20:44:03 +080093extern cs_vsnprintf_t cs_vsnprintf;
Nguyen Anh Quynhc7404072014-01-05 11:35:47 +080094
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080095#endif