From 95bb7bb74e4fd854927bc797c62444841f09a18a Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 28 Sep 2014 01:43:08 +0200 Subject: [PATCH] Define and use R_NOTNULL in RBinPlugin.load_bytes --- libr/bin/p/bin_bf.c | 2 +- libr/bin/p/bin_bios.c | 2 +- libr/bin/p/bin_dex.c | 3 +-- libr/bin/p/bin_fs.c | 2 +- libr/bin/p/bin_ninds.c | 2 +- libr/bin/p/bin_ningb.c | 2 +- libr/bin/p/bin_ningba.c | 8 -------- libr/include/r_types_base.h | 1 + 8 files changed, 7 insertions(+), 15 deletions(-) diff --git a/libr/bin/p/bin_bf.c b/libr/bin/p/bin_bf.c index 0fe686cde3..92edcda38c 100644 --- a/libr/bin/p/bin_bf.c +++ b/libr/bin/p/bin_bf.c @@ -16,7 +16,7 @@ static Sdb* get_sdb (RBinObject *o) { } static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ - return (void*)(size_t)1; + return R_NOTNULL; } static int load(RBinFile *arch) { diff --git a/libr/bin/p/bin_bios.c b/libr/bin/p/bin_bios.c index 45709b2f6a..5e1453524a 100644 --- a/libr/bin/p/bin_bios.c +++ b/libr/bin/p/bin_bios.c @@ -18,7 +18,7 @@ static Sdb* get_sdb (RBinObject *o) { static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ check_bytes (buf, sz); // XXX: this may be wrong if check_bytes is true - return NULL; + return R_NOTNULL; } static int load(RBinFile *arch) { diff --git a/libr/bin/p/bin_dex.c b/libr/bin/p/bin_dex.c index b343a06126..bfc95d1c2c 100644 --- a/libr/bin/p/bin_dex.c +++ b/libr/bin/p/bin_dex.c @@ -29,9 +29,8 @@ static Sdb* get_sdb (RBinObject *o) { static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ void *res = NULL; RBuffer *tbuf = NULL; - if (!buf || sz == 0 || sz == UT64_MAX) return NULL; - tbuf = r_buf_new(); + tbuf = r_buf_new (); r_buf_set_bytes (tbuf, buf, sz); res = r_bin_dex_new_buf (tbuf); r_buf_free (tbuf); diff --git a/libr/bin/p/bin_fs.c b/libr/bin/p/bin_fs.c index c50747adae..ebdee41a60 100644 --- a/libr/bin/p/bin_fs.c +++ b/libr/bin/p/bin_fs.c @@ -55,7 +55,7 @@ static Sdb* get_sdb (RBinObject *o) { static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ if (check_bytes (buf, sz)) - return (void*)R_TRUE; + return R_NOTNULL; return NULL; } diff --git a/libr/bin/p/bin_ninds.c b/libr/bin/p/bin_ninds.c index a1a7ee882d..cca8f0e35b 100644 --- a/libr/bin/p/bin_ninds.c +++ b/libr/bin/p/bin_ninds.c @@ -29,7 +29,7 @@ static int check_bytes(const ut8 *buf, ut64 length) { } static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb) { - return memcpy(&loaded_header, buf, sizeof(struct nds_hdr)); + return memcpy (&loaded_header, buf, sizeof(struct nds_hdr)); } static int load(RBinFile *arch) { diff --git a/libr/bin/p/bin_ningb.c b/libr/bin/p/bin_ningb.c index be66145e85..908264fabf 100644 --- a/libr/bin/p/bin_ningb.c +++ b/libr/bin/p/bin_ningb.c @@ -18,7 +18,7 @@ static Sdb* get_sdb (RBinObject *o) { } static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ - return (void*)R_TRUFAE; + return R_NOTNULL; } static int check(RBinFile *arch) { diff --git a/libr/bin/p/bin_ningba.c b/libr/bin/p/bin_ningba.c index 8be045894b..c4248bca58 100644 --- a/libr/bin/p/bin_ningba.c +++ b/libr/bin/p/bin_ningba.c @@ -9,7 +9,6 @@ static int check(RBinFile *arch); int check_bytes(const ut8 *buf, ut64 length); -static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb); static int check(RBinFile *arch) { const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL; @@ -19,7 +18,6 @@ static int check(RBinFile *arch) { } int check_bytes(const ut8 *buf, ut64 length) { - ut8 lict[156]; if (!buf || length < 160) return 0; @@ -34,15 +32,10 @@ static Sdb* get_sdb (RBinObject *o) { return NULL; } -static void * load_bytes(const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){ - return NULL; -} - static int load(RBinFile *arch) { const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL; ut64 sz = arch ? r_buf_size (arch->buf): 0; if (!arch || !arch->o) return R_FALSE; - arch->o->bin_obj = load_bytes (bytes, sz, arch->o->loadaddr, arch->sdb); return check_bytes (bytes, sz); } @@ -106,7 +99,6 @@ struct r_bin_plugin_t r_bin_plugin_ningba = { .fini = NULL, .get_sdb = &get_sdb, .load = &load, - .load_bytes = &load_bytes, .destroy = &destroy, .check = &check, .check_bytes = &check_bytes, diff --git a/libr/include/r_types_base.h b/libr/include/r_types_base.h index 34a0d713f7..e9f913f3a4 100644 --- a/libr/include/r_types_base.h +++ b/libr/include/r_types_base.h @@ -18,6 +18,7 @@ #define R_FALSE 0 #define R_TRUE 1 #define R_TRUFAE 2 +#define R_NOTNULL (void*)(size_t)1 /* limits */ #undef UT64_MAX