* Fix cmd.vprompt

* Simplify some functions in r_bin
* Added support for x86-64 for the 'ap' command
* Added dummy function calls for r_bin_demangle()
This commit is contained in:
pancake 2011-02-23 20:53:56 +01:00
parent 1163b9bd6f
commit 9efa5a50cb
7 changed files with 141 additions and 114 deletions

75
TODO
View File

@ -3,12 +3,13 @@
| < V . | . V . < _/ .-' _/| () |
|__\__|_|__|___/__|__|_\__\___/ |____(_)____/
Random stuff
-----------
* For each "call" or "push offset"+"ret" create a function.
- And, if deep code analysis is enabled:
- Search every possible function by searching typical prologs and put them in a queue.
- Perform the same actions as in the previous steps with the entry points.
pancake
-------
* mount in / results problematic sometimes.. :/
* if console width > X place comments there (ash)
* Implement BLOCK in r_core_sysenv_begin|end ()
* Fix iterators for r_macro (test only?)
* Stolen from pyew
- e anal.ops = true
INT num: Interruptions. Typically used as antiemulation (INT 4) and antidebugging tricks (INT 3).
@ -18,21 +19,10 @@ Random stuff
CPUID: Used to detect Virtual Machines and emulators.
// NOP args: NOP with arguments are typical antiemulation tricks.
SYSENTER: Direct system calls. Commonly, used as antiemulation tricks.
* implement aoe = anal op exec
- sync regs or what?
pancake
-------
* mount in / results problematic sometimes.. :/
* if console width > X place comments there (ash)
* Implement BLOCK in r_core_sysenv_begin|end ()
* Fix iterators for r_macro (test only?)
* Add support for STATIC_PLUGINS in r_lang
- r_lang_define is implemented in lang.c, but requires the collaboration
of the plugins to properly setup the environment for the script execution.
- Add support for STATIC_PLUGINS in r_lang
- dlerror(/usr/lib/radare2/lang_perl.so): libperl.so: cannot open shared object file: No such file or directory
This issue is fixed by setting LD_LIBRARY_PATH...looks like dlopen ignores rpath
capi_x
------
* Fix avr/ppc code analysis // fix or use or what? :)
earada
------
@ -45,7 +35,6 @@ earada
0-9+ = count of chars
E = end of stream
RKNS_ = start of arguments
* Fix avr/ppc code analysis // fix or use or what? :)
* Add SSL support to r_socket
* remove all uses of alloca() // mingw and grep reports them all :)
* typedef all function pointers, like in r_bp
@ -58,6 +47,13 @@ earada
nibble
------
* For each "call" or "push offset"+"ret" create a function.
- And, if deep code analysis is enabled:
- Search every possible function by searching typical prologs and put them in a queue.
- Perform the same actions as in the previous steps with the entry points.
* detect strings in code analysis
* implement aoe = anal op exec
- sync regs or what?
* comparisions doesnt works (RAnalCond)
* register renaming (per-instruction or ranges)
- r_parser fun? a specific asm.parser plugin that does all this tricks?
@ -84,14 +80,6 @@ nibble
- implement GMP in util/big.c
- http://etutorials.org/Programming/secure+programming/Chapter+7.+Public+Key+Cryptography/7.5+Generating+a+Prime+Number+Testing+for+Primality/
DEBUGGER: (pancake)
---------
* Implement DRX support
* Implement dump+restore as macros (dump,)
* Implement software stepping (with code analysis+breakpoints)
* Implement dbg.bep - in r_core? in r_debug after attach? maybe only in r2 binr?
- must be refined.. and look for better names
CORE
----
* Add "pm ?" for bit print like in pb? bit level binary memory printage
@ -109,8 +97,8 @@ nibble
- So one can change from one arch to another with a pointer
- Cool for defining ranges of memory
0.8
===
0.8: focus on debugger and UI
=============================
* Reimplement or fix the delta diffing in C - first we need to do it for ired..
* add support for .a files (r_fs supports cpio and ar archives...)
* Implement rap:// upload/download protocol commands (maybe just system() with rsc2+wget?
@ -121,6 +109,21 @@ nibble
* Create radare2-testsuite project
- tests for ired, rax2, radare2, rabin2 ...
* Is RCore->block and blocksize a RBuf ? refactor!11
* Add support for STATIC_PLUGINS in r_lang
- r_lang_define is implemented in lang.c, but requires the collaboration
of the plugins to properly setup the environment for the script execution.
- Add support for STATIC_PLUGINS in r_lang
- dlerror(/usr/lib/radare2/lang_perl.so): libperl.so: cannot open shared object file: No such file or directory
This issue is fixed by setting LD_LIBRARY_PATH...looks like dlopen ignores rpath
DEBUGGER: (pancake)
---------
* Implement DRX support
* Implement dump+restore as macros (dump,)
* Implement software stepping (with code analysis+breakpoints)
* Implement dbg.bep - in r_core? in r_debug after attach? maybe only in r2 binr?
- must be refined.. and look for better names
BINARY INFORMATION
==================
@ -196,16 +199,12 @@ Bindings
Refactoring
===========
* Import r_vm register values from flags or from r_debug->r_reg
- r_vm must use mmu cache when emulating code
- use the one from r_io? and deprecate vm->mmu_cache?
* Review the r_flags api
* Add pipe_to_buffer..not only file descriptors
* r_config set_int and so..simplify
- find/use more common cases for char* or &int maps
- automatic callbacks for most common usecases
* What do we have to do with r_th, r_vm ?
* Merge r_vm into r_anal ?
* What do we have to do with r_th
* Merge r_socket inside r_util ?
* Discuss missing r_core_sysenv_update in core/file.c:33
* Add RLog API.. pipeable to disk and stderr..also hookable ..cool for ui (partially done)
@ -231,10 +230,6 @@ Future
* install.sh (to track installed files ..)
* acr -ldl check must be fixed for kfreebsd
* Add support for float/double in r_num :?
* radare2 -e dbg.engine=vm -d ls
- load the program using r_bin in virtual space
- initialize vm and set regs
- debug backend should use the vm
* metaflags? support to define relations between flags
(flag hirearchies)
r_flagtree

View File

@ -12,7 +12,7 @@ include ../config.mk
include ${STATIC_BIN_PLUGINS}
include ${STATIC_BIN_XTR_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst bin_,p/bin_,$(STATIC_OBJ)))
OBJ=bin.o bin_meta.o bin_write.o ${STATIC_OBJS}
OBJ=bin.o bin_meta.o bin_write.o demangle.o ${STATIC_OBJS}
pre:
if [ ! -e libr_bin.${EXT_SO} ]; then rm -f ${STATIC_OBJS} ; fi

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2011 nibble<.ds@gmail.com> */
/* TODO:
* dlopen library and show address
@ -24,26 +24,26 @@ static void get_strings_range(RBinArch *arch, RList *list, int min, ut64 from, u
if ((IS_PRINTABLE (arch->buf->buf[i])) && matches < R_BIN_SIZEOF_STRINGS-1) {
str[matches] = arch->buf->buf[i];
matches++;
} else {
/* check if the length fits in our request */
if (matches >= min) {
if (!(ptr = R_NEW (RBinString))) {
eprintf ("Error allocating string\n");
break;
}
str[matches] = '\0';
ptr->offset = i-matches;
ptr->rva = ptr->offset-from+scnrva;
ptr->size = matches;
ptr->ordinal = ctr;
// copying so many bytes here..
memcpy (ptr->string, str, R_BIN_SIZEOF_STRINGS);
ptr->string[R_BIN_SIZEOF_STRINGS-1] = '\0';
r_list_append (list, ptr);
ctr++;
}
matches = 0;
continue;
}
/* check if the length fits in our request */
if (matches >= min) {
if (!(ptr = R_NEW (RBinString))) {
eprintf ("Error allocating string\n");
break;
}
str[matches] = '\0';
ptr->offset = i-matches;
ptr->rva = ptr->offset-from+scnrva;
ptr->size = matches;
ptr->ordinal = ctr;
// copying so many bytes here..
memcpy (ptr->string, str, R_BIN_SIZEOF_STRINGS);
ptr->string[R_BIN_SIZEOF_STRINGS-1] = '\0';
r_list_append (list, ptr);
ctr++;
}
matches = 0;
}
}
@ -125,6 +125,7 @@ static int r_bin_init_items(RBin *bin, int dummy) {
static void r_bin_free_items(RBin *bin) {
int i;
RBinArch *arch = &bin->curarch;
// XXX: drop all those silly conditionals! if it's null is not for freeing
if (arch->entries)
r_list_free (arch->entries);
if (arch->fields)
@ -169,30 +170,25 @@ static void r_bin_init(RBin *bin) {
static int r_bin_extract(RBin *bin, int idx) {
ut8 *buf;
int n = 1;
if (bin->curxtr && bin->curxtr->extract)
n = bin->curxtr->extract (bin, idx);
else {
bin->curarch.file = strdup (bin->file);
if (!(buf = (ut8*)r_file_slurp (bin->file, &bin->curarch.size)))
return 0;
bin->curarch.buf = r_buf_new ();
if (!r_buf_set_bytes (bin->curarch.buf, buf, bin->curarch.size)) {
free (buf);
return 0;
}
return bin->curxtr->extract (bin, idx);
bin->curarch.file = strdup (bin->file);
if (!(buf = (ut8*)r_file_slurp (bin->file, &bin->curarch.size)))
return R_FALSE;
bin->curarch.buf = r_buf_new ();
if (!r_buf_set_bytes (bin->curarch.buf, buf, bin->curarch.size)) {
free (buf);
return R_FALSE;
}
return n;
free (buf);
return R_TRUE;
}
R_API int r_bin_add(RBin *bin, RBinPlugin *foo) {
struct list_head *pos;
if (foo->init)
foo->init (bin->user);
list_for_each_prev (pos, &bin->bins) {
list_for_each_prev (pos, &bin->bins) { // XXX: use r_list here
RBinPlugin *h = list_entry (pos, RBinPlugin, list);
if (!strcmp (h->name, foo->name))
return R_FALSE;
@ -216,8 +212,7 @@ R_API int r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo) {
}
R_API void* r_bin_free(RBin *bin) {
if (!bin)
return NULL;
if (!bin) return NULL;
r_bin_free_items (bin);
if (bin->curxtr && bin->curxtr->destroy)
bin->curxtr->destroy (bin);
@ -339,12 +334,10 @@ R_API int r_bin_has_dbg_relocs (RBin *bin) {
}
R_API RBin* r_bin_new() {
RBin *bin;
int i;
RBinPlugin *static_plugin;
RBinXtrPlugin *static_xtr_plugin;
int i;
bin = R_NEW (RBin);
RBin *bin = R_NEW (RBin);
if (bin) {
memset (bin, 0, sizeof (RBin));
INIT_LIST_HEAD (&bin->bins);
@ -365,7 +358,6 @@ R_API RBin* r_bin_new() {
R_API int r_bin_set_arch(RBin *bin, const char *arch, int bits, const char *name) {
int i;
for (i = 0; i < bin->narch; i++) {
r_bin_set_archidx (bin, i);
if (!bin->curarch.info || !bin->curarch.file ||
@ -387,7 +379,6 @@ R_API int r_bin_set_archidx(RBin *bin, int idx) {
R_API void r_bin_list_archs(RBin *bin) {
int i;
for (i = 0; i < bin->narch; i++)
if (r_bin_set_archidx (bin, i) && bin->curarch.info)
printf ("%03i %s %s_%i (%s)\n", i, bin->curarch.file,
@ -418,8 +409,12 @@ R_API void r_bin_object_free(RBinObj *obj) {
free (obj);
}
R_API char *r_bin_demangle (RBin *bin, const char *str) {
R_API char *r_bin_demangle (RBin *bin, const char *str, int type) {
if (bin && bin->curarch.curplugin && bin->curarch.curplugin->demangle)
return bin->curarch.curplugin->demangle (str);
switch (type) {
case R_BIN_NM_JAVA: return r_bin_demangle_java (str);
case R_BIN_NM_CXX: return r_bin_demangle_cxx (str);
}
return NULL;
}

11
libr/bin/demangle.c Normal file
View File

@ -0,0 +1,11 @@
/* radare - LGPL - Copyright 2011 pancake<@nopcode.org> */
#include <r_bin.h>
R_API char *r_bin_demangle_java(const char *str) {
return NULL;
}
R_API char *r_bin_demangle_cxx(const char *str) {
return NULL;
}

View File

@ -1710,7 +1710,23 @@ static int cmd_print(void *data, const char *input) {
switch (input[0]) {
case '%':
eprintf ("TODO\n");
{
ut64 off = core->offset;
ut64 s = core->file?core->file->size:0;
ut64 piece = 0;
int w = core->print->cols * 4;
piece = s/w;
r_cons_strcat (" [");
for (i=0; i<w; i++) {
ut64 from = (piece*i);
ut64 to = from+piece;
if (off>=from && off<to)
r_cons_memcat ("#", 1);
else r_cons_memcat (".", 1);
// TODO: print where flags are.. code, ..
}
r_cons_strcat ("]\n");
}
break;
case '=':
for (i=0; i<core->blocksize; i++) {
@ -2514,12 +2530,25 @@ static int cmd_anal(void *data, const char *input) {
break;
case 'p':
{
const char *arch = r_config_get (core->config, "asm.arch");
int bits = r_config_get_i (core->config, "asm.bits");
// TODO: this is x86 only
// TODO: allow interruptible search
char *o = strdup (r_config_get (core->config, "search.prefix"));
r_config_set (core->config, "search.prefix", "pre.");
r_core_cmd0 (core, "fs preludes");
r_core_cmd0 (core, "./x 5589e5 && af @@ pre.");
if (!strstr (arch, "x86")) {
switch (bits) {
case 32:
r_core_cmd0 (core, "./x 5589e5 && af @@ pre.");
break;
case 64:
r_core_cmd0 (core, "./x 554989e5 && af @@ pre.");
break;
}
} else {
eprintf ("ap: Unsupported asm.arch and asm.bits\n");
}
r_config_set (core->config, "search.prefix", o);
free (o);
}
@ -2528,6 +2557,7 @@ static int cmd_anal(void *data, const char *input) {
r_cons_printf (
"Usage: a[?obfrgtv]\n"
" aa ; Analyze all (fcns + bbs)\n"
" ap ; Find and analyze function preludes\n"
" as [num] ; Analyze syscall using dbg.reg\n"
" ao[e?] [len] ; Analyze Opcodes (or emulate it)\n"
" ab[?+-l*] ; Analyze Basic blocks\n"

View File

@ -45,7 +45,6 @@ R_API int r_core_visual_trackflags(RCore *core) {
RFlagItem *flag;
#define MAX_FORMAT 2
int format = 0;
const char *ptr;
const char *fs = NULL;
char *fs2 = NULL;
int option = 0;
@ -58,10 +57,6 @@ R_API int r_core_visual_trackflags(RCore *core) {
for (;;) {
r_cons_gotoxy (0,0);
r_cons_clear ();
/* Execute visual prompt */
ptr = r_config_get (core->config, "cmd.vprompt");
if (ptr&&ptr[0])
r_core_cmd (core, ptr, 0);
if (menu) {
r_cons_printf ("\n Flags in flagspace '%s'. Press '?' for help.\n\n",
@ -276,20 +271,20 @@ static void config_visual_hit(RCore *core, const char *name) {
char buf[1024];
RConfigNode *node;
if (!(node = r_config_node_get(core->config, name)))
if (!(node = r_config_node_get (core->config, name)))
return;
if (node->flags & CN_BOOL) {
/* TOGGLE */
node->i_value = !node->i_value;
node->value = r_str_dup(node->value, node->i_value?"true":"false");
node->value = r_str_dup (node->value, node->i_value?"true":"false");
} else {
// FGETS AND SO
r_cons_printf("New value (old=%s): ", node->value);
r_cons_flush();
r_cons_set_raw(0);
r_cons_fgets(buf, 1023, 0, 0);
r_cons_set_raw(1);
node->value = r_str_dup(node->value, buf);
r_cons_printf ("New value (old=%s): ", node->value);
r_cons_flush ();
r_cons_set_raw (0);
r_cons_fgets (buf, sizeof (buf)-1, 0, 0);
r_cons_set_raw (1);
node->value = r_str_dup (node->value, buf);
}
}
@ -297,7 +292,6 @@ R_API void r_core_visual_config(RCore *core) {
char cmd[1024];
struct list_head *pos;
#define MAX_FORMAT 2
const char *ptr;
char *fs = NULL;
char *fs2 = NULL;
int option = 0;
@ -314,14 +308,6 @@ R_API void r_core_visual_config(RCore *core) {
r_cons_gotoxy (0,0);
r_cons_clear ();
/* Execute visual prompt */
ptr = r_config_get (core->config, "cmd.vprompt");
if (ptr&&ptr[0]) {
// int tmp = last_print_format;
r_core_cmd (core, ptr, 0);
// last_print_format = tmp;
}
if (fs&&!memcmp (fs, "asm.", 4))
r_core_cmd (core, "pd 5", 0);
@ -1115,10 +1101,15 @@ R_API void r_core_visual_prompt(RCore *core, int color) {
}
static void r_core_visual_refresh (RCore *core) {
const char *vi;
r_cons_get_size (NULL);
r_cons_clear00 ();
r_print_set_cursor (core->print, curset, ocursor, cursor);
r_core_visual_prompt (core, color);
vi = r_config_get (core->config, "cmd.vprompt");
if (vi) r_core_cmd (core, vi, 0);
if (zoom)
r_core_cmd (core, "pZ", 0);
else
@ -1128,7 +1119,6 @@ static void r_core_visual_refresh (RCore *core) {
R_API int r_core_visual(RCore *core, const char *input) {
const char *cmdprompt;
const char *vi;
ut64 scrseek;
int ch;
obs = core->blocksize;
@ -1136,9 +1126,6 @@ R_API int r_core_visual(RCore *core, const char *input) {
r_cons_singleton ()->data = core;
r_cons_singleton ()->event_resize = (RConsEvent)r_core_visual_refresh;
vi = r_config_get (core->config, "cmd.vprompt");
if (vi) r_core_cmd (core, vi, 0);
while (input[0]) {
if (!r_core_visual_cmd (core, input[0])) {
r_cons_clear00 ();

View File

@ -30,6 +30,12 @@ enum {
R_BIN_SYM_LAST
};
// name mangling types
enum {
R_BIN_NM_JAVA,
R_BIN_NM_CXX,
};
// XXX: isnt this a copy of Obj ?
typedef struct r_bin_arch_t {
char *file;
@ -214,7 +220,9 @@ R_API int r_bin_load(RBin *bin, const char *file, int dummy);
R_API RBinObj *r_bin_get_object(RBin *bin, int flags);
R_API ut64 r_bin_get_baddr(RBin *bin);
R_API RBinAddr* r_bin_get_sym(RBin *bin, int sym);
R_API char* r_bin_demangle(RBin *bin, const char *str);
R_API char* r_bin_demangle(RBin *bin, const char *str, int type);
R_API char *r_bin_demangle_java(const char *str);
R_API char *r_bin_demangle_cxx(const char *str);
R_API RList* r_bin_get_entries(RBin *bin);
R_API RList* r_bin_get_fields(RBin *bin);
R_API RList* r_bin_get_imports(RBin *bin);
@ -243,6 +251,7 @@ R_API char *r_bin_meta_get_source_line(RBin *bin, ut64 addr);
R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size);
R_API int r_bin_wr_rpath_del(RBin *bin);
R_API int r_bin_wr_output(RBin *bin, const char *filename);
/* plugin pointers */
extern RBinPlugin r_bin_plugin_elf;
extern RBinPlugin r_bin_plugin_elf64;