Rizin
unix-like reverse engineering framework and cli tools
X86Module.c
Go to the documentation of this file.
1 /* Capstone Disassembly Engine */
2 /* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
3 
4 #ifdef CAPSTONE_HAS_X86
5 
6 #include "../../cs_priv.h"
7 #include "../../MCRegisterInfo.h"
8 #include "X86Disassembler.h"
9 #include "X86InstPrinter.h"
10 #include "X86Mapping.h"
11 #include "X86Module.h"
12 
13 cs_err X86_global_init(cs_struct *ud)
14 {
15  MCRegisterInfo *mri;
16  mri = cs_mem_malloc(sizeof(*mri));
17 
18  X86_init(mri);
19 
20  // by default, we use Intel syntax
23  ud->printer_info = mri;
25  ud->reg_name = X86_reg_name;
29  ud->post_printer = NULL;;
30 #ifndef CAPSTONE_DIET
32 #endif
33 
34  if (ud->mode == CS_MODE_64)
36  else
38 
39  return CS_ERR_OK;
40 }
41 
43 {
44  switch(type) {
45  default:
46  break;
47  case CS_OPT_MODE:
48  if (value == CS_MODE_64)
49  handle->regsize_map = regsize_map_64;
50  else
51  handle->regsize_map = regsize_map_32;
52 
53  handle->mode = (cs_mode)value;
54  break;
55  case CS_OPT_SYNTAX:
56  switch(value) {
57  default:
58  // wrong syntax value
59  handle->errnum = CS_ERR_OPTION;
60  return CS_ERR_OPTION;
61 
64  handle->syntax = CS_OPT_SYNTAX_INTEL;
65  handle->printer = X86_Intel_printInst;
66  break;
67 
68  case CS_OPT_SYNTAX_MASM:
69  handle->printer = X86_Intel_printInst;
70  handle->syntax = (int)value;
71  break;
72 
73  case CS_OPT_SYNTAX_ATT:
74 #if !defined(CAPSTONE_DIET) && !defined(CAPSTONE_X86_ATT_DISABLE)
75  handle->printer = X86_ATT_printInst;
76  handle->syntax = CS_OPT_SYNTAX_ATT;
77  break;
78 #elif !defined(CAPSTONE_DIET) && defined(CAPSTONE_X86_ATT_DISABLE)
79  // ATT syntax is unsupported
80  handle->errnum = CS_ERR_X86_ATT;
81  return CS_ERR_X86_ATT;
82 #else // CAPSTONE_DIET
83  // this is irrelevant in CAPSTONE_DIET mode
84  handle->errnum = CS_ERR_DIET;
85  return CS_ERR_DIET;
86 #endif
87  }
88  break;
89  }
90 
91  return CS_ERR_OK;
92 }
93 
94 #endif
void X86_init(MCRegisterInfo *MRI)
bool X86_getInstruction(csh handle, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info)
void X86_ATT_printInst(MCInst *MI, SStream *OS, void *Info)
void X86_Intel_printInst(MCInst *MI, SStream *OS, void *Info)
const char * X86_reg_name(csh handle, unsigned int reg)
const char * X86_insn_name(csh handle, unsigned int id)
void X86_reg_access(const cs_insn *insn, cs_regs regs_read, uint8_t *regs_read_count, cs_regs regs_write, uint8_t *regs_write_count)
void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
const uint8_t regsize_map_32[]
const uint8_t regsize_map_64[]
const char * X86_group_name(csh handle, unsigned int id)
cs_err X86_option(cs_struct *handle, cs_opt_type type, size_t value)
cs_err X86_global_init(cs_struct *ud)
static mcore_handle handle
Definition: asm_mcore.c:8
cs_mode
Mode type.
Definition: capstone.h:102
@ CS_MODE_64
64-bit mode (X86, PPC)
Definition: capstone.h:107
cs_opt_type
Runtime option for the disassembled engine.
Definition: capstone.h:168
@ CS_OPT_MODE
Change engine's mode at run-time.
Definition: capstone.h:172
@ CS_OPT_SYNTAX
Assembly output syntax.
Definition: capstone.h:170
@ CS_OPT_SYNTAX_INTEL
X86 Intel asm syntax - default on X86 (CS_OPT_SYNTAX).
Definition: capstone.h:185
@ CS_OPT_SYNTAX_ATT
X86 ATT asm syntax (CS_OPT_SYNTAX).
Definition: capstone.h:186
@ CS_OPT_SYNTAX_MASM
X86 Intel Masm syntax (CS_OPT_SYNTAX).
Definition: capstone.h:188
@ CS_OPT_SYNTAX_DEFAULT
Default asm syntax (CS_OPT_SYNTAX).
Definition: capstone.h:184
static int value
Definition: cmd_api.c:93
#define NULL
Definition: cris-opc.c:27
cs_malloc_t cs_mem_malloc
Definition: cs.c:348
int type
Definition: mipsasm.c:17
int CS_ERR_DIET
Definition: __init__.py:245
int CS_ERR_X86_ATT
Definition: __init__.py:247
int CS_ERR_OPTION
Definition: __init__.py:241
int CS_ERR_OK
Definition: __init__.py:235
static int
Definition: sfsocketcall.h:114
GetName_t insn_name
Definition: cs_priv.h:62
GetName_t reg_name
Definition: cs_priv.h:61
void * printer_info
Definition: cs_priv.h:58
int syntax
Definition: cs_priv.h:69
Printer_t printer
Definition: cs_priv.h:57
GetID_t insn_id
Definition: cs_priv.h:64
GetName_t group_name
Definition: cs_priv.h:63
GetRegisterAccess_t reg_access
Definition: cs_priv.h:77
Disasm_t disasm
Definition: cs_priv.h:59
cs_mode mode
Definition: cs_priv.h:56
PostPrinter_t post_printer
Definition: cs_priv.h:65
const uint8_t * regsize_map
Definition: cs_priv.h:76