Skip to content

Commit

Permalink
Upgrade capstone-next to get tms320c64x support and more fixes for SFC
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Apr 17, 2017
1 parent acc2f19 commit 54f6efd
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libr/asm/p/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ARCHS+=ppc_gnu.mk ppc_cs.mk x86_udis.mk xap.mk x86_nasm.mk avr.mk
ARCHS+=sh.mk arm_winedbg.mk tms320.mk gb.mk snes.mk ebc.mk malbolge.mk ws.mk
ARCHS+=6502.mk h8300.mk cr16.mk v850.mk spc700.mk propeller.mk msp430.mk i4004.mk
ARCHS+=lh5801.mk v810.mk mcs96.mk lm32.mk
ARCHS+=riscv.mk rsp.mk
ARCHS+=riscv.mk rsp.mk tms320c64x.mk
include $(ARCHS)

all: ${ALL_TARGETS}
Expand Down
5 changes: 3 additions & 2 deletions libr/asm/p/asm_snes.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ static bool snes_asm_fini (void* user) {
free(snesflags);
snesflags = NULL;
return 0;
}

static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
static int dis(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int dlen = snesDisass (snesflags->M, snesflags->X, a->pc, op, buf, len);
if (dlen<0) dlen=0;
op->size = dlen;
Expand All @@ -43,7 +44,7 @@ RAsmPlugin r_asm_plugin_snes = {
.fini = snes_asm_fini,
.endian = R_SYS_ENDIAN_LITTLE,
.license = "LGPL3",
.disassemble = &disassemble
.disassemble = &dis
};

#ifndef CORELIB
Expand Down
72 changes: 72 additions & 0 deletions libr/asm/p/asm_tms320c64x.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* radare2 - LGPL - Copyright 2017 - pancake */

#include <r_asm.h>
#include <r_lib.h>
#include <capstone/capstone.h>
static csh cd = 0;
#include "cs_mnemonics.c"

static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
cs_insn* insn;
int n = -1, ret = -1;
int mode = CS_MODE_BIG_ENDIAN;
if (op) {
memset (op, 0, sizeof (RAsmOp));
op->size = 4;
}
if (cd != 0) {
cs_close (&cd);
}
ret = cs_open (CS_ARCH_TMS320C64X, mode, &cd);
if (ret) {
goto fin;
}
cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
if (!op) {
return 0;
}
if (a->big_endian) {
n = cs_disasm (cd, buf, len, a->pc, 1, &insn);
}
if (n < 1) {
strcpy (op->buf_asm, "invalid");
op->size = 4;
ret = -1;
goto beach;
} else {
ret = 4;
}
if (insn->size < 1) {
goto beach;
}
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_replace_char (op->buf_asm, '%', 0);
// TODO: remove the '$'<registername> in the string
cs_free (insn, n);
beach:
// cs_close (&cd);
fin:
return ret;
}

RAsmPlugin r_asm_plugin_tms320c64x = {
.name = "tms320c64x",
.desc = "Capstone TMS320c64x disassembler",
.license = "BSD",
.arch = "tms320c64x",
.bits = 32,
.endian = R_SYS_ENDIAN_BIG | R_SYS_ENDIAN_LITTLE,
.disassemble = &disassemble,
.mnemonics = mnemonics
};

#ifndef CORELIB
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_tms320c64x,
.version = R2_VERSION
};
#endif
16 changes: 16 additions & 0 deletions libr/asm/p/tms320c64x.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
OBJ_TMS320C64X_CS=asm_tms320c64x.o

include ${CURDIR}capstone.mk

STATIC_OBJ+=${OBJ_TMS320C64X_CS}
SHARED_OBJ+=${SHARED_TMS320C64X_CS}
TARGET_TMS320C64X_CS=asm_tms320c64x.${EXT_SO}

ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_TMS320C64X_CS}

${TARGET_TMS320C64X_CS}: ${OBJ_TMS320C64X_CS}
${CC} -o ${TARGET_TMS320C64X_CS} ${OBJ_TMS320C64X_CS} \
$(call libname,asm_tms320c64x) ${LDFLAGS} ${CFLAGS} $(CS_LDFLAGS)\
${SHARED2_TMS320C64X_CS}
endif
2 changes: 1 addition & 1 deletion libr/bin/p/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FORMATS=any.mk elf.mk elf64.mk pe.mk pe64.mk te.mk mach0.mk
FORMATS+=bios.mk mach064.mk fatmach0.mk dyldcache.mk java.mk
FORMATS+=dex.mk fs.mk ningb.mk coff.mk ningba.mk xbe.mk zimg.mk
FORMATS+=omf.mk cgc.mk dol.mk nes.mk mbn.mk psxexe.mk spc700.mk
FORMATS+=vsf.mk nin3ds.mk xtr_dyldcache.mk bflt.mk wasm.mk sfk.mk
FORMATS+=vsf.mk nin3ds.mk xtr_dyldcache.mk bflt.mk wasm.mk sfc.mk
include $(FORMATS)

all: ${ALL_TARGETS}
Expand Down
2 changes: 1 addition & 1 deletion libr/bin/p/bin_dex.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ static RBinInfo *info(RBinFile *arch) {
ret->rclass = strdup ("class");
ret->os = strdup ("linux");
const char *kw = "Landroid/support/wearable/view";
if (r_mem_mem (arch->buf->buf, arch->buf->length, kw, strlen (kw))) {
if (r_mem_mem (arch->buf->buf, arch->buf->length, (const ut8*)kw, strlen (kw))) {
ret->subsystem = strdup ("android-wear");
} else {
ret->subsystem = strdup ("android");
Expand Down
11 changes: 2 additions & 9 deletions libr/bin/p/bin_sfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@ static bool check_bytes(const ut8 *buf, ut64 length) {
return (cksum1 == (ut16)~cksum2);
}

static bool check(RBinFile *arch) {
const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL;
ut64 sz = arch ? r_buf_size (arch->buf): 0;
return check_bytes (bytes, sz);
}

static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){
check_bytes (buf, sz);
return R_NOTNULL;
}

static RBinInfo* info(RBinFile *arch) {
sfc_int_hdr sfchdr = {0};
sfc_int_hdr sfchdr = {{0}};
RBinInfo *ret = NULL;
int hdroffset = 0;

Expand Down Expand Up @@ -120,7 +114,7 @@ static RList* symbols(RBinFile *arch) {

static RList* sections(RBinFile *arch) {
RList *ret = NULL;
RBinSection *ptr = NULL;
// RBinSection *ptr = NULL;
int hdroffset = 0;
bool is_hirom = false;
int i = 0; //0x8000-long bank number for loops
Expand Down Expand Up @@ -282,7 +276,6 @@ RBinPlugin r_bin_plugin_sfc = {
.desc = "Super NES / Super Famicom ROM file",
.license = "LGPL3",
.load_bytes = &load_bytes,
.check = &check,
.check_bytes = &check_bytes,
.entries = &entries,
.sections = sections,
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ extern RAsmPlugin r_asm_plugin_tricore;
extern RAsmPlugin r_asm_plugin_pic18c;
extern RAsmPlugin r_asm_plugin_rsp;
extern RAsmPlugin r_asm_plugin_wasm;
extern RAsmPlugin r_asm_plugin_tms320c64x;

#endif

Expand Down
1 change: 1 addition & 0 deletions libr/include/r_bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ extern RBinPlugin r_bin_plugin_avr;
extern RBinPlugin r_bin_plugin_menuet;
extern RBinPlugin r_bin_plugin_wasm;
extern RBinPlugin r_bin_plugin_nro;
extern RBinPlugin r_bin_plugin_sfc;

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions plugins.def.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ asm.sparc_gnu
asm.spc700
asm.sysz
asm.tms320
asm.tms320c64x
asm.v850
asm.ws
asm.xap
Expand Down
4 changes: 2 additions & 2 deletions shlr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CS_PATCHES=0
else
CS_TAR=
CS_URL=$(GIT_PREFIX)github.com/aquynh/capstone.git
CS_UPD=20170318
CS_UPD=20170417
CS_BRA=next
CS_TIP=d09f56545c74b875e557cfc60cfc7076e0dc4962
CS_TIP=aaebd0b5e573599e568681eaa8dd7b9f2e0a91e9
# REVERT THIS COMMIT BECAUSE ITS WRONG
CS_REV=
CS_PATCHES=1
Expand Down

0 comments on commit 54f6efd

Please sign in to comment.