Add ik* command to load bin headers info, and use Cf for that

This commit is contained in:
pancake 2016-10-27 23:51:22 +02:00
parent f95744b9a1
commit 196e5a763c
5 changed files with 61 additions and 26 deletions

View File

@ -921,6 +921,7 @@ int main(int argc, char **argv) {
// TODO: Should be moved into core, to load those flags and formats into r2
Sdb *db = sdb_ns (bin->cur->sdb, "info", 0);
char *flagname;
char *offset = NULL;
if (db) {
SdbListIter *iter;
SdbKv *kv;
@ -935,6 +936,8 @@ int main(int argc, char **argv) {
*flagname = 0;
flagname = dup;
printf ("f %s @ %s\n", flagname, v);
free (offset);
offset = strdup (v);
}
if ((flagname = strstr (dup, ".cparse"))) {
printf ("\"td %s\"\n", v);
@ -943,6 +946,15 @@ int main(int argc, char **argv) {
*flagname = 0;
flagname = dup;
printf ("pf.%s %s\n", flagname, v);
int fmtsize = r_print_format_struct_size (v, core.print, 0);
char *offset_key = r_str_newf ("%s.offset", flagname);
const char *offset = sdb_const_get (db, offset_key, 0);
free (offset_key);
if (offset) {
printf ("Cf %d %s @ %s\n", fmtsize, v, offset);
} else {
printf ("Cf %d %s @ %s\n", fmtsize, v, "0");
}
}
free (dup);
}

View File

@ -351,7 +351,9 @@ arm_symbol:
}
}
}
static RBinInfo* info(RBinFile *arch);
static RList* symbols(RBinFile *arch) {
struct Elf_(r_bin_elf_obj_t) *bin;
struct r_bin_elf_symbol_t *symbol = NULL;
@ -649,7 +651,7 @@ static void __patch_reloc (RIOBind *iob, RBinElfReloc *rel, ut64 vaddr) {
{
ut64 num = r_swap_ut64(vaddr);
snprintf (s, sizeof (s), "%08"PFMT64x, num);
write_into_reloc();
write_into_reloc ();
}
break;
default:
@ -723,8 +725,9 @@ static RList* patch_relocs(RBin *b) {
continue;
}
ptr->vaddr = sym_addr ? sym_addr : vaddr;
if (!sym_addr)
if (!sym_addr) {
vaddr += 4;
}
r_list_append (ret, ptr);
sym_addr = 0;
}
@ -807,11 +810,14 @@ static RBinInfo* info(RBinFile *arch) {
ret->has_nx = Elf_(r_bin_elf_has_nx) (arch->o->bin_obj);
ret->intrp = Elf_(r_bin_elf_intrp) (arch->o->bin_obj);
ret->dbg_info = 0;
if (!Elf_(r_bin_elf_get_stripped) (arch->o->bin_obj))
if (!Elf_(r_bin_elf_get_stripped) (arch->o->bin_obj)) {
ret->dbg_info |= R_BIN_DBG_LINENUMS | R_BIN_DBG_SYMS | R_BIN_DBG_RELOCS;
else ret->dbg_info |= R_BIN_DBG_STRIPPED;
if (Elf_(r_bin_elf_get_static) (arch->o->bin_obj))
} else {
ret->dbg_info |= R_BIN_DBG_STRIPPED;
}
if (Elf_(r_bin_elf_get_static) (arch->o->bin_obj)) {
ret->dbg_info |= R_BIN_DBG_STATIC;
}
return ret;
}
@ -903,10 +909,11 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data,
B ("\x7F" "ELF" "\x01\x01\x01\x00", 8);
Z (8);
H (2); // ET_EXEC
if (is_arm)
if (is_arm) {
H (40); // e_machne = EM_ARM
else
} else {
H (3); // e_machne = EM_I386
}
D (1);
p_start = buf->length;
@ -960,7 +967,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data,
B (code, codelen);
if (data && datalen>0) {
if (data && datalen > 0) {
//ut32 data_section = buf->length;
eprintf ("Warning: DATA section not support for ELF yet\n");
B (data, datalen);

View File

@ -248,6 +248,9 @@ static int cmd_info(void *data, const char *input) {
free (o);
}
break;
case '*':
r_core_cmdf (core, ".!rabin2 -rk '' '%s'", core->file->desc->name);
break;
case '.':
case ' ':
if (db) {
@ -266,6 +269,7 @@ static int cmd_info(void *data, const char *input) {
case '?':
default:
eprintf ("Usage: ik [sdb-query]\n");
eprintf ("Usage: ik* # load all header information\n");
}
goto done;
break;

View File

@ -349,13 +349,15 @@ static int cmd_meta_comment(RCore *core, const char *input) {
char *s, *p;
s = strchr (input, ' ');
if (s) {
s = strdup (s+1);
s = strdup (s + 1);
} else {
eprintf ("Usage\n");
return false;
}
p = strchr (s, ' ');
if (p) *p++ = 0;
if (p) {
*p++ = 0;
}
ut64 addr;
if (input[2]=='-') {
if (input[3]) {
@ -388,9 +390,11 @@ static int cmd_meta_comment(RCore *core, const char *input) {
} else {
r_meta_add (core->anal,
R_META_TYPE_COMMENT,
addr, addr+1, p);
addr, addr + 1, p);
}
} else eprintf ("Usage: CCa [address] [comment]\n");
} else {
eprintf ("Usage: CCa [address] [comment]\n");
}
free (s);
return true;
}
@ -444,7 +448,7 @@ static int cmd_meta_hsdmf(RCore *core, const char *input) {
break;
case ' ':
case '\0':
if (type!='z' && input[1] == '*') {
if (type != 'z' && input[1] == '*') {
r_meta_list (core->anal, type, 0);
break;
}
@ -459,7 +463,9 @@ static int cmd_meta_hsdmf(RCore *core, const char *input) {
}
}
int repcnt = 0;
if (repeat < 1) repeat = 1;
if (repeat < 1) {
repeat = 1;
}
while (repcnt < repeat) {
t = strdup (r_str_chop_ro (input + 1));
p = NULL;
@ -469,12 +475,14 @@ static int cmd_meta_hsdmf(RCore *core, const char *input) {
n = r_num_math (core->num, t);
if (type == 'f') {
p = strchr (t, ' ');
if (n < 1) {
n = r_print_format_struct_size (p + 1, core->print, 0);
}
if (p) {
n = r_print_format (core->print, addr, core->block,
core->blocksize, p + 1, 0, NULL, NULL);
}
}
if (type == 's') {
} else if (type == 's') {
strncpy (name, t, sizeof (name) - 1);
(void)r_core_read_at (core, addr, (ut8*)name, sizeof (name) - 1);
name[sizeof (name) - 1] = '\0';
@ -504,7 +512,9 @@ static int cmd_meta_hsdmf(RCore *core, const char *input) {
return false;
}
}
if (!n) n++;
if (!n) {
n++;
}
addr_end = addr + n;
r_meta_add (core->anal, type, addr, addr_end, name);
free (t);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2013-2014 - pancake */
/* radare - LGPL - Copyright 2013-2016 - pancake */
#include "r_util.h"
#include "r_types.h"
@ -7,17 +7,18 @@
/* parse C code and return it in key-value form */
static void appendstring(const char *msg, char **s) {
if (!s)
if (!s) {
printf ("%s\n", msg);
else
if (*s) {
char *p = malloc (strlen (msg) + strlen (*s)+1);
} else if (*s) {
char *p = malloc (strlen (msg) + strlen (*s) + 1);
if (!p) return;
strcpy (p, *s);
free (*s);
*s = p;
strcpy (p+strlen (p), msg);
} else *s = strdup (msg);
strcpy (p + strlen (p), msg);
} else {
*s = strdup (msg);
}
}
R_API char *r_parse_c_file(const char *path) {
@ -44,11 +45,12 @@ R_API char *r_parse_c_string(const char *code) {
R_API int r_parse_is_c_file (const char *file) {
const char *ext = r_str_lchr (file, '.');
if (ext) {
ext = ext+1;
ext = ext + 1;
if (!strcmp (ext, "cparse")
|| !strcmp (ext, "c")
|| !strcmp (ext, "h"))
|| !strcmp (ext, "h")) {
return true;
}
}
return false;
}