Started changing bin_load to bin_open (#10221)

This commit is contained in:
Rene Laemmert 2018-06-20 16:19:22 +02:00 committed by radare
parent 19f6cea471
commit d11473201a
4 changed files with 24 additions and 5 deletions

View File

@ -982,11 +982,24 @@ int main(int argc, char **argv) {
r_bin_force_plugin (bin, forcebin);
r_bin_load_filter (bin, action);
if (!r_bin_load (bin, file, baddr, laddr, xtr_idx, fd, rawstr)) {
RBinOptions *bo = r_bin_options_new (0LL, baddr, rawstr);
if (!bo) {
eprintf ("Could not create RBinOptions\n");
r_core_fini (&core);
return 1;
}
bo->loadaddr = laddr;
bo->xtr_idx = xtr_idx;
bo->iofd = fd;
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_fini (&core);
return 1;
}
@ -1016,6 +1029,7 @@ int main(int argc, char **argv) {
sdb_query (bin->cur->sdb, query);
}
}
r_bin_options_free (bo);
r_core_fini (&core);
return 0;
}
@ -1061,6 +1075,7 @@ int main(int argc, char **argv) {
}
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_fini (&core);
return r;
}
@ -1111,6 +1126,7 @@ int main(int argc, char **argv) {
r_cons_print ("}");
}
r_cons_flush ();
r_bin_options_free (bo);
r_core_fini (&core);
free (stdin_buf);

View File

@ -7,6 +7,7 @@ files = [
'filter.c',
'file.c',
'obj.c',
'open.c',
'p/bin_any.c',
'p/bin_art.c',
'p/bin_avr.c',

View File

@ -18,14 +18,16 @@ R_API void r_bin_options_free(RBinOptions *bo) {
}
R_API int r_bin_open(RBin *bin, const char *filename, RBinOptions *bo) {
ut64 baddr = 0LL;
int iofd = -1, rawstr = 0;
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;
}
if (r_bin_load (bin, filename, baddr, 0, 0, iofd, rawstr)) {
if (r_bin_load (bin, filename, baddr, laddr, xtr_idx, iofd, rawstr)) {
int id = bin->cur->id;
r_id_storage_set (bin->ids, bin->cur, id);
return id;

View File

@ -582,8 +582,8 @@ typedef struct r_bin_bind_t {
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
// ut64 loadaddr; // DEPRECATED ?
int xtr_idx; // load Nth binary
int rawstr;
int iofd;