diff --git a/libr/bin/p/bin_bios.c b/libr/bin/p/bin_bios.c index 77f7089fa9..633dc4776c 100644 --- a/libr/bin/p/bin_bios.c +++ b/libr/bin/p/bin_bios.c @@ -12,6 +12,28 @@ static Sdb* get_sdb (RBinObject *o) { return NULL; } +static bool check_bytes(const ut8 *buf, ut64 length) { + if (buf && length > 0xffff && buf[0] != 0xcf) { + const ut32 ep = length - 0x10000 + 0xfff0; /* F000:FFF0 address */ + /* hacky check to avoid detecting multidex bins as bios */ + /* need better fix for this */ + if (!memcmp (buf, "dex", 3)) { + return 0; + } + /* Check if this a 'jmp' opcode */ + if ((buf[ep] == 0xea) || (buf[ep] == 0xe9)) { + return 1; + } + } + return 0; +} + +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){ if (!check_bytes (buf, sz)) { return NULL; @@ -59,28 +81,6 @@ static RBinInfo* info(RBinFile *arch) { return ret; } -static bool check_bytes(const ut8 *buf, ut64 length) { - if (buf && length > 0xffff && buf[0] != 0xcf) { - const ut32 ep = length - 0x10000 + 0xfff0; /* F000:FFF0 address */ - /* hacky check to avoid detecting multidex bins as bios */ - /* need better fix for this */ - if (!memcmp (buf, "dex", 3)) { - return 0; - } - /* Check if this a 'jmp' opcode */ - if ((buf[ep] == 0xea) || (buf[ep] == 0xe9)) { - return 1; - } - } - return 0; -} - -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 RList* sections(RBinFile *arch) { RList *ret = NULL; RBinSection *ptr = NULL; diff --git a/libr/bin/p/bin_elf64.c b/libr/bin/p/bin_elf64.c index 573607ac64..748c4ea54c 100644 --- a/libr/bin/p/bin_elf64.c +++ b/libr/bin/p/bin_elf64.c @@ -3,12 +3,6 @@ #define R_BIN_ELF64 1 #include "bin_elf.c" -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 bool check_bytes(const ut8 *buf, ut64 length) { if (buf && length >= 5) { if (!memcmp (buf, "\x7F\x45\x4c\x46\x02", 5)) { @@ -18,6 +12,12 @@ static bool check_bytes(const ut8 *buf, ut64 length) { return false; } +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); +} + extern struct r_bin_dbginfo_t r_bin_dbginfo_elf64; extern struct r_bin_write_t r_bin_write_elf64; diff --git a/libr/bin/p/bin_fs.c b/libr/bin/p/bin_fs.c index 9902b43527..8bea9819b0 100644 --- a/libr/bin/p/bin_fs.c +++ b/libr/bin/p/bin_fs.c @@ -50,6 +50,19 @@ static Sdb* get_sdb (RBinObject *o) { return NULL; } +static bool check_bytes(const ut8 *buf, ut64 length) { + if (!buf || (st64)length <1) return false; + char *p = fsname (buf, length); + free (p); + return p != NULL; +} + +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){ if (check_bytes (buf, sz)) return R_NOTNULL; @@ -103,19 +116,6 @@ static RBinInfo* info(RBinFile *arch) { return ret; } -static bool check_bytes(const ut8 *buf, ut64 length) { - if (!buf || (st64)length <1) return false; - char *p = fsname (buf, length); - free (p); - return p != NULL; -} - -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); -} - RBinPlugin r_bin_plugin_fs = { .name = "fs", .desc = "filesystem bin plugin", diff --git a/libr/bin/p/bin_nes.c b/libr/bin/p/bin_nes.c index 082da4528b..6bb8d31fbf 100644 --- a/libr/bin/p/bin_nes.c +++ b/libr/bin/p/bin_nes.c @@ -4,11 +4,6 @@ #include #include "nes/nes_specs.h" -static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ - check_bytes (buf, sz); - return R_NOTNULL; -} - static bool check_bytes(const ut8 *buf, ut64 length) { if (!buf || length < 4) return false; return (!memcmp (buf, INES_MAGIC, 4)); @@ -20,6 +15,11 @@ static bool check(RBinFile *arch) { 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) { RBinInfo *ret = NULL; ines_hdr ihdr; diff --git a/libr/bin/p/bin_nin3ds.c b/libr/bin/p/bin_nin3ds.c index fa37e00f98..a7355eb4de 100644 --- a/libr/bin/p/bin_nin3ds.c +++ b/libr/bin/p/bin_nin3ds.c @@ -10,12 +10,6 @@ static struct n3ds_firm_hdr loaded_header; -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 bool check_bytes(const ut8 *buf, ut64 length) { if (!buf || length < sizeof (struct n3ds_firm_hdr)) { return false; @@ -23,6 +17,12 @@ static bool check_bytes(const ut8 *buf, ut64 length) { return (!memcmp (buf, "FIRM", 4)); } +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) { return memcpy (&loaded_header, buf, sizeof (struct n3ds_firm_hdr)); } diff --git a/libr/bin/p/bin_psxexe.c b/libr/bin/p/bin_psxexe.c index e8eac3753b..e442314585 100644 --- a/libr/bin/p/bin_psxexe.c +++ b/libr/bin/p/bin_psxexe.c @@ -6,11 +6,6 @@ #include #include "psxexe/psxexe.h" -static void* load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb) { - check_bytes (buf, sz); - return R_NOTNULL; -} - static bool check_bytes(const ut8 *buf, ut64 length) { if (!buf || (length < PSXEXE_ID_LEN)) { return false; @@ -25,6 +20,11 @@ static bool check(RBinFile *arch) { return check_bytes (r_buf_buffer (arch->buf), r_buf_size (arch->buf)); } +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) { RBinInfo* ret = NULL; psxexe_header psxheader; diff --git a/libr/bin/p/bin_smd.c b/libr/bin/p/bin_smd.c index 1de70aed8d..ef848ffd7c 100644 --- a/libr/bin/p/bin_smd.c +++ b/libr/bin/p/bin_smd.c @@ -1,4 +1,4 @@ -/* radare - LGPL3 - 2015-2016 - pancake */ +/* radare - LGPL3 - 2015-2017 - pancake */ #include @@ -91,13 +91,6 @@ typedef struct gen_vect { }; } SMD_Vectors; - - -static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ - check_bytes (buf, sz); - return R_NOTNULL; -} - static bool check_bytes(const ut8 *buf, ut64 length) { if (length > 0x190 && !memcmp (buf+0x100, "SEGA", 4)) { return true; @@ -111,6 +104,11 @@ static bool check(RBinFile *arch) { 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) { RBinInfo *ret = NULL; if (!(ret = R_NEW0 (RBinInfo))) @@ -296,7 +294,7 @@ static RList* entries(RBinFile *arch) { //Should be 3 offsets pointed by NMI, RE return ret; } -struct r_bin_plugin_t r_bin_plugin_smd = { +RBinPlugin r_bin_plugin_smd = { .name = "smd", .desc = "SEGA Genesis/Megadrive", .license = "LGPL3", @@ -312,7 +310,7 @@ struct r_bin_plugin_t r_bin_plugin_smd = { }; #ifndef CORELIB -struct r_lib_struct_t radare_plugin = { +RLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, .data = &r_bin_plugin_smd, .version = R2_VERSION diff --git a/libr/bin/p/bin_sms.c b/libr/bin/p/bin_sms.c index 732003492c..bf44df7240 100644 --- a/libr/bin/p/bin_sms.c +++ b/libr/bin/p/bin_sms.c @@ -11,11 +11,6 @@ typedef struct gen_hdr { ut8 RegionRomSize; //Low 4 bits RomSize, Top 4 bits Region } SMS_Header; -static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ - check_bytes (buf, sz); - return R_NOTNULL; -} - #define CMP8(o,x) strncmp((const char*)bs+o,x,8) #define CMP4(o,x) strncmp((const char*)bs+o,x,4) static bool check_bytes(const ut8 *bs, ut64 length) { @@ -43,6 +38,11 @@ static bool check(RBinFile *arch) { 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) { const char *bs; SMS_Header *hdr = NULL; diff --git a/libr/bin/p/bin_spc700.c b/libr/bin/p/bin_spc700.c index 5611c5959c..901f994954 100644 --- a/libr/bin/p/bin_spc700.c +++ b/libr/bin/p/bin_spc700.c @@ -4,11 +4,6 @@ #include #include "../format/spc700/spc_specs.h" -static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ - check_bytes (buf, sz); - return R_NOTNULL; -} - static bool check_bytes(const ut8 *buf, ut64 length) { if (!buf || length < 27) { return false; @@ -22,6 +17,11 @@ static bool check(RBinFile *arch) { 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) { RBinInfo *ret = NULL; spc_hdr spchdr; diff --git a/libr/bin/p/bin_te.c b/libr/bin/p/bin_te.c index dada3874bc..48cebf2c86 100644 --- a/libr/bin/p/bin_te.c +++ b/libr/bin/p/bin_te.c @@ -144,6 +144,10 @@ static RBinInfo* info(RBinFile *arch) { return ret; } +static bool check_bytes(const ut8 *buf, ut64 length) { + return (buf && length > 2 && !memcmp (buf, "\x56\x5a", 2)); +} + static bool check(RBinFile *arch) { const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL; ut64 sz = arch ? r_buf_size (arch->buf): 0; @@ -151,10 +155,6 @@ static bool check(RBinFile *arch) { } -static bool check_bytes(const ut8 *buf, ut64 length) { - return (buf && length > 2 && !memcmp (buf, "\x56\x5a", 2)); -} - RBinPlugin r_bin_plugin_te = { .name = "te", .desc = "TE bin plugin", // Terse Executable format diff --git a/libr/bin/p/bin_zimg.c b/libr/bin/p/bin_zimg.c index 8e81e94832..0cd5a1b306 100644 --- a/libr/bin/p/bin_zimg.c +++ b/libr/bin/p/bin_zimg.c @@ -44,12 +44,6 @@ static ut64 baddr(RBinFile *arch) { return 0; } -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 bool check_bytes(const ut8 *buf, ut64 length) { if (buf && length >= 8) { // Checking ARM zImage kernel @@ -61,6 +55,12 @@ static bool check_bytes(const ut8 *buf, ut64 length) { return false; } +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 RBinInfo *info(RBinFile *arch) { RBinInfo *ret = R_NEW0 (RBinInfo); if (!ret) return NULL; @@ -94,7 +94,7 @@ struct r_bin_plugin_t r_bin_plugin_zimg = { }; #ifndef CORELIB -struct r_lib_struct_t radare_plugin = { +RLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, .data = &r_bin_plugin_zimg, .version = R2_VERSION