mirror of
https://github.com/capstone-engine/capstone.git
synced 2024-11-30 17:00:26 +00:00
77 lines
1.6 KiB
C
77 lines
1.6 KiB
C
/* Capstone Disassembly Engine */
|
|
/* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
|
|
|
|
#ifdef CAPSTONE_HAS_X86
|
|
|
|
#include "../../cs_priv.h"
|
|
#include "../../MCRegisterInfo.h"
|
|
#include "X86Disassembler.h"
|
|
#include "X86InstPrinter.h"
|
|
#include "X86Mapping.h"
|
|
|
|
static cs_err init(cs_struct *ud)
|
|
{
|
|
// verify if requested mode is valid
|
|
if (ud->mode & ~(CS_MODE_LITTLE_ENDIAN | CS_MODE_32 | CS_MODE_64 | CS_MODE_16))
|
|
return CS_ERR_MODE;
|
|
|
|
// by default, we use Intel syntax
|
|
ud->printer = X86_Intel_printInst;
|
|
ud->syntax = CS_OPT_SYNTAX_INTEL;
|
|
ud->printer_info = NULL;
|
|
ud->disasm = X86_getInstruction;
|
|
ud->reg_name = X86_reg_name;
|
|
ud->insn_id = X86_get_insn_id;
|
|
ud->insn_name = X86_insn_name;
|
|
ud->post_printer = X86_post_printer;
|
|
|
|
return CS_ERR_OK;
|
|
}
|
|
|
|
static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)
|
|
{
|
|
if (type == CS_OPT_SYNTAX) {
|
|
switch(value) {
|
|
default:
|
|
// wrong syntax value
|
|
handle->errnum = CS_ERR_OPTION;
|
|
return CS_ERR_OPTION;
|
|
|
|
case CS_OPT_SYNTAX_DEFAULT:
|
|
case CS_OPT_SYNTAX_INTEL:
|
|
handle->printer = X86_Intel_printInst;
|
|
handle->syntax = CS_OPT_SYNTAX_INTEL;
|
|
break;
|
|
|
|
case CS_OPT_SYNTAX_ATT:
|
|
#ifndef CAPSTONE_DIET
|
|
handle->printer = X86_ATT_printInst;
|
|
handle->syntax = CS_OPT_SYNTAX_ATT;
|
|
break;
|
|
#else
|
|
// this is irrelevant in CAPSTONE_DIET mode
|
|
handle->errnum = CS_ERR_DIET;
|
|
return CS_ERR_DIET;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
return CS_ERR_OK;
|
|
}
|
|
|
|
static void destroy(cs_struct *handle)
|
|
{
|
|
}
|
|
|
|
void X86_enable(void)
|
|
{
|
|
arch_init[CS_ARCH_X86] = init;
|
|
arch_option[CS_ARCH_X86] = option;
|
|
arch_destroy[CS_ARCH_X86] = destroy;
|
|
|
|
// support this arch
|
|
all_arch |= (1 << CS_ARCH_X86);
|
|
}
|
|
|
|
#endif
|