Add support for C64 PRG fileformat ##bin (#15448)

This commit is contained in:
Florian Märkl 2019-11-11 21:54:46 +01:00 committed by radare
parent cb7e8e7310
commit 432b559bb7
7 changed files with 107 additions and 1 deletions

View File

@ -47,6 +47,7 @@ r_bin_sources = [
'p/bin_pe.c',
'p/bin_pe64.c',
'p/bin_pebble.c',
'p/bin_prg.c',
'p/bin_psxexe.c',
'p/bin_qnx.c',
'p/bin_sfc.c',

View File

@ -22,7 +22,7 @@ FORMATS+=bios.mk mach064.mk dyldcache.mk xnu_kernelcache.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 bflt.mk wasm.mk sfc.mk
FORMATS+=mdmp.mk z64.mk qnx.mk
FORMATS+=mdmp.mk z64.mk qnx.mk prg.mk
FORMATS+=xtr_dyldcache.mk
FORMATS+=xtr_fatmach0.mk

92
libr/bin/p/bin_prg.c Normal file
View File

@ -0,0 +1,92 @@
/* radare - LGPL3 - 2019 - thestr4ng3r */
#include <r_bin.h>
#include <r_lib.h>
static bool check_buffer(RBuffer *b) {
// no magic
return false;
}
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
return true;
}
static ut64 baddr(RBinFile *bf) {
ut16 base = r_buf_read_le16_at (bf->buf, 0);
return base != UT16_MAX ? base : 0;
}
static RBinInfo *info(RBinFile *bf) {
RBinInfo *ret = R_NEW0 (RBinInfo);
if (!ret) {
return NULL;
}
ret->file = strdup (bf->file);
ret->type = strdup ("PRG");
ret->machine = strdup ("Commodore 64");
ret->os = strdup ("c64");
ret->arch = strdup ("6502");
ret->bits = 8;
ret->has_va = 1;
return ret;
}
static RList *sections(RBinFile *bf) {
RList *ret = r_list_newf ((RListFree)r_bin_section_free);
if (!ret) {
return NULL;
}
ut64 sz = r_buf_size (bf->buf);
if (sz < 2) {
return ret;
}
RBinSection *section = R_NEW0 (RBinSection);
if (!section) {
return ret;
}
section->name = strdup ("prg");
section->paddr = 2;
section->size = sz - 2;
section->vaddr = baddr (bf);
section->vsize = sz - 2;
section->perm = R_PERM_RWX;
section->add = true;
r_list_append (ret, section);
return ret;
}
static RList *entries(RBinFile *bf) {
RList *ret = r_list_newf (free);
if (!ret) {
return NULL;
}
RBinAddr *binaddr = R_NEW0 (RBinAddr);
if (!binaddr) {
return ret;
}
binaddr->paddr = 2;
binaddr->vaddr = baddr (bf);
r_list_append (ret, binaddr);
return ret;
}
RBinPlugin r_bin_plugin_prg = {
.name = "prg",
.desc = "C64 PRG",
.license = "LGPL3",
.load_buffer = load_buffer,
.baddr = baddr,
.check_buffer = check_buffer,
.entries = entries,
.sections = sections,
.info = info,
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_prg,
.version = R2_VERSION
};
#endif

10
libr/bin/p/prg.mk Normal file
View File

@ -0,0 +1,10 @@
OBJ_PRG=bin_prg.o
STATIC_OBJ+=${OBJ_PRG}
TARGET_PRG=bin_prg.${EXT_SO}
ALL_TARGETS+=${TARGET_PRG}
${TARGET_PRG}: ${OBJ_PRG}
${CC} $(call libname,bin_prg) -shared ${CFLAGS} \
-o ${TARGET_PRG} ${OBJ_PRG} $(LINK) $(LDFLAGS)

View File

@ -864,6 +864,7 @@ extern RBinPlugin r_bin_plugin_nro;
extern RBinPlugin r_bin_plugin_nso;
extern RBinPlugin r_bin_plugin_sfc;
extern RBinPlugin r_bin_plugin_z64;
extern RBinPlugin r_bin_plugin_prg;
#ifdef __cplusplus
}

View File

@ -156,6 +156,7 @@ bin_plugins = [
'pe',
'pe64',
'pebble',
'prg',
'psxexe',
'sfc',
'smd',

View File

@ -150,6 +150,7 @@ bin.p9
bin.pe
bin.pe64
bin.pebble
bin.prg
bin.smd
bin.sms
bin.avr