* Do not run .!rabin2 from r_core

- Use internal APIs to load binary information
  - Startup time reduced about 2-3 times
  - Thanks @earada for this patch!
This commit is contained in:
pancake 2010-10-11 17:11:43 +02:00
parent b3ac5bd4d4
commit f1e46a88f6
3 changed files with 157 additions and 20 deletions

View File

@ -37,6 +37,7 @@ static int main_version() {
// Load the binary information from rabin2
// TODO: use thread to load this, split contents line, per line and use global lock
#if 0
static int rabin_delegate(RThread *th) {
if (rabin_cmd && r_file_exist (r.file->filename)) {
char *nptr, *ptr, *cmd = r_sys_cmd_str (rabin_cmd, NULL, NULL);
@ -57,6 +58,7 @@ static int rabin_delegate(RThread *th) {
if (th) eprintf ("rabin2: done\n");
return 0;
}
#endif
int main(int argc, char **argv) {
RThreadLock *lock = NULL;
@ -221,6 +223,7 @@ int main(int argc, char **argv) {
}
if (!has_project && run_rc) {
#if 0
rabin_cmd = r_str_dup_printf ("rabin2 -rSIeMzisR%s %s",
(debug||r.io->va)?"v":"", r.file->filename);
if (threaded) {
@ -228,6 +231,7 @@ int main(int argc, char **argv) {
lock = r_th_lock_new ();
rabin_th = r_th_new (&rabin_delegate, lock, 0);
} else rabin_delegate (NULL);
#endif
} else eprintf ("Metadata loaded from 'file.project'\n");
if (r_io_is_listener (r.io))

View File

@ -299,7 +299,7 @@ static int thumb_assemble(ArmOpcode *ao, const char *str) {
if (!strcmp (ao->a1, "pc")) {
// ldr r0, [pc, n] = 4[r0-8][nn*4]
if (getreg (ao->a2) == -1) {
ao->o = 0x40 | 8+(0xf & getreg (ao->a0));
ao->o = 0x40 | (8+(0xf & getreg (ao->a0)));
ao->o |= (0xff & getnum (ao->a2)/4)<<8;
} else return 0;
} else {
@ -429,20 +429,21 @@ static int arm_assemble(ArmOpcode *ao, const char *str) {
if (!memcmp(ao->op, ops[i].name, strlen (ops[i].name))) {
ao->o = ops[i].code;
arm_opcode_cond (ao, strlen(ops[i].name));
switch(ops[i].type) {
if (ao->a0)
switch (ops[i].type) {
case TYPE_MEM:
getrange (ao->a0);
getrange (ao->a1);
getrange (ao->a2);
//printf("a0(%s) a1(%s) a2(%s)\n", ao->a0, ao->a1, ao->a2);
ao->o |= getreg(ao->a0)<<20;
ao->o |= getreg(ao->a1)<<8; // delta
ret = getreg(ao->a2);
ao->o |= getreg (ao->a0)<<20;
ao->o |= getreg (ao->a1)<<8; // delta
ret = getreg (ao->a2);
if (ret != -1) {
ao->o |= (strstr(str,"],"))?6:7;
ao->o |= (strstr (str,"],"))?6:7;
ao->o |= (ret&0x0f)<<24;//(getreg(ao->a2)&0x0f);
} else {
ao->o |= (strstr(str,"],"))?4:5;
ao->o |= (strstr (str,"],"))?4:5;
ao->o |= (getnum (ao->a2)&0x7f)<<24; // delta
}
break;

View File

@ -39,26 +39,158 @@ R_API void r_core_sysenv_update(RCore *core) {
R_API int r_core_bin_load(RCore *r, const char *file) {
RBinObj *obj;
RListIter *iter;
ut64 baddr;
int va = r_config_get_i (r->config, "io.va");
int i = 0;
char str[R_FLAG_NAME_SIZE];
if (!r_bin_load (r->bin, file, 0))
return R_FALSE;
r->file->obj = obj = r_bin_get_object (r->bin, 0);
#if 0
RListIter *iter;
baddr = r_bin_get_baddr (r->bin);
// I -> Binary info
RBinInfo *info;
if ((info = r_bin_get_info (r->bin)) != NULL) {
r_config_set (r->config, "file.type", info->rclass);
r_config_set (r->config, "cfg.bigendian", info->big_endian?"true":"false");
r_config_set (r->config, "asm.os", info->os);
r_config_set (r->config, "asm.arch", info->arch);
r_config_set (r->config, "anal.plugin", info->arch);
snprintf (str, R_FLAG_NAME_SIZE, "%i", info->bits);
r_config_set (r->config, "asm.bits", str);
r_config_set (r->config, "asm.dwarf", R_BIN_DBG_STRIPPED (info->dbg_info)?"false":"true");
}
r_flag_space_set (r->flags, "symbols");
// M -> Main
RBinAddr *binmain;
if ((binmain = r_bin_get_main (r->bin)) != NULL)
r_flag_set (r->flags, "main", va?baddr+binmain->rva:binmain->offset,
r->blocksize, 0);
// e -> Entrypoints
RList *entries;
RBinAddr *entry;
i = 0;
if ((entries = r_bin_get_entries (r->bin)) != NULL) {
r_list_foreach (entries, iter, entry) {
snprintf (str, R_FLAG_NAME_SIZE, "entry%i", i++);
r_flag_set (r->flags, str, va?baddr+entry->rva:entry->offset,
r->blocksize, 0);
}
/* Seek to the last entry point */
r_core_seek (r, va?baddr+entry->rva:entry->offset, 0);
}
// s -> Symbols
RList *symbols;
RBinSymbol *symbol;
if ((symbols = r_bin_get_symbols (r->bin)) != NULL) {
r_list_foreach (symbols, iter, symbol) {
r_flag_name_filter (symbol->name);
snprintf (str, R_FLAG_NAME_SIZE, "fcn.sym.%s", symbol->name);
if (!strncmp (symbol->type,"FUNC", 4)) {
if (symbol->size)
if (!r_anal_fcn_add (r->anal, va?baddr+symbol->rva:symbol->offset,
symbol->size, symbol->name, R_ANAL_DIFF_NULL))
eprintf ("Cannot add function: %s (duplicated)\n", symbol->name);
r_flag_space_set (r->flags, "functions");
r_flag_set (r->flags, str, va?baddr+symbol->rva:symbol->offset,
symbol->size, 0);
r_flag_space_set (r->flags, "symbols");
} else if (!strncmp (symbol->type,"OBJECT", 6))
r_meta_add (r->meta, R_META_DATA, va?baddr+symbol->rva:symbol->offset,
(va?baddr+symbol->rva:symbol->offset)+symbol->size, symbol->name);
r_flag_set (r->flags, str+4, va?baddr+symbol->rva:symbol->offset,
symbol->size, 0);
}
}
r_flag_space_set (r->flags, "relocs");
// R -> Relocations
RList *relocs;
RBinReloc *reloc;
if ((relocs = r_bin_get_relocs (r->bin)) != NULL) {
r_list_foreach (relocs, iter, reloc) {
snprintf (str, R_FLAG_NAME_SIZE, "reloc.%s", reloc->name);
r_flag_set (r->flags, str, va?baddr+reloc->rva:reloc->offset,
r->blocksize, 0);
}
}
// z -> Strings
RList *strings;
RBinString *string;
r_flag_space_set (r->flags, "strings");
if ((strings = r_bin_get_strings (r->bin)) != NULL) {
r_list_foreach (strings, iter, string) {
r_flag_name_filter (string->string);
/* Jump the withespaces before the string */
for (i=0;*(string->string+i)==' ';i++);
snprintf (str, R_FLAG_NAME_SIZE, "str.%s", string->string+i);
r_flag_set (r->flags, str, va?baddr+string->rva:string->offset,
string->size, 0);
r_meta_add (r->meta, R_META_STRING, va?baddr+string->rva:string->offset,
(va?baddr+string->rva:string->offset)+string->size, string->string+i);
}
}
// i -> Imports
RList *imports;
RBinImport *import;
if ((imports = r_bin_get_imports (r->bin)) != NULL) {
r_list_foreach (imports, iter, import) {
r_flag_name_filter (import->name);
if (import->size)
if (!r_anal_fcn_add (r->anal, va?baddr+import->rva:import->offset,
import->size, import->name, R_ANAL_DIFF_NULL))
eprintf ("Cannot add function: %s (duplicated)\n", import->name);
snprintf (str, R_FLAG_NAME_SIZE, "fcn.imp.%s", import->name);
r_flag_space_set (r->flags, "functions");
r_flag_set (r->flags, str, va?baddr+import->rva:import->offset,
import->size, 0);
r_flag_space_set (r->flags, "imports");
r_flag_set (r->flags, str+4, va?baddr+import->rva:import->offset,
import->size, 0);
}
}
// S -> Sections
RList *sections;
RBinSection *section;
r_list_foreach (obj->sections, iter, section) {
printf ("ff %s\n", section->name);
//r_flag_set(r->flags, name, section->offset, section->size, 0);
i = 0;
if ((sections = r_bin_get_sections (r->bin)) != NULL) {
r_flag_space_set (r->flags, "sections");
r_list_foreach (sections, iter, section) {
r_flag_name_filter (section->name);
snprintf (str, R_FLAG_NAME_SIZE, "section.%s", section->name);
r_flag_set (r->flags, str, va?baddr+section->rva:section->offset,
section->size, 0);
r_io_section_add (r->io, section->offset, baddr+section->rva,
section->size, section->vsize, section->srwx, section->name);
snprintf (str, R_FLAG_NAME_SIZE, "va=0x%08"PFMT64x" pa=0x%08"PFMT64x" sz=%"
PFMT64d" vsz=%"PFMT64d" rwx=%c%c%c%c %s",
baddr+section->rva, section->offset, section->size, section->vsize,
R_BIN_SCN_SHAREABLE (section->srwx)?'s':'-',
R_BIN_SCN_READABLE (section->srwx)?'r':'-',
R_BIN_SCN_WRITABLE (section->srwx)?'w':'-',
R_BIN_SCN_EXECUTABLE (section->srwx)?'x':'-',
section->name);
r_meta_add (r->meta, R_META_COMMENT, va?baddr+section->rva:section->offset,
va?baddr+section->rva:section->offset, str);
}
}
r_list_foreach (obj->imports, iter, import) {
printf ("ff %s\n", import->name);
}
r_list_foreach (obj->symbols, iter, symbol) {
printf ("ff %s\n", symbol->name);
}
#endif
// TODO: moar
return R_TRUE;
}