mirror of
https://github.com/capstone-engine/capstone.git
synced 2025-02-12 18:08:42 +00:00
cleaner implementation for arch modularization
This commit is contained in:
parent
abc02059e3
commit
f185180436
8
Makefile
8
Makefile
@ -24,28 +24,28 @@ LIBNAME = capstone
|
||||
LIBOBJ =
|
||||
LIBOBJ += cs.o utils.o SStream.o MCInstrDesc.o MCRegisterInfo.o
|
||||
ifneq (,$(filter $(CAPSTONE_ARCH), arm all))
|
||||
LIBOBJ += arch/ARM/ARMDisassembler.o arch/ARM/ARMInstPrinter.o arch/ARM/mapping.o
|
||||
LIBOBJ += arch/ARM/ARMDisassembler.o arch/ARM/ARMInstPrinter.o arch/ARM/mapping.o arch/ARM/module.o
|
||||
CFLAGS += -DCS_SUPPORT_ARM
|
||||
ifeq ($(CAPSTONE_ARCH), arm)
|
||||
LIBNAME = capstone-arm
|
||||
endif
|
||||
endif
|
||||
ifneq (, $(filter $(CAPSTONE_ARCH), x86 all))
|
||||
LIBOBJ += arch/X86/X86DisassemblerDecoder.o arch/X86/X86Disassembler.o arch/X86/X86IntelInstPrinter.o arch/X86/X86ATTInstPrinter.o arch/X86/mapping.o
|
||||
LIBOBJ += arch/X86/X86DisassemblerDecoder.o arch/X86/X86Disassembler.o arch/X86/X86IntelInstPrinter.o arch/X86/X86ATTInstPrinter.o arch/X86/mapping.o arch/X86/module.o
|
||||
CFLAGS += -DCS_SUPPORT_X86
|
||||
ifeq ($(CAPSTONE_ARCH), x86)
|
||||
LIBNAME = capstone-x86
|
||||
endif
|
||||
endif
|
||||
ifneq (, $(filter $(CAPSTONE_ARCH), mips all))
|
||||
LIBOBJ += arch/Mips/MipsDisassembler.o arch/Mips/MipsInstPrinter.o arch/Mips/mapping.o
|
||||
LIBOBJ += arch/Mips/MipsDisassembler.o arch/Mips/MipsInstPrinter.o arch/Mips/mapping.o arch/Mips/module.o
|
||||
CFLAGS += -DCS_SUPPORT_MIPS
|
||||
ifeq ($(CAPSTONE_ARCH), mips)
|
||||
LIBNAME = capstone-mips
|
||||
endif
|
||||
endif
|
||||
ifneq (, $(filter $(CAPSTONE_ARCH), arm64 all))
|
||||
LIBOBJ += arch/AArch64/AArch64BaseInfo.o arch/AArch64/AArch64Disassembler.o arch/AArch64/AArch64InstPrinter.o arch/AArch64/mapping.o
|
||||
LIBOBJ += arch/AArch64/AArch64BaseInfo.o arch/AArch64/AArch64Disassembler.o arch/AArch64/AArch64InstPrinter.o arch/AArch64/mapping.o arch/AArch64/module.o
|
||||
CFLAGS += -DCS_SUPPORT_AARCH64
|
||||
ifeq ($(CAPSTONE_ARCH), arm64)
|
||||
LIBNAME = capstone-arm64
|
||||
|
@ -1,31 +0,0 @@
|
||||
/* Capstone Disassembler Engine */
|
||||
/* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
|
||||
|
||||
#ifndef __ARM64_INCLUDE_H__
|
||||
#define __ARM64_INCLUDE_H__
|
||||
|
||||
#include "AArch64Disassembler.h"
|
||||
#include "AArch64InstPrinter.h"
|
||||
#include "mapping.h"
|
||||
|
||||
static void init_arm64(cs_struct *ud)
|
||||
{
|
||||
MCRegisterInfo *mri = malloc(sizeof(*mri));
|
||||
|
||||
AArch64_init(mri);
|
||||
ud->printer = AArch64_printInst;
|
||||
ud->printer_info = mri;
|
||||
ud->getinsn_info = mri;
|
||||
ud->disasm = AArch64_getInstruction;
|
||||
ud->reg_name = AArch64_reg_name;
|
||||
ud->insn_id = AArch64_get_insn_id;
|
||||
ud->insn_name = AArch64_insn_name;
|
||||
ud->post_printer = AArch64_post_printer;
|
||||
}
|
||||
|
||||
static void __attribute__ ((constructor)) __init_arm64__()
|
||||
{
|
||||
init_arch[CS_ARCH_ARM64] = init_arm64;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,49 +0,0 @@
|
||||
/* Capstone Disassembler Engine */
|
||||
/* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
|
||||
|
||||
#ifndef __ARM_INCLUDE_H__
|
||||
#define __ARM_INCLUDE_H__
|
||||
|
||||
#include "ARMDisassembler.h"
|
||||
#include "ARMInstPrinter.h"
|
||||
#include "mapping.h"
|
||||
|
||||
static void init_arm(cs_struct *ud)
|
||||
{
|
||||
MCRegisterInfo *mri = malloc(sizeof(*mri));
|
||||
|
||||
ARM_init(mri);
|
||||
|
||||
ud->printer = ARM_printInst;
|
||||
ud->printer_info = mri;
|
||||
ud->reg_name = ARM_reg_name;
|
||||
ud->insn_id = ARM_get_insn_id;
|
||||
ud->insn_name = ARM_insn_name;
|
||||
ud->post_printer = ARM_post_printer;
|
||||
|
||||
if (ud->mode & CS_MODE_THUMB)
|
||||
ud->disasm = Thumb_getInstruction;
|
||||
else
|
||||
ud->disasm = ARM_getInstruction;
|
||||
}
|
||||
|
||||
static cs_err option_arm(cs_struct *handle, cs_opt_type type, size_t value)
|
||||
{
|
||||
if (type == CS_OPT_MODE) {
|
||||
if (value & CS_MODE_THUMB)
|
||||
handle->disasm = Thumb_getInstruction;
|
||||
else
|
||||
handle->disasm = ARM_getInstruction;
|
||||
|
||||
handle->mode = value;
|
||||
}
|
||||
return CS_ERR_OK;
|
||||
}
|
||||
|
||||
static void __attribute__ ((constructor)) __init_arm__()
|
||||
{
|
||||
init_arch[CS_ARCH_ARM] = init_arm;
|
||||
option_arch[CS_ARCH_ARM] = option_arm;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,48 +0,0 @@
|
||||
/* Capstone Disassembler Engine */
|
||||
/* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
|
||||
|
||||
#ifndef __MIPS_INCLUDE_H__
|
||||
#define __MIPS_INCLUDE_H__
|
||||
|
||||
#include "MipsDisassembler.h"
|
||||
#include "MipsInstPrinter.h"
|
||||
#include "mapping.h"
|
||||
|
||||
static void init_mips(cs_struct *ud)
|
||||
{
|
||||
MCRegisterInfo *mri = malloc(sizeof(*mri));
|
||||
|
||||
Mips_init(mri);
|
||||
ud->printer = Mips_printInst;
|
||||
ud->printer_info = mri;
|
||||
ud->getinsn_info = mri;
|
||||
ud->reg_name = Mips_reg_name;
|
||||
ud->insn_id = Mips_get_insn_id;
|
||||
ud->insn_name = Mips_insn_name;
|
||||
|
||||
if (ud->mode & CS_MODE_32)
|
||||
ud->disasm = Mips_getInstruction;
|
||||
else
|
||||
ud->disasm = Mips64_getInstruction;
|
||||
}
|
||||
|
||||
static cs_err option_mips(cs_struct *handle, cs_opt_type type, size_t value)
|
||||
{
|
||||
if (type == CS_OPT_MODE) {
|
||||
if (value & CS_MODE_32)
|
||||
handle->disasm = Mips_getInstruction;
|
||||
else
|
||||
handle->disasm = Mips64_getInstruction;
|
||||
|
||||
handle->mode = value;
|
||||
}
|
||||
return CS_ERR_OK;
|
||||
}
|
||||
|
||||
static void __attribute__ ((constructor)) __init_mips__()
|
||||
{
|
||||
init_arch[CS_ARCH_MIPS] = init_mips;
|
||||
option_arch[CS_ARCH_MIPS] = option_mips;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,50 +0,0 @@
|
||||
/* Capstone Disassembler Engine */
|
||||
/* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
|
||||
|
||||
#ifndef __X86_INCLUDE_H__
|
||||
#define __X86_INCLUDE_H__
|
||||
|
||||
#include "X86Disassembler.h"
|
||||
#include "X86InstPrinter.h"
|
||||
#include "mapping.h"
|
||||
|
||||
static void init_x86(cs_struct *ud)
|
||||
{
|
||||
// by default, we use Intel syntax
|
||||
ud->printer = X86_Intel_printInst;
|
||||
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;
|
||||
}
|
||||
|
||||
static cs_err option_x86(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_INTEL:
|
||||
handle->printer = X86_Intel_printInst;
|
||||
break;
|
||||
|
||||
case CS_OPT_SYNTAX_ATT:
|
||||
handle->printer = X86_ATT_printInst;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return CS_ERR_OK;
|
||||
}
|
||||
|
||||
static void __attribute__ ((constructor)) __init_x86__()
|
||||
{
|
||||
init_arch[CS_ARCH_X86] = init_x86;
|
||||
option_arch[CS_ARCH_X86] = option_x86;
|
||||
}
|
||||
|
||||
#endif
|
5
cs.c
5
cs.c
@ -10,9 +10,12 @@
|
||||
|
||||
#include "MCRegisterInfo.h"
|
||||
|
||||
#include "module.h"
|
||||
#include "utils.h"
|
||||
|
||||
void (*init_arch[MAX_ARCH]) (cs_struct *);
|
||||
cs_err (*option_arch[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
|
||||
|
||||
|
||||
void cs_version(int *major, int *minor)
|
||||
{
|
||||
*major = CS_API_MAJOR;
|
||||
|
@ -44,4 +44,10 @@ typedef struct cs_struct {
|
||||
cs_opt_value detail;
|
||||
} cs_struct;
|
||||
|
||||
#define MAX_ARCH 32
|
||||
|
||||
extern void (*init_arch[MAX_ARCH]) (cs_struct *);
|
||||
extern cs_err (*option_arch[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,7 @@ extern "C" {
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Capstone API version
|
||||
#define CS_API_MAJOR 1
|
||||
|
25
module.h
25
module.h
@ -1,25 +0,0 @@
|
||||
/* Capstone Disassembler Engine */
|
||||
/* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
|
||||
|
||||
#ifndef __CS_MODULE_H__
|
||||
#define __CS_MODULE_H__
|
||||
|
||||
#define MAX_ARCH 32
|
||||
|
||||
void (*init_arch[MAX_ARCH]) (cs_struct *);
|
||||
cs_err (*option_arch[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
|
||||
|
||||
#ifdef CS_SUPPORT_X86
|
||||
#include "arch/X86/module.h"
|
||||
#endif
|
||||
#ifdef CS_SUPPORT_ARM
|
||||
#include "arch/ARM/module.h"
|
||||
#endif
|
||||
#ifdef CS_SUPPORT_AARCH64
|
||||
#include "arch/AArch64/module.h"
|
||||
#endif
|
||||
#ifdef CS_SUPPORT_MIPS
|
||||
#include "arch/Mips/module.h"
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user