mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-13 16:18:33 +00:00
Minor enhancements in pds
This commit is contained in:
parent
187ecaec7b
commit
49cab15200
@ -1402,9 +1402,11 @@ static void printraw (RCore *core, int len, int mode) {
|
||||
int obsz = core->blocksize;
|
||||
int restore_obsz = 0;
|
||||
if (len != obsz) {
|
||||
if (!r_core_block_size (core, len))
|
||||
if (!r_core_block_size (core, len)) {
|
||||
len = core->blocksize;
|
||||
else restore_obsz = 1;
|
||||
} else {
|
||||
restore_obsz = 1;
|
||||
}
|
||||
}
|
||||
r_print_raw (core->print, core->offset, core->block, len, mode);
|
||||
if (restore_obsz) {
|
||||
@ -1413,15 +1415,40 @@ static void printraw (RCore *core, int len, int mode) {
|
||||
core->cons->newline = true;
|
||||
}
|
||||
|
||||
|
||||
static void _handle_call(RCore *core, char * line, char **str) {
|
||||
if (!core || !core->assembler || !core->assembler->cur) {
|
||||
*str = NULL;
|
||||
return;
|
||||
}
|
||||
if (strstr (core->assembler->cur->arch, "x86")) {
|
||||
*str = strstr (line , "call ");
|
||||
} else if (strstr (core->assembler->cur->arch, "arm")) {
|
||||
*str = strstr (line, " b ");
|
||||
if (!*str) {
|
||||
*str = strstr (line, "bl ");
|
||||
if (!*str) { // does it come with color?
|
||||
*str = strstr (line, "bl\x1b");
|
||||
}
|
||||
}
|
||||
if (!*str) {
|
||||
*str = strstr (line, "bx ");
|
||||
if (!*str) { //does it come with color?
|
||||
*str = strstr (line, "bx\x1b");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this is just a PoC, the disasm loop should be rewritten
|
||||
// TODO: this is based on string matching, it should be written upon RAnalOp to know
|
||||
// when we have a call and such
|
||||
static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
|
||||
#define MYPAL(x) (core->cons && core->cons->pal.x)? core->cons->pal.x: ""
|
||||
const char *linecolor = NULL;
|
||||
char *ox, *qo, *string = NULL;
|
||||
char *line, *s, *str;
|
||||
char *string2 = NULL;
|
||||
int i, count;
|
||||
int use_color = r_config_get_i (core->config, "scr.color");
|
||||
char *line, *s, *str, *string2 = NULL;
|
||||
int i, count, use_color = r_config_get_i (core->config, "scr.color");
|
||||
|
||||
if (!strncmp (input, "dsf", 3)) {
|
||||
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL);
|
||||
@ -1439,7 +1466,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
|
||||
line = s = r_core_cmd_str (core, "pd");
|
||||
}
|
||||
count = r_str_split (s, '\n');
|
||||
if (!line || !*line || count <1) {
|
||||
if (!line || !*line || count < 1) {
|
||||
free (line);
|
||||
return;
|
||||
}
|
||||
@ -1452,22 +1479,26 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
|
||||
addr = r_num_get (NULL, ox);
|
||||
}
|
||||
if (qo) {
|
||||
char *qoe = strchr (qo+1, '"');
|
||||
char *qoe = strchr (qo + 1, '"');
|
||||
if (qoe) {
|
||||
int len = qoe - qo - 1;
|
||||
if (len>2) {
|
||||
if (len > 2) {
|
||||
string = r_str_ndup (qo, len+2);
|
||||
}
|
||||
linecolor = MYPAL (comment);
|
||||
}
|
||||
}
|
||||
ox = strstr (line, "; 0x");
|
||||
if (!ox) ox = strstr (line, "@ 0x");
|
||||
if (!ox) {
|
||||
ox = strstr (line, "@ 0x");
|
||||
}
|
||||
if (ox) {
|
||||
char *qoe = strchr (ox+3, ' ');
|
||||
if (!qoe) qoe = strchr(ox+3, '\x1b');
|
||||
int len = qoe? qoe-ox: strlen (ox+3);
|
||||
string2 = r_str_ndup (ox+2, len-1);
|
||||
char *qoe = strchr (ox + 3, ' ');
|
||||
if (!qoe) {
|
||||
qoe = strchr (ox + 3, '\x1b');
|
||||
}
|
||||
int len = qoe? qoe - ox: strlen (ox + 3);
|
||||
string2 = r_str_ndup (ox + 2, len - 1);
|
||||
if (r_num_get (NULL, string2) < 0x100) {
|
||||
R_FREE (string2);
|
||||
}
|
||||
@ -1475,43 +1506,37 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
|
||||
str = strstr (line, " str.");
|
||||
if (str) {
|
||||
char *qoe = NULL;
|
||||
if (!qoe) qoe = strchr (str+1, '\x1b');
|
||||
if (!qoe) qoe = strchr (str+1, ';');
|
||||
if (!qoe) qoe = strchr (str+1, ' ');
|
||||
if (!qoe) {
|
||||
qoe = strchr (str + 1, '\x1b');
|
||||
}
|
||||
if (!qoe) {
|
||||
qoe = strchr (str + 1, ';');
|
||||
}
|
||||
if (!qoe) {
|
||||
qoe = strchr (str + 1, ' ');
|
||||
}
|
||||
if (qoe) {
|
||||
string2 = r_str_ndup (str+1, qoe-str-1);
|
||||
string2 = r_str_ndup (str + 1, qoe - str - 1);
|
||||
} else {
|
||||
string2 = strdup (str+1);
|
||||
string2 = strdup (str + 1);
|
||||
}
|
||||
if (!string && string2) {
|
||||
string = string2;
|
||||
string2 = NULL;
|
||||
}
|
||||
#if 0
|
||||
if (string && string2 && !strcmp (string, string2)) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (string2) {
|
||||
R_FREE (string2);
|
||||
}
|
||||
str = strstr (line, "sym.");
|
||||
_handle_call (core, line, &str);
|
||||
if (!str) {
|
||||
str = strstr (line, "fcn.");
|
||||
str = strstr (line, "sym.");
|
||||
if (!str) {
|
||||
str = strstr (line, "fcn.");
|
||||
}
|
||||
}
|
||||
if (str) {
|
||||
char *qoe = strchr (str, ' ');
|
||||
if (qoe) {
|
||||
string2 = r_str_ndup (str, qoe - str);
|
||||
} else {
|
||||
qoe = strchr (str, ')');
|
||||
if (!qoe) qoe = strchr (str, '(');
|
||||
if (qoe) {
|
||||
string2 = r_str_ndup (str, qoe - str);
|
||||
} else {
|
||||
string2 = strdup (str);
|
||||
}
|
||||
}
|
||||
string2 = strdup (str);
|
||||
linecolor = MYPAL(call);
|
||||
}
|
||||
if (!string && string2) {
|
||||
@ -1557,9 +1582,12 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
|
||||
}
|
||||
}
|
||||
if (string && *string) {
|
||||
if (string && !strncmp (string, "0x", 2)) str = string;
|
||||
if (string2 && !strncmp (string2, "0x", 2)) str = string2;
|
||||
|
||||
if (string && !strncmp (string, "0x", 2)) {
|
||||
str = string;
|
||||
}
|
||||
if (string2 && !strncmp (string2, "0x", 2)) {
|
||||
str = string2;
|
||||
}
|
||||
ut64 ptr = r_num_math (NULL, str);
|
||||
RFlagItem *flag = NULL;
|
||||
if (str) {
|
||||
@ -1578,11 +1606,11 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) {
|
||||
r_cons_printf ("%s0x%08"PFMT64x"%s %s%s%s%s%s%s%s\n",
|
||||
MYPAL(offset), addr, Color_RESET,
|
||||
linecolor? linecolor: "",
|
||||
string2? string2: "", string2? " ":"", string,
|
||||
string2? string2: "", string2?" ":"", string,
|
||||
flag?" ":"", flag?flag->name:"", Color_RESET);
|
||||
} else {
|
||||
r_cons_printf ("0x%08"PFMT64x" %s%s%s%s%s\n", addr,
|
||||
string2?string2:"", string2?" ":"", string,
|
||||
string2? string2 :"", string2? " ":"", string,
|
||||
flag?" ":"", flag?flag->name:"");
|
||||
}
|
||||
}
|
||||
|
@ -1409,11 +1409,12 @@ R_API int r_core_init(RCore *core) {
|
||||
// TODO: get arch from r_bin or from native arch
|
||||
r_asm_use (core->assembler, R_SYS_ARCH);
|
||||
r_anal_use (core->anal, R_SYS_ARCH);
|
||||
if (R_SYS_BITS & R_SYS_BITS_64)
|
||||
if (R_SYS_BITS & R_SYS_BITS_64) {
|
||||
r_config_set_i (core->config, "asm.bits", 64);
|
||||
else
|
||||
if (R_SYS_BITS & R_SYS_BITS_32)
|
||||
}
|
||||
if (R_SYS_BITS & R_SYS_BITS_32) {
|
||||
r_config_set_i (core->config, "asm.bits", 32);
|
||||
}
|
||||
r_config_set (core->config, "asm.arch", R_SYS_ARCH);
|
||||
r_bp_use (core->dbg->bp, R_SYS_ARCH, core->anal->bits);
|
||||
update_sdb (core);
|
||||
@ -1509,8 +1510,7 @@ static int prompt_flag (RCore *r, char *s, size_t maxlen) {
|
||||
if (!f) return false;
|
||||
|
||||
if (f->offset < r->offset) {
|
||||
snprintf (s, maxlen, "%s + %" PFMT64u, f->name,
|
||||
r->offset - f->offset);
|
||||
snprintf (s, maxlen, "%s + %" PFMT64u, f->name, r->offset - f->offset);
|
||||
} else {
|
||||
snprintf (s, maxlen, "%s", f->name);
|
||||
}
|
||||
@ -1523,8 +1523,9 @@ static int prompt_flag (RCore *r, char *s, size_t maxlen) {
|
||||
|
||||
static void prompt_sec(RCore *r, char *s, size_t maxlen) {
|
||||
const RIOSection *sec = r_io_section_vget (r->io, r->offset);
|
||||
if (!sec) return;
|
||||
|
||||
if (!sec) {
|
||||
return;
|
||||
}
|
||||
snprintf (s, maxlen, "%s:", sec->name);
|
||||
}
|
||||
|
||||
@ -1620,8 +1621,12 @@ R_API int r_core_prompt(RCore *r, int sync) {
|
||||
set_prompt (r);
|
||||
|
||||
ret = r_cons_fgets (line, sizeof (line), 0, NULL);
|
||||
if (ret == -2) return R_CORE_CMD_EXIT; // ^D
|
||||
if (ret == -1) return false; // FD READ ERROR
|
||||
if (ret == -2) {
|
||||
return R_CORE_CMD_EXIT; // ^D
|
||||
}
|
||||
if (ret == -1) {
|
||||
return false; // FD READ ERROR
|
||||
}
|
||||
r->num->value = rnv;
|
||||
if (sync) {
|
||||
return r_core_prompt_exec (r);
|
||||
@ -1660,14 +1665,14 @@ R_API int r_core_block_size(RCore *core, int bsize) {
|
||||
eprintf ("Block size %d is too big\n", bsize);
|
||||
return false;
|
||||
}
|
||||
if (bsize<1) {
|
||||
if (bsize < 1) {
|
||||
bsize = 1;
|
||||
} else if (core->blocksize_max && bsize>core->blocksize_max) {
|
||||
eprintf ("bsize is bigger than `bm`. dimmed to 0x%x > 0x%x\n",
|
||||
bsize, core->blocksize_max);
|
||||
bsize = core->blocksize_max;
|
||||
}
|
||||
bump = realloc (core->block, bsize+1);
|
||||
bump = realloc (core->block, bsize + 1);
|
||||
if (!bump) {
|
||||
eprintf ("Oops. cannot allocate that much (%u)\n", bsize);
|
||||
ret = false;
|
||||
@ -1688,12 +1693,17 @@ R_API int r_core_seek_align(RCore *core, ut64 align, int times) {
|
||||
return false;
|
||||
}
|
||||
diff = core->offset%align;
|
||||
if (times == 0) {
|
||||
if (!times) {
|
||||
diff = -diff;
|
||||
} else if (diff) {
|
||||
if (inc>0) diff += align-diff;
|
||||
else diff = -diff;
|
||||
if (times) times -= inc;
|
||||
if (inc > 0) {
|
||||
diff += align-diff;
|
||||
} else {
|
||||
diff = -diff;
|
||||
}
|
||||
if (times) {
|
||||
times -= inc;
|
||||
}
|
||||
}
|
||||
while ((times*inc) > 0) {
|
||||
times -= inc;
|
||||
@ -1918,7 +1928,7 @@ reaccept:
|
||||
/* read */
|
||||
r_socket_read_block (c, (ut8*)&bufr, 4);
|
||||
i = r_read_be32 (bufr);
|
||||
if (i>0 && i < RMT_MAX) {
|
||||
if (i > 0 && i < RMT_MAX) {
|
||||
if ((cmd = malloc (i + 1))) {
|
||||
r_socket_read_block (c, (ut8*)cmd, i);
|
||||
cmd[i] = '\0';
|
||||
@ -2044,25 +2054,29 @@ reaccept:
|
||||
R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback cb) {
|
||||
int ret, len = core->blocksize;
|
||||
ut8 *buf;
|
||||
if (!(buf = malloc (len)))
|
||||
if (!(buf = malloc (len))) {
|
||||
eprintf ("Cannot allocate blocksize\n");
|
||||
else while (from<to) {
|
||||
ut64 delta = to-from;
|
||||
if (delta<len)
|
||||
len = (int)delta;
|
||||
if (!r_io_read_at (core->io, from, buf, len)) {
|
||||
eprintf ("Cannot read at 0x%"PFMT64x"\n", from);
|
||||
break;
|
||||
}
|
||||
for (ret=0; ret<len;) {
|
||||
int done = cb (core, from, buf+ret, len-ret);
|
||||
if (done<1) { /* interrupted */
|
||||
free (buf);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
while (from < to) {
|
||||
ut64 delta = to-from;
|
||||
if (delta < len) {
|
||||
len = (int)delta;
|
||||
}
|
||||
ret += done;
|
||||
if (!r_io_read_at (core->io, from, buf, len)) {
|
||||
eprintf ("Cannot read at 0x%"PFMT64x"\n", from);
|
||||
break;
|
||||
}
|
||||
for (ret = 0; ret < len;) {
|
||||
int done = cb (core, from, buf+ret, len-ret);
|
||||
if (done < 1) { /* interrupted */
|
||||
free (buf);
|
||||
return false;
|
||||
}
|
||||
ret += done;
|
||||
}
|
||||
from += len;
|
||||
}
|
||||
from += len;
|
||||
}
|
||||
free (buf);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user