* Add RBinInfo->has_va

- Used to autoforce io.va after loading the bin
  - Fixes loading kernel modules and object files
* Fix loading strings on a object file without io.va
* Add install-rev.sh script
This commit is contained in:
pancake 2011-11-29 15:29:50 +01:00
parent be843f0cda
commit 6de942e05d
15 changed files with 47 additions and 25 deletions

View File

@ -36,7 +36,8 @@ static void get_strings_range(RBinArch *arch, RList *list, int min, ut64 from, u
}
str[matches] = '\0';
ptr->offset = i-matches;
ptr->rva = ptr->offset-from+scnrva;
if (scnrva) ptr->rva = ptr->offset-from+scnrva;
else ptr->rva = ptr->offset;
ptr->size = matches+1;
ptr->ordinal = ctr;
// copying so many bytes here..
@ -449,6 +450,7 @@ R_API RBinObj *r_bin_get_object(RBin *bin, int flags) {
for (i=0; i<R_BIN_SYM_LAST; i++)
obj->binsym[i] = r_bin_get_sym (bin, i);
obj->baddr = r_bin_get_baddr (bin);
obj->info = r_bin_get_info (bin);
}
return obj;
}

View File

@ -394,16 +394,10 @@ char* Elf_(r_bin_elf_get_data_encoding)(struct Elf_(r_bin_elf_obj_t) *bin) {
}
}
char* Elf_(r_bin_elf_get_type)(struct Elf_(r_bin_elf_obj_t) *bin) {
int Elf_(r_bin_elf_has_va)(struct Elf_(r_bin_elf_obj_t) *bin) {
ut32 e_type = (ut32)bin->ehdr.e_type; // cast to avoid warn in iphone-gcc, must be ut16
if (e_type == ET_REL)
return strdup ("elf-object");
return strdup ("elf");
#if ANOTHERCHK
if (bin->ehdr.e_phnum == 0)
return strdup ("elf-object");
return strdup ("elf");
#endif
//if (bin->ehdr.e_phnum == 0)
return (e_type == ET_REL)? 0: 1;
}
// TODO: do not strdup here

View File

@ -80,7 +80,7 @@ struct Elf_(r_bin_elf_obj_t) {
struct r_buf_t* b;
};
char* Elf_(r_bin_elf_get_type)(struct Elf_(r_bin_elf_obj_t) *bin);
int Elf_(r_bin_elf_has_va)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_baddr)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_entry_offset)(struct Elf_(r_bin_elf_obj_t) *bin);
ut64 Elf_(r_bin_elf_get_main_offset)(struct Elf_(r_bin_elf_obj_t) *bin);

View File

@ -35,6 +35,7 @@ static RBinInfo * info(RBinArch *arch) {
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy (ret->type, "DEX CLASS", R_BIN_SIZEOF_STRINGS);
ret->has_va = R_FALSE;
version = r_bin_dex_get_version (arch->bin_obj);
strncpy (ret->bclass, version, R_BIN_SIZEOF_STRINGS);
free (version);

View File

@ -240,11 +240,10 @@ static RBinInfo* info(RBinArch *arch) {
return NULL;
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
str = Elf_(r_bin_elf_get_type) (arch->bin_obj);
strncpy (ret->rclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
strncpy (ret->rclass, "elf", R_BIN_SIZEOF_STRINGS);
ret->bits = Elf_(r_bin_elf_get_bits) (arch->bin_obj);
ret->big_endian=Elf_(r_bin_elf_is_big_endian) (arch->bin_obj);
ret->big_endian = Elf_(r_bin_elf_is_big_endian) (arch->bin_obj);
ret->has_va = Elf_(r_bin_elf_has_va) (arch->bin_obj);
ret->dbg_info = 0;
if (!Elf_(r_bin_elf_get_stripped) (arch->bin_obj))
ret->dbg_info |= 0x04 | 0x08 | 0x10;
@ -296,8 +295,8 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data,
ut32 baddr;
int is_arm = !strcmp (bin->curarch.info->arch, "arm");
RBuffer *buf = r_buf_new ();
if (is_arm)
baddr = 0x40000;
// XXX: hardcoded
if (is_arm) baddr = 0x40000;
else baddr = 0x8048000;
#define B(x,y) r_buf_append_bytes(buf,(const ut8*)x,y)

View File

@ -69,6 +69,7 @@ static RBinInfo* info(RBinArch *arch) {
p = fsname (arch);
strncpy (ret->arch, p, sizeof (ret->arch)-1);
free (p);
ret->has_va = 0;
ret->bits = 32;
ret->big_endian = 0;
ret->dbg_info = 0;

View File

@ -119,6 +119,7 @@ static RBinInfo* info(RBinArch *arch) {
version = r_bin_java_get_version (arch->bin_obj);
strncpy (ret->bclass, version, R_BIN_SIZEOF_STRINGS-1);
free (version);
ret->has_va = 0;
strncpy (ret->rclass, "class", R_BIN_SIZEOF_STRINGS-1);
strncpy (ret->os, "any", R_BIN_SIZEOF_STRINGS-1);
strncpy (ret->subsystem, "any", R_BIN_SIZEOF_STRINGS-1);

View File

@ -157,7 +157,7 @@ static RBinInfo* info(RBinArch *arch) {
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
strncpy(ret->rclass, "mach0", R_BIN_SIZEOF_STRINGS);
strncpy (ret->rclass, "mach0", R_BIN_SIZEOF_STRINGS);
/* TODO get os*/
strncpy (ret->os, "darwin", R_BIN_SIZEOF_STRINGS);
strncpy (ret->subsystem, "darwin", R_BIN_SIZEOF_STRINGS);
@ -177,6 +177,7 @@ static RBinInfo* info(RBinArch *arch) {
ret->big_endian = MACH0_(r_bin_mach0_is_big_endian) (arch->bin_obj);
/* TODO detailed debug info */
ret->dbg_info = 0;
ret->has_va = R_TRUE;
return ret;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2011 nibble<.ds@gmail.com> */
#include <r_types.h>
#include <r_bin.h>

View File

@ -154,6 +154,7 @@ static RBinInfo* info(RBinArch *arch) {
strncpy (ret->subsystem, "plan9", R_BIN_SIZEOF_STRINGS);
strncpy (ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_STRINGS);
ret->bits = bits;
ret->has_va = 1;
ret->big_endian = big_endian;
ret->dbg_info = 0;
ret->dbg_info = 0;

View File

@ -198,6 +198,7 @@ static RBinInfo* info(RBinArch *arch) {
ret->bits = PE_(r_bin_pe_get_bits) (arch->bin_obj);
ret->big_endian = PE_(r_bin_pe_is_big_endian) (arch->bin_obj);
ret->dbg_info = 0;
ret->has_va = 0;
if (!PE_(r_bin_pe_is_stripped_debug) (arch->bin_obj))
ret->dbg_info |= 0x01;
if (PE_(r_bin_pe_is_stripped_line_nums) (arch->bin_obj))

View File

@ -80,27 +80,26 @@ static int bin_info (RCore *r, int mode) {
// XXX: hack to disable io.va when loading an elf object
// XXX: this must be something generic for all filetypes
// XXX: needs new api in r_bin_has_va () or something..
int has_va = (!strcmp (info->rclass, "elf-object"))? 0: 1;
//int has_va = (!strcmp (info->rclass, "elf-object"))? 0: 1;
//if (!strcmp (info->type, "REL"))...relocatable object..
r_cons_printf (
"e file.type=%s\n"
"e io.va=%d\n"
"e cfg.bigendian=%s\n"
"e asm.os=%s\n"
"e asm.arch=%s\n"
"e anal.plugin=%s\n"
"e asm.bits=%i\n"
"e asm.dwarf=%s\n",
info->rclass, has_va,
info->big_endian?"true":"false", info->os,
info->rclass, r_str_bool (info->big_endian), info->os,
info->arch, info->arch, info->bits,
R_BIN_DBG_STRIPPED (info->dbg_info)?"false":"true");
r_str_bool (R_BIN_DBG_STRIPPED (info->dbg_info)));
}
} else {
// if type is 'fs' show something different?
r_cons_printf ("[File info]\n");
r_cons_printf ("File=%s\n"
"Type=%s\n"
"HasVA=%s\n"
"RootClass=%s\n"
"Class=%s\n"
"Arch=%s %i\n"
@ -114,7 +113,8 @@ static int bin_info (RCore *r, int mode) {
"Local_syms=%s\n"
"Relocs=%s\n"
"RPath=%s\n",
info->file, info->type, info->rclass, info->bclass,
info->file, info->type, r_str_bool (info->has_va),
info->rclass, info->bclass,
info->arch, info->bits, info->machine, info->os,
info->subsystem,
r_str_bool (info->big_endian),

View File

@ -105,6 +105,9 @@ R_API int r_core_bin_load(RCore *r, const char *file) {
} else if (!r_bin_load (r->bin, file, R_TRUE))
return R_FALSE;
r->file->obj = r_bin_get_object (r->bin, 0);
if (r->file->obj->info != NULL) {
r_config_set_i (r->config, "io.va", r->file->obj->info->has_va);
} else r_config_set_i (r->config, "io.va", 0);
{
ut64 offset = r_bin_get_offset (r->bin);
r_core_bin_info (r, R_CORE_BIN_ACC_ALL, R_CORE_BIN_SET, va, NULL, offset);

View File

@ -195,6 +195,7 @@ typedef struct r_bin_info_t {
char subsystem[R_BIN_SIZEOF_STRINGS];
char rpath[R_BIN_SIZEOF_STRINGS];
int bits;
int has_va;
int big_endian;
ut64 dbg_info;
} RBinInfo;

17
sys/install-rev.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: install-rev [revision-number]"
exit 1
fi
REV="$1"
MAKE=make
gmake --help >/dev/null 2>&1
[ $? = 0 ] && MAKE=gmake
# find root
cd `dirname $PWD/$0` ; cd ..
echo hg up -C -r "${REV}"
hg up -C -r "${REV}"
./sys/build.sh && sudo ${MAKE} symstall