- Show filesize in '-x' output
  - Select "sub-bin" using '-a arch_bits' and '-n filename'
* r_bin
  - Add argument "name" to r_bin_set_arch
This commit is contained in:
Nibble 2010-10-01 10:09:50 +02:00
parent 4b558bec3b
commit 41bd2fd0ea
3 changed files with 40 additions and 36 deletions

View File

@ -45,30 +45,31 @@ static char *name = NULL;
static int rabin_show_help() {
printf ("rabin2 [options] [file]\n"
" -a [arch] [bits] Set arch\n"
" -A List archs\n"
" -b [addr] Override baddr\n"
" -e Entrypoint\n"
" -M Main\n"
" -i Imports (symbols imported from libraries)\n"
" -s Symbols (exports)\n"
" -S Sections\n"
" -z Strings\n"
" -I Binary info\n"
" -H Header fields\n"
" -l Linked libraries\n"
" -R Relocations\n"
" -O [str] Write/Extract operations (str=help for help)\n"
" -o [file] Output file for write operations (a.out by default)\n"
" -r radare output\n"
" -v Use vaddr in radare output\n"
" -m [addr] Show source line at addr\n"
" -L List supported bin plugins\n"
" -@ [addr] Show section, symbol or import at addr\n"
" -n [str] Show section, symbol or import named str\n"
" -x Extract bins contained in file\n"
" -V Show version information\n"
" -h This help\n");
" -a [arch_bits] Set arch\n"
" -A List archs\n"
" -b [addr] Override baddr\n"
" -e Entrypoint\n"
" -M Main\n"
" -i Imports (symbols imported from libraries)\n"
" -s Symbols (exports)\n"
" -S Sections\n"
" -z Strings\n"
" -I Binary info\n"
" -H Header fields\n"
" -l Linked libraries\n"
" -R Relocations\n"
" -O [str] Write/Extract operations (str=help for help)\n"
" -o [file] Output file for write operations (a.out by default)\n"
" -r radare output\n"
" -v Use vaddr in radare output\n"
" -m [addr] Show source line at addr\n"
" -L List supported bin plugins\n"
" -@ [addr] Show section, symbol or import at addr\n"
" -n [str] Show section, symbol or import named str\n"
" or extract, analyze arch named str\n"
" -x Extract bins contained in file\n"
" -V Show version information\n"
" -h This help\n");
return 1;
}
@ -132,7 +133,7 @@ static int rabin_extract(int all) {
if (!r_file_dump (out, bin->arch[i].buf->buf, bin->arch[i].size)) {
eprintf ("Error extracting %s\n", out);
return R_FALSE;
} else eprintf ("%s created\n", out);
} else eprintf ("%s created (%i)\n", out, bin->arch[i].size);
}
} else {
if ((ptr = strrchr (bin->arch[i].file, '/')))
@ -143,7 +144,7 @@ static int rabin_extract(int all) {
if (!r_file_dump (out, bin->curarch->buf->buf, bin->curarch->size)) {
eprintf ("Error extracting %s\n", out);
return R_FALSE;
} else eprintf ("%s created\n", out);
} else eprintf ("%s created (%i)\n", out, bin->arch[i].size);
}
return R_TRUE;
}
@ -634,7 +635,7 @@ static int __lib_bin_xtr_dt(struct r_lib_plugin_t *pl, void *p, void *u) {
int main(int argc, char **argv)
{
int c, bits = 32;
int c, bits = 0;
int action = ACTION_UNK;
const char *op = NULL;
char *arch = NULL;
@ -755,7 +756,7 @@ int main(int argc, char **argv)
bits = r_num_math (NULL, ptr+1);
}
}
if (action&ACTION_LISTARCHS || (arch && !r_bin_set_arch (bin, arch, bits))) {
if (action&ACTION_LISTARCHS || !r_bin_set_arch (bin, arch, bits, name)) {
rabin_list_archs ();
free (arch);
r_bin_free (bin);
@ -785,7 +786,7 @@ int main(int argc, char **argv)
if (action&ACTION_SRCLINE)
rabin_show_srcline(at);
if (action&ACTION_EXTRACT)
rabin_extract(arch==NULL);
rabin_extract((arch==NULL&&name==NULL&&bits==0));
if (op != NULL && action&ACTION_OPERATION)
rabin_do_operation (op);

View File

@ -349,14 +349,17 @@ R_API RBin* r_bin_new() {
return bin;
}
R_API int r_bin_set_arch(RBin *bin, const char *arch, int bits) {
R_API int r_bin_set_arch(RBin *bin, const char *arch, int bits, const char *name) {
int i;
for (i = 0; i < bin->narch; i++)
if (!strcmp (arch, bin->arch[i].info->arch) && bits == bin->arch[i].info->bits) {
bin->curarch = &bin->arch[i];
return R_TRUE;
}
for (i = 0; i < bin->narch; i++) {
if ((arch && !strstr (arch, bin->arch[i].info->arch)) ||
(bits && bits != bin->arch[i].info->bits) ||
(name && !strstr (bin->arch[i].file, name)))
continue;
bin->curarch = &bin->arch[i];
return R_TRUE;
}
return R_FALSE;
}

View File

@ -203,7 +203,7 @@ R_API int r_bin_has_dbg_linenums (RBin *bin);
R_API int r_bin_has_dbg_syms (RBin *bin);
R_API int r_bin_has_dbg_relocs (RBin *bin);
R_API RBin* r_bin_new();
R_API int r_bin_set_arch(RBin *bin, const char *arch, int bits);
R_API int r_bin_set_arch(RBin *bin, const char *arch, int bits, const char *name);
R_API void r_bin_set_user_ptr(RBin *bin, void *user);
/* bin_meta.c */