2014-04-29 03:21:04 +00:00
|
|
|
/* Capstone Disassembly Engine */
|
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2014-01-02 05:15:07 +00:00
|
|
|
#ifndef CS_PRIV_H
|
|
|
|
#define CS_PRIV_H
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
#include <capstone.h>
|
|
|
|
|
|
|
|
#include "MCInst.h"
|
|
|
|
#include "SStream.h"
|
|
|
|
|
|
|
|
typedef void (*Printer_t)(MCInst *MI, SStream *OS, void *info);
|
|
|
|
|
|
|
|
// function to be called after Printer_t
|
|
|
|
// this is the best time to gather insn's characteristics
|
2014-05-19 08:46:31 +00:00
|
|
|
typedef void (*PostPrinter_t)(csh handle, cs_insn *, char *mnem, MCInst *mci);
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2014-05-07 00:25:24 +00:00
|
|
|
typedef bool (*Disasm_t)(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info);
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2014-07-08 00:59:27 +00:00
|
|
|
typedef const char *(*GetName_t)(csh handle, unsigned int id);
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2014-01-06 02:56:59 +00:00
|
|
|
typedef void (*GetID_t)(cs_struct *h, cs_insn *insn, unsigned int id);
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2014-03-10 16:18:50 +00:00
|
|
|
// return register name, given register ID
|
|
|
|
typedef char *(*GetRegisterName_t)(unsigned RegNo);
|
|
|
|
|
2013-12-02 05:16:44 +00:00
|
|
|
// for ARM only
|
|
|
|
typedef struct ARM_ITStatus {
|
|
|
|
unsigned char ITStates[128]; // FIXME
|
|
|
|
unsigned int size;
|
|
|
|
} ARM_ITStatus;
|
|
|
|
|
2013-12-29 16:15:25 +00:00
|
|
|
struct cs_struct {
|
2013-11-27 04:11:31 +00:00
|
|
|
cs_arch arch;
|
|
|
|
cs_mode mode;
|
|
|
|
Printer_t printer; // asm printer
|
|
|
|
void *printer_info; // aux info for printer
|
|
|
|
Disasm_t disasm; // disassembler
|
|
|
|
void *getinsn_info; // auxiliary info for printer
|
|
|
|
bool big_endian;
|
|
|
|
GetName_t reg_name;
|
|
|
|
GetName_t insn_name;
|
2014-07-08 00:59:27 +00:00
|
|
|
GetName_t group_name;
|
2013-11-27 04:11:31 +00:00
|
|
|
GetID_t insn_id;
|
|
|
|
PostPrinter_t post_printer;
|
2013-11-27 07:24:47 +00:00
|
|
|
cs_err errnum;
|
2013-12-02 05:16:44 +00:00
|
|
|
ARM_ITStatus ITBlock; // for Arm only
|
2013-12-13 16:23:41 +00:00
|
|
|
cs_opt_value detail;
|
2014-03-10 16:18:50 +00:00
|
|
|
int syntax; // asm syntax for simple printer such as ARM, Mips & PPC
|
2013-12-31 14:40:04 +00:00
|
|
|
bool doing_mem; // handling memory operand in InstPrinter code
|
2014-01-06 02:56:59 +00:00
|
|
|
unsigned short *insn_cache; // index caching for mapping.c
|
2014-03-10 16:18:50 +00:00
|
|
|
GetRegisterName_t get_regname;
|
2014-04-09 15:49:30 +00:00
|
|
|
bool skipdata; // set this to True if we skip data when disassembling
|
|
|
|
uint8_t skipdata_size; // how many bytes to skip
|
|
|
|
cs_opt_skipdata skipdata_setup; // user-defined skipdata setup
|
2014-06-18 04:16:24 +00:00
|
|
|
uint8_t *regsize_map; // map to register size (x86-only for now)
|
2013-12-29 16:15:25 +00:00
|
|
|
};
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2013-12-22 03:13:07 +00:00
|
|
|
#define MAX_ARCH 8
|
2013-12-21 04:16:47 +00:00
|
|
|
|
2013-12-22 03:10:56 +00:00
|
|
|
// constructor initialization for all archs
|
2013-12-29 16:15:25 +00:00
|
|
|
extern cs_err (*arch_init[MAX_ARCH]) (cs_struct *);
|
2013-12-22 03:10:56 +00:00
|
|
|
|
|
|
|
// support cs_option() for all archs
|
|
|
|
extern cs_err (*arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
|
2013-12-21 04:16:47 +00:00
|
|
|
|
2014-01-03 09:08:58 +00:00
|
|
|
// deinitialized functions: to be called when cs_close() is called
|
|
|
|
extern void (*arch_destroy[MAX_ARCH]) (cs_struct*);
|
|
|
|
|
2013-12-22 02:40:58 +00:00
|
|
|
extern unsigned int all_arch;
|
2013-12-21 04:16:47 +00:00
|
|
|
|
2014-01-11 04:55:31 +00:00
|
|
|
extern cs_malloc_t cs_mem_malloc;
|
|
|
|
extern cs_calloc_t cs_mem_calloc;
|
|
|
|
extern cs_realloc_t cs_mem_realloc;
|
|
|
|
extern cs_free_t cs_mem_free;
|
2014-01-15 12:44:03 +00:00
|
|
|
extern cs_vsnprintf_t cs_vsnprintf;
|
2014-01-05 03:35:47 +00:00
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
#endif
|