* Drop 'r_cons.h' from r_fs

* Fix visual glitch in Vej and Vt
* Handle demangled names as comments
  - in rabin2 and core->bin_load
  - Needs to be a RAnalCall at some point
  - bin_java calls the dummy r_bin_demangle_java
  - Add R_BIN_NM_ANY enum
* Add asm.lbytes config to align disasm bytes to left
* Fix visual glitch in function boundaries
* Import upgraded versions of the idc2rdb scripts in doc/
This commit is contained in:
pancake 2011-02-25 04:19:30 +01:00
parent 4c66b9177a
commit e557d9a385
16 changed files with 211 additions and 92 deletions

79
TODO
View file

@ -6,39 +6,20 @@
pancake
-------
* RAsmAop -> RAsmOp EVERYFUCKINGWHERE
* mount in / results problematic sometimes.. :/
* idc2rdb !!! important
* check search multiple keywords and signatures
* "wx jeje" does not says "invalid hexpair string" (must report error)
* Vdu -> does not undefine a function
* Visual disassembly cursor does not displays on scr.color=0
* if console width > X place comments there (ash)
* Implement BLOCK in r_core_sysenv_begin|end ()
* Fix iterators for r_macro (test only?)
capi_x
------
* Fix avr/ppc code analysis // fix or use or what? :)
earada
------
* Add print support for bitfields (pm b...)
- r_bin_demangle (); // r_util maybe?
* _ZN7WebCore11CounterNode7recountERKNS_12AtomicStringE
- demangle c++ and objc names
WebCore.CounterNode.recount(AtomicString)
_ZN = begin of stream
0-9+ = count of chars
E = end of stream
RKNS_ = start of arguments
* 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
* Implement case-insensitive search (e search.casematters ?) any better name? Use /i?
* Implement /. to search using a file .. isnt zignatures about this?
* Implement /p to search for patterns
- implement it in r_core ?? or add r_io_bind support
* Implement search and replace /s
- insert or append? (see r1 cfg vars)
nibble
------
* code analysis must resolve jump tables
* allow to hook r_asm_disassemble and assemble with custom callbacks
- extend a disassembler with own instructions.
* 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.
@ -64,6 +45,31 @@ nibble
2nd level:
- basic block level diffing (output in graph mode)
capi_x
------
* code analysis for msil
* Fix avr/ppc code analysis // fix or use or what? :)
earada
------
* Add print support for bitfields (pm b...)
- r_bin_demangle (); // r_util maybe?
* _ZN7WebCore11CounterNode7recountERKNS_12AtomicStringE
- demangle c++ and objc names
WebCore.CounterNode.recount(AtomicString)
_ZN = begin of stream
0-9+ = count of chars
E = end of stream
RKNS_ = start of arguments
* 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
* Implement case-insensitive search (e search.casematters ?) any better name? Use /i?
* Implement /. to search using a file .. isnt zignatures about this?
* Implement /p to search for patterns
- implement it in r_core ?? or add r_io_bind support
* Implement search and replace /s
- insert or append? (see r1 cfg vars)
0.7 release
===========
@ -74,14 +80,9 @@ nibble
CORE
----
* Add "pm ?" for bit print like in pb? bit level binary memory printage
- add support for PDB files
- Handle ^C in searches (at least)
- Add support for DEX file format
- display filesize info instead of virtual space address limit
- "wx jeje" does not says "invalid hexpair string" (must report error)
- allow to hook r_asm_disassemble and assemble with custom callbacks
- extend a disassembler with own instructions.
Assembler
---------
@ -108,13 +109,6 @@ nibble
- 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
@ -127,7 +121,6 @@ dwarf, pdb, def, lib
Things to improve in r2
=======================
* focus in single arch (rock allover) mips, ppc64 or arm?
* code analysis must resolve jump tables
* Enhace code analysis
- calculate multiple execution paths to give branch prediction results
- get/set register status of the vm
@ -149,6 +142,10 @@ Debugger
* Add support for windbg+virtualkd
* Floating point registers
* MMX/XMM/DRX control
* 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
pancake
-------
@ -156,8 +153,6 @@ pancake
* fork/clone child . inject code to create new threads or pids
* Functions in r_util to get lil/big ut8,16,32 from ut8*
- already done..must find better names probably
* support for macro scripting
* better debugger support for OSX and iOS
* rarc2 allows to compile invalid code like calling puts() out of context
* Implement RAnalCall (analyze function arguments, return values, propagate types..)
- define number of arguments for given function

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:
* -L [lib] dlopen library and show address
@ -287,6 +287,11 @@ static int rabin_show_symbols() {
printf("%s\n", symbol->name);
} else {
if (rad) {
char *mn = r_bin_demangle (bin, symbol->name, R_BIN_NM_ANY);
if (mn) {
printf ("CC %s@0x%08"PFMT64x"\n", mn, symbol->offset);
free (mn);
}
r_flag_name_filter (symbol->name);
if (!strncmp (symbol->type,"FUNC", 4)) {
printf ("fs functions\n");

91
doc/idc2rdb.idc Normal file
View file

@ -0,0 +1,91 @@
/*
* ida2rdb.idc
* ===========
*
* Exports an ida database in a format to be handled by radare
*
* author: pancake <@youterm.com>
*
* TODO:
* * Add stack frame related information (stack size, and so) as comments
*
*/
#include <idc.idc>
static dumpMeNot(fd, ea) {
auto func, comment, sz, i, ref;
// Loop from start to end in the current segment
//SegStart(ea);
for (func=ea; func != BADADDR && func < SegEnd(ea); func=NextFunction(func)) {
// If the current address is function process it
// if (GetFunctionFlags(func) != -1) {
fprintf(fd, "f %s @ 0x%08lx\n", GetFunctionName(func), func);
comment = GetFunctionCmt(func, 0);
if (comment != "")
fprintf(fd, "CC %s@0x%08x\n", comment, func);
fprintf(fd, "CC framesize=%d@0x%08x\n", func, GetFrameSize(func));
sz = FindFuncEnd(func);
fprintf(fd, "CC bytes=0x%08lx ", func);
for(i=func;i<sz;i++)
fprintf(fd, "%02x ", Byte(i));
fprintf(fd, "\n");
// Find all code references to func
for (ref=RfirstB(func); ref != BADADDR; ref=RnextB(func, ref)) {
//fprintf(fd, "; xref from %08lX (%s)\n", ref, GetFunctionName(ref));
fprintf(fd, "Cx 0x%08lx 0x%08lx\n", func, ref);
}
// }
}
for (func=ea; func != BADADDR && func < SegEnd(ea); func=func+1) {
comment = CommentEx(func, 0);
if (comment != "")
fprintf(fd, "CC %s@0x%08x\n", comment, func);
comment = GetConstCmt(func, 0);
if (comment != "")
fprintf(fd, "CC %s@0x%08x\n", comment, func);
comment = GetEnumCmt(func, 0);
if (comment != "")
fprintf(fd, "CC %s@0x%08x\n", comment, func);
}
}
static main() {
auto fd;
auto file;
auto i, func, ref,sz;
auto ord,ea;
auto comment;
auto entry;
file = GetInputFile()+".txt";
fd = fopen(file, "w");
if (!fd) {
Message("Cannot open '"+file+"'\n");
Exit(1);
}
entry="";
// Walk entrypoints
for ( i=0; ; i++ ) {
ord = GetEntryOrdinal(i);
if ( ord == 0 ) break;
ea = GetEntryPoint(ord);
fprintf(fd, "entry=0x%08lx %s\n", ea, Name(ea));
entry = ea;
}
// XXX last entrypoint taken as ok??
dumpMeNot(fd, entry);
// eof
fclose(fd);
Message(file+"file generated.\n");
}

19
doc/idc2rdb.pl Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/perl
# author: pancake <youterm.com>
# MakeName (0X804C1AF, "the_forker");
# MakeRptCmt (0X804C1B6, "comentari chachi\n");
open FD, "<".$ARGV[0] or die "Cannot open file\n";
print "fs symbols\n";
while(<FD>) {
$str=$_;
if ($str=~/MakeName[^X]*.([^,]*)[^"]*.([^"]*)/) {
print "f sym.$2 @ 0x$1\n";
}
elsif ($str=~/MakeRptCmt[^X]*.([^,]*)[^"]*.([^"]*)/) {
$cmt = $2;
$off = $1;
$cmt=~s/\\n//g;
print "CC $cmt @ 0x$off\n";
}
}

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2011 nibble<.ds@gmail.com> */
#include <stdio.h>

View file

@ -408,13 +408,3 @@ R_API void r_bin_object_free(RBinObj *obj) {
// XXX: leak
free (obj);
}
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;
}

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2011 nibble<.ds@gmail.com> */
#include <r_types.h>
#include <r_util.h>

View file

@ -9,3 +9,15 @@ R_API char *r_bin_demangle_java(const char *str) {
R_API char *r_bin_demangle_cxx(const char *str) {
return NULL;
}
R_API char *r_bin_demangle (RBin *bin, const char *str, int type) {
switch (type) {
case R_BIN_NM_JAVA: return r_bin_demangle_java (str);
case R_BIN_NM_CXX: return r_bin_demangle_cxx (str);
case R_BIN_NM_ANY:
if (bin && bin->curarch.curplugin && bin->curarch.curplugin->demangle)
return bin->curarch.curplugin->demangle (str);
return NULL;
}
return NULL;
}

View file

@ -1,4 +1,5 @@
/* radare - GPL3 - Copyright 2009 nibble<.ds@gmail.com> */
/* radare - GPL3 - Copyright 2009-2011 */
/* authors: pancake, nibble */
#include <r_types.h>
#include <r_util.h>
@ -129,11 +130,6 @@ static int check(RBinArch *arch) {
return ret;
}
static char *demangle (const char *str) {
// TODO: implement java symbol demangler code here
return strdup (str);
}
struct r_bin_plugin_t r_bin_plugin_java = {
.name = "java",
.desc = "java bin plugin",
@ -155,7 +151,7 @@ struct r_bin_plugin_t r_bin_plugin_java = {
.relocs = NULL,
.meta = NULL,
.write = NULL,
.demangle = demangle,
.demangle = r_bin_demangle_java,
};
#ifndef CORELIB

View file

@ -150,6 +150,7 @@ static void r_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len,
int show_xrefs = r_config_get_i (core->config, "asm.xrefs");
int show_functions = r_config_get_i (core->config, "asm.functions");
int cursor, nb, nbytes = r_config_get_i (core->config, "asm.nbytes");
int lbytes = r_config_get_i (core->config, "asm.lbytes");
int linesopts = 0;
const char *pre = "";
nb = nbytes*2;
@ -257,13 +258,13 @@ r_cons_printf ("%s ", pre);
pre = "";
if (f->addr == at) {
char *sign = r_anal_fcn_to_string (core->anal, f);
r_cons_printf ("/* %s: %s (%d) */\n",
f->type == R_ANAL_FCN_TYPE_FCN?"function":"loc", f->name, f->size);
r_cons_printf ("/ %s: %s (%d)\n: ",
f->type == R_ANAL_FCN_TYPE_FCN?"function":"loc", f->name, f->size);
if (sign) r_cons_printf ("// %s\n", sign);
free (sign);
stackptr = 0;
} else if (f->addr+f->size-1 == at) {
r_cons_printf ("\\*");
r_cons_printf ("\\ ");
} else if (at > f->addr && at < f->addr+f->size-1) {
r_cons_printf (": ");
pre = ": ";
@ -336,19 +337,25 @@ r_cons_printf ("%s ", pre);
}
if (show_bytes) {
char *str, pad[64];
const char *extra = " ";
char extra[64];
strcpy (extra, " ");
if (!flag) {
str = strdup (asmop.buf_hex);
if (strlen (str) > nb) {
str[nb] = '.';
str[nb+1] = '\0';
extra = "";
*extra = 0;
}
k = nb-strlen (str);
if (k<0) k = 0;
for (j=0; j<k; j++)
pad[j] = ' ';
pad[j] = '\0';
if (lbytes) {
// hack to align bytes left
strcpy (extra, pad);
*pad=0;
}
if (show_color) {
char *nstr;
p->cur_enabled = cursor!=-1;

View file

@ -298,12 +298,6 @@ R_API int r_core_config_init(RCore *core) {
RConfig *cfg = cfg = core->config = r_config_new (core);
cfg->printf = r_cons_printf;
r_config_set_cb (cfg, "asm.arch", R_SYS_ARCH, &config_asmarch_callback);
// XXX: not portable
r_parse_use (core->parser, "x86.pseudo");
r_config_set_cb (cfg, "asm.parser", "x86.pseudo",
&config_asmparser_callback);
r_config_set (cfg, "dir.plugins", LIBDIR"/radare2/"R2_VERSION"/");
/* anal */
r_config_set_i (cfg, "anal.depth", 100);
@ -311,8 +305,14 @@ R_API int r_core_config_init(RCore *core) {
r_config_set_cb (cfg, "anal.split", "true", &config_analsplit_callback);
r_config_set_cb (cfg, "anal.plugin", "x86", &config_analplugin_callback);
/* asm */
r_config_set_cb (cfg, "asm.arch", R_SYS_ARCH, &config_asmarch_callback);
// XXX: not portable
r_parse_use (core->parser, "x86.pseudo");
r_config_set_cb (cfg, "asm.parser", "x86.pseudo",
&config_asmparser_callback);
r_config_set_i_cb (cfg, "asm.bits", 32, &config_asmbits_callback);
r_config_set (cfg, "asm.bytes", "true");
r_config_set_i (cfg, "asm.lbytes", "true");
r_config_set (cfg, "asm.middle", "false"); // jump in the middle because of antidisasm tricks
r_config_set (cfg, "asm.comments", "true");
r_config_set (cfg, "asm.stackptr", "true");
@ -323,7 +323,6 @@ R_API int r_core_config_init(RCore *core) {
r_config_set (cfg, "asm.varsub", "true");
r_config_set (cfg, "asm.trace", "true");
r_config_set (cfg, "asm.decode", "false");
r_config_set (cfg, "asm.bytes", "true");
r_config_set (cfg, "asm.offset", "true");
r_config_set (cfg, "asm.lines", "true");
r_config_set (cfg, "asm.linesout", "true");

View file

@ -131,6 +131,7 @@ R_API int r_core_bin_load(RCore *r, const char *file) {
// s -> Symbols
if ((list = r_bin_get_symbols (r->bin)) != NULL) {
char *name;
r_list_foreach (list, iter, symbol) {
r_flag_name_filter (symbol->name);
snprintf (str, R_FLAG_NAME_SIZE, "fcn.sym.%s", symbol->name);
@ -144,6 +145,12 @@ R_API int r_core_bin_load(RCore *r, const char *file) {
(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);
name = r_bin_demangle (r->bin, symbol->name, R_BIN_NM_ANY);
if (name) {
r_meta_add (r->meta, R_META_COMMENT, va?baddr+symbol->rva:symbol->offset,
symbol->size, name);
free (name);
}
}
}

View file

@ -87,9 +87,9 @@ R_API int r_core_visual_trackflags(RCore *core) {
r_cons_printf ("\n Selected: %s\n\n", fs2);
switch (format) {
case 0: sprintf (cmd, "px @ %s", fs2); printidx = 0; break;
case 1: sprintf (cmd, "pd 12 @ %s", fs2); printidx = 1; break;
case 2: sprintf (cmd, "ps @ %s", fs2); printidx = 5; break;
case 0: sprintf (cmd, "px @ %s:128", fs2); printidx = 0; break;
case 1: sprintf (cmd, "pd 12 @ %s:128", fs2); printidx = 1; break;
case 2: sprintf (cmd, "ps @ %s:128", fs2); printidx = 5; break;
default: format = 0; continue;
}
if (*cmd) r_core_cmd (core, cmd, 0);
@ -308,9 +308,6 @@ R_API void r_core_visual_config(RCore *core) {
r_cons_gotoxy (0,0);
r_cons_clear ();
if (fs&&!memcmp (fs, "asm.", 4))
r_core_cmd (core, "pd 5", 0);
switch (menu) {
case 0: // flag space
r_cons_printf ("\n Eval spaces:\n\n");
@ -350,13 +347,13 @@ R_API void r_core_visual_config(RCore *core) {
j = i = 0;
// TODO: cut -d '.' -f 1 | sort | uniq !!!
list_for_each (pos, &(core->config->nodes)) {
RConfigNode *bt = list_entry(pos, RConfigNode, list);
RConfigNode *bt = list_entry (pos, RConfigNode, list);
if (option==i) {
fs2 = bt->name;
hit = 1;
}
if (!r_str_ccmp(bt->name, fs, '.')) {
if( (i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
if (!r_str_ccmp (bt->name, fs, '.')) {
if ( (i>=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
// TODO: Better align
r_cons_printf (" %c %s = %s\n", (option==i)?'>':' ', bt->name, bt->value);
j++;
@ -371,6 +368,9 @@ R_API void r_core_visual_config(RCore *core) {
if (fs2 != NULL)
r_cons_printf("\n Selected: %s\n\n", fs2);
}
if (fs&&!memcmp (fs, "asm.", 4))
r_core_cmd (core, "pd 5", 0);
r_cons_flush();
ch = r_cons_readchar();
ch = r_cons_arrow_to_hjkl(ch); // get ESC+char, return 'hjkl' char

View file

@ -252,7 +252,7 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
} else strcpy (path, "/");
for (;;) {
printf (Color_MAGENTA"[%s]> "Color_RESET, path);
printf ("[%s]> ", path);
fflush (stdout);
fgets (buf, sizeof (buf)-1, stdin);
if (feof (stdin)) break;
@ -312,7 +312,7 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
r_list_foreach (fs->roots, iter, root) {
eprintf ("%s %s\n", root->path, root->p->name);
}
} else if (!memcmp (buf, "get ",4)) {
} else if (!memcmp (buf, "get ", 4)) {
input = buf+3;
while (input[0] == ' ')
input++;
@ -328,10 +328,10 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
r_fs_close (fs, file);
} else printf ("Cannot open file\n");
} else if (!memcmp (buf, "help", 4) || !strcmp (buf, "?")) {
printf (
eprintf (
"Commands:\n"
" !cmd ; escape to system\n"
" ls ; list current directory\n"
" ls [path] ; list current directory\n"
" cd path ; change current directory\n"
" cat file ; print contents of file\n"
" get file ; dump file to disk\n"
@ -339,9 +339,7 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
" q/exit ; leave prompt mode\n"
" ?/help ; show this help\n"
);
} else {
printf ("Unknown command %s\n", buf);
}
} else eprintf ("Unknown command %s\n", buf);
}
clearerr (stdin);
printf ("\n");

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2008-2011 nibble<.ds@gmail.com> */
#ifndef _INCLUDE_R_BIN_H_
#define _INCLUDE_R_BIN_H_
@ -34,6 +34,7 @@ enum {
enum {
R_BIN_NM_JAVA,
R_BIN_NM_CXX,
R_BIN_NM_ANY=-1,
};
// XXX: isnt this a copy of Obj ?

View file

@ -4,7 +4,6 @@
#include <r_types.h>
#include <r_list.h>
#include <r_io.h>
#include <r_cons.h>
struct r_fs_plugin_t;
struct r_fs_root_t;