* rax2 -s (without arg) uses stdin now
* Show help when no file given to rabin2 -O help * Fix ELF strtab section read issue (workaround?)
This commit is contained in:
parent
9be6f53757
commit
28e5244064
|
@ -576,18 +576,23 @@ static int rabin_do_operation(const char *op) {
|
|||
case 'd':
|
||||
if (!ptr)
|
||||
goto _rabin_do_operation_error;
|
||||
if (ptr[0]=='s') {
|
||||
switch (*ptr) {
|
||||
case 's':
|
||||
if (ptr2) {
|
||||
if (!rabin_dump_symbols (r_num_math(NULL, ptr2)))
|
||||
return R_FALSE;
|
||||
} else if (!rabin_dump_symbols (0))
|
||||
return R_FALSE;
|
||||
} else if (ptr[0]=='S') {
|
||||
break;
|
||||
case 'S':
|
||||
if (!ptr2)
|
||||
goto _rabin_do_operation_error;
|
||||
if (!rabin_dump_sections (ptr2))
|
||||
return R_FALSE;
|
||||
} else goto _rabin_do_operation_error;
|
||||
break;
|
||||
default:
|
||||
goto _rabin_do_operation_error;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
r_bin_wr_scn_resize (bin, ptr, r_num_math (NULL, ptr2));
|
||||
|
@ -715,6 +720,8 @@ int main(int argc, char **argv) {
|
|||
case 'O':
|
||||
op = optarg;
|
||||
action |= ACTION_OPERATION;
|
||||
if (optind==argc)
|
||||
return rabin_do_operation (op);
|
||||
break;
|
||||
case 'o':
|
||||
output = optarg;
|
||||
|
|
|
@ -6,7 +6,7 @@ static int flags = 0;
|
|||
|
||||
static int format_output (char mode, ut64 n);
|
||||
static int help ();
|
||||
static int rax (char *str);
|
||||
static int rax (char *str, int last);
|
||||
static int use_stdin ();
|
||||
|
||||
static int format_output (char mode, ut64 n) {
|
||||
|
@ -61,7 +61,7 @@ static int help () {
|
|||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int rax (char *str) {
|
||||
static int rax (char *str, int last) {
|
||||
float f;
|
||||
char *p, *buf, out_mode = '0';
|
||||
int i;
|
||||
|
@ -89,6 +89,8 @@ static int rax (char *str) {
|
|||
printf ("Usage: rax2 [options] [expression]\n");
|
||||
return help ();
|
||||
}
|
||||
if (last)
|
||||
return use_stdin ();
|
||||
return R_TRUE;
|
||||
} else
|
||||
if (*str=='q')
|
||||
|
@ -102,7 +104,7 @@ static int rax (char *str) {
|
|||
buf = malloc (sizeof (char) * n);
|
||||
memset (buf, '\0', n);
|
||||
n = r_hex_str2bin (str, (ut8*)buf);
|
||||
printf ("%s\n", buf);
|
||||
write (1, buf, n);
|
||||
free (buf);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
@ -162,7 +164,7 @@ static int use_stdin () {
|
|||
fgets (buf, sizeof (buf), stdin);
|
||||
if (feof (stdin)) break;
|
||||
buf[strlen (buf)-1] = '\0';
|
||||
if (!rax (buf)) break;
|
||||
if (!rax (buf, 0)) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -172,6 +174,6 @@ int main (int argc, char **argv) {
|
|||
if (argc == 1)
|
||||
return use_stdin ();
|
||||
for (i=1; i<argc; i++)
|
||||
rax (argv[i]);
|
||||
rax (argv[i], (i+1)==argc);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
* Compile
|
||||
|
||||
./configure --without-ssl --prefix=/usr
|
||||
./configure --without-ssl --prefix=/usr --with-little-endian
|
||||
make
|
||||
|
||||
* Create the package
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <r_util.h>
|
||||
#include "elf.h"
|
||||
|
||||
static ut64 Elf_(r_bin_elf_get_section_size)(struct Elf_(r_bin_elf_obj_t) *bin, const char *section_name);
|
||||
|
||||
static inline int __strnlen(const char *str, int len) {
|
||||
int l = 0;
|
||||
while (*str && --len) {
|
||||
|
@ -92,19 +94,36 @@ static int Elf_(r_bin_elf_init_shdr)(struct Elf_(r_bin_elf_obj_t) *bin) {
|
|||
}
|
||||
|
||||
static int Elf_(r_bin_elf_init_strtab)(struct Elf_(r_bin_elf_obj_t) *bin) {
|
||||
ut64 size;
|
||||
if (!bin->shdr)
|
||||
return R_FALSE;
|
||||
bin->strtab_section = &bin->shdr[bin->ehdr.e_shstrndx];
|
||||
if ((bin->strtab = (char *)malloc (bin->strtab_section->sh_size)) == NULL) {
|
||||
bin->strtab_size = size = bin->strtab_section->sh_size;
|
||||
|
||||
if ((bin->strtab = (char *)malloc (size)) == NULL) {
|
||||
perror ("malloc");
|
||||
return R_FALSE;
|
||||
}
|
||||
if (r_buf_read_at (bin->b, bin->strtab_section->sh_offset, (ut8*)bin->strtab,
|
||||
bin->strtab_section->sh_size) == -1) {
|
||||
if (r_buf_read_at (bin->b, bin->strtab_section->sh_offset, (ut8*)bin->strtab, size) == -1) {
|
||||
eprintf ("Error: read (strtab)\n");
|
||||
R_FREE (bin->strtab);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
size = Elf_(r_bin_elf_get_section_size)(bin, ".strtab");
|
||||
if (size != UT64_MAX) {
|
||||
bin->strtab_size = size;
|
||||
free (bin->strtab);
|
||||
if ((bin->strtab = (char *)malloc (size)) == NULL) {
|
||||
perror ("malloc");
|
||||
return R_FALSE;
|
||||
}
|
||||
if (r_buf_read_at (bin->b, bin->strtab_section->sh_offset, (ut8*)bin->strtab, size) == -1) {
|
||||
eprintf ("Error: read (strtab)\n");
|
||||
R_FREE (bin->strtab);
|
||||
return R_FALSE;
|
||||
}
|
||||
}
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
|
@ -112,6 +131,7 @@ static int Elf_(r_bin_elf_init)(struct Elf_(r_bin_elf_obj_t) *bin) {
|
|||
bin->phdr = NULL;
|
||||
bin->shdr = NULL;
|
||||
bin->strtab = NULL;
|
||||
bin->strtab_size = 0;
|
||||
bin->strtab_section = NULL;
|
||||
if (!Elf_(r_bin_elf_init_ehdr) (bin)) {
|
||||
eprintf ("Warning: File is not ELF\n");
|
||||
|
@ -128,6 +148,19 @@ static int Elf_(r_bin_elf_init)(struct Elf_(r_bin_elf_obj_t) *bin) {
|
|||
return R_TRUE;
|
||||
}
|
||||
|
||||
static ut64 Elf_(r_bin_elf_get_section_size)(struct Elf_(r_bin_elf_obj_t) *bin, const char *section_name) {
|
||||
int i;
|
||||
if (!bin->shdr || !bin->strtab)
|
||||
return -1;
|
||||
for (i = 0; i < bin->ehdr.e_shnum; i++) {
|
||||
if (bin->shdr[i].sh_name > bin->strtab_section->sh_size)
|
||||
continue;
|
||||
if (!strcmp (&bin->strtab[bin->shdr[i].sh_name], section_name))
|
||||
return (ut64)bin->shdr[i].sh_size;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static ut64 Elf_(r_bin_elf_get_section_offset)(struct Elf_(r_bin_elf_obj_t) *bin, const char *section_name) {
|
||||
int i;
|
||||
if (!bin->shdr || !bin->strtab)
|
||||
|
@ -553,10 +586,11 @@ struct r_bin_elf_reloc_t* Elf_(r_bin_elf_get_relocs)(struct Elf_(r_bin_elf_obj_t
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < bin->ehdr.e_shnum; i++) {
|
||||
if (bin->shdr[i].sh_name > bin->strtab_section->sh_size) {
|
||||
if (bin->shdr[i].sh_name > bin->strtab_size) {
|
||||
eprintf ("Invalid shdr index in strtab %d/%"PFMT64d"\n",
|
||||
bin->shdr[i].sh_name, (ut64) bin->strtab_section->sh_size);
|
||||
bin->shdr[i].sh_name, (ut64) bin->strtab_size);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp (&bin->strtab[bin->shdr[i].sh_name], ".rel.plt"))
|
||||
|
@ -688,7 +722,8 @@ struct r_bin_elf_section_t* Elf_(r_bin_elf_get_sections)(struct Elf_(r_bin_elf_o
|
|||
ret[i].size = bin->shdr[i].sh_size;
|
||||
ret[i].align = bin->shdr[i].sh_addralign;
|
||||
ret[i].flags = bin->shdr[i].sh_flags;
|
||||
strncpy (ret[i].name, bin->strtab?&bin->strtab[bin->shdr[i].sh_name]:"unknown", ELF_STRING_LENGTH);
|
||||
strncpy (ret[i].name, bin->strtab?
|
||||
&bin->strtab[bin->shdr[i].sh_name]: "unknown", ELF_STRING_LENGTH);
|
||||
ret[i].last = 0;
|
||||
}
|
||||
ret[i].last = 1;
|
||||
|
|
|
@ -67,6 +67,7 @@ struct Elf_(r_bin_elf_obj_t) {
|
|||
Elf_(Phdr)* phdr;
|
||||
Elf_(Shdr)* shdr;
|
||||
Elf_(Shdr) *strtab_section;
|
||||
ut64 strtab_size;
|
||||
char* strtab;
|
||||
int bss;
|
||||
int size;
|
||||
|
|
Loading…
Reference in New Issue