mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-31 10:22:37 +00:00
ELF parser more permissive, add 'fsr' and other fixes
Make ELF loader more permissive Add 'fsr' to rename flagspaces Fix parsing issue in 'yy' Fix crash in r_num
This commit is contained in:
parent
5f4623ed46
commit
ba3ad8112a
@ -1,5 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2008-2012 - nibble, pancake */
|
||||
// TODO: review the rest of strtab index out of range
|
||||
/* radare - LGPL - Copyright 2008-2013 - nibble, pancake */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -553,7 +552,7 @@ int Elf_(r_bin_elf_get_bits)(struct Elf_(r_bin_elf_obj_t) *bin) {
|
||||
case ELFCLASSNONE: return 0;
|
||||
case ELFCLASS32: return 32;
|
||||
case ELFCLASS64: return 64;
|
||||
default: return -1;
|
||||
default: return 32; // defaults
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,8 @@ static RList* fields(RBinArch *arch) {
|
||||
#if !R_BIN_ELF64
|
||||
static int check(RBinArch *arch) {
|
||||
if (arch && arch->buf && arch->buf->buf)
|
||||
if (!memcmp (arch->buf->buf, "\x7F\x45\x4c\x46\x01", 5))
|
||||
//if (!memcmp (arch->buf->buf, "\x7F\x45\x4c\x46\x01", 5))
|
||||
if (!memcmp (arch->buf->buf, "\x7F\x45\x4c\x46", 4))
|
||||
return R_TRUE;
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -188,13 +188,16 @@ static int cmd_rap(void *data, const char *input) {
|
||||
|
||||
static int cmd_yank(void *data, const char *input) {
|
||||
int i;
|
||||
ut64 n;
|
||||
RCore *core = (RCore *)data;
|
||||
switch (input[0]) {
|
||||
case ' ':
|
||||
r_core_yank (core, core->offset, r_num_math (core->num, input+1));
|
||||
break;
|
||||
case 'y':
|
||||
r_core_yank_paste (core, r_num_math (core->num, input+2), 0);
|
||||
while (input[1]==' ') input++;
|
||||
n = input[1]? r_num_math (core->num, input+1): core->offset;
|
||||
r_core_yank_paste (core, n, 0);
|
||||
break;
|
||||
case 'x':
|
||||
r_print_hexdump (core->print, 0LL, core->yank_buf, core->yank_len, 16, 4);
|
||||
|
@ -24,9 +24,7 @@ static int cmd_flag(void *data, const char *input) {
|
||||
if (r_str_glob (flag->name, ptr+1))
|
||||
flag->offset += base;
|
||||
}
|
||||
} else {
|
||||
core->flags->base = r_num_math (core->num, input+1);
|
||||
}
|
||||
} else core->flags->base = r_num_math (core->num, input+1);
|
||||
free (str);
|
||||
str = NULL;
|
||||
break;
|
||||
@ -113,6 +111,11 @@ static int cmd_flag(void *data, const char *input) {
|
||||
break;
|
||||
case 's':
|
||||
switch (input[1]) {
|
||||
case 'r':
|
||||
if (input[2]==' ')
|
||||
r_flag_space_rename (core->flags, NULL, input+2);
|
||||
else eprintf ("Usage: fsr [newname]\n");
|
||||
break;
|
||||
case 'j':
|
||||
case '\0':
|
||||
case '*':
|
||||
@ -236,6 +239,7 @@ static int cmd_flag(void *data, const char *input) {
|
||||
" fs ; display flagspaces\n"
|
||||
" fs * ; set all flagspace\n"
|
||||
" fs sections ; set flagspace (f will only list flags from selected ones)\n"
|
||||
" fsr newname ; set flagspace (f will only list flags from selected ones)\n"
|
||||
" fsm [addr] ; move flags at given address to the current flagspace\n"
|
||||
" fb [addr] ; set base address for new flags\n"
|
||||
" fb [addr] [flag*]; move flags matching 'flag' to relative addr\n"
|
||||
|
@ -37,7 +37,7 @@ R_API int r_core_yank(struct r_core_t *core, ut64 addr, int len) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_core_yank_paste(struct r_core_t *core, ut64 addr, int len) {
|
||||
R_API int r_core_yank_paste(RCore *core, ut64 addr, int len) {
|
||||
if (len == 0)
|
||||
len = core->yank_len;
|
||||
if (len > core->yank_len)
|
||||
|
@ -38,15 +38,15 @@ R_API void r_flag_space_set(RFlag *f, const char *name) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0;i<R_FLAG_SPACES_MAX;i++) {
|
||||
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
||||
if (f->spaces[i] != NULL)
|
||||
if (!strcmp (name, f->spaces[i])) {
|
||||
f->space_idx = i; //flag_space_idx = i;
|
||||
f->space_idx = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* not found */
|
||||
for (i=0;i<R_FLAG_SPACES_MAX;i++) {
|
||||
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
||||
if (f->spaces[i] == NULL) {
|
||||
f->spaces[i] = strdup (name);
|
||||
f->space_idx = i;
|
||||
@ -81,3 +81,23 @@ R_API int r_flag_space_list(RFlag *f, int mode) {
|
||||
r_cons_printf ("]\n");
|
||||
return j;
|
||||
}
|
||||
|
||||
R_API int r_flag_space_rename (RFlag *f, const char *oname, const char *nname) {
|
||||
int i;
|
||||
if (!oname) {
|
||||
if (f->space_idx == -1)
|
||||
return R_FALSE;
|
||||
oname = f->spaces[f->space_idx];
|
||||
}
|
||||
if (!nname) return R_FALSE;
|
||||
while (*oname==' ') oname++;
|
||||
while (*nname==' ') nname++;
|
||||
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
|
||||
if (f->spaces[i] && !strcmp (oname, f->spaces[i])) {
|
||||
free (f->spaces[i]);
|
||||
f->spaces[i] = strdup (nname);
|
||||
return R_TRUE;
|
||||
}
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ typedef struct r_flag_t {
|
||||
st64 base;
|
||||
int space_idx;
|
||||
int space_idx2;
|
||||
const char *spaces[R_FLAG_SPACES_MAX];
|
||||
char *spaces[R_FLAG_SPACES_MAX];
|
||||
#if USE_HT
|
||||
RHashTable64 *ht_off;
|
||||
RHashTable64 *ht_name;
|
||||
@ -67,6 +67,7 @@ R_API int r_flag_space_get(RFlag *f, const char *name);
|
||||
R_API const char *r_flag_space_get_i(RFlag *f, int idx);
|
||||
R_API void r_flag_space_set(RFlag *f, const char *name);
|
||||
R_API int r_flag_space_list(RFlag *f, int mode);
|
||||
R_API int r_flag_space_rename (RFlag *f, const char *oname, const char *nname);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -78,6 +78,7 @@ R_API ut64 r_num_get(RNum *num, const char *str) {
|
||||
|
||||
if (!str) return 0;
|
||||
for (; *str==' '; ) str++;
|
||||
if (!*str) return 0;
|
||||
|
||||
/* resolve string with an external callback */
|
||||
if (num && num->callback) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user