Another RBin API cleanup ##bin

* remove R_API from functions not used outside of RBin module
* move not-exported functions to a separate private header
* move bin_private in i/private.h
* fix and use R_IPI
* fix mips_assemble
This commit is contained in:
Riccardo Schirone 2018-11-05 11:25:31 +01:00 committed by radare
parent 3facb9cd15
commit 936512916b
25 changed files with 120 additions and 165 deletions

View file

@ -3,16 +3,12 @@
#include <r_types.h>
#include <r_util.h>
#ifndef R_IPI
#define R_IPI
#endif
static const char * const regs[33] = {
"zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
NULL
static const char *const regs[33] = {
"zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
NULL
};
static struct {
@ -35,9 +31,9 @@ static struct {
{ "xori", 'I', 3, 14, 0 },
{ "addi", 'I', 3, 8, 0 },
{ "addiu", 'I', 3, 9, 0 },
{ "b", 'B', -1, 4, 0},
{ "b", 'B', -1, 4, 0 },
{ "bnez", 'B', 2, 5, 0 },
{ "bal", 'B', -1, -1, 17},
{ "bal", 'B', -1, -1, 17 },
{ "bne", 'B', 3, 5, 0 },
{ "beq", 'B', 3, 4, 0 },
{ "bgez", 'B', -2, -1, 1 },
@ -76,7 +72,7 @@ static struct {
{ "jalr", 'R', -2, 9, 0 },
{ "jr", 'R', 1, 8, 0 },
{ "jal", 'J', 1, 3, 0 },
{ "j", 'J', 1, 2, 0 },
{ "j", 'J', 1, 2, 0 },
{ NULL }
};

View file

@ -3,8 +3,8 @@
#include <r_asm.h>
#include <r_lib.h>
#include <capstone/capstone.h>
#define R_IPI static
#include "../arch/mips/mipsasm.c"
R_IPI int mips_assemble(const char *str, ut64 pc, ut8 *out);
static csh cd = 0;
#include "cs_mnemonics.c"

View file

@ -27,7 +27,6 @@ OBJS+=mangling/demangler.o
OBJS+=mangling/microsoft_demangle.o
OBJS+=mangling/objc.o mangling/cxx.o mangling/msvc.o
OBJS+=mangling/swift.o mangling/swift-sd.o
OBJS+=mangling/dlang.o
OBJS+=mangling/java.o
OBJS+=mangling/rust.o
OBJS+=pdb/pdb_downloader.o pdb/omap.o pdb/stream_pe.o pdb/gdata.o

View file

@ -1,6 +1,7 @@
/* radare2 - LGPL - Copyright 2009-2018 - pancake, nibble, dso */
#include <r_bin.h>
#include "i/private.h"
// maybe too big sometimes? 2KB of stack eaten here..
#define R_STRING_SCAN_BUFFER_SIZE 2048
@ -259,7 +260,7 @@ static char *swiftField(const char *dn, const char *cn) {
return NULL;
}
R_API RList *r_bin_classes_from_symbols(RBinFile *bf, RBinObject *o) {
R_IPI RList *r_bin_classes_from_symbols(RBinFile *bf, RBinObject *o) {
RBinSymbol *sym;
RListIter *iter;
RList *symbols = o->symbols;
@ -307,7 +308,7 @@ R_API RList *r_bin_classes_from_symbols(RBinFile *bf, RBinObject *o) {
return classes;
}
R_API RBinFile *r_bin_file_new(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr) {
R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr) {
RBinFile *binfile = R_NEW0 (RBinFile);
if (!binfile) {
return NULL;
@ -410,12 +411,11 @@ R_API bool r_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 bas
return true;
}
R_API RBinFile *r_bin_file_new_from_fd(RBin *bin, int fd, RBinFileOptions *options) {
int file_sz = 0;
R_IPI RBinFile *r_bin_file_new_from_fd(RBin *bin, int fd, RBinFileOptions *options) {
int file_sz = 0;
RBinPlugin *plugin = NULL;
RBinFile *bf = r_bin_file_create_append (bin, "-", NULL, 0, file_sz,
0, fd, NULL, false);
0, fd, NULL, false);
if (!bf) {
return NULL;
}
@ -466,7 +466,7 @@ int file_sz = 0;
return bf;
}
R_API RBinFile *r_bin_file_new_from_bytes(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname, const char *xtrname, ut64 offset, bool steal_ptr) {
R_IPI RBinFile *r_bin_file_new_from_bytes(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname, const char *xtrname, ut64 offset, bool steal_ptr) {
ut8 binfile_created = false;
RBinPlugin *plugin = NULL;
RBinXtrPlugin *xtr = NULL;
@ -567,10 +567,10 @@ R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bi
return binfile;
}
R_API RBinObject *r_bin_file_object_find_by_id(RBinFile *binfile, ut32 binobj_id) {
R_IPI RBinObject *r_bin_file_object_find_by_id(RBinFile *binfile, ut32 binobj_id) {
RBinObject *obj;
RListIter *iter;
if (binfile) {
if (binfile) {
r_list_foreach (binfile->objs, iter, obj) {
if (obj->id == binobj_id) {
return obj;
@ -580,7 +580,7 @@ R_API RBinObject *r_bin_file_object_find_by_id(RBinFile *binfile, ut32 binobj_id
return NULL;
}
R_API RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id) {
R_IPI RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id) {
RListIter *iter;
RBinFile *binfile;
r_list_foreach (bin->binfiles, iter, binfile) {
@ -591,7 +591,7 @@ R_API RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id) {
return NULL;
}
R_API RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 binfile_id) {
R_IPI RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 binfile_id) {
RBinFile *binfile = NULL;
RListIter *iter = NULL;
r_list_foreach (bin->binfiles, iter, binfile) {
@ -603,7 +603,7 @@ R_API RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 binfile_id) {
return binfile;
}
R_API int r_bin_file_object_add(RBinFile *binfile, RBinObject *o) {
R_IPI int r_bin_file_object_add(RBinFile *binfile, RBinObject *o) {
if (!o) {
return false;
}
@ -669,7 +669,7 @@ R_API RBinFile *r_bin_file_find_by_name(RBin *bin, const char *name) {
return bf;
}
R_API RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx) {
R_IPI RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx) {
RListIter *iter;
RBinFile *bf = NULL;
int i = 0;
@ -694,7 +694,7 @@ R_API int r_bin_file_set_cur_by_fd(RBin *bin, ut32 bin_fd) {
return r_bin_file_set_cur_binfile (bin, bf);
}
R_API bool r_bin_file_set_cur_binfile_obj(RBin *bin, RBinFile *bf, RBinObject *obj) {
R_IPI bool r_bin_file_set_cur_binfile_obj(RBin *bin, RBinFile *bf, RBinObject *obj) {
RBinPlugin *plugin = NULL;
if (!bin || !bf || !obj) {
return false;
@ -752,13 +752,13 @@ R_API int r_bin_file_deref(RBin *bin, RBinFile *a) {
return res;
}
R_API int r_bin_file_ref_by_bind(RBinBind *binb) {
R_IPI int r_bin_file_ref_by_bind(RBinBind *binb) {
RBin *bin = binb? binb->bin: NULL;
RBinFile *a = r_bin_cur (bin);
return r_bin_file_ref (bin, a);
}
R_API int r_bin_file_ref(RBin *bin, RBinFile *a) {
R_IPI int r_bin_file_ref(RBin *bin, RBinFile *a) {
RBinObject *o = r_bin_cur_object (bin);
if (a && o) {
o->referenced--;
@ -802,9 +802,9 @@ R_API void r_bin_file_free(void /*RBinFile*/ *bf_) {
}
// This is an unnecessary piece of overengineering
R_API RBinFile *r_bin_file_create_append(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, bool steal_ptr) {
R_IPI RBinFile *r_bin_file_create_append(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, bool steal_ptr) {
RBinFile *bf = r_bin_file_new (bin, file, bytes, sz, file_sz, rawstr,
fd, xtrname, bin->sdb, steal_ptr);
fd, xtrname, bin->sdb, steal_ptr);
if (bf) {
r_list_append (bin->binfiles, bf);
}
@ -813,7 +813,7 @@ R_API RBinFile *r_bin_file_create_append(RBin *bin, const char *file, const ut8
// This function populate RBinFile->xtr_data, that information is enough to
// create RBinObject when needed using r_bin_file_object_new_from_xtr_data
R_API RBinFile *r_bin_file_xtr_load_bytes(RBin *bin, RBinXtrPlugin *xtr, const char *filename, const ut8 *bytes, ut64 sz, ut64 file_sz, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr) {
R_IPI RBinFile *r_bin_file_xtr_load_bytes(RBin *bin, RBinXtrPlugin *xtr, const char *filename, const ut8 *bytes, ut64 sz, ut64 file_sz, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr) {
if (!bin || !bytes) {
return NULL;
}
@ -848,7 +848,7 @@ R_API RBinFile *r_bin_file_xtr_load_bytes(RBin *bin, RBinXtrPlugin *xtr, const c
}
#define LIMIT_SIZE 0
R_API bool r_bin_file_set_bytes(RBinFile *binfile, const ut8 *bytes, ut64 sz, bool steal_ptr) {
R_IPI bool r_bin_file_set_bytes(RBinFile *binfile, const ut8 *bytes, ut64 sz, bool steal_ptr) {
if (!binfile) {
return false;
}
@ -885,7 +885,7 @@ static int is_data_section(RBinFile *a, RBinSection *s) {
return strstr (s->name, "_const") != NULL;
}
R_API RList *r_bin_file_get_strings(RBinFile *a, int min, int dump, int raw) {
R_IPI RList *r_bin_file_get_strings(RBinFile *a, int min, int dump, int raw) {
RListIter *iter;
RBinSection *section;
RBinObject *o = a? a->o: NULL;
@ -959,7 +959,7 @@ R_API RList *r_bin_file_get_strings(RBinFile *a, int min, int dump, int raw) {
return ret;
}
R_API void r_bin_file_get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 from, ut64 to) {
R_IPI void r_bin_file_get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 from, ut64 to) {
RBinPlugin *plugin = r_bin_file_cur_plugin (bf);
RBinString *ptr;
RListIter *it;

View file

@ -6,6 +6,7 @@
#include <r_lib.h>
#include <r_io.h>
#include <config.h>
#include "i/private.h"
R_LIB_VERSION (r_bin);
@ -1276,7 +1277,7 @@ R_API RList * /*<RBinClass>*/ r_bin_get_classes(RBin *bin) {
return o ? o->classes : NULL;
}
R_API void r_bin_class_free(RBinClass *c) {
R_IPI void r_bin_class_free(RBinClass *c) {
free (c->name);
free (c->super);
r_list_free (c->methods);
@ -1284,8 +1285,8 @@ R_API void r_bin_class_free(RBinClass *c) {
free (c);
}
R_API RBinClass *r_bin_class_new(RBinFile *binfile, const char *name,
const char *super, int view) {
R_IPI RBinClass *r_bin_class_new(RBinFile *binfile, const char *name,
const char *super, int view) {
if (!binfile || !binfile->o) {
return NULL;
}
@ -1319,7 +1320,7 @@ R_API RBinClass *r_bin_class_new(RBinFile *binfile, const char *name,
return c;
}
R_API RBinClass *r_bin_class_get(RBinFile *binfile, const char *name) {
R_IPI RBinClass *r_bin_class_get(RBinFile *binfile, const char *name) {
r_return_val_if_fail (binfile && binfile->o && name, NULL);
RBinClass *c;
@ -1333,7 +1334,7 @@ R_API RBinClass *r_bin_class_get(RBinFile *binfile, const char *name) {
return NULL;
}
R_API RBinSymbol *r_bin_class_add_method(RBinFile *binfile, const char *classname, const char *name, int nargs) {
R_IPI RBinSymbol *r_bin_class_add_method(RBinFile *binfile, const char *classname, const char *name, int nargs) {
r_return_val_if_fail (binfile, NULL);
RBinClass *c = r_bin_class_get (binfile, classname);
@ -1360,7 +1361,7 @@ R_API RBinSymbol *r_bin_class_add_method(RBinFile *binfile, const char *classnam
return sym;
}
R_API void r_bin_class_add_field(RBinFile *binfile, const char *classname, const char *name) {
R_IPI void r_bin_class_add_field(RBinFile *binfile, const char *classname, const char *name) {
//TODO: add_field into class
//eprintf ("TODO add field: %s \n", name);
}
@ -1526,7 +1527,7 @@ R_API const char *r_bin_get_meth_flag_string(ut64 flag, bool compact) {
}
}
R_API void r_bin_section_free(RBinSection *bs) {
R_IPI void r_bin_section_free(RBinSection *bs) {
free (bs->format);
free (bs);
}

View file

@ -171,7 +171,7 @@ R_API int r_bin_load_languages(RBinFile *binfile) {
return R_BIN_NM_NONE;
}
R_API int r_bin_lang_type(RBinFile *binfile, const char *def, const char *sym) {
R_IPI int r_bin_lang_type(RBinFile *binfile, const char *def, const char *sym) {
int type = 0;
RBinPlugin *plugin;
if (sym && sym[0] == sym[1] && sym[0] == '_') {
@ -196,4 +196,3 @@ R_API int r_bin_lang_type(RBinFile *binfile, const char *def, const char *sym) {
}
return type;
}

View file

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2011-2018 - pancake */
#include <r_bin.h>
#include "i/private.h"
#include <cxx/demangle.h>
R_API void r_bin_demangle_list(RBin *bin) {
@ -34,7 +35,7 @@ R_API char *r_bin_demangle_plugin(RBin *bin, const char *name, const char *str)
return NULL;
}
R_API const char *r_bin_lang_tostring (int lang) {
R_IPI const char *r_bin_lang_tostring(int lang) {
switch (lang) {
case R_BIN_NM_SWIFT:
return "swift";
@ -54,7 +55,7 @@ R_API const char *r_bin_lang_tostring (int lang) {
return NULL;
}
R_API int r_bin_demangle_type (const char *str) {
R_API int r_bin_demangle_type(const char *str) {
if (!str || !*str) {
return R_BIN_NM_NONE;
}

View file

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2015 - pancake */
#include <r_bin.h>
#include "i/private.h"
static void hashify(char *s, ut64 vaddr) {
if (!s) {

View file

@ -1,5 +1,6 @@
/* radare - LGPL - Copyright 2015-2018 - inisider */
#include "../../i/private.h"
#include "mach0_classes.h"
#define RO_META (1 << 0)

47
libr/bin/i/private.h Normal file
View file

@ -0,0 +1,47 @@
#ifndef R_BIN_PRIVATE_H_
#define R_BIN_PRIVATE_H_
#include <r_bin.h>
#include <r_util.h>
#include <r_types.h>
R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr);
R_IPI RBinFile *r_bin_file_new_from_bytes(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname, const char *xtrname, ut64 offset, bool steal_ptr);
R_IPI RBinFile *r_bin_file_new_from_fd(RBin *bin, int fd, RBinFileOptions *options);
R_IPI RBinObject *r_bin_file_object_find_by_id(RBinFile *binfile, ut32 binobj_id);
R_IPI RList *r_bin_file_get_strings(RBinFile *a, int min, int dump, int raw);
R_IPI void r_bin_file_get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 from, ut64 to);
R_IPI RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id);
R_IPI RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 binfile_id);
R_IPI int r_bin_file_object_add(RBinFile *binfile, RBinObject *o);
R_IPI RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx);
R_IPI bool r_bin_file_set_cur_binfile_obj(RBin *bin, RBinFile *bf, RBinObject *obj);
R_IPI int r_bin_file_ref(RBin *bin, RBinFile *a);
R_IPI RBinFile *r_bin_file_create_append(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, bool steal_ptr);
R_IPI RBinFile *r_bin_file_xtr_load_bytes(RBin *bin, RBinXtrPlugin *xtr, const char *filename, const ut8 *bytes, ut64 sz, ut64 file_sz, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr);
R_IPI bool r_bin_file_set_bytes(RBinFile *binfile, const ut8 *bytes, ut64 sz, bool steal_ptr);
R_IPI int r_bin_file_ref_by_bind(RBinBind *binb);
R_IPI void r_bin_section_free(RBinSection *bs);
R_IPI void r_bin_object_free(void /*RBinObject*/ *o_);
R_IPI ut64 r_bin_object_get_baddr(RBinObject *o);
R_IPI void r_bin_object_filter_strings(RBinObject *bo);
R_IPI void r_bin_object_set_baddr(RBinObject *o, ut64 baddr);
R_IPI RBinObject *r_bin_object_new(RBinFile *binfile, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz);
R_IPI RBinObject *r_bin_object_get_cur(RBin *bin);
R_IPI RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *arch, int bits, const char *name);
R_IPI void r_bin_object_delete_items(RBinObject *o);
R_IPI const char *r_bin_lang_tostring(int lang);
R_IPI int r_bin_lang_type(RBinFile *binfile, const char *def, const char *sym);
R_IPI bool r_bin_lang_swift(RBinFile *binfile);
R_IPI RBinClass *r_bin_class_get(RBinFile *binfile, const char *name);
R_IPI RBinClass *r_bin_class_new(RBinFile *binfile, const char *name, const char *super, int view);
R_IPI void r_bin_class_free(RBinClass *c);
R_IPI RBinSymbol *r_bin_class_add_method(RBinFile *binfile, const char *classname, const char *name, int nargs);
R_IPI void r_bin_class_add_field(RBinFile *binfile, const char *classname, const char *name);
R_IPI RList *r_bin_classes_from_symbols(RBinFile *bf, RBinObject *o);
#endif

View file

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2013-2018 - pancake */
#include <r_bin.h>
#include "../i/private.h"
#include "./cxx/demangle.h"
static inline bool is_cxx_symbol (const char *name) {

View file

@ -1,46 +0,0 @@
/* radare - LGPL - Copyright 2015 - pancake */
#include <r_bin.h>
// The dlang-demangler is written in D and available at radare2-extras
static int is_dlang_symbol (const char *name) {
if (!strncmp (name, "_D2", 3)) {
return 1;
}
if (!strncmp (name, "_D4", 3)) {
return 1;
}
return 0;
}
R_API bool r_bin_lang_dlang(RBinFile *binfile) {
RBinObject *o = binfile ? binfile->o : NULL;
RBinInfo *info = o ? o->info : NULL;
bool hasdlang = false;
RBinSymbol *sym;
RListIter *iter;
const char *lib;
if (!info) {
return false;
}
r_list_foreach (o->libs, iter, lib) {
if (strstr (lib, "phobos")) {
hasdlang = true;
break;
}
}
if (!hasdlang) {
r_list_foreach (o->symbols, iter, sym) {
if (sym->name && is_dlang_symbol (sym->name)) {
hasdlang = true;
break;
}
}
}
if (hasdlang) {
info->lang = "dlang";
}
return hasdlang;
}

View file

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2012-2015 - pancake */
#include <r_bin.h>
#include "../i/private.h"
R_API char *r_bin_demangle_objc(RBinFile *binfile, const char *sym) {
char *ret = NULL;

View file

@ -2,9 +2,9 @@
#include <r_bin.h>
R_API bool r_bin_lang_swift(RBinFile *binfile) {
RBinObject *o = binfile ? binfile->o : NULL;
RBinInfo *info = o ? o->info : NULL;
R_IPI bool r_bin_lang_swift(RBinFile *binfile) {
RBinObject *o = binfile? binfile->o: NULL;
RBinInfo *info = o? o->info: NULL;
RBinSymbol *sym;
RListIter *iter;
if (info) {

View file

@ -98,7 +98,6 @@ files = [
'mangling/cxx.c',
'mangling/cxx/cp-demangle.c',
'mangling/demangler.c',
'mangling/dlang.c',
'mangling/rust.c',
'mangling/java.c',
'mangling/microsoft_demangle.c',

View file

@ -2,10 +2,13 @@
#include <r_bin.h>
#include <r_util.h>
#include "i/private.h"
#define bprintf if(binfile->rbin->verbose)eprintf
#define bprintf \
if (binfile->rbin->verbose) \
eprintf
R_API void r_bin_object_free(void /*RBinObject*/ *o_) {
R_IPI void r_bin_object_free(void /*RBinObject*/ *o_) {
RBinObject *o = o_;
if (!o) {
return;
@ -16,7 +19,7 @@ R_API void r_bin_object_free(void /*RBinObject*/ *o_) {
R_FREE (o);
}
R_API RBinObject *r_bin_object_new(RBinFile *binfile, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz) {
R_IPI RBinObject *r_bin_object_new(RBinFile *binfile, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz) {
const ut8 *bytes = binfile? r_buf_buffer (binfile->buf): NULL;
ut64 bytes_sz = binfile? r_buf_size (binfile->buf): 0;
Sdb *sdb = binfile? binfile->sdb: NULL;
@ -296,7 +299,7 @@ R_API int r_bin_object_set_items(RBinFile *binfile, RBinObject *o) {
return true;
}
R_API RBinObject *r_bin_object_get_cur(RBin *bin) {
R_IPI RBinObject *r_bin_object_get_cur(RBin *bin) {
r_return_val_if_fail (bin, NULL);
return r_bin_file_object_get_cur (r_bin_cur (bin));
}
@ -311,7 +314,7 @@ static void r_bin_mem_free(void *data) {
free (mem);
}
R_API void r_bin_object_delete_items(RBinObject *o) {
R_IPI void r_bin_object_delete_items(RBinObject *o) {
ut32 i = 0;
r_return_if_fail (o);
sdb_free (o->addr2klassmethod);
@ -349,7 +352,7 @@ R_API void r_bin_object_delete_items(RBinObject *o) {
}
}
R_API RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *arch, int bits, const char *name) {
R_IPI RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *arch, int bits, const char *name) {
RBinObject *obj = NULL;
RListIter *iter = NULL;
@ -367,7 +370,7 @@ R_API RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *
return NULL;
}
R_API ut64 r_bin_object_get_baddr(RBinObject *o) {
R_IPI ut64 r_bin_object_get_baddr(RBinObject *o) {
r_return_val_if_fail (o, UT64_MAX);
return o->baddr + o->baddr_shift;
}
@ -406,14 +409,14 @@ R_API bool r_bin_object_delete(RBin *bin, ut32 binfile_id, ut32 binobj_id) {
return res;
}
R_API void r_bin_object_set_baddr(RBinObject *o, ut64 baddr) {
R_IPI void r_bin_object_set_baddr(RBinObject *o, ut64 baddr) {
r_return_if_fail (o);
if (baddr != UT64_MAX) {
o->baddr_shift = baddr - o->baddr;
}
}
R_API void r_bin_object_filter_strings(RBinObject *bo) {
R_IPI void r_bin_object_filter_strings(RBinObject *bo) {
r_return_if_fail (bo);
RList *strings = bo->strings;

View file

@ -5,6 +5,7 @@
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
#include "../i/private.h"
#include "dex/dex.h"
#define r_hash_adler32 __adler32
#include "../../hash/adler32.c"

View file

@ -7,6 +7,7 @@
#include <r_bin.h>
#include <r_io.h>
#include <r_cons.h>
#include "../i/private.h"
#include "elf/elf.h"
static RBinInfo* info(RBinFile *bf);

View file

@ -4,6 +4,7 @@
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
#include "../i/private.h"
#include "mach0/mach0.h"
#include "objc/mach0_classes.h"

View file

@ -4,6 +4,7 @@
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
#include "../i/private.h"
#include "pe/pe.h"
static Sdb* get_sdb (RBinFile *bf) {

View file

@ -4,6 +4,7 @@
#include <r_types.h>
#include <r_lib.h>
#include <r_bin.h>
#include "../i/private.h"
#include "psxexe/psxexe.h"
static bool check_bytes(const ut8 *buf, ut64 length) {

View file

@ -664,89 +664,37 @@ R_API void r_bin_force_plugin(RBin *bin, const char *pname);
R_API const char *r_bin_string_type(int type);
/* file.c */
R_API RBinFile *r_bin_file_new(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr);
R_API bool r_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 baseaddr, ut64 loadaddr, RBinXtrData *data);
R_API RBinFile *r_bin_file_new_from_bytes(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname, const char *xtrname, ut64 offset, bool steal_ptr);
R_API RBinFile *r_bin_file_new_from_fd(RBin *bin, int fd, RBinFileOptions *options);
R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits, const char *name);
R_API RBinObject *r_bin_file_object_find_by_id(RBinFile *binfile, ut32 binobj_id);
R_API RList *r_bin_file_get_strings(RBinFile *a, int min, int dump, int raw);
R_API void r_bin_file_get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 from, ut64 to);
R_API RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id);
R_API RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 binfile_id);
R_API int r_bin_file_object_add(RBinFile *binfile, RBinObject *o);
R_API int r_bin_file_delete_all(RBin *bin);
R_API int r_bin_file_delete(RBin *bin, ut32 bin_fd);
R_API RBinFile *r_bin_file_find_by_fd(RBin *bin, ut32 bin_fd);
R_API RBinFile *r_bin_file_find_by_name(RBin *bin, const char *name);
R_API RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx);
R_API bool r_bin_file_set_cur_binfile_obj(RBin *bin, RBinFile *bf, RBinObject *obj);
R_API int r_bin_file_set_cur_binfile(RBin *bin, RBinFile *bf);
R_API int r_bin_file_set_cur_by_name(RBin *bin, const char *name);
R_API RBinObject *r_bin_file_object_get_cur(RBinFile *binfile);
R_API int r_bin_file_ref(RBin *bin, RBinFile *a);
R_API void r_bin_file_free(void /*RBinFile*/ *bf_);
R_API RBinFile *r_bin_file_create_append(RBin *bin, const char *file, const ut8 *bytes, ut64 sz, ut64 file_sz, int rawstr, int fd, const char *xtrname, bool steal_ptr);
R_API RBinFile *r_bin_file_xtr_load_bytes(RBin *bin, RBinXtrPlugin *xtr, const char *filename, const ut8 *bytes, ut64 sz, ut64 file_sz, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr);
R_API bool r_bin_file_set_bytes(RBinFile *binfile, const ut8 *bytes, ut64 sz, bool steal_ptr);
R_API RBinPlugin *r_bin_file_cur_plugin(RBinFile *binfile);
R_API int r_bin_file_deref_by_bind(RBinBind *binb);
R_API int r_bin_file_deref(RBin *bin, RBinFile *a);
R_API int r_bin_file_ref_by_bind(RBinBind *binb);
R_API int r_bin_file_ref(RBin *bin, RBinFile *a);
R_API bool r_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 baseaddr, ut64 loadaddr, RBinXtrData *xtr_data);
R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits, const char *name);
R_API int r_bin_file_delete(RBin *bin, ut32 bin_fd);
R_API int r_bin_file_delete_all(RBin *bin);
R_API int r_bin_file_set_cur_by_fd(RBin *bin, ut32 bin_fd);
R_API RBinFile *r_bin_file_find_by_fd(RBin *bin, ut32 bin_fd);
R_API RBinFile *r_bin_file_find_by_name(RBin *bin, const char *name);
R_API RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx);
R_API RBinPlugin *r_bin_file_cur_plugin(RBinFile *binfile);
/* section */
R_API void r_bin_section_free(RBinSection *bs);
/* obj.c */
R_API void r_bin_object_free(void /*RBinObject*/ *o_);
R_API ut64 r_bin_object_get_baddr(RBinObject *o);
R_API void r_bin_object_filter_strings(RBinObject *bo);
R_API void r_bin_object_set_baddr(RBinObject *o, ut64 baddr);
R_API RBinObject *r_bin_object_new(RBinFile *binfile, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz);
R_API int r_bin_object_set_items(RBinFile *binfile, RBinObject *o);
R_API RBinObject *r_bin_object_get_cur(RBin *bin);
R_API RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *arch, int bits, const char *name);
R_API bool r_bin_object_delete(RBin *bin, ut32 binfile_id, ut32 binobj_id);
R_API void r_bin_object_delete_items(RBinObject *o);
R_API const char *r_bin_entry_type_string(int etype);
R_API char *r_bin_demangle(RBinFile *binfile, const char *lang, const char *str, ut64 vaddr);
R_API int r_bin_demangle_type(const char *str);
R_API const char *r_bin_lang_tostring (int lang);
R_API char *r_bin_demangle_java(const char *str);
R_API char *r_bin_demangle_cxx(RBinFile *binfile, const char *str, ut64 vaddr);
R_API char *r_bin_demangle_msvc(const char *str);
R_API char *r_bin_demangle_swift(const char *s, bool syscmd);
R_API char *r_bin_demangle_objc(RBinFile *binfile, const char *sym);
R_API char *r_bin_demangle_rust(RBinFile *binfile, const char *str, ut64 vaddr);
R_API int r_bin_lang_type(RBinFile *binfile, const char *def, const char *sym);
R_API bool r_bin_lang_objc(RBinFile *binfile);
R_API bool r_bin_lang_swift(RBinFile *binfile);
R_API bool r_bin_lang_cxx(RBinFile *binfile);
R_API bool r_bin_lang_msvc(RBinFile *binfile);
R_API bool r_bin_lang_dlang(RBinFile *binfile);
R_API bool r_bin_lang_rust(RBinFile *binfile);
R_API const char *r_bin_get_meth_flag_string(ut64 flag, bool compact);
// TODO: rename to r_bin_file_get_class() etc
R_API RBinClass *r_bin_class_get(RBinFile *binfile, const char *name);
R_API RBinClass *r_bin_class_new(RBinFile *binfile, const char *name, const char *super, int view);
R_API void r_bin_class_free(RBinClass *c);
R_API RBinSymbol *r_bin_class_add_method(RBinFile *binfile, const char *classname, const char *name, int nargs);
R_API void r_bin_class_add_field(RBinFile *binfile, const char *classname, const char *name);
R_API RList *r_bin_classes_from_symbols(RBinFile *bf, RBinObject *o);
R_API RBinSection *r_bin_get_section_at(RBinObject *o, ut64 off, int va);
/* dbginfo.c */

View file

@ -256,6 +256,8 @@ typedef int (*PrintfCallback)(const char *str, ...);
#undef R_IPI
#endif
#define R_IPI
#ifdef R_HEAP
#undef R_HEAP
#endif

View file

@ -11,15 +11,12 @@ typedef struct java_op {
ut64 op_type;
} JavaOp;
#ifndef R_IPI
#define R_IPI
#endif
#define JAVA_OPS_COUNT 297
extern struct java_op JAVA_OPS[JAVA_OPS_COUNT];
R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *bytes, int len, char *output, int outlen);
R_API int r_java_disasm(RBinJavaObj *obj, ut64 addr, const ut8 *bytes, int len, char *output, int outlen);
R_API int r_java_assemble(ut64 addr, ut8 *bytes, const char *string);
//R_API void r_java_set_obj(RBinJavaObj *obj);
R_API void r_java_new_method (void);
R_API void r_java_new_method(void);
#endif

View file

@ -129,7 +129,7 @@ def main():
# handle functions definitions/declarations: do not use space before (
for i, l in enumerate(formatted_code):
if formatted_code[i].startswith('R_API ') or formatted_code[i].startswith('static '):
if formatted_code[i].startswith('R_API ') or formatted_code[i].startswith('static ') or formatted_code[i].startswith('R_IPI '):
formatted_code[i] = formatted_code[i].replace(' (', '(')
if modified_lines and i not in modified_lines: