Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
742 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
OBJ_M68K_CS=anal_m68k_cs.o | ||
|
||
include ${CURDIR}capstone.mk | ||
|
||
STATIC_OBJ+=$(OBJ_M68K_CS) | ||
|
||
TARGET_M68K_CS=anal_m68k_cs.${EXT_SO} | ||
|
||
ALL_TARGETS+=${TARGET_M68K_CS} | ||
|
||
${TARGET_M68K_CS}: ${OBJ_M68K_CS} | ||
${CC} ${CFLAGS} $(call libname,anal_m68k_cs) $(CS_CFLAGS) \ | ||
-o anal_m68k_cs.${EXT_SO} ${OBJ_M68K_CS} $(CS_LDFLAGS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* radare2 - LGPL - Copyright 2015 - pancake */ | ||
|
||
#include <r_asm.h> | ||
#include <r_lib.h> | ||
#include <capstone/capstone.h> | ||
|
||
#if CS_API_MAJOR>=4 && CS_NEXT_VERSION>=3 | ||
#define CAPSTONE_HAS_M68K 1 | ||
#else | ||
#define CAPSTONE_HAS_M68K 0 | ||
#warning Cannot find capstone-m68k support | ||
#endif | ||
|
||
#if CAPSTONE_HAS_M68K | ||
|
||
static bool check_features(RAsm *a, cs_insn *insn); | ||
static csh cd; | ||
|
||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { | ||
cs_insn* insn = NULL; | ||
cs_mode mode = 0; | ||
int ret, n = 0; | ||
mode |= (a->big_endian)? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN; | ||
|
||
// replace this with the asm.features? | ||
if (a->cpu && strstr (a->cpu, "mclass")) | ||
mode |= CS_MODE_MCLASS; | ||
if (a->cpu && strstr (a->cpu, "v8")) | ||
mode |= CS_MODE_V8; | ||
op->size = 4; | ||
op->buf_asm[0] = 0; | ||
ret = cs_open (CS_ARCH_M68K, mode, &cd); | ||
if (ret) { | ||
ret = -1; | ||
goto beach; | ||
} | ||
if (a->syntax == R_ASM_SYNTAX_REGNUM) { | ||
cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME); | ||
} else cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT); | ||
if (a->features && *a->features) { | ||
cs_option (cd, CS_OPT_DETAIL, CS_OPT_ON); | ||
} else { | ||
cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF); | ||
} | ||
n = cs_disasm (cd, buf, R_MIN (4, len), | ||
a->pc, 1, &insn); | ||
if (n<1) { | ||
ret = -1; | ||
goto beach; | ||
} | ||
op->size = 0; | ||
if (insn->size<1) { | ||
ret = -1; | ||
goto beach; | ||
} | ||
if (a->features && *a->features) { | ||
if (!check_features (a, insn)) { | ||
op->size = insn->size; | ||
strcpy (op->buf_asm, "illegal"); | ||
} | ||
} | ||
if (!op->size) { | ||
op->size = insn->size; | ||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s", | ||
insn->mnemonic, | ||
insn->op_str[0]?" ":"", | ||
insn->op_str); | ||
r_str_rmch (op->buf_asm, '#'); | ||
} | ||
cs_free (insn, n); | ||
beach: | ||
cs_close (&cd); | ||
if (!op->buf_asm[0]) | ||
strcpy (op->buf_asm, "invalid"); | ||
return op->size; | ||
} | ||
|
||
RAsmPlugin r_asm_plugin_m68k_cs = { | ||
.name = "m68k.cs", | ||
.desc = "Capstone M68K disassembler", | ||
.cpus = "68000,68010,68020,68030,68040,68060", | ||
.license = "BSD", | ||
.arch = "m68k", | ||
.bits = 32, | ||
.disassemble = &disassemble, | ||
.features = NULL | ||
}; | ||
|
||
static bool check_features(RAsm *a, cs_insn *insn) { | ||
/* TODO: Implement support for m68k */ | ||
return true; | ||
} | ||
|
||
#ifndef CORELIB | ||
struct r_lib_struct_t radare_plugin = { | ||
.type = R_LIB_TYPE_ASM, | ||
.data = &r_asm_plugin_m68k_cs, | ||
.version = R2_VERSION | ||
}; | ||
#endif | ||
|
||
#else | ||
RAsmPlugin r_asm_plugin_m68k_cs = { | ||
.name = "m68k.cs (unsupported)", | ||
.desc = "Capstone M68K disassembler (unsupported)", | ||
.license = "BSD", | ||
.arch = "m68k", | ||
.bits = 32, | ||
}; | ||
struct r_lib_struct_t radare_plugin = { | ||
.type = R_LIB_TYPE_ASM, | ||
.data = &r_asm_plugin_m68k_cs, | ||
.version = R2_VERSION | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# capstone-m68k | ||
|
||
OBJ_M68KCS=asm_m68k_cs.o | ||
|
||
include p/capstone.mk | ||
|
||
STATIC_OBJ+=${OBJ_M68KCS} | ||
SHARED_OBJ+=${SHARED_M68KCS} | ||
TARGET_M68KCS=asm_m68k_cs.${EXT_SO} | ||
|
||
ifeq ($(WITHPIC),1) | ||
ALL_TARGETS+=${TARGET_M68KCS} | ||
|
||
${TARGET_M68KCS}: ${OBJ_M68KCS} | ||
${CC} $(call libname,asm_m68k_cs) ${LDFLAGS} ${CFLAGS} ${CS_CFLAGS} \ | ||
-o ${TARGET_M68KCS} ${OBJ_M68KCS} ${CS_LDFLAGS} | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters