Add length and size fields in RBinString

This commit is contained in:
pancake 2014-02-11 00:08:12 +01:00
parent 521e2076d5
commit 1390d9f2d5
7 changed files with 48 additions and 46 deletions

View File

@ -84,6 +84,7 @@ static void get_strings_range(RBinFile *arch, RList *list, int min, ut64 from, u
}
//HACK if (scnrva) ptr->rva = ptr->offset-from+scnrva; else ptr->rva = ptr->offset;
ptr->size = matches+1;
ptr->length = ptr->size << ((type=='W')? 1:0);
ptr->type = type;
type = 'A';
ptr->ordinal = ctr;
@ -671,7 +672,7 @@ R_API RBin* r_bin_new() {
bin->cur = R_NEW0 (RBinFile);
bin->cur->o = R_NEW0 (RBinObject);
bin->binfiles = r_list_new();
bin->binfiles->free = r_bin_file_free;
bin->binfiles->free = (RListFree)r_bin_file_free;
for (i=0; bin_static_plugins[i]; i++) {
r_bin_add (bin, bin_static_plugins[i]); //static_plugin);
}

View File

@ -42,7 +42,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj
curoffset = bin->hdr.startaddr+idx*32;
libla = *(ut64*)(bin->b->buf+curoffset);
liboff = libla - *(ut64*)&bin->b->buf[bin->hdr.baseaddroff];
if (liboff < 0 || liboff > bin->size) {
if (liboff > bin->size) {
eprintf ("Corrupted file\n");
free (ret);
return NULL;

View File

@ -495,7 +495,7 @@ static int MACH0_(r_bin_mach0_parse_import_stub)(struct MACH0_(r_bin_mach0_obj_t
symbol->name[0] = '\0';
for (i = 0; i < bin->nsects; i++) {
if ((bin->sects[i].flags & SECTION_TYPE) == S_SYMBOL_STUBS &&
bin->sects[i].reserved1 >= 0 && bin->sects[i].reserved2 > 0) {
bin->sects[i].reserved2 > 0) {
nsyms = (int)(bin->sects[i].size / bin->sects[i].reserved2);
for (j = 0; j < nsyms; j++) {
if (bin->sects[i].reserved1 + j >= bin->nindirectsyms)
@ -596,8 +596,7 @@ static int MACH0_(r_bin_mach0_parse_import_ptr)(struct MACH0_(r_bin_mach0_obj_t)
#undef CASE
for (i = 0; i < bin->nsects; i++) {
if ((bin->sects[i].flags & SECTION_TYPE) == stype &&
bin->sects[i].reserved1 >= 0) {
if ((bin->sects[i].flags & SECTION_TYPE) == stype) {
for (j=0, sym=-1; bin->sects[i].reserved1+j < bin->nindirectsyms; j++)
if (idx == bin->indirectsyms[bin->sects[i].reserved1 + j]) {
sym = j;

View File

@ -192,10 +192,11 @@ static inline ut32 getmethodoffset (struct r_bin_dex_obj_t *bin, int n, ut32 *si
static char *get_string (struct r_bin_dex_obj_t *bin, int idx) {
const ut8 buf[128], *buf2;
int len, uleblen;
ut64 len;
int uleblen;
r_buf_read_at (bin->b, bin->strings[idx], (ut8*)&buf, 8);
len = dex_read_uleb128 (buf);
buf2 = r_uleb128 (buf, (ut32*) &len);
buf2 = r_uleb128 (buf, &len);
uleblen = (size_t)(buf2 - buf);
// XXX what about 0 length strings?
if (len>0 && len < R_BIN_SIZEOF_STRINGS) {
@ -270,34 +271,34 @@ static int dex_loadcode(RBinFile *arch, RBinDexObj *bin) {
p = r_buf_get_at (arch->buf, c->class_data_offset, NULL);
/* data header */
{
ut32 SF, IF, DM, VM;
ut64 SF, IF, DM, VM;
p = r_uleb128 (p, &SF);
p = r_uleb128 (p, &IF);
p = r_uleb128 (p, &DM);
p = r_uleb128 (p, &VM);
dprintf (" static fields: %d\n", SF);
dprintf (" static fields: %u\n", (ut32)SF);
/* static fields */
for (j=0; j<SF; j++) {
ut32 FI, FA;
ut64 FI, FA;
p = r_uleb128 (p, &FI);
p = r_uleb128 (p, &FA);
dprintf (" field_idx: %d\n", FI);
dprintf (" field access_flags: %d\n", FA);
dprintf (" field_idx: %u\n", (ut32)FI);
dprintf (" field access_flags: %u\n", (ut32)FA);
}
/* instance fields */
dprintf (" instance fields: %d\n", IF);
dprintf (" instance fields: %u\n", (ut32)IF);
for (j=0; j<IF; j++) {
ut32 FI, FA;
ut64 FI, FA;
p = r_uleb128 (p, &FI);
p = r_uleb128 (p, &FA);
dprintf (" field_idx: %d,\n", FI);
dprintf (" field access_flags: %d,\n", FA);
dprintf (" field_idx: %u,\n", (ut32)FI);
dprintf (" field access_flags: %u,\n", (ut32)FA);
}
/* direct methods */
dprintf (" direct methods: %d\n", DM);
dprintf (" direct methods: %u\n", (ut32)DM);
for (j=0; j<DM; j++) {
char *method_name, *flag_name;
ut32 MI, MA, MC;
ut64 MI, MA, MC;
p = r_uleb128 (p, &MI);
p = r_uleb128 (p, &MA);
p = r_uleb128 (p, &MC);
@ -307,14 +308,14 @@ static int dex_loadcode(RBinFile *arch, RBinDexObj *bin) {
if (MC>0 && bin->code_to<MC) bin->code_to = MC;
method_name = dex_method_name (bin, MI);
dprintf ("METHOD NAME %d\n", MI);
dprintf ("METHOD NAME %u\n", (ut32)MI);
if (!method_name) method_name = strdup ("unknown");
flag_name = flagname (class_name, method_name);
dprintf ("f %s @ 0x%x\n", flag_name, MC);
dprintf ("f %s @ 0x%x\n", flag_name, (ut32)MC);
dprintf (" { name: %s,\n", method_name);
dprintf (" idx: %d,\n", MI);
dprintf (" access_flags: 0x%x,\n", MA);
dprintf (" code_offset: 0x%x },\n", MC);
dprintf (" idx: %u,\n", (ut32)MI);
dprintf (" access_flags: 0x%x,\n", (ut32)MA);
dprintf (" code_offset: 0x%x },\n", (ut32)MC);
/* add symbol */
{
RBinSymbol *sym = R_NEW0 (RBinSymbol);
@ -327,9 +328,9 @@ static int dex_loadcode(RBinFile *arch, RBinDexObj *bin) {
free (flag_name);
}
/* virtual methods */
dprintf (" virtual methods: %d\n", VM);
dprintf (" virtual methods: %u\n", (ut32)VM);
for (j=0; j<VM; j++) {
ut32 MI, MA, MC;
ut64 MI, MA, MC;
p = r_uleb128 (p, &MI);
p = r_uleb128 (p, &MA);
p = r_uleb128 (p, &MC);
@ -340,9 +341,9 @@ static int dex_loadcode(RBinFile *arch, RBinDexObj *bin) {
name = dex_method_name (bin, MI);
dprintf (" method name: %s\n", name);
dprintf (" method_idx: %d\n", MI);
dprintf (" method access_flags: %d\n", MA);
dprintf (" method code_offset: %d\n", MC);
dprintf (" method_idx: %u\n", (ut32)MI);
dprintf (" method access_flags: %u\n", (ut32)MA);
dprintf (" method code_offset: %u\n", (ut32)MC);
free (name);
}
}
@ -458,7 +459,7 @@ static RList* classes (RBinFile *arch) {
dprintf ("error malloc string length %d\n", len);
break;
}
if ((entry.source_file>bin->header.strings_size) || (entry.source_file<0))
if (entry.source_file>bin->header.strings_size)
continue;
r_buf_read_at (bin->b, bin->strings[entry.source_file],
(ut8*)name, len);

View File

@ -183,7 +183,7 @@ static RBinInfo* info(RBinFile *arch) {
memset (ret, '\0', sizeof (RBinInfo));
ret->lang = NULL;
r_buf_read_at (arch->buf,0x104,rom_header,76);
strncpy (ret->file, &rom_header[48], 16);
strncpy (ret->file, (const char*)&rom_header[48], 16);
gb_get_gbtype (ret->type,rom_header[66],rom_header[63]);
gb_add_cardtype (ret->type,rom_header[67]); // XXX
strncpy (ret->machine, "Gameboy", sizeof (ret->machine)-1);

View File

@ -34,7 +34,7 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) {
RBinString *string;
RListIter *iter;
RList *list;
int size, i = 0;
int i = 0;
if (!(hasstr = r_config_get_i (r->config, "bin.strings")))
return 0;
@ -68,13 +68,12 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) {
string->offset): string->offset;
q = strdup (string->string);
//r_name_filter (str, 128);
for (p=q; *p; p++) if (*p=='"')*p='\'';
size = string->size;
if (string->type == 'W')
size *= 2;
for (p=q; *p; p++) if (*p=='"') *p = '\'';
r_cons_printf ("%s{\"offset\":%"PFMT64d
",\"length\":%d,\"type\":\"%s\",\"string\":\"%s\"}",
iter->p? ",": "", addr, size,
",\"length\":%d,\"size\":%d,"
"\"type\":\"%s\",\"string\":\"%s\"}",
iter->p? ",": "", addr,
string->length, string->size,
string->type=='W'?"wide":"ascii", q);
free (q);
}
@ -82,11 +81,10 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) {
} else
if ((mode & R_CORE_BIN_SIMPLE)) {
r_list_foreach (list, iter, string) {
int size = (string->type == 'W')? string->size*2: string->size;
ut64 addr = va? r_bin_get_vaddr (r->bin, baddr, string->rva,
string->offset): string->offset;
r_cons_printf ("%"PFMT64d" %d %s\n",
addr, size, string->string);
r_cons_printf ("%"PFMT64d" %d %d %s\n",
addr, string->size, string->length, string->string);
}
} else
if ((mode & R_CORE_BIN_SET)) {
@ -100,7 +98,8 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) {
for (i=0; *(string->string+i)==' '; i++);
r_meta_add (r->anal, R_META_TYPE_STRING,
va?baddr+string->rva:string->offset,
(va?baddr+string->rva:string->offset)+size, string->string+i);
(va?baddr+string->rva:string->offset)+string->size,
string->string+i);
r_name_filter (string->string, 128);
snprintf (str, R_FLAG_NAME_SIZE, "str.%s", string->string);
r_flag_set (r->flags, str,
@ -121,10 +120,11 @@ static int bin_strings (RCore *r, int mode, ut64 baddr, int va) {
"Cs %"PFMT64d" @ 0x%08"PFMT64x"\n",
string->string, size, va?baddr+string->rva:string->offset,
string->size, va?baddr+string->rva:string->offset);
} else r_cons_printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x" ordinal=%03"PFMT64d" "
"sz=%"PFMT64d" section=%s type=%c string=%s\n",
} else r_cons_printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x
" ordinal=%03"PFMT64d" "
"sz=%d len=%d section=%s type=%c string=%s\n",
baddr+string->rva, string->offset,
string->ordinal, size,
string->ordinal, string->size, string->length,
section?section->name:"unknown",
string->type, string->string);
i++;

View File

@ -258,8 +258,9 @@ typedef struct r_bin_string_t {
ut64 rva;
ut64 offset;
ut64 ordinal;
ut64 size;
char type; // Ascii Wide ...
int size; // size of buffer containing the string in bytes
int length; // length of string in chars
char type; // Ascii Wide cp850 utf8 ...
} RBinString;
typedef struct r_bin_field_t {