2014-04-29 03:21:04 +00:00
|
|
|
/* Capstone Disassembly Engine */
|
2019-02-26 07:19:51 +00:00
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */
|
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
|
|
|
|
2019-05-20 03:22:27 +00:00
|
|
|
#ifdef CAPSTONE_DEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
2015-02-24 03:55:55 +00:00
|
|
|
#include <capstone/capstone.h>
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2015-03-25 07:02:13 +00:00
|
|
|
// return registers accessed by instruction
|
|
|
|
typedef void (*GetRegisterAccess_t)(const cs_insn *insn,
|
|
|
|
cs_regs regs_read, uint8_t *regs_read_count,
|
|
|
|
cs_regs regs_write, uint8_t *regs_write_count);
|
|
|
|
|
2013-12-02 05:16:44 +00:00
|
|
|
// for ARM only
|
2023-07-19 09:56:27 +00:00
|
|
|
typedef struct ARM_ITBlock {
|
2015-06-03 14:25:22 +00:00
|
|
|
unsigned char ITStates[8];
|
2013-12-02 05:16:44 +00:00
|
|
|
unsigned int size;
|
2023-07-19 09:56:27 +00:00
|
|
|
} ARM_ITBlock;
|
|
|
|
|
|
|
|
typedef struct ARM_VPTBlock {
|
|
|
|
unsigned char VPTStates[8];
|
|
|
|
unsigned int size;
|
|
|
|
} ARM_VPTBlock;
|
2013-12-02 05:16:44 +00:00
|
|
|
|
2015-04-26 14:54:41 +00:00
|
|
|
// Customize mnemonic for instructions with alternative name.
|
|
|
|
struct customized_mnem {
|
|
|
|
// ID of instruction to be customized.
|
|
|
|
unsigned int id;
|
|
|
|
// Customized instruction mnemonic.
|
2015-04-27 01:47:59 +00:00
|
|
|
char mnemonic[CS_MNEMONIC_SIZE];
|
2015-04-26 14:54:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct insn_mnem {
|
|
|
|
struct customized_mnem insn;
|
|
|
|
struct insn_mnem *next; // linked list of customized mnemonics
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
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;
|
2023-07-19 09:56:27 +00:00
|
|
|
ARM_ITBlock ITBlock; // for Arm only
|
|
|
|
ARM_VPTBlock VPTBlock; // for ARM only
|
|
|
|
bool PrintBranchImmNotAsAddress;
|
2016-03-14 05:52:23 +00:00
|
|
|
cs_opt_value detail, imm_unsigned;
|
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
|
2022-09-30 15:34:09 +00:00
|
|
|
bool doing_SME_Index; // handling a SME instruction that has index
|
2014-01-06 02:56:59 +00:00
|
|
|
unsigned short *insn_cache; // index caching for mapping.c
|
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
|
2017-10-22 00:45:40 +00:00
|
|
|
const uint8_t *regsize_map; // map to register size (x86-only for now)
|
2015-03-25 07:02:13 +00:00
|
|
|
GetRegisterAccess_t reg_access;
|
2015-04-26 14:54:41 +00:00
|
|
|
struct insn_mnem *mnem_list; // linked list of customized instruction mnemonic
|
2013-12-29 16:15:25 +00:00
|
|
|
};
|
2013-11-27 04:11:31 +00:00
|
|
|
|
M680X: Target ready for pull request (#1034)
* Added new M680X target. Supports M6800/1/2/3/9, HD6301
* M680X: Reformat for coding guide lines. Set alphabetical order in HACK.TXT
* M680X: Prepare for python binding. Move cs_m680x, m680x_insn to m680x_info. Chec
> k cpu type, no default.
* M680X: Add python bindings. Added python tests.
* M680X: Added cpu types to usage message.
* cstool: Avoid segfault for invalid <arch+mode>.
* Make test_m680x.c/test_m680x.py output comparable (diff params: -bu). Keep xprint.py untouched.
* M680X: Update CMake/make for m680x support. Update .gitignore.
* M680X: Reduce compiler warnings.
* M680X: Reduce compiler warnings.
* M680X: Reduce compiler warnings.
* M680X: Make test_m680x.c/test_m680x.py output comparable (diff params: -bu).
* M680X: Add ocaml bindings and tests.
* M680X: Add java bindings and tests.
* M680X: Added tests for all indexed addressing modes. C/Python/Ocaml
* M680X: Naming, use page1 for PAGE1 instructions (without prefix).
* M680X: Naming, use page1 for PAGE1 instructions (without prefix).
* M680X: Used M680X_FIRST_OP_IN_MNEM in tests C/python/java/ocaml.
* M680X: Added access property to cs_m680x_op.
* M680X: Added operand size.
* M680X: Remove compiler warnings.
* M680X: Added READ/WRITE access property per operator.
* M680X: Make reg_inherent_hdlr independent of CPU type.
* M680X: Add HD6309 support + bug fixes
* M680X: Remove errors and warning.
* M680X: Add Bcc/LBcc to group BRAREL (relative branch).
* M680X: Add group JUMP to BVS/BVC/LBVS/LBVC. Remove BRAREL from BRN/LBRN.
* M680X: Remove LBRN from group BRAREL.
* M680X: Refactored cpu_type initialization for better readability.
* M680X: Add two operands for insn having two reg. in mnemonic. e.g. ABX.
* M680X: Remove typo in cstool.c
* M680X: Some format improvements in changed_regs.
* M680X: Remove insn id string list from tests (C/python/java/ocaml).
* M680X: SEXW, set access of reg. D to WRITE.
* M680X: Sort changed_regs in increasing m680x_insn order.
* M680X: Add M68HC11 support + Reduced from two to one INDEXED operand.
* M680X: cstool, also write '(in mnemonic)' for second reg. operand.
* M680X: Add BRN/LBRN to group JUMP and BRAREL.
* M680X: For Bcc/LBcc/BRSET/BRCLR set reg. CC to read access.
* M680X: Correctly print negative immediate values with option CS_OPT_UNSIGNED.
* M680X: Rename some instruction handlers.
* M680X: Add M68HC05 support.
* M680X: Dont print prefix '<' for direct addr. mode.
* M680X: Add M68HC08 support + resorted tables + bug fixes.
* M680X: Add Freescale HCS08 support.
* M680X: Changed group names, avoid spaces.
* M680X: Refactoring, rename addessing mode handlers.
* M680X: indexed addr. mode, changed pre/post inc-/decrement representation.
* M680X: Rename some M6809/HD6309 specific functions.
* M680X: Add CPU12 (68HC12/HCS12) support.
* M680X: Correctly display illegal instruction as FCB .
* M680X: bugfix: BRA/BRN/BSR/LBRA/LBRN/LBSR does not read CC reg.
* M680X: bugfix: Correctly check for sufficient code size for M6809 indexed addressing.
* M680X: Better support for changing insn id within handler for addessing mode.
* M680X: Remove warnings.
* M680X: In set_changed_regs_read_write_counts use own access_mode.
* M680X: Split cpu specific tables into separate *.inc files.
* M680X: Remove warnings.
* M680X: Removed address_mode. Addressing mode is available in operand.type
* M680X: Bugfix: BSET/BCLR/BRSET/BRCLR correct read/modify CC reg.
* M680X: Remove register TMP1. It is first visible in CPU12X.
* M680X: Performance improvement + bug fixes.
* M680X: Performance improvement, make cpu_tables const static.
* M680X: Simplify operand decoding by using two handlers.
* M680X: Replace M680X_OP_INDEX by M680X_OP_CONSTANT + bugfix in java/python/ocaml bindings.
* M680X: Format with astyle.
* M680X: Update documentation.
* M680X: Corrected author for m680x specific files.
* M680X: Make max. number of architectures single source.
2017-10-21 13:44:36 +00:00
|
|
|
#define MAX_ARCH CS_ARCH_MAX
|
2013-12-21 04:16:47 +00:00
|
|
|
|
2017-10-20 15:33:24 +00:00
|
|
|
// Returns a bool (0 or 1) whether big endian is enabled for a mode
|
|
|
|
#define MODE_IS_BIG_ENDIAN(mode) (((mode) & CS_MODE_BIG_ENDIAN) != 0)
|
|
|
|
|
2023-07-01 23:57:10 +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;
|
|
|
|
extern cs_vsnprintf_t cs_vsnprintf;
|
2014-01-05 03:35:47 +00:00
|
|
|
|
2019-05-20 03:22:27 +00:00
|
|
|
// By defining CAPSTONE_DEBUG assertions can be used.
|
|
|
|
// For any release build CAPSTONE_DEBUG has to be undefined.
|
|
|
|
#ifdef CAPSTONE_DEBUG
|
|
|
|
#define CS_ASSERT(expr) assert(expr)
|
|
|
|
#else
|
|
|
|
#define CS_ASSERT(expr)
|
|
|
|
#endif
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
#endif
|