mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 12:12:06 +00:00
Initial de-rcorefile-fication
This commit is contained in:
parent
fbee0b46b4
commit
52d93207af
@ -9,9 +9,6 @@ static bool load(RBin *bin) {
|
||||
if (!bin || !bin->cur) {
|
||||
return false;
|
||||
}
|
||||
if (!bin->cur->xtr_obj) {
|
||||
bin->cur->xtr_obj = r_bin_dyldcache_new (bin->cur->file);
|
||||
}
|
||||
if (!bin->file) {
|
||||
bin->file = bin->cur->file;
|
||||
}
|
||||
|
@ -1776,7 +1776,7 @@ static int cmpfcn(const void *_a, const void *_b) {
|
||||
static int fcnlist_gather_metadata(RAnal *anal, RList *fcns) {
|
||||
RListIter *iter;
|
||||
RAnalFunction *fcn;
|
||||
RList *refs, *xrefs;
|
||||
RList *xrefs;
|
||||
|
||||
r_list_foreach (fcns, iter, fcn) {
|
||||
// Count the number of references and number of calls
|
||||
|
@ -3268,8 +3268,8 @@ R_API int r_core_bin_info(RCore *core, int action, int mode, int va, RCoreBinFil
|
||||
}
|
||||
|
||||
R_API int r_core_bin_set_arch_bits(RCore *r, const char *name, const char * arch, ut16 bits) {
|
||||
RCoreFile *cf = r_core_file_cur (r);
|
||||
RIODesc *desc = cf ? r_io_desc_get (r->io, cf->fd) : NULL;
|
||||
int fd = r_io_fd_get_current (r->io);
|
||||
RIODesc *desc = r_io_desc_get (r->io, fd);
|
||||
RBinFile *curfile, *binfile = NULL;
|
||||
if (!name) {
|
||||
name = (desc) ? desc->name : NULL;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2017 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2018 - pancake */
|
||||
|
||||
#include <string.h>
|
||||
#include "r_bin.h"
|
||||
@ -133,8 +133,8 @@ static void r_core_file_info(RCore *core, int mode) {
|
||||
bool io_cache = r_config_get_i (core->config, "io.cache");
|
||||
RBinInfo *info = r_bin_get_info (core->bin);
|
||||
RBinFile *binfile = r_core_bin_cur (core);
|
||||
RCoreFile *cf = core->file;
|
||||
RIODesc *desc = cf ? r_io_desc_get (core->io, cf->fd) : NULL;
|
||||
int fd = r_io_fd_get_current (core->io);
|
||||
RIODesc *desc = r_io_desc_get (core->io, fd);
|
||||
RBinPlugin *plugin = r_bin_file_cur_plugin (binfile);
|
||||
if (mode == R_CORE_BIN_JSON) {
|
||||
r_cons_printf ("{");
|
||||
@ -153,7 +153,7 @@ static void r_core_file_info(RCore *core, int mode) {
|
||||
} else {
|
||||
fn = desc ? desc->name: NULL;
|
||||
}
|
||||
if (cf && mode == R_CORE_BIN_JSON) {
|
||||
if (desc && mode == R_CORE_BIN_JSON) {
|
||||
const char *uri = fn;
|
||||
if (!uri) {
|
||||
if (desc && desc->uri && *desc->uri) {
|
||||
@ -202,7 +202,7 @@ static void r_core_file_info(RCore *core, int mode) {
|
||||
}
|
||||
}
|
||||
r_cons_printf ("}");
|
||||
} else if (cf && mode != R_CORE_BIN_SIMPLE) {
|
||||
} else if (desc && mode != R_CORE_BIN_SIMPLE) {
|
||||
//r_cons_printf ("# Core file info\n");
|
||||
if (dbg) {
|
||||
dbg = R_IO_WRITE | R_IO_EXEC;
|
||||
@ -308,8 +308,8 @@ static void playMsg(RCore *core, const char *n, int len) {
|
||||
static int cmd_info(void *data, const char *input) {
|
||||
RCore *core = (RCore *) data;
|
||||
bool newline = r_config_get_i (core->config, "scr.interactive");
|
||||
RCoreFile *cf = core->file;
|
||||
RIODesc *desc = cf ? r_io_desc_get (core->io, cf->fd) : NULL;
|
||||
int fd = r_io_fd_get_current (core->io);
|
||||
RIODesc *desc = r_io_desc_get (core->io, fd);
|
||||
int i, va = core->io->va || core->io->debug;
|
||||
int mode = 0; //R_CORE_BIN_SIMPLE;
|
||||
int is_array = 0;
|
||||
@ -404,7 +404,7 @@ static int cmd_info(void *data, const char *input) {
|
||||
break;
|
||||
case 'o':
|
||||
{
|
||||
if (!cf) {
|
||||
if (!desc) {
|
||||
eprintf ("Core file not open\n");
|
||||
return 0;
|
||||
}
|
||||
@ -594,15 +594,16 @@ static int cmd_info(void *data, const char *input) {
|
||||
} else {
|
||||
eprintf ("Warning: Cannot find base address, flags will probably be misplaced\n");
|
||||
}
|
||||
RCoreFile *file = r_core_file_open (core, filename, R_IO_READ, baddr);
|
||||
r_core_bin_load (core, filename, baddr);
|
||||
if (!file) {
|
||||
void *res = r_core_file_open (core, filename, R_IO_READ, baddr);
|
||||
if (!res) {
|
||||
eprintf ("Error while opening '%s'", filename);
|
||||
break;
|
||||
}
|
||||
int fd = r_io_fd_get_current (core->io);
|
||||
r_core_bin_load (core, filename, baddr);
|
||||
RCoreBinFilter filter = { 0 };
|
||||
r_core_bin_info (core, R_CORE_BIN_ACC_PDB, mode, true, &filter, NULL);
|
||||
r_core_file_close (core, file);
|
||||
r_core_file_close_fd (core, fd);
|
||||
free (filename);
|
||||
break;
|
||||
case '?':
|
||||
|
@ -294,29 +294,27 @@ static void cmd_open_bin(RCore *core, const char *input) {
|
||||
}
|
||||
} else {
|
||||
ut64 addr = r_num_math (core->num, input + 2);
|
||||
RCoreFile *cf = r_core_file_cur (core);
|
||||
if (cf) {
|
||||
RIODesc *desc = r_io_desc_get (core->io, cf->fd);
|
||||
if (desc) {
|
||||
r_bin_load_io (core->bin, desc->fd, addr, 0, 0);
|
||||
r_core_cmd0 (core, ".is*");
|
||||
} else {
|
||||
eprintf ("No file to load bin from?\n");
|
||||
}
|
||||
int fd = r_io_fd_get_current (core->io);
|
||||
RIODesc *desc = r_io_desc_get (core->io, fd);
|
||||
if (desc) {
|
||||
r_bin_load_io (core->bin, desc->fd, addr, 0, 0);
|
||||
r_core_cmd0 (core, ".is*");
|
||||
} else {
|
||||
eprintf ("No file to load bin from?\n");
|
||||
}
|
||||
}
|
||||
free (arg);
|
||||
} else {
|
||||
/* reload all bininfo */
|
||||
eprintf ("RCoreFile has been killed here, this needs to be redone properly from non-uri iofiles\n");
|
||||
RList *files = r_id_storage_list (core->io->files);
|
||||
RIODesc *desc;
|
||||
RListIter *iter;
|
||||
RCoreFile *file;
|
||||
r_list_foreach (core->files, iter, file) {
|
||||
desc = r_io_desc_get (core->io, file->fd);
|
||||
r_list_foreach (files, iter, desc) {
|
||||
r_bin_load_io (core->bin, desc->fd, core->offset, 0, 0);
|
||||
r_core_cmd0 (core, ".is*");
|
||||
break;
|
||||
}
|
||||
r_list_free (files);
|
||||
}
|
||||
//r_bin_load_io_at_offset_as (core->bin, core->file->desc,
|
||||
break;
|
||||
@ -1010,7 +1008,8 @@ static int cmd_open(void *data, const char *input) {
|
||||
}
|
||||
r_core_block_read (core);
|
||||
return 0;
|
||||
#if 0
|
||||
#if 1
|
||||
// XXX projects use the of command, but i think we should deprecate it... keeping it for now
|
||||
case 'f': // "of"
|
||||
if ((input[1] == 's') && (input[2] == ' ')) {
|
||||
silence = true;
|
||||
@ -1035,6 +1034,28 @@ static int cmd_open(void *data, const char *input) {
|
||||
}
|
||||
r_str_argv_free (argv);
|
||||
return 0;
|
||||
#else
|
||||
{
|
||||
if ((input[1] == 's') && (input[2] == ' ')) {
|
||||
silence = true;
|
||||
input++;
|
||||
}
|
||||
addr = 0; // honor bin.baddr ?
|
||||
const char *argv0 = r_str_trim_ro (input + 2);
|
||||
if ((file = r_core_file_open (core, argv0, perms, addr))) {
|
||||
fd = file->fd;
|
||||
if (!silence) {
|
||||
eprintf ("%d\n", fd);
|
||||
}
|
||||
r_core_bin_load (core, argv0, baddr);
|
||||
} else if (!nowarn) {
|
||||
eprintf ("cannot open file %s\n", argv0);
|
||||
}
|
||||
r_str_argv_free (argv);
|
||||
}
|
||||
r_core_block_read (core);
|
||||
return 0;
|
||||
break;
|
||||
#endif
|
||||
case 'p': // "op"
|
||||
/* handle priorize */
|
||||
@ -1053,24 +1074,6 @@ static int cmd_open(void *data, const char *input) {
|
||||
}
|
||||
return 0;
|
||||
break;
|
||||
case 'f': // "of"
|
||||
{
|
||||
addr = 0; // honor bin.baddr ?
|
||||
const char *argv0 = r_str_trim_ro (input + 2);
|
||||
if ((file = r_core_file_open (core, argv0, perms, addr))) {
|
||||
fd = file->fd;
|
||||
if (!silence) {
|
||||
eprintf ("%d\n", fd);
|
||||
}
|
||||
r_core_bin_load (core, argv0, baddr);
|
||||
} else if (!nowarn) {
|
||||
eprintf ("cannot open file %s\n", argv0);
|
||||
}
|
||||
r_str_argv_free (argv);
|
||||
}
|
||||
r_core_block_read (core);
|
||||
return 0;
|
||||
break;
|
||||
case '+': // "o+"
|
||||
perms |= R_IO_WRITE;
|
||||
case 's': // "os"
|
||||
|
@ -2233,12 +2233,12 @@ reaccept:
|
||||
if (flg & R_IO_WRITE) {
|
||||
perm |= R_IO_WRITE;
|
||||
}
|
||||
RCoreFile *file = r_core_file_open (core, (const char *)ptr, perm, 0);
|
||||
if (file) {
|
||||
if (r_core_file_open (core, (const char *)ptr, perm, 0)) {
|
||||
int fd = r_io_fd_get_current (core->io);
|
||||
r_core_bin_load (core, NULL, baddr);
|
||||
r_io_map_add (core->io, file->fd, perm, 0, 0, r_io_fd_size (core->io, file->fd), true);
|
||||
r_io_map_add (core->io, fd, perm, 0, 0, r_io_fd_size (core->io, fd), true);
|
||||
if (core->file) {
|
||||
pipefd = core->file->fd;
|
||||
pipefd = fd;
|
||||
} else {
|
||||
pipefd = -1;
|
||||
}
|
||||
|
@ -3467,11 +3467,11 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
jump_op = true;
|
||||
}
|
||||
if (!jump_op) {
|
||||
RCore *core = ds->core;
|
||||
const char *prefix;
|
||||
char *escstr;
|
||||
ut32 len = sizeof (str) -1;
|
||||
ut32 len = sizeof (str) -1;
|
||||
#if 0
|
||||
RCore *core = ds->core;
|
||||
ut32 len = core->blocksize + 256;
|
||||
if (len < core->blocksize || len > R_DISASM_MAX_STR) {
|
||||
len = R_DISASM_MAX_STR;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2017 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2018 - pancake */
|
||||
|
||||
#include <r_core.h>
|
||||
#include <stdlib.h>
|
||||
@ -19,7 +19,7 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
: NULL;
|
||||
RIODesc *odesc = (core->io && ofile) ? r_io_desc_get (core->io, ofile->fd) : NULL;
|
||||
char *ofilepath = NULL, *obinfilepath = bf? strdup (bf->file): NULL;
|
||||
int newpid, ret = false;
|
||||
int ret = false;
|
||||
ut64 origoff = core->offset;
|
||||
if (odesc) {
|
||||
if (odesc->referer) {
|
||||
@ -40,7 +40,7 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
free (obinfilepath);
|
||||
return false;
|
||||
}
|
||||
newpid = odesc? odesc->fd: -1;
|
||||
int newpid = odesc? odesc->fd: -1;
|
||||
|
||||
if (isdebug) {
|
||||
r_debug_kill (core->dbg, core->dbg->pid, core->dbg->tid, 9); // KILL
|
||||
@ -875,6 +875,8 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
RCoreFile *f;
|
||||
RIODesc *desc;
|
||||
ut64 from;
|
||||
RListIter *it;
|
||||
RBinFile *bf;
|
||||
RListIter *iter;
|
||||
if (mode == 'j') {
|
||||
r_cons_printf ("[");
|
||||
@ -894,22 +896,24 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
break;
|
||||
case '*':
|
||||
case 'r':
|
||||
// TODO: use a getter
|
||||
{
|
||||
RListIter *it;
|
||||
RBinFile *bf;
|
||||
bool fileHaveBin = false;
|
||||
char *absfile = r_file_abspath (desc->uri);
|
||||
r_list_foreach (core->bin->binfiles, it, bf) {
|
||||
if (bf->fd == f->fd) {
|
||||
char *absfile = r_file_abspath (desc->uri);
|
||||
r_cons_printf ("o %s 0x%"PFMT64x "\n", absfile, (ut64) from);
|
||||
free(absfile);
|
||||
fileHaveBin = true;
|
||||
}
|
||||
}
|
||||
if (!fileHaveBin && !strstr (absfile, "://")) {
|
||||
r_cons_printf ("o %s 0x%"PFMT64x "\n", absfile, (ut64) from);
|
||||
}
|
||||
free (absfile);
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
{
|
||||
RListIter *it;
|
||||
RBinFile *bf;
|
||||
bool header_loaded = false;
|
||||
r_list_foreach (core->bin->binfiles, it, bf) {
|
||||
if (bf->fd == f->fd) {
|
||||
|
@ -417,7 +417,6 @@ R_API bool r_core_project_open(RCore *core, const char *prjfile, bool thready) {
|
||||
}
|
||||
}
|
||||
if (close_current_session) {
|
||||
RCoreFile *fh;
|
||||
// delete
|
||||
r_core_file_close_fd (core, -1);
|
||||
r_io_close_all (core->io);
|
||||
@ -429,8 +428,7 @@ R_API bool r_core_project_open(RCore *core, const char *prjfile, bool thready) {
|
||||
r_io_desc_init (core->io);
|
||||
if (filepath[0]) {
|
||||
/* Old-style project without embedded on commands to open all files. */
|
||||
fh = r_core_file_open (core, filepath, 0, 0);
|
||||
if (!fh) {
|
||||
if (!r_core_file_open (core, filepath, 0, 0)) {
|
||||
eprintf ("Cannot open file '%s'\n", filepath);
|
||||
ret = false;
|
||||
goto beach;
|
||||
|
@ -1222,7 +1222,6 @@ static int r_core_rtr_gdb_run(RCore *core, int launch, const char *path) {
|
||||
char port[10];
|
||||
char *file = NULL, *args = NULL;
|
||||
libgdbr_t *g;
|
||||
RCoreFile *cf;
|
||||
|
||||
if (!core || !path) {
|
||||
return -1;
|
||||
@ -1258,7 +1257,7 @@ static int r_core_rtr_gdb_run(RCore *core, int launch, const char *path) {
|
||||
args = "";
|
||||
}
|
||||
|
||||
if (!(cf = r_core_file_open (core, file, R_IO_READ, 0))) {
|
||||
if (!r_core_file_open (core, file, R_IO_READ, 0)) {
|
||||
eprintf ("Cannot open file (%s)\n", file);
|
||||
return -1;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ R_API void r_id_storage_delete(RIDStorage *storage, ut32 id);
|
||||
R_API void *r_id_storage_take(RIDStorage *storage, ut32 id);
|
||||
R_API bool r_id_storage_foreach(RIDStorage *storage, RIDStorageForeachCb cb, void *user);
|
||||
R_API void r_id_storage_free(RIDStorage *storage);
|
||||
R_API RList *r_id_storage_list(RIDStorage *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -195,3 +195,14 @@ R_API void r_id_storage_free(RIDStorage* storage) {
|
||||
}
|
||||
free (storage);
|
||||
}
|
||||
|
||||
static bool _list(void* user, void* data, ut32 id) {
|
||||
r_list_append (user, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API RList *r_id_storage_list(RIDStorage *s) {
|
||||
RList *list = r_list_newf (NULL);
|
||||
r_id_storage_foreach (s, _list, list);
|
||||
return list;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user