Add support for SPC700 file format

This commit is contained in:
Maijin 2015-11-27 00:19:10 +01:00 committed by pancake
parent 3b14470e3f
commit e68ed8dd91
7 changed files with 178 additions and 2 deletions

View File

@ -11,7 +11,7 @@ OBJS += p/bin_ningb.c ;
OBJS += p/bin_bios.c ;
OBJS += p/bin_rar.c ;
OBJS += p/bin_xbe.c ;
OBJS += p/bin_spc700.c ;
# PSX-EXE
OBJS += p/bin_psxexe.c ;

View File

@ -0,0 +1,78 @@
/* radare - LGPL - 2015 - maijin */
#ifndef _SPC_H
#define _SPC_H
#define SPC_MAGIC "SNES-SPC700 Sound File Data"
#define SPC_HDR_SIZE sizeof (spc_hdr)
#define RAM_START_ADDRESS 0x100
#define RAM_SIZE 0x10000
#define DSP_REG_START_ADDRESS 0x10100
#define DSP_REG_SIZE 0x80
#define EXTRA_RAM_START_ADDRESS 0x101C0
#define EXTRA_RAM_SIZE 0x40
#define EXTENDED_ID666_START_ADDRESS 0x10200
typedef enum {
UNKNOWN,
ZSNES,
SNES9X,
} emulator_used;
typedef struct __attribute__((__packed__)) { //SNES9x
char song_title [32];
char game_title [32];
char name_of_dumper [16];
char comments [32];
ut8 date[11];
ut8 num_sec_bef_fade_out[3];
ut8 len_fade_out[5];
char artist_song [32];
bool default_channel_disabled;
emulator_used emulator_used[1];
ut8 reserved[1];
} id666_tag_text;
typedef struct __attribute__((__packed__)) { //ZSNES
char song_title [32];
char game_title [32];
char name_of_dumper [16];
char comments [32];
ut8 date[4];
ut8 unused[8];
ut8 num_sec_bef_fade_out[3];
ut8 len_fade_out[4];
char artist_song [32];
bool default_channel_disabled;
ut8 reserved[1];
} id666_tag_binary;
typedef struct __attribute__((__packed__)) {
char signature [33];
ut8 signature2 [2];
ut8 has_id666;
ut8 version;
} spc_hdr;
typedef struct __attribute__((__packed__)) {
ut8 pcl, pch;
ut8 a;
ut8 x;
ut8 y;
ut8 psw;
ut8 sp;
ut8 reserved_1, reserved_2;
} spc_reg;
typedef struct __attribute__((__packed__)) {
ut8 ram [0x10000];
ut8 dsp [128];
ut8 unused [0x40];
ut8 ipl_rom [0x40];
} spc_data;
#endif // _SPC_H

View File

@ -12,7 +12,7 @@ ALL_TARGETS=
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
FORMATS+=omf.mk cgc.mk dol.mk nes.mk mbn.mk psxexe.mk spc700.mk
include $(FORMATS)
all: ${ALL_TARGETS}

87
libr/bin/p/bin_spc700.c Normal file
View File

@ -0,0 +1,87 @@
/* radare - LGPL - 2015 - maijin */
#include <r_bin.h>
#include "../format/spc700/spc_specs.h"
static int check(RBinFile *arch);
static int check_bytes(const ut8 *buf, ut64 length);
static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){
check_bytes (buf, sz);
return R_NOTNULL;
}
static int 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 int check_bytes(const ut8 *buf, ut64 length) {
if (!buf || length < 27) return false;
return (!memcmp (buf, SPC_MAGIC, 27));
}
static RBinInfo* info(RBinFile *arch) {
RBinInfo *ret = NULL;
spc_hdr spchdr;
memset (&spchdr, 0, SPC_HDR_SIZE);
int reat = r_buf_read_at (arch->buf, 0, (ut8*)&spchdr, SPC_HDR_SIZE);
if (reat != SPC_HDR_SIZE) {
eprintf ("Truncated Header\n");
return NULL;
}
if (!(ret = R_NEW0 (RBinInfo)))
return NULL;
ret->file = strdup (arch->file);
ret->type = strdup ("Sound File Data");
ret->machine = strdup ("SPC700");
ret->os = strdup ("spc700");
ret->arch = strdup ("spc700");
ret->bits = 16;
ret->has_va = 1;
return ret;
}
static RList* sections(RBinFile *arch) {
RList *ret = NULL;
RBinSection *ptr = NULL;
spc_hdr spchdr;
memset (&spchdr, 0, SPC_HDR_SIZE);
int reat = r_buf_read_at (arch->buf, 0, (ut8*)&spchdr, SPC_HDR_SIZE);
if (reat != SPC_HDR_SIZE) {
eprintf ("Truncated Header\n");
return NULL;
}
if (!(ret = r_list_new ()))
return NULL;
if (!(ptr = R_NEW0 (RBinSection)))
return ret;
strcpy (ptr->name, "RAM");
ptr->paddr = RAM_START_ADDRESS;
ptr->size = RAM_SIZE;
ptr->vaddr = 0x0;
ptr->vsize = RAM_SIZE;
ptr->srwx = R_BIN_SCN_MAP;
r_list_append (ret, ptr);
return ret;
}
struct r_bin_plugin_t r_bin_plugin_spc700 = {
.name = "spc700",
.desc = "SNES-SPC700 Sound File Data",
.license = "LGPL3",
.load_bytes = &load_bytes,
.check = &check,
.check_bytes = &check_bytes,
.sections = &sections,
.info = &info,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_spc700,
.version = R2_VERSION
};
#endif

9
libr/bin/p/spc700.mk Normal file
View File

@ -0,0 +1,9 @@
OBJ_SPC700=bin_spc700.o
STATIC_OBJ+=${OBJ_SPC700}
TARGET_SPC700=bin_spc700.${EXT_SO}
ALL_TARGETS+=${TARGET_SPC700}
${TARGET_SPC700}: ${OBJ_SPC700}
${CC} $(call libname,bin_spc700) -shared ${CFLAGS} \
-o ${TARGET_SPC700} ${OBJ_SPC700} ${LDFLAGS}

View File

@ -557,6 +557,7 @@ extern RBinPlugin r_bin_plugin_mbn;
extern RBinPlugin r_bin_plugin_smd;
extern RBinPlugin r_bin_plugin_sms;
extern RBinPlugin r_bin_plugin_psxexe;
extern RBinPlugin r_bin_plugin_spc700;
#ifdef __cplusplus
}

View File

@ -122,6 +122,7 @@ bin.pebble
bin.rar
bin.smd
bin.sms
bin.spc700
bin.te
bin.xbe
bin_xtr.dyldcache