mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-31 10:22:37 +00:00
More r2-indent fixes. and reindent a bunch of files
This commit is contained in:
parent
4bbc73a0e2
commit
0ae4a5c3e8
@ -477,7 +477,7 @@ static int use_stdin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int main (int argc, char** argv) {
|
||||
int i;
|
||||
num = r_num_new (NULL, NULL, NULL);
|
||||
if (argc == 1) {
|
||||
|
@ -9,9 +9,9 @@ input_tab_size = 8
|
||||
output_tab_size = 8
|
||||
sp_arith = Force
|
||||
sp_assign = Force
|
||||
sp_after_ptr_star = Force
|
||||
sp_after_ptr_star_func = Force
|
||||
sp_before_ptr_star_func = Remove
|
||||
sp_after_ptr_star = Remove
|
||||
sp_after_ptr_star_func = Remove
|
||||
sp_before_ptr_star_func = Force
|
||||
sp_before_ptr_star = Remove
|
||||
sp_after_cast = Force
|
||||
sp_func_call_user_paren = Remove
|
||||
@ -75,7 +75,7 @@ indent_switch_case = 0
|
||||
indent_case_shift = 0
|
||||
indent_case_brace = 0
|
||||
indent_col1_comment = false
|
||||
indent_label = 1
|
||||
indent_label = 1
|
||||
indent_access_spec = 1
|
||||
indent_access_spec_body = false
|
||||
indent_paren_nl = false
|
||||
@ -119,11 +119,11 @@ sp_paren_paren = remove
|
||||
sp_cparen_oparen = ignore
|
||||
sp_balance_nested_parens = false
|
||||
sp_paren_brace = ignore
|
||||
#sp_before_ptr_star = ignore
|
||||
#sp_before_unnamed_ptr_star = ignore
|
||||
#sp_between_ptr_star = remove
|
||||
#sp_after_ptr_star_qualifier = ignore
|
||||
#sp_ptr_star_paren = ignore
|
||||
sp_before_ptr_star = add
|
||||
sp_before_unnamed_ptr_star = ignore
|
||||
sp_between_ptr_star = remove
|
||||
sp_after_ptr_star_qualifier = ignore
|
||||
sp_ptr_star_paren = ignore
|
||||
sp_before_byref = ignore
|
||||
sp_before_unnamed_byref = ignore
|
||||
sp_after_byref = ignore
|
||||
@ -253,7 +253,7 @@ sp_cond_question = ignore
|
||||
sp_cond_question_before = ignore
|
||||
sp_cond_question_after = ignore
|
||||
sp_cond_ternary_short = ignore
|
||||
sp_case_label = ignore
|
||||
sp_case_label = remove
|
||||
sp_range = ignore
|
||||
sp_after_for_colon = ignore
|
||||
sp_before_for_colon = ignore
|
||||
@ -274,7 +274,7 @@ align_on_tabstop = false
|
||||
align_number_left = false
|
||||
align_keep_extra_space = false
|
||||
align_func_params = false
|
||||
align_same_func_call_params = true
|
||||
align_same_func_call_params = false
|
||||
align_var_def_span = 0
|
||||
align_var_def_star_style = 0
|
||||
align_var_def_amp_style = 0
|
||||
@ -483,7 +483,7 @@ nl_before_block_comment = 0
|
||||
nl_before_c_comment = 0
|
||||
nl_before_cpp_comment = 0
|
||||
nl_after_multiline_comment = false
|
||||
nl_after_label_colon = false
|
||||
nl_after_label_colon = force
|
||||
nl_after_struct = 0
|
||||
nl_before_class = 0
|
||||
nl_after_class = 0
|
||||
|
@ -31,7 +31,7 @@ static int bbExist(AbbState *abb, ut64 addr) {
|
||||
RAnalBlock *bb;
|
||||
RListIter *iter;
|
||||
if (abb->bbdb) {
|
||||
return (int)sdb_num_get (abb->bbdb, sdb_fmt (0, "0x%08" PFMT64x, addr), NULL);
|
||||
return (int) sdb_num_get (abb->bbdb, sdb_fmt (0, "0x%08" PFMT64x, addr), NULL);
|
||||
}
|
||||
r_list_foreach (abb->bbs, iter, bb) {
|
||||
if (bb->addr == addr) {
|
||||
@ -42,11 +42,11 @@ static int bbExist(AbbState *abb, ut64 addr) {
|
||||
}
|
||||
|
||||
static int fcnExist(AbbState *abb, ut64 addr) {
|
||||
AbbAddr* a;
|
||||
AbbAddr *a;
|
||||
RListIter *iter;
|
||||
#if 0
|
||||
if (abb->bbdb) {
|
||||
return (int)sdb_num_get (abb->bbdb, sdb_fmt (0, "fcn.0x%08" PFMT64x, addr), NULL);
|
||||
return (int) sdb_num_get (abb->bbdb, sdb_fmt (0, "fcn.0x%08" PFMT64x, addr), NULL);
|
||||
}
|
||||
#endif
|
||||
r_list_foreach (abb->fcnents, iter, a) {
|
||||
@ -113,7 +113,7 @@ static bool appendNextBB(AbbState *abb, ut64 addr, int bits, int type) {
|
||||
|
||||
static RAnalBlock *parseOpcode(AbbState *abb, RAnalOp *aop) {
|
||||
RFlagItem *fi = r_flag_get_i (abb->core->flags, aop->addr + aop->size);
|
||||
bool eob = fi ? true:false; //strncmp (fi->name, "sym.", 4): false;
|
||||
bool eob = fi? true: false; //strncmp (fi->name, "sym.", 4): false;
|
||||
if (eob) {
|
||||
aop->fail = UT64_MAX;
|
||||
}
|
||||
@ -139,7 +139,7 @@ static RAnalBlock *parseOpcode(AbbState *abb, RAnalOp *aop) {
|
||||
RFlagItem *fi = r_flag_get_i (abb->core->flags, aop->jump);
|
||||
if (fi) {
|
||||
if (r_anal_noreturn_at_name (abb->core->anal, fi->name)) {
|
||||
//if (r_anal_noreturn_at_addr (abb->core->anal, aop->jump))
|
||||
//if (r_anal_noreturn_at_addr (abb->core->anal, aop->jump))
|
||||
eob = true;
|
||||
}
|
||||
}
|
||||
@ -150,8 +150,8 @@ static RAnalBlock *parseOpcode(AbbState *abb, RAnalOp *aop) {
|
||||
if (aop->fail != UT64_MAX && !eob) {
|
||||
appendNextBB (abb, aop->fail, 0, 0);
|
||||
}
|
||||
aop->jump = aop->fail; //UT64_MAX;
|
||||
aop->fail = UT64_MAX;
|
||||
aop->jump = aop->fail; //UT64_MAX;
|
||||
aop->fail = UT64_MAX;
|
||||
#endif
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_CJMP:
|
||||
@ -184,7 +184,7 @@ aop->fail = UT64_MAX;
|
||||
bb->addr = abb->bb_addr;
|
||||
bb->size = aop->addr - abb->bb_addr + aop->size;
|
||||
if (bb->size < 1) {
|
||||
eprintf ("Invalid block size at 0x%08"PFMT64x"\n", bb->addr);
|
||||
eprintf ("Invalid block size at 0x%08"PFMT64x "\n", bb->addr);
|
||||
// XXX
|
||||
bb->size = aop->size;
|
||||
}
|
||||
@ -215,10 +215,10 @@ static void printBasicBlocks(AbbState *abb, ut64 fcnaddr, ut64 addr) {
|
||||
sdb_bool_set (abb->bbdb, sdb_fmt (0, "bb.0x%08" PFMT64x ".0x%08" PFMT64x, fcnaddr, addr), true, 0);
|
||||
r_cons_printf ("afb+ 0x%08" PFMT64x " 0x%08" PFMT64x " %d", fcnaddr, bb->addr, bb->size);
|
||||
if (bb->jump != UT64_MAX) {
|
||||
r_cons_printf (" 0x%08" PFMT64x, bb->jump);
|
||||
if (bb->fail != UT64_MAX) {
|
||||
r_cons_printf (" 0x%08" PFMT64x, bb->fail);
|
||||
}
|
||||
r_cons_printf (" 0x%08" PFMT64x, bb->jump);
|
||||
if (bb->fail != UT64_MAX) {
|
||||
r_cons_printf (" 0x%08" PFMT64x, bb->fail);
|
||||
}
|
||||
}
|
||||
r_cons_newline ();
|
||||
if (bb->jump != UT64_MAX) {
|
||||
@ -230,7 +230,7 @@ static void printBasicBlocks(AbbState *abb, ut64 fcnaddr, ut64 addr) {
|
||||
}
|
||||
|
||||
static void printFunction(ut64 addr, const char *name) {
|
||||
char *_name = name? (char *)name: r_str_newf ("fcn.%" PFMT64x, addr);
|
||||
char *_name = name? (char *) name: r_str_newf ("fcn.%" PFMT64x, addr);
|
||||
r_cons_printf ("af+ 0x%08" PFMT64x " %s\n", addr, _name);
|
||||
if (!name) {
|
||||
free (_name);
|
||||
@ -253,13 +253,13 @@ static void findFunctions(RCore *core, AbbState *abb) {
|
||||
// if there's a flag, consider it a function
|
||||
RFlagItem *fi = r_flag_get_i (core->flags, bb->addr);
|
||||
if (fi) {
|
||||
printFunction(bb->addr, fi->name);
|
||||
printFunction (bb->addr, fi->name);
|
||||
} else {
|
||||
// eprintf ("# orphan bb 0x%08"PFMT64x"\n", bb->addr);
|
||||
printFunction (bb->addr, NULL);
|
||||
}
|
||||
printBasicBlocks (abb, bb->addr, bb->addr);
|
||||
// printFunction (a->addr, a->name);
|
||||
// printFunction (a->addr, a->name);
|
||||
// printBasicBlocks (abb, ->addr, a->addr);
|
||||
}
|
||||
#if 0
|
||||
@ -288,7 +288,7 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
|
||||
//RListIter *iter;
|
||||
ut64 at = core->offset;
|
||||
abb->addr = at;
|
||||
(void)r_io_read_at (core->io, abb->addr, abb->buf, len);
|
||||
(void) r_io_read_at (core->io, abb->addr, abb->buf, len);
|
||||
int ti = -1;
|
||||
int oi = 0;
|
||||
abb->last = at;
|
||||
@ -303,8 +303,8 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
|
||||
}
|
||||
oi = i;
|
||||
ut64 obb_addr = abb->bb_addr;
|
||||
mountain:
|
||||
if (!r_anal_op (core->anal, &aop, abb->addr + i, abb->buf + i, R_MIN (R_MAX(0, len - i), 16))) {
|
||||
mountain:
|
||||
if (!r_anal_op (core->anal, &aop, abb->addr + i, abb->buf + i, R_MIN (R_MAX (0, len - i), 16))) {
|
||||
continue;
|
||||
}
|
||||
int next = bbExist (abb, at + i);
|
||||
@ -352,7 +352,7 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
|
||||
i = nat->addr - at;
|
||||
abb->bb_addr = nat->addr;
|
||||
if (nat->type == 'c') {
|
||||
// r_list_append (abb->fcnents, nat);
|
||||
// r_list_append (abb->fcnents, nat);
|
||||
} else {
|
||||
free (nat);
|
||||
}
|
||||
@ -394,15 +394,15 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
|
||||
} else {
|
||||
name = r_str_newf ("bb.%"PFMT64x, bb->addr);
|
||||
}
|
||||
r_cons_printf ("agn 0x%08"PFMT64x" \"%s\"\n", bb->addr, name);
|
||||
r_cons_printf ("agn 0x%08"PFMT64x " \"%s\"\n", bb->addr, name);
|
||||
free (name);
|
||||
}
|
||||
r_list_foreach (abb->bbs, iter, bb) {
|
||||
if (bb->jump != UT64_MAX) {
|
||||
r_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", bb->addr, bb->jump);
|
||||
r_cons_printf ("age 0x%08"PFMT64x " 0x%08"PFMT64x "\n", bb->addr, bb->jump);
|
||||
}
|
||||
if (bb->fail != UT64_MAX) {
|
||||
r_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", bb->addr, bb->fail);
|
||||
r_cons_printf ("age 0x%08"PFMT64x " 0x%08"PFMT64x "\n", bb->addr, bb->fail);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -37,7 +37,9 @@ static bool demangle_internal(RCore *core, const char *lang, const char *s) {
|
||||
return true;
|
||||
}
|
||||
if (res) {
|
||||
if (*res) printf ("%s\n", res);
|
||||
if (*res) {
|
||||
printf ("%s\n", res);
|
||||
}
|
||||
free (res);
|
||||
return false;
|
||||
}
|
||||
@ -47,7 +49,9 @@ static bool demangle_internal(RCore *core, const char *lang, const char *s) {
|
||||
static int demangle(RCore *core, const char *s) {
|
||||
char *p, *q;
|
||||
const char *ss = strchr (s, ' ');
|
||||
if (!*s) return 0;
|
||||
if (!*s) {
|
||||
return 0;
|
||||
}
|
||||
if (!ss) {
|
||||
const char *lang = r_config_get (core->config, "bin.lang");
|
||||
demangle_internal (core, lang, s);
|
||||
@ -61,8 +65,8 @@ static int demangle(RCore *core, const char *s) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define STR(x) (x)?(x):""
|
||||
static void r_core_file_info (RCore *core, int mode) {
|
||||
#define STR(x) (x)? (x): ""
|
||||
static void r_core_file_info(RCore *core, int mode) {
|
||||
const char *fn = NULL;
|
||||
int dbg = r_config_get_i (core->config, "cfg.debug");
|
||||
bool io_cache = r_config_get_i (core->config, "io.cache");
|
||||
@ -70,24 +74,27 @@ static void r_core_file_info (RCore *core, int mode) {
|
||||
RBinFile *binfile = r_core_bin_cur (core);
|
||||
RCoreFile *cf = core->file;
|
||||
RBinPlugin *plugin = r_bin_file_cur_plugin (binfile);
|
||||
if (mode == R_CORE_BIN_JSON)
|
||||
if (mode == R_CORE_BIN_JSON) {
|
||||
r_cons_printf ("{");
|
||||
if (mode == R_CORE_BIN_RADARE)
|
||||
}
|
||||
if (mode == R_CORE_BIN_RADARE) {
|
||||
return;
|
||||
if (mode == R_CORE_BIN_SIMPLE)
|
||||
}
|
||||
if (mode == R_CORE_BIN_SIMPLE) {
|
||||
return;
|
||||
}
|
||||
if (info) {
|
||||
fn = info->file;
|
||||
switch (mode) {
|
||||
case R_CORE_BIN_JSON:
|
||||
r_cons_printf ("\"type\":\"%s\"", STR(info->type));
|
||||
r_cons_printf ("\"type\":\"%s\"", STR (info->type));
|
||||
break;
|
||||
default:
|
||||
pair ("type", info->type);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
fn = (cf && cf->desc) ? cf->desc->name : NULL;
|
||||
fn = (cf && cf->desc)? cf->desc->name: NULL;
|
||||
}
|
||||
if (cf && mode == R_CORE_BIN_JSON) {
|
||||
const char *uri = fn;
|
||||
@ -99,67 +106,78 @@ static void r_core_file_info (RCore *core, int mode) {
|
||||
}
|
||||
}
|
||||
r_cons_printf (",\"file\":\"%s\"", uri);
|
||||
if (dbg) dbg = R_IO_WRITE | R_IO_EXEC;
|
||||
if (dbg) {
|
||||
dbg = R_IO_WRITE | R_IO_EXEC;
|
||||
}
|
||||
if (cf->desc) {
|
||||
ut64 fsz = r_io_desc_size (core->io, cf->desc);
|
||||
r_cons_printf (",\"fd\":%d", cf->desc->fd);
|
||||
if (fsz != UT64_MAX) {
|
||||
r_cons_printf (",\"size\":%"PFMT64d, fsz);
|
||||
}
|
||||
r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache || \
|
||||
cf->desc->flags & R_IO_WRITE ));
|
||||
r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache ||\
|
||||
cf->desc->flags & R_IO_WRITE ));
|
||||
r_cons_printf (",\"mode\":\"%s\"", r_str_rwx_i (
|
||||
cf->desc->flags & 7 ));
|
||||
r_cons_printf (",\"obsz\":%"PFMT64d, (ut64)core->io->desc->obsz);
|
||||
if (cf->desc->referer && *cf->desc->referer)
|
||||
cf->desc->flags & 7 ));
|
||||
r_cons_printf (",\"obsz\":%"PFMT64d, (ut64) core->io->desc->obsz);
|
||||
if (cf->desc->referer && *cf->desc->referer) {
|
||||
r_cons_printf (",\"referer\":\"%s\"", cf->desc->referer);
|
||||
}
|
||||
}
|
||||
r_cons_printf (",\"block\":%d", core->blocksize);
|
||||
if (binfile) {
|
||||
if (binfile->curxtr)
|
||||
if (binfile->curxtr) {
|
||||
r_cons_printf (",\"packet\":\"%s\"",
|
||||
binfile->curxtr->name);
|
||||
if (plugin)
|
||||
}
|
||||
if (plugin) {
|
||||
r_cons_printf (",\"format\":\"%s\"",
|
||||
plugin->name);
|
||||
}
|
||||
}
|
||||
r_cons_printf ("}");
|
||||
} else if (cf && mode != R_CORE_BIN_SIMPLE) {
|
||||
//r_cons_printf ("# Core file info\n");
|
||||
pair ("file", fn ? fn : cf->desc->uri);
|
||||
if (dbg) dbg = R_IO_WRITE | R_IO_EXEC;
|
||||
pair ("file", fn? fn: cf->desc->uri);
|
||||
if (dbg) {
|
||||
dbg = R_IO_WRITE | R_IO_EXEC;
|
||||
}
|
||||
if (cf->desc) {
|
||||
ut64 fsz = r_io_desc_size (core->io, cf->desc);
|
||||
if (cf->desc->referer && *cf->desc->referer)
|
||||
if (cf->desc->referer && *cf->desc->referer) {
|
||||
pair ("referer", cf->desc->referer);
|
||||
}
|
||||
pair ("fd", sdb_fmt (0, "%d", cf->desc->fd));
|
||||
if (fsz != UT64_MAX) {
|
||||
pair ("size", sdb_fmt (0,"0x%"PFMT64x, fsz));
|
||||
}
|
||||
pair ("iorw", r_str_bool ( io_cache || \
|
||||
cf->desc->flags & R_IO_WRITE ));
|
||||
pair ("iorw", r_str_bool ( io_cache ||\
|
||||
cf->desc->flags & R_IO_WRITE ));
|
||||
pair ("blksz", sdb_fmt (0, "0x%"PFMT64x,
|
||||
(ut64)core->io->desc->obsz));
|
||||
(ut64) core->io->desc->obsz));
|
||||
pair ("mode", r_str_rwx_i (cf->desc->flags & 7));
|
||||
}
|
||||
pair ("block", sdb_fmt (0, "0x%x", core->blocksize));
|
||||
if (binfile && binfile->curxtr)
|
||||
if (binfile && binfile->curxtr) {
|
||||
pair ("packet", binfile->curxtr->name);
|
||||
if (plugin)
|
||||
}
|
||||
if (plugin) {
|
||||
pair ("format", plugin->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int bin_is_executable (RBinObject *obj){
|
||||
static int bin_is_executable(RBinObject *obj){
|
||||
RListIter *it;
|
||||
RBinSection* sec;
|
||||
RBinSection *sec;
|
||||
if (obj) {
|
||||
if (obj->info && obj->info->arch) {
|
||||
return true;
|
||||
}
|
||||
r_list_foreach (obj->sections, it, sec){
|
||||
if (R_BIN_SCN_EXECUTABLE & sec->srwx)
|
||||
if (R_BIN_SCN_EXECUTABLE & sec->srwx) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -209,7 +227,7 @@ static void playMsg(RCore *core, const char *n, int len) {
|
||||
}
|
||||
|
||||
static int cmd_info(void *data, const char *input) {
|
||||
RCore *core = (RCore *)data;
|
||||
RCore *core = (RCore *) data;
|
||||
bool newline = r_config_get_i (core->config, "scr.interactive");
|
||||
RBinObject *o = r_bin_cur_object (core->bin);
|
||||
RCoreFile *cf = core->file;
|
||||
@ -218,7 +236,7 @@ static int cmd_info(void *data, const char *input) {
|
||||
int is_array = 0;
|
||||
Sdb *db;
|
||||
|
||||
for (i = 0; input[i] && i<2; i++) {
|
||||
for (i = 0; input[i] && i < 2; i++) {
|
||||
switch (input[i]) {
|
||||
case '*': mode = R_CORE_BIN_RADARE; break;
|
||||
case 'j': mode = R_CORE_BIN_JSON; break;
|
||||
@ -227,8 +245,9 @@ static int cmd_info(void *data, const char *input) {
|
||||
}
|
||||
|
||||
if (mode == R_CORE_BIN_JSON) {
|
||||
if (strlen (input+1)>1)
|
||||
if (strlen (input + 1) > 1) {
|
||||
is_array = 1;
|
||||
}
|
||||
}
|
||||
if (is_array) {
|
||||
r_cons_printf ("{");
|
||||
@ -244,10 +263,10 @@ static int cmd_info(void *data, const char *input) {
|
||||
while (*input) {
|
||||
switch (*input) {
|
||||
case 'b': // "ib"
|
||||
{
|
||||
{
|
||||
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
||||
if (input[1] == ' ') {
|
||||
baddr = r_num_math (core->num, input+1);
|
||||
baddr = r_num_math (core->num, input + 1);
|
||||
}
|
||||
// XXX: this will reload the bin using the buffer.
|
||||
// An assumption is made that assumes there is an underlying
|
||||
@ -256,16 +275,18 @@ static int cmd_info(void *data, const char *input) {
|
||||
r_core_bin_reload (core, NULL, baddr);
|
||||
r_core_block_read (core);
|
||||
newline = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'k':
|
||||
db = o ? o->kv : NULL;
|
||||
db = o? o->kv: NULL;
|
||||
//:eprintf ("db = %p\n", db);
|
||||
switch (input[1]) {
|
||||
case 'v':
|
||||
if (db) {
|
||||
char *o = sdb_querys (db, NULL, 0, input+3);
|
||||
if (o && *o) r_cons_print (o);
|
||||
char *o = sdb_querys (db, NULL, 0, input + 3);
|
||||
if (o && *o) {
|
||||
r_cons_print (o);
|
||||
}
|
||||
free (o);
|
||||
}
|
||||
break;
|
||||
@ -285,7 +306,9 @@ static int cmd_info(void *data, const char *input) {
|
||||
case '\0':
|
||||
if (db) {
|
||||
char *o = sdb_querys (db, NULL, 0, "*");
|
||||
if (o && *o) r_cons_print (o);
|
||||
if (o && *o) {
|
||||
r_cons_print (o);
|
||||
}
|
||||
free (o);
|
||||
}
|
||||
break;
|
||||
@ -297,26 +320,27 @@ static int cmd_info(void *data, const char *input) {
|
||||
goto done;
|
||||
break;
|
||||
case 'o':
|
||||
{
|
||||
if (!cf) {
|
||||
eprintf ("Core file not open\n");
|
||||
return 0;
|
||||
}
|
||||
const char *fn = input[1]==' '? input+2: cf->desc->name;
|
||||
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
||||
r_core_bin_load (core, fn, baddr);
|
||||
{
|
||||
if (!cf) {
|
||||
eprintf ("Core file not open\n");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
#define RBININFO(n,x,y,z) \
|
||||
if (is_array) { \
|
||||
if (is_array == 1) is_array++; else r_cons_printf (","); \
|
||||
r_cons_printf ("\"%s\":",n); \
|
||||
}\
|
||||
if (z) playMsg(core, n, z);\
|
||||
r_core_bin_info (core, x, mode, va, NULL, y);
|
||||
const char *fn = input[1] == ' '? input + 2: cf->desc->name;
|
||||
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
||||
r_core_bin_load (core, fn, baddr);
|
||||
}
|
||||
break;
|
||||
#define RBININFO(n,x,y,z)\
|
||||
if (is_array) {\
|
||||
if (is_array == 1) { is_array++;\
|
||||
} else { r_cons_printf (",");}\
|
||||
r_cons_printf ("\"%s\":",n);\
|
||||
}\
|
||||
if (z) { playMsg (core, n, z);}\
|
||||
r_core_bin_info (core, x, mode, va, NULL, y);
|
||||
case 'A':
|
||||
newline = false;
|
||||
if (input[1]=='j') {
|
||||
if (input[1] == 'j') {
|
||||
r_cons_printf ("{");
|
||||
r_bin_list_archs (core->bin, 'j');
|
||||
r_cons_printf ("}\n");
|
||||
@ -330,17 +354,17 @@ static int cmd_info(void *data, const char *input) {
|
||||
//we comes from ia or iS
|
||||
if ((input[1] == 'm' && input[2] == 'z') || !input[1]) {
|
||||
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, NULL, 0);
|
||||
} else { //iS entropy,sha1
|
||||
} else { //iS entropy,sha1
|
||||
RBinObject *obj = r_bin_cur_object (core->bin);
|
||||
if (mode == R_CORE_BIN_RADARE || mode == R_CORE_BIN_JSON || mode == R_CORE_BIN_SIMPLE) {
|
||||
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, input + 2,
|
||||
obj ? r_list_length (obj->sections) : 0);
|
||||
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, input + 2,
|
||||
obj? r_list_length (obj->sections): 0);
|
||||
} else {
|
||||
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, input + 1,
|
||||
obj ? r_list_length (obj->sections) : 0);
|
||||
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, input + 1,
|
||||
obj? r_list_length (obj->sections): 0);
|
||||
}
|
||||
//we move input until get '\0'
|
||||
while (*(++input));
|
||||
while (*(++input)) ;
|
||||
//input-- because we are inside a while that does input++
|
||||
// oob read if not input--
|
||||
input--;
|
||||
@ -352,7 +376,7 @@ static int cmd_info(void *data, const char *input) {
|
||||
break;
|
||||
}
|
||||
case 'h': RBININFO ("fields", R_CORE_BIN_ACC_FIELDS, NULL, 0); break;
|
||||
case 'l': RBININFO ("libs", R_CORE_BIN_ACC_LIBS, NULL, obj? r_list_length (obj->libs):0); break;
|
||||
case 'l': RBININFO ("libs", R_CORE_BIN_ACC_LIBS, NULL, obj? r_list_length (obj->libs): 0); break;
|
||||
case 'L':
|
||||
r_bin_list (core->bin, input[1] == 'j');
|
||||
break;
|
||||
@ -364,7 +388,7 @@ static int cmd_info(void *data, const char *input) {
|
||||
if (f->offset == addr || !f->offset) {
|
||||
r_cons_printf ("%s", f->name);
|
||||
} else {
|
||||
r_cons_printf ("%s+%d", f->name, (int)(addr-f->offset));
|
||||
r_cons_printf ("%s+%d", f->name, (int) (addr - f->offset));
|
||||
}
|
||||
}
|
||||
input++;
|
||||
@ -401,7 +425,7 @@ static int cmd_info(void *data, const char *input) {
|
||||
mode = R_CORE_BIN_SIMPLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
mode = R_CORE_BIN_PRINT;
|
||||
break;
|
||||
}
|
||||
@ -416,20 +440,20 @@ static int cmd_info(void *data, const char *input) {
|
||||
input++;
|
||||
}
|
||||
if (obj) {
|
||||
RBININFO ("strings", R_CORE_BIN_ACC_STRINGS, NULL,
|
||||
RBININFO ("strings", R_CORE_BIN_ACC_STRINGS, NULL,
|
||||
obj? r_list_length (obj->strings): 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'c': // for r2 `ic`
|
||||
if (input[1]== '?') {
|
||||
if (input[1] == '?') {
|
||||
eprintf ("Usage: ic[ljq*] [class-index]\n");
|
||||
} else if (input[1]== ' ' || input[1] == 'q' || input[1] == 'j' || input[1] == 'l') {
|
||||
} else if (input[1] == ' ' || input[1] == 'q' || input[1] == 'j' || input[1] == 'l') {
|
||||
RBinClass *cls;
|
||||
RBinSymbol *sym;
|
||||
RListIter *iter, *iter2;
|
||||
RBinObject *obj = r_bin_cur_object (core->bin);
|
||||
int idx = r_num_math (core->num, input +2);
|
||||
int idx = r_num_math (core->num, input + 2);
|
||||
int count = 0;
|
||||
if (obj) {
|
||||
if (input[2]) {
|
||||
@ -440,8 +464,8 @@ static int cmd_info(void *data, const char *input) {
|
||||
switch (input[1]) {
|
||||
case '*':
|
||||
r_list_foreach (cls->methods, iter2, sym) {
|
||||
r_cons_printf ("f sym.%s @ 0x%"PFMT64x"\n",
|
||||
sym->name, sym->vaddr);
|
||||
r_cons_printf ("f sym.%s @ 0x%"PFMT64x "\n",
|
||||
sym->name, sym->vaddr);
|
||||
}
|
||||
input++;
|
||||
break;
|
||||
@ -459,16 +483,16 @@ static int cmd_info(void *data, const char *input) {
|
||||
r_cons_printf (",\"methods\":[");
|
||||
r_list_foreach (cls->methods, iter2, sym) {
|
||||
const char *comma = iter2->p? ",": "";
|
||||
r_cons_printf ("%s{\"name\":\"%s\",\"vaddr\":%"PFMT64d"}",
|
||||
comma, sym->name, sym->vaddr);
|
||||
r_cons_printf ("%s{\"name\":\"%s\",\"vaddr\":%"PFMT64d "}",
|
||||
comma, sym->name, sym->vaddr);
|
||||
}
|
||||
r_cons_printf ("]");
|
||||
break;
|
||||
default:
|
||||
r_cons_printf ("class %s\n", cls->name);
|
||||
r_list_foreach (cls->methods, iter2, sym) {
|
||||
r_cons_printf ("0x%08"PFMT64x" method %s %s\n",
|
||||
sym->vaddr, cls->name, sym->name);
|
||||
r_cons_printf ("0x%08"PFMT64x " method %s %s\n",
|
||||
sym->vaddr, cls->name, sym->name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -498,7 +522,7 @@ static int cmd_info(void *data, const char *input) {
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
if (input[1]!=' ' || !demangle (core, input + 2)) {
|
||||
if (input[1] != ' ' || !demangle (core, input + 2)) {
|
||||
eprintf ("|Usage: iD lang symbolname\n");
|
||||
}
|
||||
return 0;
|
||||
@ -511,7 +535,7 @@ static int cmd_info(void *data, const char *input) {
|
||||
}
|
||||
break;
|
||||
case '?': {
|
||||
const char * help_message[] = {
|
||||
const char *help_message[] = {
|
||||
"Usage: i", "", "Get info from opened file (see rabin2's manpage)",
|
||||
"Output mode:", "", "",
|
||||
"'*'", "", "Output in radare commands",
|
||||
@ -546,9 +570,9 @@ static int cmd_info(void *data, const char *input) {
|
||||
"izz", "", "Search for Strings in the whole binary",
|
||||
"iZ", "", "Guess size of binary program",
|
||||
NULL
|
||||
};
|
||||
r_core_cmd_help (core, help_message);
|
||||
}
|
||||
};
|
||||
r_core_cmd_help (core, help_message);
|
||||
}
|
||||
goto done;
|
||||
case '*':
|
||||
mode = R_CORE_BIN_RADARE;
|
||||
@ -574,8 +598,11 @@ static int cmd_info(void *data, const char *input) {
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (is_array)
|
||||
if (is_array) {
|
||||
r_cons_printf ("}\n");
|
||||
if (newline) r_cons_newline();
|
||||
}
|
||||
if (newline) {
|
||||
r_cons_newline ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include "r_print.h"
|
||||
|
||||
static int cmd_project(void *data, const char *input) {
|
||||
RCore *core = (RCore *)data;
|
||||
const char *file, *arg = (input && *input)? input+1: NULL;
|
||||
RCore *core = (RCore *) data;
|
||||
const char *file, *arg = (input && *input)? input + 1: NULL;
|
||||
const char *fileproject = r_config_get (core->config, "prj.name");
|
||||
char *str = NULL;
|
||||
|
||||
@ -28,14 +28,14 @@ static int cmd_project(void *data, const char *input) {
|
||||
file = arg;
|
||||
switch (input[0]) {
|
||||
case 'c':
|
||||
if (input[1]==' ') {
|
||||
r_core_project_cat (core, input+2);
|
||||
if (input[1] == ' ') {
|
||||
r_core_project_cat (core, input + 2);
|
||||
} else {
|
||||
eprintf ("Usage: Pc [prjname]\n");
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
// if (r_file_is_regular (file))
|
||||
// if (r_file_is_regular (file))
|
||||
if (input[1] == '&') {
|
||||
r_core_project_open (core, file, true);
|
||||
} else if (input[1]) {
|
||||
@ -63,7 +63,7 @@ static int cmd_project(void *data, const char *input) {
|
||||
break;
|
||||
case 'S':
|
||||
if (input[1] == ' ') {
|
||||
r_core_project_save_rdb (core, input+2, R_CORE_PRJ_ALL);
|
||||
r_core_project_save_rdb (core, input + 2, R_CORE_PRJ_ALL);
|
||||
} else {
|
||||
eprintf ("Usage: PS [file]\n");
|
||||
}
|
||||
@ -71,110 +71,113 @@ static int cmd_project(void *data, const char *input) {
|
||||
case 'n':
|
||||
if (!fileproject || !*fileproject) {
|
||||
eprintf ("No project\n");
|
||||
} else
|
||||
switch (input[1]) {
|
||||
case '-':
|
||||
/* remove lines containing specific words */
|
||||
} else {
|
||||
switch (input[1]) {
|
||||
case '-':
|
||||
/* remove lines containing specific words */
|
||||
{
|
||||
FILE *fd = r_sandbox_fopen (str, "w");
|
||||
if (!fd) {
|
||||
eprintf ("Cannot open %s\n", str);
|
||||
} else {
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
char *data = r_file_slurp (str, NULL);
|
||||
int del = 0;
|
||||
if (data) {
|
||||
char *ptr, *nl;
|
||||
for (ptr = data; ptr; ptr = nl) {
|
||||
nl = strchr (ptr, '\n');
|
||||
if (nl) {
|
||||
*nl++ = 0;
|
||||
if (strstr (ptr, input+2))
|
||||
del++;
|
||||
else
|
||||
fprintf (fd, "%s\n", ptr);
|
||||
FILE *fd = r_sandbox_fopen (str, "w");
|
||||
if (!fd) {
|
||||
eprintf ("Cannot open %s\n", str);
|
||||
} else {
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
char *data = r_file_slurp (str, NULL);
|
||||
int del = 0;
|
||||
if (data) {
|
||||
char *ptr, *nl;
|
||||
for (ptr = data; ptr; ptr = nl) {
|
||||
nl = strchr (ptr, '\n');
|
||||
if (nl) {
|
||||
*nl++ = 0;
|
||||
if (strstr (ptr, input + 2)) {
|
||||
del++;
|
||||
} else {
|
||||
fprintf (fd, "%s\n", ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
free (data);
|
||||
}
|
||||
free (data);
|
||||
}
|
||||
if (del>0) {
|
||||
eprintf ("Deleted %d lines\n", del);
|
||||
}
|
||||
free (str);
|
||||
fclose (fd);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ' ':
|
||||
if (input[2]=='-') {
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
// edit with cfg.editor
|
||||
const char *editor = r_config_get (core->config, "cfg.editor");
|
||||
if (str && *str && editor && *editor)
|
||||
r_sys_cmdf ("%s %s", editor, str);
|
||||
else eprintf ("No cfg.editor configured\n");
|
||||
free (str);
|
||||
} else {
|
||||
//char *str = r_core_project_notes_file (core, fileproject);
|
||||
// append line to project notes
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
char *data = r_file_slurp (str, NULL);
|
||||
FILE *fd = r_sandbox_fopen (str, "a");
|
||||
if (fd) {
|
||||
fprintf (fd, "%s\n", input+2);
|
||||
if (del > 0) {
|
||||
eprintf ("Deleted %d lines\n", del);
|
||||
}
|
||||
free (str);
|
||||
fclose (fd);
|
||||
}
|
||||
free (str);
|
||||
free (data);
|
||||
}
|
||||
break;
|
||||
case 'j':
|
||||
if (!input[2]) {
|
||||
int len = 0;
|
||||
/* get base64 string */
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
if (str) {
|
||||
char *data = r_file_slurp (str, &len);
|
||||
char *res = r_base64_encode_dyn (data, len);
|
||||
if (res) {
|
||||
r_cons_println (res);
|
||||
free (res);
|
||||
case ' ':
|
||||
if (input[2] == '-') {
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
// edit with cfg.editor
|
||||
const char *editor = r_config_get (core->config, "cfg.editor");
|
||||
if (str && *str && editor && *editor) {
|
||||
r_sys_cmdf ("%s %s", editor, str);
|
||||
} else {
|
||||
eprintf ("No cfg.editor configured\n");
|
||||
}
|
||||
free (data);
|
||||
free (str);
|
||||
} else {
|
||||
//char *str = r_core_project_notes_file (core, fileproject);
|
||||
// append line to project notes
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
char *data = r_file_slurp (str, NULL);
|
||||
FILE *fd = r_sandbox_fopen (str, "a");
|
||||
if (fd) {
|
||||
fprintf (fd, "%s\n", input + 2);
|
||||
fclose (fd);
|
||||
}
|
||||
free (str);
|
||||
free (data);
|
||||
}
|
||||
} else if (input[2] == ' ') {
|
||||
/* set base64 string */
|
||||
ut8 *data = r_base64_decode_dyn (input+3, -1);
|
||||
if (data) {
|
||||
break;
|
||||
case 'j':
|
||||
if (!input[2]) {
|
||||
int len = 0;
|
||||
/* get base64 string */
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
if (str) {
|
||||
r_file_dump (str, data, strlen ((const char*)data), 0);
|
||||
char *data = r_file_slurp (str, &len);
|
||||
char *res = r_base64_encode_dyn (data, len);
|
||||
if (res) {
|
||||
r_cons_println (res);
|
||||
free (res);
|
||||
}
|
||||
free (data);
|
||||
free (str);
|
||||
}
|
||||
} else if (input[2] == ' ') {
|
||||
/* set base64 string */
|
||||
ut8 *data = r_base64_decode_dyn (input + 3, -1);
|
||||
if (data) {
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
if (str) {
|
||||
r_file_dump (str, data, strlen ((const char *) data), 0);
|
||||
free (str);
|
||||
}
|
||||
free (data);
|
||||
}
|
||||
} else {
|
||||
eprintf ("Usage: `Pnj` or `Pnj ...`\n");
|
||||
}
|
||||
break;
|
||||
case 'x':
|
||||
r_core_project_execute_cmds (core, fileproject);
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
char *data = r_file_slurp (str, NULL);
|
||||
if (data) {
|
||||
r_cons_println (data);
|
||||
free (data);
|
||||
}
|
||||
} else {
|
||||
eprintf ("Usage: `Pnj` or `Pnj ...`\n");
|
||||
free (str);
|
||||
}
|
||||
break;
|
||||
case 'x':
|
||||
r_core_project_execute_cmds (core, fileproject);
|
||||
break;
|
||||
case 0:
|
||||
case '?':
|
||||
{
|
||||
char *str = r_core_project_notes_file (core, fileproject);
|
||||
char *data = r_file_slurp (str, NULL);
|
||||
if (data) {
|
||||
r_cons_println (data);
|
||||
free (data);
|
||||
}
|
||||
free (str);
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
{
|
||||
const char* help_msg[] = {
|
||||
const char *help_msg[] = {
|
||||
"Usage:", "Pn[j-?] [...]", "Project Notes",
|
||||
"Pn", "", "show project notes",
|
||||
"Pn", " -", "edit notes with cfg.editor",
|
||||
@ -183,10 +186,12 @@ static int cmd_project(void *data, const char *input) {
|
||||
"Pnx", "", "run project note commands",
|
||||
"Pnj", "", "show notes in base64",
|
||||
"Pnj", " [base64]", "set notes in base64",
|
||||
NULL};
|
||||
NULL
|
||||
};
|
||||
r_core_cmd_help (core, help_msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
@ -197,23 +202,24 @@ static int cmd_project(void *data, const char *input) {
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
const char* help_msg[] = {
|
||||
"Usage:", "P[?osi] [file]", "Project management",
|
||||
"Pc", " [file]", "show project script to console",
|
||||
"Pd", " [file]", "delete project",
|
||||
"Pi", " [file]", "show project information",
|
||||
"Pl", "", "list all projects",
|
||||
"Pn", "[j]", "show project notes (Pnj for json)",
|
||||
"Pn", " [base64]", "set notes text",
|
||||
"Pn", " -", "edit notes with cfg.editor",
|
||||
"Po", " [file]", "open project",
|
||||
"Ps", " [file]", "save project",
|
||||
"PS", " [file]", "save script file",
|
||||
"NOTE:", "", "See 'e??prj.'",
|
||||
"NOTE:", "", "project are stored in ~/.config/radare2/projects",
|
||||
NULL};
|
||||
const char *help_msg[] = {
|
||||
"Usage:", "P[?osi] [file]", "Project management",
|
||||
"Pc", " [file]", "show project script to console",
|
||||
"Pd", " [file]", "delete project",
|
||||
"Pi", " [file]", "show project information",
|
||||
"Pl", "", "list all projects",
|
||||
"Pn", "[j]", "show project notes (Pnj for json)",
|
||||
"Pn", " [base64]", "set notes text",
|
||||
"Pn", " -", "edit notes with cfg.editor",
|
||||
"Po", " [file]", "open project",
|
||||
"Ps", " [file]", "save project",
|
||||
"PS", " [file]", "save script file",
|
||||
"NOTE:", "", "See 'e??prj.'",
|
||||
"NOTE:", "", "project are stored in ~/.config/radare2/projects",
|
||||
NULL
|
||||
};
|
||||
r_core_cmd_help (core, help_msg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
free (str);
|
||||
|
288
libr/core/file.c
Executable file → Normal file
288
libr/core/file.c
Executable file → Normal file
@ -4,10 +4,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UPDATE_TIME(a) r->times->file_open_time = r_sys_now() - a
|
||||
#define UPDATE_TIME(a) r->times->file_open_time = r_sys_now () - a
|
||||
|
||||
static int r_core_file_do_load_for_debug (RCore *r, ut64 loadaddr, const char *filenameuri);
|
||||
static int r_core_file_do_load_for_io_plugin (RCore *r, ut64 baseaddr, ut64 loadaddr);
|
||||
static int r_core_file_do_load_for_debug(RCore *r, ut64 loadaddr, const char *filenameuri);
|
||||
static int r_core_file_do_load_for_io_plugin(RCore *r, ut64 baseaddr, ut64 loadaddr);
|
||||
|
||||
R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbin) {
|
||||
int isdebug = r_config_get_i (core->config, "cfg.debug");
|
||||
@ -15,11 +15,11 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
ut64 ofrom = 0, laddr = r_config_get_i (core->config, "bin.laddr");
|
||||
RCoreFile *file = NULL;
|
||||
RCoreFile *ofile = core->file;
|
||||
RBinFile *bf = (ofile && ofile->desc)
|
||||
? r_bin_file_find_by_fd (core->bin, ofile->desc->fd)
|
||||
: NULL;
|
||||
RIODesc *odesc = ofile ? ofile->desc : NULL;
|
||||
char *ofilepath = NULL, *obinfilepath = bf ? strdup (bf->file) : NULL;
|
||||
RBinFile *bf = (ofile && ofile->desc)
|
||||
? r_bin_file_find_by_fd (core->bin, ofile->desc->fd)
|
||||
: NULL;
|
||||
RIODesc *odesc = ofile? ofile->desc: NULL;
|
||||
char *ofilepath = NULL, *obinfilepath = bf? strdup (bf->file): NULL;
|
||||
int newpid, ret = false;
|
||||
ut64 origoff = core->offset;
|
||||
if (odesc) {
|
||||
@ -41,7 +41,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;
|
||||
newpid = odesc? odesc->fd: -1;
|
||||
|
||||
if (isdebug) {
|
||||
r_debug_kill (core->dbg, core->dbg->pid, core->dbg->tid, 9); // KILL
|
||||
@ -88,7 +88,7 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
}
|
||||
ofile = NULL;
|
||||
odesc = NULL;
|
||||
// core->file = file;
|
||||
// core->file = file;
|
||||
eprintf ("File %s reopened in %s mode\n", path,
|
||||
(perm & R_IO_WRITE)? "read-write": "read-only");
|
||||
|
||||
@ -101,13 +101,13 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
}
|
||||
|
||||
if (core->bin->cur && file->desc && !loadbin) {
|
||||
//force here NULL because is causing uaf look this better in future XXX @alvarofe
|
||||
//force here NULL because is causing uaf look this better in future XXX @alvarofe
|
||||
core->bin->cur = NULL;
|
||||
}
|
||||
// close old file
|
||||
} else if (ofile) {
|
||||
eprintf ("r_core_file_reopen: Cannot reopen file: %s with perms 0x%04x,"
|
||||
" attempting to open read-only.\n", path, perm);
|
||||
" attempting to open read-only.\n", path, perm);
|
||||
// lower it down back
|
||||
//ofile = r_core_file_open (core, path, R_IO_READ, addr);
|
||||
r_core_file_set_by_file (core, ofile);
|
||||
@ -137,8 +137,8 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
r_debug_select (core->dbg, newpid, newtid);
|
||||
}
|
||||
if (core->file) {
|
||||
RCoreFile * cf = core->file;
|
||||
RIODesc *desc = cf ? cf->desc : NULL;
|
||||
RCoreFile *cf = core->file;
|
||||
RIODesc *desc = cf? cf->desc: NULL;
|
||||
if (desc) {
|
||||
#if 0
|
||||
r_io_raise (core->io, desc->fd);
|
||||
@ -146,7 +146,7 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
#endif
|
||||
r_core_block_read (core);
|
||||
} else {
|
||||
const char *name = (cf && cf->desc) ? cf->desc->name : "ERROR";
|
||||
const char *name = (cf && cf->desc)? cf->desc->name: "ERROR";
|
||||
eprintf ("Error: Unable to switch the view to file: %s\n", name);
|
||||
}
|
||||
}
|
||||
@ -175,34 +175,34 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
|
||||
// because they can be replaced by commands in the given
|
||||
// command.. we should only expose the most essential and
|
||||
// unidirectional ones.
|
||||
R_API void r_core_sysenv_help(const RCore* core) {
|
||||
const char* help_msg[] = {
|
||||
"Usage:", "!<cmd>", " Run given command as in system(3)",
|
||||
"!", "", "list all historic commands",
|
||||
"!", "ls", "execute 'ls' in shell",
|
||||
"!!", "", "save command history to hist file",
|
||||
"!!", "ls~txt", "print output of 'ls' and grep for 'txt'",
|
||||
".!", "rabin2 -rpsei ${FILE}", "run each output line as a r2 cmd",
|
||||
"!", "echo $SIZE", "display file size",
|
||||
"!=!", "", "enable remotecmd mode",
|
||||
"=!=", "", "disable remotecmd mode",
|
||||
"\nEnvironment:", "", "",
|
||||
"R2_FILE", "", "file name",
|
||||
"R2_OFFSET", "", "10base offset 64bit value",
|
||||
"R2_BYTES", "", "TODO: variable with bytes in curblock",
|
||||
"R2_XOFFSET", "", "same as above, but in 16 base",
|
||||
"R2_BSIZE", "", "block size",
|
||||
"R2_ENDIAN", "", "'big' or 'little'",
|
||||
"R2_IOVA", "", "is io.va true? virtual addressing (1,0)",
|
||||
"R2_DEBUG", "", "debug mode enabled? (1,0)",
|
||||
"R2_BLOCK", "", "TODO: dump current block to tmp file",
|
||||
"R2_SIZE", "","file size",
|
||||
"R2_ARCH", "", "value of asm.arch",
|
||||
"R2_BITS", "", "arch reg size (8, 16, 32, 64)",
|
||||
"RABIN2_LANG", "", "assume this lang to demangle",
|
||||
"RABIN2_DEMANGLE", "", "demangle or not",
|
||||
"PDB_SERVER", "", "e pdb.server",
|
||||
NULL
|
||||
R_API void r_core_sysenv_help(const RCore *core) {
|
||||
const char *help_msg[] = {
|
||||
"Usage:", "!<cmd>", " Run given command as in system(3)",
|
||||
"!", "", "list all historic commands",
|
||||
"!", "ls", "execute 'ls' in shell",
|
||||
"!!", "", "save command history to hist file",
|
||||
"!!", "ls~txt", "print output of 'ls' and grep for 'txt'",
|
||||
".!", "rabin2 -rpsei ${FILE}", "run each output line as a r2 cmd",
|
||||
"!", "echo $SIZE", "display file size",
|
||||
"!=!", "", "enable remotecmd mode",
|
||||
"=!=", "", "disable remotecmd mode",
|
||||
"\nEnvironment:", "", "",
|
||||
"R2_FILE", "", "file name",
|
||||
"R2_OFFSET", "", "10base offset 64bit value",
|
||||
"R2_BYTES", "", "TODO: variable with bytes in curblock",
|
||||
"R2_XOFFSET", "", "same as above, but in 16 base",
|
||||
"R2_BSIZE", "", "block size",
|
||||
"R2_ENDIAN", "", "'big' or 'little'",
|
||||
"R2_IOVA", "", "is io.va true? virtual addressing (1,0)",
|
||||
"R2_DEBUG", "", "debug mode enabled? (1,0)",
|
||||
"R2_BLOCK", "", "TODO: dump current block to tmp file",
|
||||
"R2_SIZE", "","file size",
|
||||
"R2_ARCH", "", "value of asm.arch",
|
||||
"R2_BITS", "", "arch reg size (8, 16, 32, 64)",
|
||||
"RABIN2_LANG", "", "assume this lang to demangle",
|
||||
"RABIN2_DEMANGLE", "", "demangle or not",
|
||||
"PDB_SERVER", "", "e pdb.server",
|
||||
NULL
|
||||
};
|
||||
r_core_cmd_help (core, help_msg);
|
||||
}
|
||||
@ -224,11 +224,11 @@ R_API void r_core_sysenv_end(RCore *core, const char *cmd) {
|
||||
}
|
||||
|
||||
#if DISCUSS
|
||||
EDITOR r_sys_setenv ("EDITOR", r_config_get (core->config, "cfg.editor"));
|
||||
CURSOR cursor position (offset from curseek)
|
||||
VERBOSE cfg.verbose
|
||||
EDITOR r_sys_setenv ("EDITOR", r_config_get (core->config, "cfg.editor"));
|
||||
CURSOR cursor position (offset from curseek)
|
||||
VERBOSE cfg.verbose
|
||||
#endif
|
||||
R_API char *r_core_sysenv_begin(RCore *core, const char *cmd) {
|
||||
R_API char *r_core_sysenv_begin(RCore * core, const char *cmd) {
|
||||
char *f, *ret = strdup (cmd);
|
||||
if (strstr (cmd, "R2_BYTES")) {
|
||||
char *s = r_hex_bin2strdup (core->block, core->blocksize);
|
||||
@ -239,7 +239,7 @@ R_API char *r_core_sysenv_begin(RCore *core, const char *cmd) {
|
||||
if (core->file && core->file->desc && core->file->desc->name) {
|
||||
r_sys_setenv ("R2_FILE", core->file->desc->name);
|
||||
r_sys_setenv ("R2_SIZE", sdb_fmt (0, "%"PFMT64d,
|
||||
r_io_desc_size (core->io, core->file->desc)));
|
||||
r_io_desc_size (core->io, core->file->desc)));
|
||||
if (strstr (cmd, "R2_BLOCK")) {
|
||||
// replace BLOCK in RET string
|
||||
if ((f = r_file_temp ("r2block"))) {
|
||||
@ -257,10 +257,10 @@ R_API char *r_core_sysenv_begin(RCore *core, const char *cmd) {
|
||||
r_sys_setenv ("R2_ENDIAN", core->assembler->big_endian? "big": "little");
|
||||
r_sys_setenv ("R2_BSIZE", sdb_fmt (0, "%d", core->blocksize));
|
||||
r_sys_setenv ("R2_ARCH", r_config_get (core->config, "asm.arch"));
|
||||
r_sys_setenv ("R2_BITS", sdb_fmt(0, "%d", r_config_get_i (core->config, "asm.bits")));
|
||||
r_sys_setenv ("R2_BITS", sdb_fmt (0, "%d", r_config_get_i (core->config, "asm.bits")));
|
||||
r_sys_setenv ("R2_COLOR", r_config_get_i (core->config, "scr.color")? "1": "0");
|
||||
r_sys_setenv ("R2_DEBUG", r_config_get_i (core->config, "cfg.debug")?"1":"0");
|
||||
r_sys_setenv ("R2_IOVA", r_config_get_i (core->config, "io.va")?"1":"0");
|
||||
r_sys_setenv ("R2_DEBUG", r_config_get_i (core->config, "cfg.debug")? "1": "0");
|
||||
r_sys_setenv ("R2_IOVA", r_config_get_i (core->config, "io.va")? "1": "0");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -275,9 +275,15 @@ static ut64 get_base_from_maps(RCore *core, const char *file) {
|
||||
if ((map->perm & 5) == 5) {
|
||||
// TODO: make this more flexible
|
||||
// XXX - why "copy/" here?
|
||||
if (map->name && strstr (map->name, "copy/")) return map->addr;
|
||||
if (map->file && !strcmp (map->file, file)) return map->addr;
|
||||
if (map->name && !strcmp (map->name, file)) return map->addr;
|
||||
if (map->name && strstr (map->name, "copy/")) {
|
||||
return map->addr;
|
||||
}
|
||||
if (map->file && !strcmp (map->file, file)) {
|
||||
return map->addr;
|
||||
}
|
||||
if (map->name && !strcmp (map->name, file)) {
|
||||
return map->addr;
|
||||
}
|
||||
// XXX - Commented out, as this could unexpected results
|
||||
//b = map->addr;
|
||||
}
|
||||
@ -296,7 +302,7 @@ static ut64 get_base_from_maps(RCore *core, const char *file) {
|
||||
R_API int r_core_bin_reload(RCore *r, const char *file, ut64 baseaddr) {
|
||||
int result = 0;
|
||||
RCoreFile *cf = r_core_file_cur (r);
|
||||
RIODesc *desc = cf ? cf->desc : NULL;
|
||||
RIODesc *desc = cf? cf->desc: NULL;
|
||||
RBinFile *bf = NULL;
|
||||
if (desc) {
|
||||
result = r_bin_reload (r->bin, desc, baseaddr);
|
||||
@ -309,7 +315,9 @@ R_API int r_core_bin_reload(RCore *r, const char *file, ut64 baseaddr) {
|
||||
static bool setbpint(RCore *r, const char *mode, const char *sym) {
|
||||
RBreakpointItem *bp;
|
||||
RFlagItem *fi = r_flag_get (r->flags, sym);
|
||||
if (!fi) return false;
|
||||
if (!fi) {
|
||||
return false;
|
||||
}
|
||||
bp = r_bp_add_sw (r->dbg->bp, fi->offset, 1, R_BP_PROT_EXEC);
|
||||
if (bp) {
|
||||
bp->internal = true;
|
||||
@ -325,9 +333,9 @@ static bool setbpint(RCore *r, const char *mode, const char *sym) {
|
||||
}
|
||||
|
||||
// XXX - need to handle index selection during debugging
|
||||
static int r_core_file_do_load_for_debug (RCore *r, ut64 baseaddr, const char *filenameuri) {
|
||||
static int r_core_file_do_load_for_debug(RCore *r, ut64 baseaddr, const char *filenameuri) {
|
||||
RCoreFile *cf = r_core_file_cur (r);
|
||||
RIODesc *desc = cf ? cf->desc : NULL;
|
||||
RIODesc *desc = cf? cf->desc: NULL;
|
||||
RBinFile *binfile = NULL;
|
||||
RBinPlugin *plugin;
|
||||
int xtr_idx = 0; // if 0, load all if xtr is used
|
||||
@ -394,7 +402,7 @@ static int r_core_file_do_load_for_debug (RCore *r, ut64 baseaddr, const char *f
|
||||
r->bin->maxstrbuf = r_config_get_i (r->config, "bin.maxstrbuf");
|
||||
} else if (binfile) {
|
||||
RBinObject *obj = r_bin_get_object (r->bin);
|
||||
RBinInfo * info = obj ? obj->info : NULL;
|
||||
RBinInfo *info = obj? obj->info: NULL;
|
||||
if (plugin && strcmp (plugin->name, "any") && info) {
|
||||
r_core_bin_set_arch_bits (r, binfile->file, info->arch, info->bits);
|
||||
}
|
||||
@ -408,10 +416,10 @@ static int r_core_file_do_load_for_debug (RCore *r, ut64 baseaddr, const char *f
|
||||
|
||||
static int r_core_file_do_load_for_io_plugin(RCore *r, ut64 baseaddr, ut64 loadaddr) {
|
||||
RCoreFile *cf = r_core_file_cur (r);
|
||||
RIODesc *desc = cf ? cf->desc : NULL;
|
||||
RIODesc *desc = cf? cf->desc: NULL;
|
||||
RBinFile *binfile = NULL;
|
||||
int xtr_idx = 0; // if 0, load all if xtr is used
|
||||
RBinPlugin * plugin;
|
||||
RBinPlugin *plugin;
|
||||
|
||||
if (!desc) {
|
||||
return false;
|
||||
@ -425,9 +433,9 @@ static int r_core_file_do_load_for_io_plugin(RCore *r, ut64 baseaddr, ut64 loada
|
||||
binfile = r_bin_cur (r->bin);
|
||||
r_core_bin_set_env (r, binfile);
|
||||
plugin = r_bin_file_cur_plugin (binfile);
|
||||
if (plugin && !strcmp (plugin->name, "any") ) {
|
||||
if (plugin && !strcmp (plugin->name, "any")) {
|
||||
RBinObject *obj = r_bin_get_object (r->bin);
|
||||
RBinInfo * info = obj ? obj->info : NULL;
|
||||
RBinInfo *info = obj? obj->info: NULL;
|
||||
if (!info) {
|
||||
return false;
|
||||
}
|
||||
@ -440,7 +448,7 @@ static int r_core_file_do_load_for_io_plugin(RCore *r, ut64 baseaddr, ut64 loada
|
||||
r->bin->maxstrbuf = r_config_get_i (r->config, "bin.maxstrbuf");
|
||||
} else if (binfile) {
|
||||
RBinObject *obj = r_bin_get_object (r->bin);
|
||||
RBinInfo * info = obj ? obj->info : NULL;
|
||||
RBinInfo *info = obj? obj->info: NULL;
|
||||
if (!info) {
|
||||
return false;
|
||||
}
|
||||
@ -474,7 +482,7 @@ R_API bool r_core_file_loadlib(RCore *core, const char *lib, ut64 libaddr) {
|
||||
"./",
|
||||
NULL
|
||||
};
|
||||
const char **libpath = (const char **)&ldlibrarypath;
|
||||
const char * *libpath = (const char * *) &ldlibrarypath;
|
||||
|
||||
if (*lib == '/') {
|
||||
if (try_loadlib (core, lib, libaddr)) {
|
||||
@ -501,7 +509,7 @@ R_API int r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
const char *suppress_warning = r_config_get (r->config, "file.nowarn");
|
||||
RCoreFile *cf = r_core_file_cur (r);
|
||||
RBinFile *binfile = NULL;
|
||||
RIODesc *desc = cf ? cf->desc : NULL;
|
||||
RIODesc *desc = cf? cf->desc: NULL;
|
||||
RBinPlugin *plugin = NULL;
|
||||
int is_io_load;
|
||||
// NULL deref guard
|
||||
@ -521,7 +529,7 @@ R_API int r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
// new RCoreFile * should be opened.
|
||||
if (!strcmp (suppress_warning, "false")) {
|
||||
eprintf ("Error: The filenameuri '%s' is not the same as in RCoreFile: %s\n",
|
||||
filenameuri, cf->desc->name);
|
||||
filenameuri, cf->desc->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -568,12 +576,13 @@ R_API int r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
r->bin->maxstrbuf = r_config_get_i (r->config, "bin.maxstrbuf");
|
||||
} else if (binfile) {
|
||||
RBinObject *obj = r_bin_get_object (r->bin);
|
||||
RBinInfo * info = obj ? obj->info : NULL;
|
||||
if (plugin && plugin->name && info)
|
||||
RBinInfo *info = obj? obj->info: NULL;
|
||||
if (plugin && plugin->name && info) {
|
||||
if (strcmp (plugin->name, "any")) {
|
||||
r_core_bin_set_arch_bits (r, binfile->file,
|
||||
info->arch, info->bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plugin && plugin->name && !strcmp (plugin->name, "dex")) {
|
||||
r_core_cmd0 (r, "\"(fix-dex,wx `#sha1 $s-32 @32` @12 ;"
|
||||
@ -587,9 +596,7 @@ R_API int r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
}
|
||||
}
|
||||
if (r_config_get_i (r->config, "bin.libs")) {
|
||||
ut64 libaddr = (r->assembler->bits == 64)
|
||||
? 0x00007fff00000000LL
|
||||
: 0x7f000000;
|
||||
ut64 libaddr = (r->assembler->bits == 64)? 0x00007fff00000000LL: 0x7f000000;
|
||||
const char *lib;
|
||||
RListIter *iter;
|
||||
RList *libs = r_bin_get_libs (r->bin);
|
||||
@ -602,26 +609,31 @@ R_API int r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API RIOMap *r_core_file_get_next_map (RCore *core, RCoreFile * fh, int mode, ut64 loadaddr) {
|
||||
R_API RIOMap *r_core_file_get_next_map(RCore *core, RCoreFile *fh, int mode, ut64 loadaddr) {
|
||||
const char *loadmethod = r_config_get (core->config, "file.loadmethod");
|
||||
const char *suppress_warning = r_config_get (core->config, "file.nowarn");
|
||||
ut64 load_align = r_config_get_i (core->config, "file.loadalign");
|
||||
if (!loadmethod || !suppress_warning) return NULL;
|
||||
if (!loadmethod || !suppress_warning) {
|
||||
return NULL;
|
||||
}
|
||||
RIOMap *map = NULL;
|
||||
if (!strcmp (loadmethod, "overwrite"))
|
||||
if (!strcmp (loadmethod, "overwrite")) {
|
||||
map = r_io_map_new (core->io, fh->desc->fd, mode, 0, loadaddr, r_io_desc_size (core->io, fh->desc));
|
||||
if (!strcmp (loadmethod, "fail"))
|
||||
}
|
||||
if (!strcmp (loadmethod, "fail")) {
|
||||
map = r_io_map_add (core->io, fh->desc->fd, mode, 0, loadaddr, r_io_desc_size (core->io, fh->desc));
|
||||
}
|
||||
if (!strcmp (loadmethod, "append") && load_align) {
|
||||
map = r_io_map_add_next_available (core->io, fh->desc->fd, mode, 0, loadaddr, r_io_desc_size (core->io, fh->desc), load_align);
|
||||
}
|
||||
if (!strcmp (suppress_warning, "false")) {
|
||||
if (!map) {
|
||||
eprintf ("r_core_file_get_next_map: Unable to load specified file to 0x%08"PFMT64x"\n", loadaddr);
|
||||
eprintf ("r_core_file_get_next_map: Unable to load specified file to 0x%08"PFMT64x "\n", loadaddr);
|
||||
} else {
|
||||
if (map->from != loadaddr)
|
||||
eprintf ("r_core_file_get_next_map: Unable to load specified file to 0x%08"PFMT64x",\n"
|
||||
"but loaded to 0x%08"PFMT64x"\n", loadaddr, map->from);
|
||||
if (map->from != loadaddr) {
|
||||
eprintf ("r_core_file_get_next_map: Unable to load specified file to 0x%08"PFMT64x ",\n"
|
||||
"but loaded to 0x%08"PFMT64x "\n", loadaddr, map->from);
|
||||
}
|
||||
}
|
||||
}
|
||||
r_io_sort_maps (core->io); //necessary ???
|
||||
@ -642,13 +654,15 @@ R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut
|
||||
|
||||
list_fds = r_io_open_many (r->io, file, flags, 0644);
|
||||
|
||||
if (!list_fds || r_list_length (list_fds) == 0 ) {
|
||||
if (!list_fds || r_list_length (list_fds) == 0) {
|
||||
r_list_free (list_fds);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cp = r_config_get (r->config, "file.loadmethod");
|
||||
if (cp) loadmethod = strdup (cp);
|
||||
if (cp) {
|
||||
loadmethod = strdup (cp);
|
||||
}
|
||||
r_config_set (r->config, "file.loadmethod", "append");
|
||||
|
||||
r_list_foreach_safe (list_fds, fd_iter, iter2, fd) {
|
||||
@ -686,7 +700,7 @@ R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut
|
||||
if (!top_file) {
|
||||
top_file = fh;
|
||||
// check load addr to make sure its still valid
|
||||
loadaddr = top_file->map->from;
|
||||
loadaddr = top_file->map->from;
|
||||
}
|
||||
r_bin_bind (r->bin, &(fh->binb));
|
||||
r_list_append (r->files, fh);
|
||||
@ -703,7 +717,9 @@ R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut
|
||||
|
||||
r_config_set (r->config, "file.path", r_file_abspath (top_file->desc->name));
|
||||
r_config_set_i (r->config, "zoom.to", top_file->map->from + r_io_desc_size (r->io, top_file->desc));
|
||||
if (loadmethod) r_config_set (r->config, "file.loadmethod", loadmethod);
|
||||
if (loadmethod) {
|
||||
r_config_set (r->config, "file.loadmethod", loadmethod);
|
||||
}
|
||||
free (loadmethod);
|
||||
|
||||
return top_file;
|
||||
@ -711,7 +727,7 @@ R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut
|
||||
|
||||
/* loadaddr is r2 -m (mapaddr) */
|
||||
R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int flags, ut64 loadaddr) {
|
||||
ut64 prev = r_sys_now();
|
||||
ut64 prev = r_sys_now ();
|
||||
const char *suppress_warning = r_config_get (r->config, "file.nowarn");
|
||||
const int openmany = r_config_get_i (r->config, "file.openmany");
|
||||
const char *cp;
|
||||
@ -794,7 +810,7 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int flags, ut64 lo
|
||||
r_config_set_i (r->config, "dbg.swstep", swstep);
|
||||
}
|
||||
beach:
|
||||
r->times->file_open_time = r_sys_now() - prev;
|
||||
r->times->file_open_time = r_sys_now () - prev;
|
||||
return fh;
|
||||
}
|
||||
|
||||
@ -818,7 +834,7 @@ R_API void r_core_file_free(RCoreFile *cf) {
|
||||
// double free libr/io/io.c:70 performs free
|
||||
RIO *io = NULL;
|
||||
if (cf) {
|
||||
io = (RIO*)(cf->desc ? cf->desc->io : NULL);
|
||||
io = (RIO *) (cf->desc? cf->desc->io: NULL);
|
||||
if (cf->map) {
|
||||
r_io_map_del (io, cf->map->fd);
|
||||
cf->map = NULL;
|
||||
@ -833,8 +849,8 @@ R_API void r_core_file_free(RCoreFile *cf) {
|
||||
|
||||
R_API int r_core_file_close(RCore *r, RCoreFile *fh) {
|
||||
int ret;
|
||||
RIODesc *desc = fh && fh->desc? fh->desc : NULL;
|
||||
RCoreFile *prev_cf = r && r->file != fh ? r->file : NULL;
|
||||
RIODesc *desc = fh && fh->desc? fh->desc: NULL;
|
||||
RCoreFile *prev_cf = r && r->file != fh? r->file: NULL;
|
||||
|
||||
// TODO: This is not correclty done. because map and iodesc are
|
||||
// still referenced // we need to fully clear all R_IO structs
|
||||
@ -846,10 +862,13 @@ R_API int r_core_file_close(RCore *r, RCoreFile *fh) {
|
||||
// fh in the r->files list, we are hosed. (design flaw)
|
||||
// TODO maybe using sdb to keep track of the allocated and
|
||||
// deallocated files might be a good solutions
|
||||
if (!r || !desc || r_list_empty (r->files))
|
||||
if (!r || !desc || r_list_empty (r->files)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fh == r->file) r->file = NULL;
|
||||
if (fh == r->file) {
|
||||
r->file = NULL;
|
||||
}
|
||||
|
||||
r_core_file_set_by_fd (r, fh->desc->fd);
|
||||
r_core_bin_set_by_fd (r, fh->desc->fd);
|
||||
@ -862,13 +881,15 @@ R_API int r_core_file_close(RCore *r, RCoreFile *fh) {
|
||||
|
||||
ret = r_list_delete_data (r->files, fh);
|
||||
if (ret) {
|
||||
if (!prev_cf && r_list_length (r->files) > 0)
|
||||
if (!prev_cf && r_list_length (r->files) > 0) {
|
||||
prev_cf = (RCoreFile *) r_list_get_n (r->files, 0);
|
||||
}
|
||||
|
||||
if (prev_cf) {
|
||||
RIODesc *desc = prev_cf->desc;
|
||||
if (!desc)
|
||||
if (!desc) {
|
||||
eprintf ("Error: RCoreFile's found with out a supporting RIODesc.\n");
|
||||
}
|
||||
ret = r_core_file_set_by_file (r, prev_cf);
|
||||
}
|
||||
}
|
||||
@ -918,56 +939,60 @@ R_API int r_core_file_list(RCore *core, int mode) {
|
||||
switch (mode) {
|
||||
case 'j':
|
||||
r_cons_printf ("{\"raised\":%s,\"fd\":%d,\"uri\":\"%s\",\"from\":%"
|
||||
PFMT64d",\"writable\":%s,\"size\":%d,\"overlaps\":%s}%s",
|
||||
core->io->raised == f->desc->fd?"true":"false",
|
||||
(int)f->desc->fd, f->desc->uri, (ut64)from,
|
||||
PFMT64d ",\"writable\":%s,\"size\":%d,\"overlaps\":%s}%s",
|
||||
core->io->raised == f->desc->fd? "true": "false",
|
||||
(int) f->desc->fd, f->desc->uri, (ut64) from,
|
||||
f->desc->flags & R_IO_WRITE? "true": "false",
|
||||
(int)r_io_desc_size (core->io, f->desc),
|
||||
overlapped?"true":"false",
|
||||
iter->n? ",":"");
|
||||
(int) r_io_desc_size (core->io, f->desc),
|
||||
overlapped? "true": "false",
|
||||
iter->n? ",": "");
|
||||
break;
|
||||
case '*':
|
||||
case 'r':
|
||||
r_cons_printf ("o %s 0x%"PFMT64x"\n", f->desc->uri, (ut64)from);
|
||||
r_cons_printf ("o %s 0x%"PFMT64x "\n", f->desc->uri, (ut64) from);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
{
|
||||
ut64 sz = r_io_desc_size (core->io, f->desc);
|
||||
const char *fmt;
|
||||
if (sz == UT64_MAX) {
|
||||
fmt = "%c %d %d %s @ 0x%"PFMT64x" ; %s size=%"PFMT64d" %s\n";
|
||||
fmt = "%c %d %d %s @ 0x%"PFMT64x " ; %s size=%"PFMT64d " %s\n";
|
||||
} else {
|
||||
fmt = "%c %d %d %s @ 0x%"PFMT64x" ; %s size=%"PFMT64u" %s\n";
|
||||
fmt = "%c %d %d %s @ 0x%"PFMT64x " ; %s size=%"PFMT64u " %s\n";
|
||||
}
|
||||
r_cons_printf (fmt,
|
||||
core->io->raised == f->desc->fd?'*':'-',
|
||||
count,
|
||||
(int)f->desc->fd, f->desc->uri, (ut64)from,
|
||||
f->desc->flags & R_IO_WRITE? "rw": "r",
|
||||
r_io_desc_size (core->io, f->desc),
|
||||
overlapped?"overlaps":"");
|
||||
}
|
||||
break;
|
||||
core->io->raised == f->desc->fd? '*': '-',
|
||||
count,
|
||||
(int) f->desc->fd, f->desc->uri, (ut64) from,
|
||||
f->desc->flags & R_IO_WRITE? "rw": "r",
|
||||
r_io_desc_size (core->io, f->desc),
|
||||
overlapped? "overlaps": "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (mode=='j') {
|
||||
if (mode == 'j') {
|
||||
r_cons_printf ("]\n");
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// XXX - needs to account for binfile index and bin object index
|
||||
R_API int r_core_file_bin_raise (RCore *core, ut32 binfile_idx) {
|
||||
R_API int r_core_file_bin_raise(RCore *core, ut32 binfile_idx) {
|
||||
RBin *bin = core->bin;
|
||||
int v = binfile_idx > 1 ? binfile_idx : 1;
|
||||
int v = binfile_idx > 1? binfile_idx: 1;
|
||||
RBinFile *bf = r_list_get_n (bin->binfiles, v);
|
||||
int res = false;
|
||||
if (bf) {
|
||||
res = r_bin_file_set_cur_binfile (bin, bf);
|
||||
if (res) r_io_raise (core->io, bf->fd);
|
||||
res = res ? r_core_file_set_by_fd (core, bf->fd) : res;
|
||||
if (res) core->switch_file_view = 1;
|
||||
if (res) {
|
||||
r_io_raise (core->io, bf->fd);
|
||||
}
|
||||
res = res? r_core_file_set_by_fd (core, bf->fd): res;
|
||||
if (res) {
|
||||
core->switch_file_view = 1;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -978,7 +1003,7 @@ R_API int r_core_file_binlist(RCore *core) {
|
||||
RCoreFile *cur_cf = core->file, *cf = NULL;
|
||||
RBinFile *binfile = NULL;
|
||||
RBin *bin = core->bin;
|
||||
const RList *binfiles = bin ? bin->binfiles: NULL;
|
||||
const RList *binfiles = bin? bin->binfiles: NULL;
|
||||
|
||||
if (!binfiles) {
|
||||
return false;
|
||||
@ -987,8 +1012,8 @@ R_API int r_core_file_binlist(RCore *core) {
|
||||
int fd = binfile->fd;
|
||||
cf = r_core_file_get_by_fd (core, fd);
|
||||
if (cf && cf->map) {
|
||||
r_cons_printf ("%c %d %s @ 0x%"PFMT64x" ; %s\n",
|
||||
core->io->raised == cf->desc->fd?'*':'-',
|
||||
r_cons_printf ("%c %d %s @ 0x%"PFMT64x " ; %s\n",
|
||||
core->io->raised == cf->desc->fd? '*': '-',
|
||||
fd, cf->desc->uri, cf->map->from,
|
||||
cf->desc->flags & R_IO_WRITE? "rw": "r");
|
||||
}
|
||||
@ -1008,8 +1033,9 @@ R_API int r_core_file_close_fd(RCore *core, int fd) {
|
||||
core->file = NULL; // deref
|
||||
}
|
||||
#if 0
|
||||
if (r_list_empty (core->files))
|
||||
if (r_list_empty (core->files)) {
|
||||
core->file = NULL;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@ -1037,7 +1063,7 @@ R_API int r_core_hash_load(RCore *r, const char *file) {
|
||||
if (cf && r_io_desc_size (r->io, cf->desc) > limit) {
|
||||
return false;
|
||||
}
|
||||
buf = (ut8*)r_file_slurp (file, &buf_len);
|
||||
buf = (ut8 *) r_file_slurp (file, &buf_len);
|
||||
if (!buf) {
|
||||
return false;
|
||||
}
|
||||
@ -1065,7 +1091,7 @@ R_API int r_core_hash_load(RCore *r, const char *file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API RCoreFile * r_core_file_find_by_fd (RCore *core, ut64 fd) {
|
||||
R_API RCoreFile *r_core_file_find_by_fd(RCore *core, ut64 fd) {
|
||||
RListIter *iter;
|
||||
RCoreFile *cf = NULL;
|
||||
r_list_foreach (core->files, iter, cf) {
|
||||
@ -1077,7 +1103,7 @@ R_API RCoreFile * r_core_file_find_by_fd (RCore *core, ut64 fd) {
|
||||
return cf;
|
||||
}
|
||||
|
||||
R_API RCoreFile * r_core_file_find_by_name (RCore * core, const char * name) {
|
||||
R_API RCoreFile *r_core_file_find_by_name(RCore *core, const char *name) {
|
||||
RListIter *iter;
|
||||
RCoreFile *cf = NULL;
|
||||
|
||||
@ -1090,20 +1116,20 @@ R_API RCoreFile * r_core_file_find_by_name (RCore * core, const char * name) {
|
||||
return cf;
|
||||
}
|
||||
|
||||
R_API int r_core_file_set_by_fd (RCore * core, ut64 fd) {
|
||||
R_API int r_core_file_set_by_fd(RCore *core, ut64 fd) {
|
||||
RCoreFile *cf = r_core_file_find_by_fd (core, fd);
|
||||
return r_core_file_set_by_file (core, cf);
|
||||
}
|
||||
|
||||
R_API int r_core_file_set_by_name (RCore * core, const char * name) {
|
||||
R_API int r_core_file_set_by_name(RCore *core, const char *name) {
|
||||
RCoreFile *cf = r_core_file_find_by_name (core, name);
|
||||
return r_core_file_set_by_file (core, cf);
|
||||
}
|
||||
|
||||
R_API int r_core_file_set_by_file (RCore * core, RCoreFile *cf) {
|
||||
R_API int r_core_file_set_by_file(RCore *core, RCoreFile *cf) {
|
||||
if (cf) {
|
||||
RIODesc *desc = cf->desc;
|
||||
core->offset = cf && cf->map ? cf->map->from : 0LL;
|
||||
core->offset = cf && cf->map? cf->map->from: 0LL;
|
||||
core->file = cf;
|
||||
if (desc) {
|
||||
r_io_use_desc (core->io, desc);
|
||||
@ -1114,15 +1140,15 @@ R_API int r_core_file_set_by_file (RCore * core, RCoreFile *cf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API ut32 r_core_file_cur_fd (RCore *core) {
|
||||
RIODesc *desc = core->file ? core->file->desc : NULL;
|
||||
R_API ut32 r_core_file_cur_fd(RCore *core) {
|
||||
RIODesc *desc = core->file? core->file->desc: NULL;
|
||||
if (desc) {
|
||||
return desc->fd;
|
||||
}
|
||||
return UT32_MAX;
|
||||
}
|
||||
|
||||
R_API RCoreFile * r_core_file_cur (RCore *r) {
|
||||
R_API RCoreFile *r_core_file_cur(RCore *r) {
|
||||
// Add any locks here
|
||||
return r->file;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,19 +38,19 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
|
||||
// grab the current file descriptor, so we can reset core and io state
|
||||
// after our io op is done
|
||||
RIODesc *yankfd = NULL;
|
||||
ut64 fd = core->file ? core->file->desc->fd : -1, yank_file_sz = 0,
|
||||
loadaddr = 0, addr = offset;
|
||||
ut64 fd = core->file? core->file->desc->fd: -1, yank_file_sz = 0,
|
||||
loadaddr = 0, addr = offset;
|
||||
int res = false;
|
||||
|
||||
if (filename && *filename) {
|
||||
ut64 load_align = r_config_get_i (core->config, "file.loadalign");
|
||||
RIOMap * map = NULL;
|
||||
RIOMap *map = NULL;
|
||||
yankfd = r_io_open_nomap (core->io, filename, R_IO_READ, 0644);
|
||||
// map the file in for IO operations.
|
||||
if (yankfd && load_align) {
|
||||
yank_file_sz = r_io_size (core->io);
|
||||
map = r_io_map_add_next_available (core->io, yankfd->fd, R_IO_READ, 0, 0, yank_file_sz, load_align);
|
||||
loadaddr = map ? map->from : -1;
|
||||
loadaddr = map? map->from: -1;
|
||||
if (yankfd && map && loadaddr != -1) {
|
||||
// ***NOTE*** this is important, we need to
|
||||
// address the file at its physical address!
|
||||
@ -74,7 +74,7 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
|
||||
// map into the IO layer
|
||||
if (yankfd) {
|
||||
ut64 res = r_io_seek (core->io, addr, R_IO_SEEK_SET);
|
||||
ut64 actual_len = len <= yank_file_sz ? len : 0;
|
||||
ut64 actual_len = len <= yank_file_sz? len: 0;
|
||||
ut8 *buf = NULL;
|
||||
if (actual_len > 0 && res == addr) {
|
||||
buf = malloc (actual_len);
|
||||
@ -91,7 +91,7 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
|
||||
} else if (actual_len == 0) {
|
||||
eprintf (
|
||||
"ERROR: Unable to yank from file: addr+len (0x%"
|
||||
PFMT64x ") > file_sz (0x%"PFMT64x ")\n", addr+len,
|
||||
PFMT64x ") > file_sz (0x%"PFMT64x ")\n", addr + len,
|
||||
yank_file_sz );
|
||||
}
|
||||
r_io_close (core->io, yankfd);
|
||||
@ -118,9 +118,9 @@ R_API int r_core_yank_set(RCore *core, ut64 addr, const ut8 *buf, ut32 len) {
|
||||
// Call set and then null terminate the bytes.
|
||||
R_API int r_core_yank_set_str(RCore *core, ut64 addr, const char *str, ut32 len) {
|
||||
//free (core->yank_buf);
|
||||
int res = r_core_yank_set (core, addr, (ut8*)str, len);
|
||||
int res = r_core_yank_set (core, addr, (ut8 *) str, len);
|
||||
if (res == true) {
|
||||
core->yank_buf->buf[len-1] = 0;
|
||||
core->yank_buf->buf[len - 1] = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -171,7 +171,7 @@ R_API int r_core_yank_string(RCore *core, ut64 addr, int maxlen) {
|
||||
r_core_read_at (core, addr, buf, core->blocksize);
|
||||
if (maxlen == 0) {
|
||||
// Don't use strnlen, see: http://sourceforge.net/p/mingw/bugs/1912/
|
||||
maxlen = r_str_nlen ((const char*)buf, core->blocksize);
|
||||
maxlen = r_str_nlen ((const char *) buf, core->blocksize);
|
||||
} else if (maxlen > core->blocksize) {
|
||||
maxlen = core->blocksize;
|
||||
}
|
||||
@ -200,7 +200,7 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) {
|
||||
char *str, *arg;
|
||||
int res = false;
|
||||
|
||||
while (*_arg==' ') {
|
||||
while (*_arg == ' ') {
|
||||
_arg++;
|
||||
}
|
||||
arg = strdup (_arg);
|
||||
@ -208,7 +208,7 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) {
|
||||
if (str) {
|
||||
str[0] = '\0';
|
||||
len = r_num_math (core->num, arg);
|
||||
pos = r_num_math (core->num, str+1);
|
||||
pos = r_num_math (core->num, str + 1);
|
||||
str[0] = ' ';
|
||||
}
|
||||
if (len < 1) {
|
||||
@ -231,10 +231,10 @@ R_API int r_core_yank_dump(RCore *core, ut64 pos) {
|
||||
int res = false, i = 0;
|
||||
int ybl = core->yank_buf->length;
|
||||
if (ybl > 0) {
|
||||
if (pos<ybl) {
|
||||
if (pos < ybl) {
|
||||
r_cons_printf ("0x%08"PFMT64x " %d ",
|
||||
core->yank_buf->base+pos,
|
||||
core->yank_buf->length-pos);
|
||||
core->yank_buf->base + pos,
|
||||
core->yank_buf->length - pos);
|
||||
for (i = pos; i < core->yank_buf->length; i++) {
|
||||
r_cons_printf ("%02x",
|
||||
core->yank_buf->buf[i]);
|
||||
@ -272,7 +272,7 @@ R_API int r_core_yank_cat(RCore *core, ut64 pos) {
|
||||
int ybl = core->yank_buf->length;
|
||||
if (ybl > 0) {
|
||||
if (pos < ybl) {
|
||||
r_cons_memcat ((const char*)core->yank_buf->buf + pos,
|
||||
r_cons_memcat ((const char *) core->yank_buf->buf + pos,
|
||||
core->yank_buf->length - pos);
|
||||
r_cons_newline ();
|
||||
return true;
|
||||
@ -288,8 +288,8 @@ R_API int r_core_yank_cat_string(RCore *core, ut64 pos) {
|
||||
int ybl = core->yank_buf->length;
|
||||
if (ybl > 0) {
|
||||
if (pos < ybl) {
|
||||
int len = r_str_nlen ((const char *)core->yank_buf->buf + pos, ybl - pos);
|
||||
r_cons_memcat ((const char*)core->yank_buf->buf + pos, len);
|
||||
int len = r_str_nlen ((const char *) core->yank_buf->buf + pos, ybl - pos);
|
||||
r_cons_memcat ((const char *) core->yank_buf->buf + pos, len);
|
||||
r_cons_newline ();
|
||||
return true;
|
||||
}
|
||||
@ -311,7 +311,7 @@ R_API int r_core_yank_hud_file(RCore *core, const char *input) {
|
||||
/* nothing */
|
||||
}
|
||||
buf = r_cons_hud_file (input);
|
||||
len = buf ? strlen ((const char*)buf) + 1 : 0;
|
||||
len = buf? strlen ((const char *) buf) + 1: 0;
|
||||
res = r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len);
|
||||
free (buf);
|
||||
return res;
|
||||
@ -321,11 +321,11 @@ R_API int r_core_yank_hud_path(RCore *core, const char *input, int dir) {
|
||||
char *buf = NULL;
|
||||
ut32 len = 0;
|
||||
int res;
|
||||
for (input++; *input==' '; input++) {
|
||||
for (input++; *input == ' '; input++) {
|
||||
/* nothing */
|
||||
}
|
||||
buf = r_cons_hud_path (input, dir);
|
||||
len = buf ? strlen ((const char*)buf) + 1 : 0;
|
||||
len = buf? strlen ((const char *) buf) + 1: 0;
|
||||
res = r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len);
|
||||
free (buf);
|
||||
return res;
|
||||
@ -340,13 +340,13 @@ R_API bool r_core_yank_file_ex(RCore *core, const char *input) {
|
||||
}
|
||||
// get the number of bytes to yank
|
||||
adv = consume_chars (input, ' ');
|
||||
len = r_num_math (core->num, input+adv);
|
||||
len = r_num_math (core->num, input + adv);
|
||||
if (len == 0) {
|
||||
eprintf ("ERROR: Number of bytes read must be > 0\n");
|
||||
return res;
|
||||
}
|
||||
// get the addr/offset from in the file we want to read
|
||||
adv += find_next_char (input+adv, ' ');
|
||||
adv += find_next_char (input + adv, ' ');
|
||||
if (adv == 0) {
|
||||
eprintf ("ERROR: Address must be specified\n");
|
||||
return res;
|
||||
@ -354,9 +354,9 @@ R_API bool r_core_yank_file_ex(RCore *core, const char *input) {
|
||||
adv++;
|
||||
|
||||
// XXX - bug, will fail if address needs to be computed and has spaces
|
||||
addr = r_num_math (core->num, input+adv);
|
||||
addr = r_num_math (core->num, input + adv);
|
||||
|
||||
adv += find_next_char (input+adv, ' ');
|
||||
adv += find_next_char (input + adv, ' ');
|
||||
if (adv == 0) {
|
||||
eprintf ("ERROR: File must be specified\n");
|
||||
return res;
|
||||
@ -365,7 +365,7 @@ R_API bool r_core_yank_file_ex(RCore *core, const char *input) {
|
||||
|
||||
// grab the current file descriptor, so we can reset core and io state
|
||||
// after our io op is done
|
||||
return perform_mapped_file_yank (core, addr, len, input+adv);
|
||||
return perform_mapped_file_yank (core, addr, len, input + adv);
|
||||
}
|
||||
|
||||
R_API int r_core_yank_file_all(RCore *core, const char *input) {
|
||||
@ -374,5 +374,5 @@ R_API int r_core_yank_file_all(RCore *core, const char *input) {
|
||||
return false;
|
||||
}
|
||||
adv = consume_chars (input, ' ');
|
||||
return perform_mapped_file_yank (core, 0, -1, input+adv);
|
||||
return perform_mapped_file_yank (core, 0, -1, input + adv);
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# known bugs
|
||||
# ----------
|
||||
# - labels are indented
|
||||
# - #if 0 code is indented
|
||||
# - //comment should be // comment
|
||||
|
||||
IFILE="$1"
|
||||
P=`readlink $0`
|
||||
cd `dirname $P`/..
|
||||
|
Loading…
x
Reference in New Issue
Block a user