Some code cleanup and asserts in RBin ##refactor

* libr/bin: no need to allocate RBinOptions on the heap
* bin: start using r_return_* around, that's just the beginning
* bin: remove io_owned since it's not used anywhere
* io: make r_io_bind return nothing
* bin: remove unused functions and simplify r_bin_load_io
r_bin_load_io was calling r_bin_load_io2 with UT64_MAX as sz parameter,
but r_bin_load_io2 just returns false if (st64)sz is less than 0, so
that call is actually useless and can be removed.
* bin/bin: fix some preconditions
* bin/open: fix precondition to check for bin and filename too
This commit is contained in:
Riccardo Schirone 2018-10-21 01:27:15 +02:00 committed by radare
parent c595ebe447
commit 64d16fc506
11 changed files with 249 additions and 357 deletions

View file

@ -997,24 +997,20 @@ int main(int argc, char **argv) {
r_bin_force_plugin (bin, forcebin);
r_bin_load_filter (bin, action);
RBinOptions *bo = r_bin_options_new (0LL, baddr, rawstr);
if (!bo) {
eprintf ("Could not create RBinOptions\n");
r_core_file_free (fh);
r_core_fini (&core);
return 1;
}
RBinOptions bo = {
.offset = 0LL,
.baseaddr = baddr,
.rawstr = rawstr,
.loadaddr = laddr,
.xtr_idx = xtr_idx,
.iofd = fd,
};
bo->loadaddr = laddr;
bo->xtr_idx = xtr_idx;
bo->iofd = fd;
if (!r_bin_open (bin, file, bo)) {
if (!r_bin_open (bin, file, &bo)) {
//if this return null means that we did not return a valid bin object
//but we have yet the chance that this file is a fat binary
if (!bin->cur || !bin->cur->xtr_data) {
eprintf ("r_bin: Cannot open file\n");
r_bin_options_free (bo);
r_core_file_free (fh);
r_core_fini (&core);
return 1;
@ -1045,7 +1041,6 @@ int main(int argc, char **argv) {
sdb_query (bin->cur->sdb, query);
}
}
r_bin_options_free (bo);
r_core_file_free (fh);
r_core_fini (&core);
return 0;
@ -1090,9 +1085,8 @@ int main(int argc, char **argv) {
r_config_set (core.config, "pdb.symstore", tmp);
R_FREE (tmp);
}
pdbopts.symbol_store_path = (char*) r_config_get (core.config, "pdb.symstore");
pdbopts.symbol_store_path = (char *)r_config_get (core.config, "pdb.symstore");
int r = r_bin_pdb_download (&core, isradjson, &actions_done, &pdbopts);
r_bin_options_free (bo);
r_core_file_free (fh);
r_core_fini (&core);
return r;
@ -1144,7 +1138,6 @@ int main(int argc, char **argv) {
r_cons_print ("}");
}
r_cons_flush ();
r_bin_options_free (bo);
r_core_file_free (fh);
r_core_fini (&core);
free (stdin_buf);

View file

@ -261,7 +261,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_API RList *r_bin_classes_from_symbols(RBinFile *bf, RBinObject *o) {
RBinSymbol *sym;
RListIter *iter;
RList *symbols = o->symbols;
@ -324,13 +324,13 @@ R_API RBinFile *r_bin_file_new(RBin *bin, const char *file, const ut8 *bytes, ut
}
int res = r_bin_file_set_bytes (binfile, bytes, sz, steal_ptr);
if (!res && steal_ptr) { // we own the ptr, free on error
free((void*) bytes);
free ((void *)bytes);
}
binfile->rbin = bin;
binfile->file = file? strdup (file): NULL;
binfile->file = file ? strdup (file) : NULL;
binfile->rawstr = rawstr;
binfile->fd = fd;
binfile->curxtr = r_bin_get_xtrplugin_by_name (bin, xtrname);
binfile->curxtr = xtrname ? r_bin_get_xtrplugin_by_name (bin, xtrname) : NULL;
binfile->sdb = sdb;
binfile->size = file_sz;
binfile->xtr_data = r_list_newf ((RListFree)r_bin_xtrdata_free);

View file

@ -32,17 +32,9 @@ static RBinPlugin *bin_static_plugins[] = { R_BIN_STATIC_PLUGINS, NULL };
static RBinXtrPlugin *bin_xtr_static_plugins[] = { R_BIN_XTR_STATIC_PLUGINS, NULL };
static RBinLdrPlugin *bin_ldr_static_plugins[] = { R_BIN_LDR_STATIC_PLUGINS, NULL };
// TODO: try to deprecate and just call the r_bin_load_io_at_offset_as_az
R_API bool r_bin_load_io (RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int xtr_idx, ut64 offset, const char *name) {
// adding file_sz to help reduce the performance impact on the system
// in this case the number of bytes read will be limited to 2MB
// (MIN_LOAD_SIZE)
// if it fails, the whole file is loaded.
const ut64 MAX_LOAD_SIZE = 0; // 0xfffff; //128 * (1 << 10 << 10);
int res = r_bin_load_io2 (bin, fd, baseaddr,
loadaddr, xtr_idx, offset, name, MAX_LOAD_SIZE);
return res? res: r_bin_load_io2 (bin, fd, baseaddr,
loadaddr, xtr_idx, offset, name, UT64_MAX);
R_API bool r_bin_load_io(RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int xtr_idx, ut64 offset, const char *name) {
r_return_val_if_fail (bin, false);
return r_bin_load_io2 (bin, fd, baseaddr, loadaddr, xtr_idx, offset, name, 0);
}
static int getoffset(RBin *bin, int type, int idx) {
@ -64,11 +56,7 @@ static const char *getname(RBin *bin, int type, int idx) {
}
static ut64 binobj_a2b(RBinObject *o, ut64 addr) {
return addr + (o? o->baddr_shift: 0);
}
R_API void r_bin_iobind(RBin *bin, RIO *io) {
r_io_bind (io, &bin->iob);
return o ? addr + o->baddr_shift : addr;
}
// TODO: move these two function do a different file
@ -97,7 +85,7 @@ R_API RBinXtrData *r_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size,
return data;
}
R_API const char *r_bin_string_type (int type) {
R_API const char *r_bin_string_type(int type) {
switch (type) {
case 'a': return "ascii";
case 'u': return "utf8";
@ -123,16 +111,20 @@ R_API void r_bin_xtrdata_free(void /*RBinXtrData*/ *data_) {
}
}
R_API RList* r_bin_raw_strings(RBinFile *bf, int min) {
R_API RList *r_bin_raw_strings(RBinFile *bf, int min) {
r_return_val_if_fail (bf, NULL);
return r_bin_file_get_strings (bf, min, 0, 2);
}
R_API RList* r_bin_dump_strings(RBinFile *a, int min, int raw) {
return r_bin_file_get_strings (a, min, 1, raw);
R_API RList *r_bin_dump_strings(RBinFile *bf, int min, int raw) {
r_return_val_if_fail (bf, NULL);
return r_bin_file_get_strings (bf, min, 1, raw);
}
/* This is very slow if there are lot of symbols */
R_API int r_bin_load_languages(RBinFile *binfile) {
r_return_val_if_fail (binfile, R_BIN_NM_NONE);
if (r_bin_lang_rust (binfile)) {
return R_BIN_NM_RUST;
}
@ -175,6 +167,8 @@ R_API void r_bin_info_free(RBinInfo *rb) {
}
R_API RBinImport *r_bin_import_clone(RBinImport *o) {
r_return_val_if_fail (o, NULL);
RBinImport *res = r_mem_dup (o, sizeof (*o));
if (res) {
res->name = R_STR_DUP (o->name);
@ -195,6 +189,8 @@ R_API void r_bin_import_free(void *_imp) {
}
R_API RBinSymbol *r_bin_symbol_clone(RBinSymbol *o) {
r_return_val_if_fail (o, NULL);
RBinSymbol *res = r_mem_dup (o, sizeof (*o));
if (!res) {
return NULL;
@ -226,57 +222,21 @@ R_API void r_bin_string_free(void *_str) {
// XXX - this is a rather hacky way to do things, there may need to be a better
// way.
R_API int r_bin_load(RBin *bin, const char *file, ut64 baseaddr, ut64 loadaddr, int xtr_idx, int fd, int rawstr) {
if (!bin) {
return false;
}
// ALIAS? return r_bin_load_as (bin, file, baseaddr, loadaddr,
// xtr_idx, fd, rawstr, 0, file);
r_return_val_if_fail (bin && bin->iob.io, false);
RIOBind *iob = &(bin->iob);
if (!iob) {
return false;
}
if (!iob->io) {
iob->io = r_io_new (); //wtf
if (!iob->io) {
return false;
}
bin->io_owned = true;
r_io_bind (iob->io, &bin->iob); //memleak?
iob = &bin->iob;
}
if (!iob->desc_get (iob->io, fd)) {
fd = iob->fd_open (iob->io, file, R_PERM_R, 0644);
}
bin->rawstr = rawstr;
// Use the current RIODesc otherwise r_io_map_select can swap them later on
if (fd < 0) {
if (bin->io_owned) {
r_io_free (iob->io);
memset (&bin->iob, 0, sizeof (bin->iob));
bin->io_owned = false;
}
return false;
}
//Use the current RIODesc otherwise r_io_map_select can swap them later on
return r_bin_load_io (bin, fd, baseaddr, loadaddr, xtr_idx, 0, NULL);
}
R_API int r_bin_load_as(RBin *bin, const char *file, ut64 baseaddr,
ut64 loadaddr, int xtr_idx, int fd, int rawstr,
int fileoffset, const char *name) {
RIOBind *iob = &(bin->iob);
if (!iob || !iob->io) {
return false;
}
if (fd < 0) {
fd = iob->fd_open (iob->io, file, R_PERM_R, 0644);
}
if (fd < 0) {
return false;
}
return r_bin_load_io (bin, fd, baseaddr, loadaddr, xtr_idx, fileoffset, name);
}
R_API int r_bin_reload(RBin *bin, int fd, ut64 baseaddr) {
RIOBind *iob = &(bin->iob);
RList *the_obj_list = NULL;
@ -285,10 +245,8 @@ R_API int r_bin_reload(RBin *bin, int fd, ut64 baseaddr) {
ut8 *buf_bytes = NULL;
ut64 sz = UT64_MAX;
if (!iob || !iob->io) {
res = false;
goto error;
}
r_return_val_if_fail (bin && iob && iob->io, false);
const char *name = iob->fd_get_name (iob->io, fd);
bf = r_bin_file_find_by_name (bin, name);
if (!bf) {
@ -309,8 +267,7 @@ R_API int r_bin_reload(RBin *bin, int fd, ut64 baseaddr) {
res = false;
goto error;
}
// TODO: deprecate, the code in the else should be enough
#if 1
// TODO: deprecate, the code in the else should be enough
if (sz == UT64_MAX && iob->fd_is_dbg (iob->io, fd)) {
// attempt a local open and read
// This happens when a plugin like debugger does not have a
@ -359,9 +316,6 @@ R_API int r_bin_reload(RBin *bin, int fd, ut64 baseaddr) {
}
bool yes_plz_steal_ptr = true;
r_bin_file_set_bytes (bf, buf_bytes, sz, yes_plz_steal_ptr);
#else
bf->buf = r_buf_new_with_io (iob, fd);
#endif
if (r_list_length (the_obj_list) == 1) {
RBinObject *old_o = (RBinObject *)r_list_get_n (the_obj_list, 0);
@ -392,9 +346,8 @@ R_API bool r_bin_load_io2(RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int x
RBinFile *binfile = NULL;
int tfd = -1;
if (!io || (fd < 0) || (st64)sz < 0) {
return false;
}
r_return_val_if_fail (bin && io && fd >= 0 && (st64)sz >= 0, false);
bool is_debugger = iob->fd_is_dbg (io, fd);
const char *fname = iob->fd_get_name (io, fd);
if (loadaddr == UT64_MAX) {
@ -494,11 +447,12 @@ R_API bool r_bin_load_io2(RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int x
R_API RBinPlugin *r_bin_get_binplugin_by_name(RBin *bin, const char *name) {
RBinPlugin *plugin;
RListIter *it;
if (bin && name) {
r_list_foreach (bin->plugins, it, plugin) {
if (!strcmp (plugin->name, name)) {
return plugin;
}
r_return_val_if_fail (bin && name, NULL);
r_list_foreach (bin->plugins, it, plugin) {
if (!strcmp (plugin->name, name)) {
return plugin;
}
}
return NULL;
@ -507,9 +461,9 @@ R_API RBinPlugin *r_bin_get_binplugin_by_name(RBin *bin, const char *name) {
R_API RBinPlugin *r_bin_get_binplugin_by_bytes(RBin *bin, const ut8 *bytes, ut64 sz) {
RBinPlugin *plugin;
RListIter *it;
if (!bin || !bytes) {
return NULL;
}
r_return_val_if_fail (bin && bytes, NULL);
r_list_foreach (bin->plugins, it, plugin) {
if (plugin->check_bytes && plugin->check_bytes (bytes, sz)) {
return plugin;
@ -521,9 +475,9 @@ R_API RBinPlugin *r_bin_get_binplugin_by_bytes(RBin *bin, const ut8 *bytes, ut64
R_API RBinXtrPlugin *r_bin_get_xtrplugin_by_name(RBin *bin, const char *name) {
RBinXtrPlugin *xtr;
RListIter *it;
if (!bin || !name) {
return NULL;
}
r_return_val_if_fail (bin && name, NULL);
// TODO: use a hashtable here
r_list_foreach (bin->binxtrs, it, xtr) {
if (!strcmp (xtr->name, name)) {
@ -537,6 +491,7 @@ R_API RBinXtrPlugin *r_bin_get_xtrplugin_by_name(RBin *bin, const char *name) {
// TODO: deprecate
R_API RBinPlugin *r_bin_get_binplugin_any(RBin *bin) {
r_return_val_if_fail (bin, NULL);
return r_bin_get_binplugin_by_name (bin, "any");
}
@ -551,6 +506,9 @@ static void r_bin_plugin_free(RBinPlugin *p) {
R_API bool r_bin_add(RBin *bin, RBinPlugin *foo) {
RListIter *it;
RBinPlugin *plugin;
r_return_val_if_fail (bin && foo, false);
if (foo->init) {
foo->init (bin->user);
}
@ -569,6 +527,8 @@ R_API bool r_bin_ldr_add(RBin *bin, RBinLdrPlugin *foo) {
RListIter *it;
RBinLdrPlugin *ldr;
r_return_val_if_fail (bin && foo, false);
if (foo->init) {
foo->init (bin->user);
}
@ -586,6 +546,8 @@ R_API bool r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo) {
RListIter *it;
RBinXtrPlugin *xtr;
r_return_val_if_fail (bin && foo, false);
if (foo->init) {
foo->init (bin->user);
}
@ -603,9 +565,6 @@ R_API void *r_bin_free(RBin *bin) {
if (!bin) {
return NULL;
}
if (bin->io_owned) {
r_io_free (bin->iob.io);
}
bin->file = NULL;
free (bin->force);
free (bin->srcdir);
@ -734,6 +693,8 @@ R_API int r_bin_list_plugin(RBin *bin, const char* name, int json) {
RBinPlugin *bp;
RBinXtrPlugin *bx;
r_return_val_if_fail (bin && name, false);
r_list_foreach (bin->plugins, it, bp) {
if (!r_str_cmp (name, bp->name, strlen (name))) {
continue;
@ -753,28 +714,33 @@ R_API int r_bin_list_plugin(RBin *bin, const char* name, int json) {
/* returns the base address of bin or UT64_MAX in case of errors */
R_API ut64 r_bin_get_baddr(RBin *bin) {
r_return_val_if_fail (bin, UT64_MAX);
RBinObject *o = r_bin_cur_object (bin);
return r_bin_object_get_baddr (o);
}
/* returns the load address of bin or UT64_MAX in case of errors */
R_API ut64 r_bin_get_laddr(RBin *bin) {
r_return_val_if_fail (bin, UT64_MAX);
RBinObject *o = r_bin_cur_object (bin);
return o? o->loadaddr: UT64_MAX;
return o ? o->loadaddr : UT64_MAX;
}
R_API void r_bin_set_baddr(RBin *bin, ut64 baddr) {
r_return_if_fail (bin);
RBinObject *o = r_bin_cur_object (bin);
r_bin_object_set_baddr (o, baddr);
// XXX - update all the infos?
}
R_API ut64 r_bin_get_boffset(RBin *bin) {
r_return_val_if_fail (bin, UT64_MAX);
RBinObject *o = r_bin_cur_object (bin);
return o? o->boffset: UT64_MAX;
return o ? o->boffset : UT64_MAX;
}
R_API RBinAddr *r_bin_get_sym(RBin *bin, int sym) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
if (sym < 0 || sym >= R_BIN_SYM_LAST) {
return NULL;
@ -784,31 +750,37 @@ R_API RBinAddr *r_bin_get_sym(RBin *bin, int sym) {
// XXX: those accessors are redundant
R_API RList *r_bin_get_entries(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->entries: NULL;
return o ? o->entries : NULL;
}
R_API RList *r_bin_get_fields(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->fields: NULL;
return o ? o->fields : NULL;
}
R_API RList *r_bin_get_imports(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->imports: NULL;
return o ? o->imports : NULL;
}
R_API RBinInfo *r_bin_get_info(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->info: NULL;
return o ? o->info : NULL;
}
R_API RList *r_bin_get_libs(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->libs: NULL;
return o ? o->libs : NULL;
}
R_API RList * r_bin_patch_relocs(RBin *bin) {
R_API RList *r_bin_patch_relocs(RBin *bin) {
r_return_val_if_fail (bin, NULL);
static bool first = true;
RBinObject *o = r_bin_cur_object (bin);
if (!o) {
@ -834,13 +806,15 @@ R_API RList * r_bin_patch_relocs(RBin *bin) {
}
R_API RList *r_bin_get_relocs(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->relocs: NULL;
return o ? o->relocs : NULL;
}
R_API RList *r_bin_get_sections(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->sections: NULL;
return o ? o->sections : NULL;
}
// TODO: Move into section.c and rename it to r_io_section_get_at ()
@ -848,15 +822,14 @@ R_API RBinSection *r_bin_get_section_at(RBinObject *o, ut64 off, int va) {
RBinSection *section;
RListIter *iter;
ut64 from, to;
if (o) {
// TODO: must be O(1) .. use sdb here
r_list_foreach (o->sections, iter, section) {
from = va? binobj_a2b (o, section->vaddr): section->paddr;
to = va? (binobj_a2b (o, section->vaddr) + section->vsize) :
(section->paddr + section->size);
if (off >= from && off < to) {
return section;
}
r_return_val_if_fail (o, NULL);
// TODO: must be O(1) .. use sdb here
r_list_foreach (o->sections, iter, section) {
from = va ? binobj_a2b (o, section->vaddr) : section->paddr;
to = va ? (binobj_a2b (o, section->vaddr) + section->vsize) : (section->paddr + section->size);
if (off >= from && off < to) {
return section;
}
}
return NULL;
@ -892,8 +865,9 @@ R_API RList *r_bin_reset_strings(RBin *bin) {
}
R_API RList *r_bin_get_strings(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->strings: NULL;
return o ? o->strings : NULL;
}
R_API int r_bin_is_string(RBin *bin, ut64 va) {
@ -916,6 +890,7 @@ R_API int r_bin_is_string(RBin *bin, ut64 va) {
//callee must not free the symbol
R_API RBinSymbol *r_bin_get_symbol_at_vaddr(RBin *bin, ut64 addr) {
r_return_val_if_fail (bin, NULL);
//use skiplist here
RList *symbols = r_bin_get_symbols (bin);
RListIter *iter;
@ -930,6 +905,7 @@ R_API RBinSymbol *r_bin_get_symbol_at_vaddr(RBin *bin, ut64 addr) {
//callee must not free the symbol
R_API RBinSymbol *r_bin_get_symbol_at_paddr(RBin *bin, ut64 addr) {
r_return_val_if_fail (bin, NULL);
//use skiplist here
RList *symbols = r_bin_get_symbols (bin);
RListIter *iter;
@ -943,26 +919,31 @@ R_API RBinSymbol *r_bin_get_symbol_at_paddr(RBin *bin, ut64 addr) {
}
R_API RList *r_bin_get_symbols(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->symbols: NULL;
return o ? o->symbols : NULL;
}
R_API RList *r_bin_get_mem(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->mem: NULL;
return o ? o->mem : NULL;
}
R_API int r_bin_is_big_endian(RBin *bin) {
r_return_val_if_fail (bin, -1);
RBinObject *o = r_bin_cur_object (bin);
return (o && o->info)? o->info->big_endian: -1;
return (o && o->info) ? o->info->big_endian : -1;
}
R_API int r_bin_is_stripped(RBin *bin) {
r_return_val_if_fail (bin, -1);
RBinObject *o = r_bin_cur_object (bin);
return o? (R_BIN_DBG_STRIPPED & o->info->dbg_info): 1;
return o ? (R_BIN_DBG_STRIPPED & o->info->dbg_info) : 1;
}
R_API int r_bin_is_static(RBin *bin) {
r_return_val_if_fail (bin, false);
RBinObject *o = r_bin_cur_object (bin);
if (o && r_list_length (o->libs) > 0) {
return R_BIN_DBG_STATIC & o->info->dbg_info;
@ -972,18 +953,21 @@ R_API int r_bin_is_static(RBin *bin) {
// TODO: Integrate with r_bin_dbg */
R_API int r_bin_has_dbg_linenums(RBin *bin) {
r_return_val_if_fail (bin, false);
RBinObject *o = r_bin_cur_object (bin);
return o? (R_BIN_DBG_LINENUMS & o->info->dbg_info): false;
return o ? (R_BIN_DBG_LINENUMS & o->info->dbg_info) : false;
}
R_API int r_bin_has_dbg_syms(RBin *bin) {
r_return_val_if_fail (bin, false);
RBinObject *o = r_bin_cur_object (bin);
return o? (R_BIN_DBG_SYMS & o->info->dbg_info): false;
return o ? (R_BIN_DBG_SYMS & o->info->dbg_info) : false;
}
R_API int r_bin_has_dbg_relocs(RBin *bin) {
r_return_val_if_fail (bin, false);
RBinObject *o = r_bin_cur_object (bin);
return o? (R_BIN_DBG_RELOCS & o->info->dbg_info): false;
return o ? (R_BIN_DBG_RELOCS & o->info->dbg_info) : false;
}
R_API RBin *r_bin_new() {
@ -1003,7 +987,6 @@ R_API RBin *r_bin_new() {
bin->strpurge = NULL;
bin->want_dbginfo = true;
bin->cur = NULL;
bin->io_owned = false;
bin->ids = r_id_storage_new (0, ST32_MAX);
/* bin parsers */
@ -1039,6 +1022,8 @@ R_API RBin *r_bin_new() {
}
R_API int r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name) {
r_return_val_if_fail (bin && arch, false);
RBinFile *binfile = r_bin_file_find_by_arch_bits (bin, arch, bits, name);
RBinObject *obj = NULL;
if (binfile) {
@ -1078,9 +1063,11 @@ R_API int r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name
}
R_API int r_bin_select(RBin *bin, const char *arch, int bits, const char *name) {
r_return_val_if_fail (bin, false);
RBinFile *cur = r_bin_cur (bin);
RBinObject *obj = NULL;
name = !name && cur? cur->file: name;
name = !name && cur ? cur->file : name;
RBinFile *binfile = r_bin_file_find_by_arch_bits (bin, arch, bits, name);
if (binfile && name) {
obj = r_bin_object_find_by_arch_bits (binfile, arch, bits, name);
@ -1089,11 +1076,14 @@ R_API int r_bin_select(RBin *bin, const char *arch, int bits, const char *name)
}
R_API int r_bin_select_object(RBinFile *binfile, const char *arch, int bits, const char *name) {
r_return_val_if_fail (binfile, false);
RBinObject *obj = r_bin_object_find_by_arch_bits (binfile, arch, bits, name);
return r_bin_file_set_cur_binfile_obj (binfile->rbin, binfile, obj);
}
R_API int r_bin_select_by_ids(RBin *bin, ut32 binfile_id, ut32 binobj_id) {
r_return_val_if_fail (bin, false);
RBinFile *binfile = NULL;
RBinObject *obj = NULL;
@ -1177,6 +1167,8 @@ static void list_xtr_archs(RBin *bin, int mode) {
}
R_API void r_bin_list_archs(RBin *bin, int mode) {
r_return_if_fail (bin);
RListIter *iter;
int i = 0;
char unk[128];
@ -1330,30 +1322,8 @@ R_API RBuffer *r_bin_create(RBin *bin, const ut8 *code, int codelen,
R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RList *files) {
if (!strcmp (type, "zip")) {
#if 0
int zep = 0;
struct zip * z = zip_open (file, 8 | 1, &zep);
if (z) {
RListIter *iter;
const char *f;
eprintf ("zip file created\n");
r_list_foreach (files, iter, f) {
struct zip_source *zs = NULL;
zs = zip_source_file (z, f, 0, 1024);
if (zs) {
eprintf ("ADD %s\n", f);
zip_add (z, f, zs);
zip_source_free (zs);
} else {
eprintf ("Cannot find file %s\n", f);
}
eprintf ("zS %p\n", zs);
}
zip_close (z);
} else {
eprintf ("Cannot create zip file\n");
}
#endif
// XXX: implement me
r_warn_if_reached ();
} else if (!strcmp (type, "fat")) {
const char *f;
RListIter *iter;
@ -1412,6 +1382,7 @@ R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RLis
}
R_API RBinObject *r_bin_get_object(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
if (o) {
o->referenced++;
@ -1420,8 +1391,9 @@ R_API RBinObject *r_bin_get_object(RBin *bin) {
}
R_API RList * /*<RBinClass>*/ r_bin_get_classes(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinObject *o = r_bin_cur_object (bin);
return o? o->classes: NULL;
return o ? o->classes : NULL;
}
R_API void r_bin_class_free(RBinClass *c) {
@ -1470,9 +1442,8 @@ R_API RBinClass *r_bin_class_new(RBinFile *binfile, const char *name,
}
R_API RBinClass *r_bin_class_get(RBinFile *binfile, const char *name) {
if (!binfile || !binfile->o || !name) {
return NULL;
}
r_return_val_if_fail (binfile && binfile->o && name, NULL);
RBinClass *c;
RListIter *iter;
RList *list = binfile->o->classes;
@ -1485,6 +1456,8 @@ R_API RBinClass *r_bin_class_get(RBinFile *binfile, const char *name) {
}
R_API 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);
if (!c) {
c = r_bin_class_new (binfile, classname, NULL, 0);
@ -1517,22 +1490,20 @@ R_API void r_bin_class_add_field(RBinFile *binfile, const char *classname, const
/* returns vaddr, rebased with the baseaddr of binfile, if va is enabled for
* bin, paddr otherwise */
R_API ut64 r_bin_file_get_vaddr(RBinFile *binfile, ut64 paddr, ut64 vaddr) {
r_return_val_if_fail (binfile, paddr);
int use_va = 0;
if (binfile && binfile->o && binfile->o->info) {
if (binfile->o && binfile->o->info) {
use_va = binfile->o->info->has_va;
}
return use_va? binobj_a2b (binfile->o, vaddr): paddr;
return use_va ? binobj_a2b (binfile->o, vaddr) : paddr;
}
/* returns vaddr, rebased with the baseaddr of bin, if va is enabled for bin,
* paddr otherwise */
R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr) {
if (!bin) {
return UT64_MAX;
}
if (paddr == UT64_MAX) {
return UT64_MAX;
}
r_return_val_if_fail (bin && paddr != UT64_MAX, UT64_MAX);
if (!bin->cur) {
return paddr;
}
@ -1552,34 +1523,37 @@ R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr) {
}
R_API ut64 r_bin_a2b(RBin *bin, ut64 addr) {
r_return_val_if_fail (bin, UT64_MAX);
RBinObject *o = r_bin_cur_object (bin);
return o? o->baddr_shift + addr: addr;
return binobj_a2b (o, addr);
}
R_API ut64 r_bin_get_size(RBin *bin) {
r_return_val_if_fail (bin, UT64_MAX);
RBinObject *o = r_bin_cur_object (bin);
return o ? o->size : 0;
}
R_API RBinFile *r_bin_cur(RBin *bin) {
return bin? bin->cur: NULL;
r_return_val_if_fail (bin, NULL);
return bin->cur;
}
R_API RBinObject *r_bin_cur_object(RBin *bin) {
r_return_val_if_fail (bin, NULL);
RBinFile *binfile = r_bin_cur (bin);
return binfile? binfile->o: NULL;
return binfile ? binfile->o : NULL;
}
R_API void r_bin_force_plugin(RBin *bin, const char *name) {
r_return_if_fail (bin);
free (bin->force);
bin->force = (name && *name)? strdup (name): NULL;
bin->force = (name && *name) ? strdup (name) : NULL;
}
R_API int r_bin_read_at(RBin *bin, ut64 addr, ut8 *buf, int size) {
RIOBind *iob;
if (!bin || !(iob = &(bin->iob))) {
return false;
}
r_return_val_if_fail (bin, false);
RIOBind *iob = &(bin->iob);
return iob->read_at (iob->io, addr, buf, size);
}

View file

@ -105,11 +105,9 @@ R_API int r_bin_object_set_items(RBinFile *binfile, RBinObject *o) {
RBinObject *old_o;
RBinPlugin *cp;
int i, minlen;
// int type;
if (!binfile || !o || !o->plugin) {
return false;
}
r_return_val_if_fail (binfile && o && o->plugin, false);
RBin *bin = binfile->rbin;
old_o = binfile->o;
cp = o->plugin;
@ -264,6 +262,7 @@ R_API int r_bin_object_set_items(RBinFile *binfile, RBinObject *o) {
}
R_API 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));
}
@ -321,10 +320,13 @@ R_API RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *
RBinObject *obj = NULL;
RListIter *iter = NULL;
RBinInfo *info = NULL;
r_return_val_if_fail (binfile && arch && name, NULL);
r_list_foreach (binfile->objs, iter, obj) {
info = obj->info;
if (info && info->arch && info->file &&
(bits == info->bits) &&
(bits == info->bits) &&
!strcmp (info->arch, arch) &&
!strcmp (info->file, name)) {
break;
@ -335,7 +337,8 @@ R_API RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *
}
R_API ut64 r_bin_object_get_baddr(RBinObject *o) {
return o? o->baddr + o->baddr_shift: UT64_MAX;
r_return_val_if_fail (o, UT64_MAX);
return o->baddr + o->baddr_shift;
}
R_API int r_bin_object_delete(RBin *bin, ut32 binfile_id, ut32 binobj_id) {
@ -343,15 +346,17 @@ R_API int r_bin_object_delete(RBin *bin, ut32 binfile_id, ut32 binobj_id) {
RBinObject *obj = NULL;
int res = false;
r_return_val_if_fail (bin, false);
if (binfile_id == UT32_MAX) {
binfile = r_bin_file_find_by_object_id (bin, binobj_id);
obj = binfile? r_bin_file_object_find_by_id (binfile, binobj_id): NULL;
obj = binfile ? r_bin_file_object_find_by_id (binfile, binobj_id) : NULL;
} else if (binobj_id == UT32_MAX) {
binfile = r_bin_file_find_by_id (bin, binfile_id);
obj = binfile? binfile->o: NULL;
obj = binfile ? binfile->o : NULL;
} else {
binfile = r_bin_file_find_by_id (bin, binfile_id);
obj = binfile? r_bin_file_object_find_by_id (binfile, binobj_id): NULL;
obj = binfile ? r_bin_file_object_find_by_id (binfile, binobj_id) : NULL;
}
if (binfile && bin->cur == binfile) {
bin->cur = NULL;
@ -371,13 +376,15 @@ R_API int r_bin_object_delete(RBin *bin, ut32 binfile_id, ut32 binobj_id) {
}
R_API void r_bin_object_set_baddr(RBinObject *o, ut64 baddr) {
if (!o || baddr == UT64_MAX) {
return;
r_return_if_fail (o);
if (baddr != UT64_MAX) {
o->baddr_shift = baddr - o->baddr;
}
o->baddr_shift = baddr - o->baddr;
}
R_API void r_bin_object_filter_strings (RBinObject *bo) {
R_API void r_bin_object_filter_strings(RBinObject *bo) {
r_return_if_fail (bo);
RList *strings = bo->strings;
RBinString *ptr;
RListIter *iter;
@ -407,4 +414,3 @@ R_API void r_bin_object_filter_strings (RBinObject *bo) {
}
}
}

View file

@ -2,33 +2,17 @@
#include <r_bin.h>
R_API RBinOptions *r_bin_options_new (ut64 offset, ut64 baddr, int rawstr) {
RBinOptions *bo = R_NEW0 (RBinOptions);
if (bo) {
bo->loadaddr = UT64_MAX;
bo->offset = offset;
bo->baseaddr = baddr;
bo->rawstr = rawstr;
bo->iofd = -1;
}
return bo;
}
R_API void r_bin_options_free(RBinOptions *bo) {
free (bo->name);
free (bo);
}
R_API int r_bin_open(RBin *bin, const char *filename, RBinOptions *bo) {
ut64 baddr = 0LL, laddr = 0LL;
int iofd = -1, rawstr = 0, xtr_idx = 0;
if (bo) {
baddr = bo->baseaddr;
laddr = bo->loadaddr;
xtr_idx = bo->xtr_idx;
iofd = bo->iofd;
rawstr = bo->rawstr;
}
r_return_val_if_fail (bin && filename && bo, -1);
baddr = bo->baseaddr;
laddr = bo->loadaddr;
xtr_idx = bo->xtr_idx;
iofd = bo->iofd;
rawstr = bo->rawstr;
if (r_bin_load (bin, filename, baddr, laddr, xtr_idx, iofd, rawstr)) {
int id = bin->cur->id; // TODO rename to bd?
r_id_storage_set (bin->ids, bin->cur, id);
@ -37,7 +21,7 @@ R_API int r_bin_open(RBin *bin, const char *filename, RBinOptions *bo) {
return -1;
}
R_API RBinFile *r_bin_get_file (RBin *bin, int bd) {
R_API RBinFile *r_bin_get_file(RBin *bin, int bd) {
return r_id_storage_take (bin->ids, bd);
}
@ -50,50 +34,3 @@ R_API bool r_bin_close(RBin *bin, int bd) {
}
return false;
}
#if 0
// usage example
var bin = new RBin ();
int fd = bin.open("/bin/ls", null);
var binfile = bin.get_file(fd);
binfile.symbols.foreach(sym => {
print(sym.name);
});
bin.close(fd);
// binfile is invalid here
int bd = bin->cur;
r_list_foreach (r_bin_list (bin, bd, R_BIN_REQ_SYMBOLS), iter, sym) {
eprintf ("Symbol: %s\n", sym->name);
}
bool cb(void *user, void *data) {
}
r_bin_foreach (bin, bd, R_BIN_REQ_SYMBOLS, cb, user);
#if 0
// TODO: rename to r_bin_cmd() to match r2 commands ?
// TODO: use this api in r2
// TODO: add queryf api (or cmdf)
R_API bool r_bin_query(RBin *bin, const char *query) {
bool ret = false;
char *q = strdup (query);
const char *at = strchr (q, '@');
if (at) {
*at++ = 0;
}
if (!strcmp (q, "s")) {
// symbols
ret = true;
} else {
eprintf ("Unknown command\n");
}
return ret;
// r_bin_query (bin, "o@0x8048080"); // return symbol at given address
// r_bin_query (bin, "s@0x8048080"); // return symbol at given address
// r_bin_query (bin, "z/str/"); // return list subset of strings matching
// r_bin_query (bin, "i\"printf\""); // imports
}
#endif
#endif

View file

@ -291,7 +291,6 @@ static int r_core_file_do_load_for_debug(RCore *r, ut64 baseaddr, const char *fi
RIODesc *desc = cf ? r_io_desc_get (r->io, cf->fd) : NULL;
RBinFile *binfile = NULL;
RBinPlugin *plugin;
RBinOptions *bo = NULL;
int xtr_idx = 0; // if 0, load all if xtr is used
// TODO : Honor file.path eval var too?
@ -314,21 +313,20 @@ static int r_core_file_do_load_for_debug(RCore *r, ut64 baseaddr, const char *fi
}
#endif
int fd = cf ? cf->fd : -1;
RBinOptions bo = {
.offset = 0LL,
.baseaddr = baseaddr,
.rawstr = false,
.xtr_idx = xtr_idx,
.iofd = fd,
.loadaddr = UT64_MAX,
};
bo = r_bin_options_new (0LL, baseaddr, false);
if (!bo) {
eprintf ("Failed to create bin options\n");
return false;
}
bo->xtr_idx = xtr_idx;
bo->iofd = fd;
if (r_bin_open (r->bin, filenameuri, bo) == -1) {
if (r_bin_open (r->bin, filenameuri, &bo) == -1) {
eprintf ("RBinLoad: Cannot open %s\n", filenameuri);
if (r_config_get_i (r->config, "bin.rawstr")) {
bo->rawstr = true;
if (r_bin_open (r->bin, filenameuri, bo) == -1) {
r_bin_options_free (bo);
bo.rawstr = true;
if (r_bin_open (r->bin, filenameuri, &bo) == -1) {
return false;
}
}
@ -367,7 +365,6 @@ static int r_core_file_do_load_for_debug(RCore *r, ut64 baseaddr, const char *fi
r_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ; wx `ph adler32 $s-12 @12` @8)\"\n");
}
r_bin_options_free (bo);
return true;
}

View file

@ -256,8 +256,7 @@ static void cmd_search_bin(RCore *core, RInterval itv) {
r_io_read_at (core->io, from, buf, sz);
plug = r_bin_get_binplugin_by_bytes (core->bin, buf, sz);
if (plug) {
r_cons_printf ("0x%08"PFMT64x " %s\n", from, plug->name);
// TODO: load the bin and calculate its size
r_cons_printf ("0x%08" PFMT64x " %s\n", from, plug->name);
if (plug->size) {
r_bin_load_io2 (core->bin, core->file->fd,
0, 0, 0, core->offset, plug->name, 4096);
@ -2477,10 +2476,10 @@ static ut8 *v_writebuf(RCore *core, RList *nums, int len, char ch, int bsize) {
}
// maybe useful as in util/big.c .?
static void incBuffer (ut8 *buf, int bufsz) {
static void incBuffer(ut8 *buf, int bufsz) {
int i = 0;
while (i < bufsz) {
buf[i] ++;
buf[i]++;
if (!buf[i]) {
i++;
continue;
@ -2490,7 +2489,7 @@ static void incBuffer (ut8 *buf, int bufsz) {
// may overflow/hang/end/stop/whatever here
}
static void search_collisions (RCore *core, const char *hashName, const ut8 *hashValue, int hashLength) {
static void search_collisions(RCore *core, const char *hashName, const ut8 *hashValue, int hashLength) {
ut8 R_ALIGNED(8) cmphash[128];
int i, algoType = R_HASH_CRC32;
int bufsz = core->blocksize;

View file

@ -320,7 +320,6 @@ typedef struct r_bin_t {
ut64 filter_rules;
bool demanglercmd;
bool verbose;
bool io_owned;
bool use_xtr; // use extract plugins when loading a file?
bool use_ldr; // use loader plugins when loading a file?
} RBin;
@ -347,9 +346,9 @@ typedef struct r_bin_xtr_extract_t {
RBinXtrMetadata *metadata;
} RBinXtrData;
R_API RBinXtrData * r_bin_xtrdata_new (RBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RBinXtrMetadata *metadata);
R_API void r_bin_xtrdata_free (void /*RBinXtrData*/ *data);
R_API void r_bin_info_free (RBinInfo *rb);
R_API RBinXtrData *r_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RBinXtrMetadata *metadata);
R_API void r_bin_xtrdata_free(void /*RBinXtrData*/ *data);
R_API void r_bin_info_free(RBinInfo *rb);
R_API void r_bin_import_free(void *_imp);
R_API void r_bin_symbol_free(void *_sym);
R_API void r_bin_string_free(void *_str);
@ -607,27 +606,22 @@ typedef struct r_bin_options_t {
ut64 offset; // starting physical address to read from the target file
ut64 baseaddr; // where the linker maps the binary in memory
ut64 loadaddr; // the desired offset where the binary should be loaded
ut64 size; // restrict the size of the target fd
int xtr_idx; // load Nth binary
int rawstr;
int iofd;
char *name; // or comment :?
} RBinOptions;
R_API RBinImport *r_bin_import_clone(RBinImport *o);
R_API RBinSymbol *r_bin_symbol_clone(RBinSymbol *o);
R_API RBinOptions *r_bin_options_new (ut64 offset, ut64 baddr, int rawstr);
R_API void r_bin_options_free(RBinOptions *bo);
R_API int r_bin_open(RBin *bin, const char *filename, RBinOptions *bo);
R_API RBinFile *r_bin_get_file (RBin *bin, int bd);
R_API RBinFile *r_bin_get_file(RBin *bin, int bd);
R_API bool r_bin_close(RBin *bin, int bd);
R_API bool r_bin_query(RBin *bin, const char *query);
/* load */
R_API int r_bin_load(RBin *bin, const char *file, ut64 baseaddr, ut64 loadaddr, int xtr_idx, int fd, int rawstr);
R_API int r_bin_load_as(RBin *bin, const char *file, ut64 baseaddr, ut64 loadaddr, int xtr_idx, int fd, int rawstr, int fileoffset, const char *name);
R_API bool r_bin_load_io (RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int xtr_idx, ut64 offset, const char *name);
R_API bool r_bin_load_io(RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int xtr_idx, ut64 offset, const char *name);
R_API bool r_bin_load_io2(RBin *bin, int fd, ut64 baseaddr, ut64 loadaddr, int xtr_idx, ut64 offset, const char *name, ut64 sz);
/* bin.c */
@ -643,8 +637,8 @@ R_API void* r_bin_free(RBin *bin);
R_API RList *r_bin_raw_strings(RBinFile *a, int min);
R_API RList *r_bin_dump_strings(RBinFile *a, int min, int raw);
//io-wrappers
R_API int r_bin_read_at (RBin *bin, ut64 addr, ut8 *buf, int size);
R_API int r_bin_write_at (RBin *bin, ut64 addr, const ut8 *buf, int size);
R_API int r_bin_read_at(RBin *bin, ut64 addr, ut8 *buf, int size);
R_API int r_bin_write_at(RBin *bin, ut64 addr, const ut8 *buf, int size);
/* 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);
@ -681,7 +675,7 @@ 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_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);
@ -691,21 +685,20 @@ R_API int r_bin_object_delete(RBin *bin, ut32 binfile_id, ut32 binobj_id);
R_API void r_bin_object_delete_items(RBinObject *o);
// ref
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,
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);
#define MODE_PRINT 0x000
#define MODE_RADARE 0x001
#define MODE_SIMPLE 0x004
RBinXtrData *xtr_data);
R_API int r_bin_list(RBin *bin, int json);
R_API int r_bin_list_plugin(RBin *bin, const char* name, int json);
R_API int r_bin_list_plugin(RBin *bin, const char *name, int json);
R_API RBinObject *r_bin_get_object(RBin *bin);
R_API ut64 r_binfile_get_baddr (RBinFile *binfile);
R_API ut64 r_binfile_get_baddr(RBinFile *binfile);
R_API ut64 r_bin_get_baddr(RBin *bin);
R_API void r_bin_set_baddr(RBin *bin, ut64 baddr);
R_API ut64 r_bin_get_laddr(RBin *bin);
@ -717,8 +710,8 @@ R_API RBinXtrPlugin *r_bin_get_xtrplugin_by_name(RBin *bin, const char *name);
R_API RBinPlugin *r_bin_get_binplugin_by_name(RBin *bin, const char *name);
R_API RBinPlugin *r_bin_get_binplugin_any(RBin *bin);
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 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 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);
@ -734,30 +727,30 @@ 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);
R_API RList* r_bin_get_entries(RBin *bin);
R_API RList* r_bin_get_fields(RBin *bin);
R_API RList* r_bin_get_imports(RBin *bin);
R_API RBinInfo* r_bin_get_info(RBin *bin);
R_API RList* r_bin_get_libs(RBin *bin);
R_API ut64 r_bin_get_size (RBin *bin);
R_API RList* r_bin_patch_relocs(RBin *bin);
R_API RList* r_bin_get_relocs(RBin *bin);
R_API RList* r_bin_get_sections(RBin *bin);
R_API RList* /*<RBinClass>*/r_bin_get_classes(RBin *bin);
R_API RList *r_bin_get_entries(RBin *bin);
R_API RList *r_bin_get_fields(RBin *bin);
R_API RList *r_bin_get_imports(RBin *bin);
R_API RBinInfo *r_bin_get_info(RBin *bin);
R_API RList *r_bin_get_libs(RBin *bin);
R_API ut64 r_bin_get_size(RBin *bin);
R_API RList *r_bin_patch_relocs(RBin *bin);
R_API RList *r_bin_get_relocs(RBin *bin);
R_API RList *r_bin_get_sections(RBin *bin);
R_API RList * /*<RBinClass>*/ r_bin_get_classes(RBin *bin);
// 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 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 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);
R_API RList* r_bin_get_strings(RBin *bin);
R_API RBinSection *r_bin_get_section_at(RBinObject *o, ut64 off, int va);
R_API RList *r_bin_get_strings(RBin *bin);
R_API int r_bin_is_string(RBin *bin, ut64 va);
R_API RList* r_bin_reset_strings(RBin *bin);
R_API RList* r_bin_get_symbols(RBin *bin);
R_API RList *r_bin_reset_strings(RBin *bin);
R_API RList *r_bin_get_symbols(RBin *bin);
R_API RBinSymbol *r_bin_get_symbol_at_vaddr(RBin *bin, ut64 addr);
R_API RBinSymbol *r_bin_get_symbol_at_paddr(RBin *bin, ut64 addr);
R_API int r_bin_is_big_endian(RBin *bin);
@ -766,32 +759,31 @@ R_API int r_bin_is_static(RBin *bin);
R_API int r_bin_has_dbg_linenums(RBin *bin);
R_API int r_bin_has_dbg_syms(RBin *bin);
R_API int r_bin_has_dbg_relocs(RBin *bin);
R_API RBin* r_bin_new(void);
R_API void r_bin_iobind(RBin *bin, RIO *io);
R_API RBinFile * r_bin_cur(RBin *bin);
R_API RBinObject * r_bin_cur_object(RBin *bin);
R_API RBin *r_bin_new(void);
R_API RBinFile *r_bin_cur(RBin *bin);
R_API RBinObject *r_bin_cur_object(RBin *bin);
R_API int r_bin_io_load(RBin *bin, RIO *io, int fd, ut64 baseaddr, ut64 loadaddr, int dummy);
R_API int r_bin_select(RBin *bin, const char *arch, int bits, const char *name);
R_API int r_bin_select_idx(RBin *bin, const char *name, int idx);
R_API int r_bin_select_by_ids(RBin *bin, ut32 binfile_id, ut32 binobj_id);
R_API int r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name);
R_API RBinFile * r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits, const char *name);
R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits, const char *name);
R_API void r_bin_list_archs(RBin *bin, int mode);
R_API void r_bin_set_user_ptr(RBin *bin, void *user);
R_API RBuffer *r_bin_create (RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen);
R_API RBuffer *r_bin_package (RBin *bin, const char *type, const char *file, RList *files);
R_API ut64 r_bin_get_vaddr (RBin *bin, ut64 paddr, ut64 vaddr);
R_API ut64 r_bin_a2b (RBin *bin, ut64 addr);
R_API RBuffer *r_bin_create(RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen);
R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RList *files);
R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr);
R_API ut64 r_bin_a2b(RBin *bin, ut64 addr);
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);
R_API void r_bin_force_plugin (RBin *bin, const char *pname);
R_API const char *r_bin_string_type (int type);
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);
R_API void r_bin_force_plugin(RBin *bin, const char *pname);
R_API const char *r_bin_string_type(int type);
/* dbginfo.c */
R_API int r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line);
@ -809,18 +801,18 @@ R_API RList *r_bin_dwarf_parse_line(RBin *a, int mode);
R_API RList *r_bin_dwarf_parse_aranges(RBin *a, int mode);
R_API RBinDwarfDebugAbbrev *r_bin_dwarf_parse_abbrev(RBin *a, int mode);
R_API RBinPlugin * r_bin_get_binplugin_by_bytes (RBin *bin, const ut8* bytes, ut64 sz);
R_API RBinPlugin *r_bin_get_binplugin_by_bytes(RBin *bin, const ut8 *bytes, ut64 sz);
R_API void r_bin_demangle_list(RBin *bin);
R_API char *r_bin_demangle_plugin(RBin *bin, const char *name, const char *str);
R_API RList *r_bin_get_mem (RBin *bin);
R_API RList *r_bin_get_mem(RBin *bin);
/* filter.c */
R_API void r_bin_filter_name(Sdb *db, ut64 addr, char *name, int maxlen);
R_API void r_bin_filter_symbols (RList *list);
R_API void r_bin_filter_sections (RList *list);
R_API void r_bin_filter_classes (RList *list);
R_API void r_bin_filter_symbols(RList *list);
R_API void r_bin_filter_sections(RList *list);
R_API void r_bin_filter_classes(RList *list);
R_API bool r_bin_strpurge(RBin *bin, const char *str, ut64 addr);
R_API bool r_bin_string_filter(RBin *bin, const char *str, ut64 addr);
R_API bool r_bin_is_cxx(RBinFile *binfile);

View file

@ -346,7 +346,7 @@ R_API char *r_io_system (RIO *io, const char* cmd);
R_API bool r_io_resize (RIO *io, ut64 newsize);
R_API int r_io_extend_at (RIO *io, ut64 addr, ut64 size);
R_API bool r_io_set_write_mask (RIO *io, const ut8 *mask, int len);
R_API int r_io_bind (RIO *io, RIOBind *bnd);
R_API void r_io_bind(RIO *io, RIOBind *bnd);
R_API int r_io_shift (RIO *io, ut64 start, ut64 end, st64 move);
R_API ut64 r_io_seek (RIO *io, ut64 offset, int whence);
R_API int r_io_fini (RIO *io);

View file

@ -529,10 +529,9 @@ R_API bool r_io_set_write_mask(RIO* io, const ut8* mask, int len) {
return true;
}
R_API int r_io_bind(RIO* io, RIOBind* bnd) {
if (!io || !bnd) {
return false;
}
R_API void r_io_bind(RIO *io, RIOBind *bnd) {
r_return_if_fail (io && bnd);
bnd->io = io;
bnd->init = true;
bnd->desc_use = r_io_use_fd;
@ -564,7 +563,6 @@ R_API int r_io_bind(RIO* io, RIOBind* bnd) {
#if HAVE_PTRACE
bnd->ptrace = r_io_ptrace;
#endif
return true;
}
/* moves bytes up (+) or down (-) within the specified range */

View file

@ -40,7 +40,6 @@ try:
except ImportError:
from io import StringIO
def main():
parser = argparse.ArgumentParser(description=
'Reformat changed lines in diff. Without -i '
@ -130,9 +129,6 @@ def main():
# handle functions definitions/declarations: do not use space before (
for i, l in enumerate(formatted_code):
if lines and i + 1 not in modified_lines:
continue
if l.startswith('R_API ') or l.startswith('static '):
formatted_code[i] = l.replace(' (', '(')