Add RBinInfo.has_lit for 15% speedup loading DEX bins

This commit is contained in:
pancake 2017-07-24 01:15:56 +02:00
parent e61f5ef0a0
commit 4d2bfe135a
13 changed files with 24 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2015 - pancake */
/* radare - LGPL - Copyright 2015-2017 - pancake */
#include <r_types.h>
#include <r_util.h>
@ -105,9 +105,7 @@ static RBinInfo *info(RBinFile *arch) {
if (!ret) {
return NULL;
}
// art_header_load (&art, arch->buf);
ao = arch->o->bin_obj;
ret->lang = NULL;
ret->file = arch->file? strdup (arch->file): NULL;
@ -123,6 +121,7 @@ static RBinInfo *info(RBinFile *arch) {
ret->machine = strdup ("arm");
ret->arch = strdup ("arm");
ret->has_va = 1;
ret->has_lit = true;
ret->has_pi = ao->art.compile_pic;
ret->bits = 16; // 32? 64?
ret->big_endian = 0;
@ -215,7 +214,7 @@ static RList *sections(RBinFile *arch) {
return ret;
}
struct r_bin_plugin_t r_bin_plugin_art = {
RBinPlugin r_bin_plugin_art = {
.name = "art",
.desc = "Android Runtime",
.license = "LGPL3",
@ -232,7 +231,7 @@ struct r_bin_plugin_t r_bin_plugin_art = {
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_art,
.version = R2_VERSION

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2016 - pancake */
/* radare - LGPL - Copyright 2016-2017 - pancake */
#include <r_bin.h>
@ -84,6 +84,7 @@ static RBinInfo* info(RBinFile *arch) {
ret->machine = strdup ("ATmel");
ret->os = strdup ("avr");
ret->has_va = 0; // 1;
ret->has_lit = false;
ret->arch = strdup ("avr");
ret->bits = 8;
// bs = (const char*)arch->buf->buf;

View File

@ -269,6 +269,7 @@ static RBinInfo *info(RBinFile *arch) {
ret->big_endian = obj->endian;
ret->has_va = false;
ret->dbg_info = 0;
ret->has_lit = true;
if (r_coff_is_stripped (obj)) {
ret->dbg_info |= R_BIN_DBG_STRIPPED;

View File

@ -64,7 +64,6 @@ static RBinInfo *info(RBinFile *arch) {
ret->has_va = true;
ret->big_endian = big_endian;
ret->dbg_info = 0;
ret->dbg_info = 0;
return ret;
}

View File

@ -809,6 +809,7 @@ static RBinInfo* info(RBinFile *arch) {
}
ret->type = str;
ret->has_pi = (strstr (str, "DYN"))? 1: 0;
ret->has_lit = true;
ret->has_canary = has_canary (arch);
if (!(str = Elf_(r_bin_elf_get_elf_class) (arch->o->bin_obj))) {
free (ret);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2015 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2017 - pancake, nibble */
#define R_BIN_ELF64 1
#include "bin_elf.c"

View File

@ -439,6 +439,7 @@ static RBinInfo* info(RBinFile *arch) {
ret->subsystem = strdup ("darwin");
ret->arch = MACH0_(get_cputype) (arch->o->bin_obj);
ret->machine = MACH0_(get_cpusubtype) (arch->o->bin_obj);
ret->has_lit = true;
ret->type = MACH0_(get_filetype) (arch->o->bin_obj);
ret->big_endian = MACH0_(is_big_endian) (arch->o->bin_obj);
ret->bits = 32;

View File

@ -481,6 +481,7 @@ static RBinInfo *info(RBinFile *arch) {
}
ret->bits = 64;
ret->has_va = true;
ret->has_lit = true;
ret->big_endian = false;
ret->dbg_info = 0;
ret->dbg_info = 0;

View File

@ -136,6 +136,7 @@ static RBinInfo *info(RBinFile *arch) {
ret->arch = strdup ("x86");
ret->big_endian = false;
ret->has_va = true;
ret->has_lit = true;
ret->bits = r_bin_omf_get_bits (arch->o->bin_obj);
ret->dbg_info = 0;
ret->has_nx = false;

View File

@ -180,7 +180,6 @@ static RBinInfo *info(RBinFile *arch) {
ret->has_va = true;
ret->big_endian = big_endian;
ret->dbg_info = 0;
ret->dbg_info = 0;
return ret;
}

View File

@ -450,7 +450,7 @@ static RBinInfo* info(RBinFile *arch) {
ret->machine = PE_(r_bin_pe_get_machine) (arch->o->bin_obj);
ret->subsystem = PE_(r_bin_pe_get_subsystem) (arch->o->bin_obj);
if (is_dot_net (arch)) {
ret->lang = "msil";
ret->lang = "cil";
}
if (is_vb6 (arch)) {
ret->lang = "vb";
@ -466,6 +466,7 @@ static RBinInfo* info(RBinFile *arch) {
ret->bits = PE_(r_bin_pe_get_bits) (arch->o->bin_obj);
ret->big_endian = PE_(r_bin_pe_is_big_endian) (arch->o->bin_obj);
ret->dbg_info = 0;
ret->has_lit = true;
ret->has_canary = has_canary (arch);
ret->has_nx = haschr (arch, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
ret->has_pi = haschr (arch, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);

View File

@ -1366,7 +1366,7 @@ static RList *osymbols = NULL;
static RBinSymbol *get_symbol(RBin *bin, RList *symbols, const char *name, ut64 addr) {
RBinSymbol *symbol, *res = NULL;
RListIter *iter;
if (mydb && symbols != osymbols) {
if (mydb && symbols && symbols != osymbols) {
sdb_free (mydb);
mydb = NULL;
osymbols = symbols;
@ -1400,6 +1400,7 @@ static RBinSymbol *get_symbol(RBin *bin, RList *symbols, const char *name, ut64
}
}
}
osymbols = symbols;
}
return res;
}
@ -1445,9 +1446,11 @@ static ut64 impaddr(RBin *bin, int va, const char *name) {
}
static int bin_imports(RCore *r, int mode, int va, const char *name) {
RBinInfo *info = r_bin_get_info (r->bin);
int bin_demangle = r_config_get_i (r->config, "bin.demangle");
RBinImport *import;
RListIter *iter;
bool lit = info ? info->has_lit: false;
char *str;
int i = 0;
@ -1460,13 +1463,11 @@ static int bin_imports(RCore *r, int mode, int va, const char *name) {
r_cons_println ("[Imports]");
}
r_list_foreach (imports, iter, import) {
char *symname;
ut64 addr;
if (name && strcmp (import->name, name)) {
continue;
}
symname = strdup (import->name);
addr = impaddr (r->bin, va, symname);
char *symname = strdup (import->name);
ut64 addr = lit ? impaddr (r->bin, va, symname): 0;
if (bin_demangle) {
char *dname = r_bin_demangle (r->bin->cur, NULL, symname, addr);
if (dname) {
@ -1476,8 +1477,7 @@ static int bin_imports(RCore *r, int mode, int va, const char *name) {
}
}
if (r->bin->prefix) {
char *prname;
prname = r_str_newf ("%s.%s", r->bin->prefix, symname);
char *prname = r_str_newf ("%s.%s", r->bin->prefix, symname);
free (symname);
symname = prname;
}
@ -1529,6 +1529,8 @@ static int bin_imports(RCore *r, int mode, int va, const char *name) {
r_cons_printf ("\n%i imports\n", i);
}
#if MYDB
// NOTE: if we comment out this, it will leak.. but it will be faster
// because it will keep the cache across multiple RBin calls
osymbols = NULL;
sdb_free (mydb);
mydb = NULL;

View File

@ -174,6 +174,7 @@ typedef struct r_bin_info_t {
int has_crypto;
int has_nx;
int big_endian;
bool has_lit;
char *actual_checksum;
char *claimed_checksum;
int pe_overlay;