* Very early work on r_anal_call api

* Initial support for visual cursor with invert cons in 'pd' bytes
  - Some changes in '*' and '/' keys in visual modes (+-16)
  - '+/-' in visual cursor works as in r1 (inc/dec cursor byte)
* Rename 'zf' into 'zh' for header, not function
  - 'zf' stands now for function signatures (args, types, ret, ...)
This commit is contained in:
pancake 2010-06-17 17:55:39 +02:00
parent 9e49939dab
commit c8da941768
13 changed files with 155 additions and 66 deletions

4
TODO
View File

@ -7,6 +7,10 @@
VERY IMPORTANT
==============
* trace counts after step..thats not correct!
* implement GMP in util/big.c
* pancake: fix RAnalCond because jz is not only !eax.. comparision doesnt works
* pancake: implement RAnalCall (analyze function arguments, return values, propagate types..)
* nibble: rename characteristics into srwx
* Visual byte cursor in disassembly
* Write manpages for r2, r2rc, r2rc-tool, rafind2 and rasign2

View File

@ -4,6 +4,11 @@ TODO for hackatons
Inconcrete things to do
=======================
* Compile radare2 on many OS and platforms as possible
- Windows? 32/64 bits (mingw32, cygwin)
- OSX?
- Solaris? (-lsocket ..)
* Test w32 bins with rabin2, r2, ..
* Implement process launcher wrapper // anybody
@ -60,11 +65,3 @@ Concrete TODO points
- Update vapi (r_search_regexp not implemented)
- Enable/disable nested hits? (discuss+ implement in parent app?)
- Just skip bytes until end of keyword
Portability
===========
* Compile radare2 on many OS and platforms as possible
- Windows? 32/64 bits (mingw32, cygwin)
- OSX?
- Solaris? (-lsocket ..)

View File

@ -1,3 +1,25 @@
Current development fronts
==========================
33 decompilation -- we need better code analysis, but basic decompilation will be in 0.5
we will provide at some point a decompiler as a plugin (more news soon)
many enhacements and fixes are being done in the code analysis backend
29 bindiffing (graph) --
basicblock tree diffing should be implemented for 0.5
we need to fix ired's bdiff in order to have binary diffing
26 better code analysis -- pancake and nibble are working on this now, it's advancing
18 code emulation -- some work has been done in r_vm, but needs much more refactoring
do we need code emulation? how ? anal ? vm? eval?
13 radare scripting like in r1 -- please, report issues in mailing list or privmail
8 signature support -- formatstring not yet implemented, this will be helpful for code analysis
6 web interface -- r2w, somebody interested?
3 osx support -- more prio? x86-32 and x86-64 hardware required, volunteers? read doc/osx fmi
Full poll
=========
33 decompilation -- we need better code analysis, but basic decompilation will be in 0.5
29 bindiffing (graph) -- nibble is working on this too, pancake has some binary diffing in C
26 better code analysis -- nibble is mainly working on this now
@ -5,8 +27,7 @@
22 gdb remote support -- not prioritary atm (volunteers?) linked to bochs/qemu
20 hardware breakpoints -- no plans for next release..will probably be in 0.6
18 code emulation -- some work has been done in r_vm, but needs much more refactoring
18 Debug programs in isolated environment
-- this is simple issue, any volunteer?
18 Debug programs in isolated environment -- this is simple issue, any volunteer?
14 threaded debugger -- some work will be done, but dont expect big changes
13 radare scripting like in r1 -- please, report issues in mailing list or privmail
13 dalvik (android) -- no plans, no hw, any volunteer? please ask for things to be done if you want to help on this
@ -15,7 +36,7 @@
9 pdb support -- any volunteer to convert pdb into radare script
9 RLine with autocompletion -- no plans atm, but this feature will come eventually
8 signature support -- DONE (volunteers to generate database
6 web interface -- volunteers?
6 web interface -- r2w
5 floating point debugger -- very low priority at this point
3 osx support -- x86-32 and x86-64 hardware required, volunteers? read doc/osx fmi
3 extended dwarf support -- zero priority for next release :)

View File

@ -11,7 +11,8 @@ foo: pre libr_anal.${EXT_SO} libr_anal.${EXT_AR} plugins
include ${STATIC_ANAL_PLUGINS}
#STATIC_OBJS=$(subst ..,p/..,$(subst anal_,p/anal_,$(STATIC_OBJ)))
STATIC_OBJS=$(subst ../ar,p/../ar,$(subst anal_,p/anal_,$(STATIC_OBJ)))
OBJ=${STATIC_OBJS} ctx.o reflines.o ref.o aop.o fcn.o bb.o var.o anal.o cond.o value.o
OBJLIBS=ctx.o reflines.o ref.o aop.o fcn.o bb.o var.o anal.o cond.o value.o call.o
OBJ=${STATIC_OBJS} ${OBJLIBS}
pre:
if [ ! -e libr_anal.${EXT_SO} ]; then rm -f ${STATIC_OBJS} ; fi

9
libr/anal/call.c Normal file
View File

@ -0,0 +1,9 @@
/* radare - LGPL - Copyright 2010 */
/* pancake<nopcode.org> */
#include <r_anal.h>
R_API RAnalCall *r_anal_call(RAnal *anal, ut64 addr) {
// TODO: must use anal->sign to retrieve function signature
return NULL;
}

View File

@ -40,8 +40,7 @@ const char *r_cons_color_names[CONS_COLORS_SIZE+1] = {
"bgreen", "byellow", "bturqoise", "reset", "bgblack", "bgred", NULL
};
void r_cons_invert(int set, int color)
{
R_API void r_cons_invert(int set, int color) {
if (color) {
if (set) r_cons_strcat("\x1b[7m");
else r_cons_strcat("\x1b[0m");

View File

@ -44,10 +44,15 @@ static void r_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len,
int show_comments = r_config_get_i (core->config, "asm.comments");
int show_stackptr = r_config_get_i (core->config, "asm.stackptr");
int linesopts = 0;
int cursor = (core->print->cur_enabled)?core->print->cur:-1;
int nb, nbytes = r_config_get_i (core->config, "asm.nbytes");
int cursor, nb, nbytes = r_config_get_i (core->config, "asm.nbytes");
nb = nbytes*2;
if (core->print->cur_enabled) {
if (core->print->cur<0)
core->print->cur = 0;
cursor = core->print->cur;
} else cursor = -1;
if (r_config_get_i (core->config, "asm.linesstyle"))
linesopts |= R_ANAL_REFLINE_STYLE;
if (r_config_get_i (core->config, "asm.lineswide"))
@ -77,12 +82,10 @@ static void r_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len,
for (i=idx=ret=0; idx < len && i<l; idx+=ret,i++) {
ut64 addr = core->offset + idx;
r_asm_set_pc (core->assembler, addr);
if (show_comments) {
comment = r_meta_get_string (core->meta, R_META_COMMENT, addr);
if (comment) {
r_cons_strcat (comment);
free (comment);
}
if (show_comments)
if ((comment = r_meta_get_string (core->meta, R_META_COMMENT, addr))) {
r_cons_strcat (comment);
free (comment);
}
line = r_anal_reflines_str (core->anal, core->reflines, addr, linesopts);
ret = r_asm_disassemble (core->assembler, &asmop, buf+idx, len-idx);
@ -171,7 +174,7 @@ static void r_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len,
pad[j] = ' ';
pad[j] = '\0';
if (show_color) {
char *nstr = r_print_hexpair (p, str);
char *nstr = r_print_hexpair (p, str, cursor-idx);
free (str);
str = nstr;
}
@ -360,12 +363,13 @@ static int cmd_zign(void *data, const char *input) {
break;
case 'a':
case 'b':
case 'h':
case 'f':
ptr = strchr (input+3, ' ');
if (ptr) {
*ptr = 0;
r_sign_add (core->sign, core->anal, (int)*input, input+2, ptr+1);
} else eprintf ("Usage: z%c [name] [bytes]\n", *input);
} else eprintf ("Usage: z%c [name] [arg]\n", *input);
break;
case 'c':
item = r_sign_check (core->sign, core->block, core->blocksize);
@ -446,8 +450,9 @@ static int cmd_zign(void *data, const char *input) {
" z-prefix unload zignatures prefixed as\n"
" z-* unload all zignatures\n"
" za ... define new zignature for analysis\n"
" zb name bytes define new zignature for bytes\n"
" zf name bytes define new function prelude zignature\n"
" zf name fmt define function zignature (fast/slow, args, types)\n"
" zb name bytes define zignature for bytes\n"
" zh name bytes define function header zignature\n"
" zg pfx [file] generate siganture for current file\n"
" .zc @ fcn.foo flag signature if matching (.zc@@fcn)\n"
" z/ [ini] [end] search zignatures between these regions\n"

View File

@ -176,10 +176,14 @@ R_API int r_core_visual_trackflags(RCore *core) {
if (menu<=0) return R_TRUE; menu--;
break;
case '*':
r_core_block_size (core, core->blocksize+16);
break;
case '+':
r_core_block_size (core, core->blocksize+1);
break;
case '/':
r_core_block_size (core, core->blocksize-16);
break;
case '-':
r_core_block_size (core, core->blocksize-1);
break;
@ -470,8 +474,9 @@ R_API void r_core_visual_define (RCore *core) {
/* TODO: use r_cmd here in core->vcmd..optimize over 255 table */
R_API int r_core_visual_cmd(RCore *core, int ch) {
char buf[1024];
ch = r_cons_arrow_to_hjkl(ch);
ch = r_cons_arrow_to_hjkl (ch);
// do we need hotkeys for data references? not only calls?
if (ch>='0'&&ch<='9') {
if (core->reflines) {
struct list_head *pos;
@ -545,7 +550,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
case 'J':
if (curset) {
if (ocursor==-1) ocursor = cursor;
cursor+=16;
cursor += 16;
} else r_core_cmd (core, "s++", 0);
break;
case 'g':
@ -625,17 +630,31 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
case 'P':
printidx--;
break;
case '-':
r_core_block_size (core, core->blocksize-1);
break;
case 'm':
r_core_visual_mark (core, r_cons_readchar());
break;
case '\'':
r_core_visual_mark_seek (core, r_cons_readchar());
break;
case '-':
if (core->print->cur_enabled) {
ut8 ch;
int cur = core->print->cur;
if (cur>=core->blocksize)
cur = core->print->cur-1;
ch = core->block[cur]-1;
r_core_write_at (core, core->offset+cur, &ch, 1);
} else r_core_block_size (core, core->blocksize-1);
break;
case '+':
r_core_block_size (core, core->blocksize+1);
if (core->print->cur_enabled) {
ut8 ch;
int cur = core->print->cur;
if (cur>=core->blocksize)
cur = core->print->cur-1;
ch = core->block[cur]+1;
r_core_write_at (core, core->offset+cur, &ch, 1);
} else r_core_block_size (core, core->blocksize-1);
break;
case '/':
r_core_block_size (core, core->blocksize-16);

View File

@ -184,6 +184,16 @@ typedef struct r_anal_bb_t {
RAnalCond *cond;
} RAnalBlock;
// TODO: add other call convections here
enum {
R_ANAL_CALL_FAST='f',
R_ANAL_CALL_SLOW='s',
};
typedef struct r_anal_call_t {
int type; // fast, stack/slow
RAnalValue *args[16]; // XXX
} RAnalCall;
typedef struct r_anal_fcn_t {
char *name;
ut64 addr;

View File

@ -27,7 +27,7 @@ typedef struct r_print_t {
} RPrint;
#ifdef R_API
R_API char *r_print_hexpair(RPrint *p, const char *str);
R_API char *r_print_hexpair(RPrint *p, const char *str, int idx);
R_API RPrint *r_print_new();
R_API RPrint *r_print_free(RPrint *p);
R_API void r_print_set_flags(RPrint *p, int _flags);

View File

@ -7,8 +7,9 @@
#include "list.h"
enum {
R_SIGN_BYTES = 'b',
R_SIGN_FUNC= 'f',
R_SIGN_BYTE = 'b',
R_SIGN_FUNC = 'f',
R_SIGN_HEAD = 'h',
R_SIGN_ANAL = 'a',
};
@ -17,14 +18,17 @@ typedef struct r_sign_item_t {
int type;
char name[32];
int size;
ut64 addr;
ut8 *bytes;
ut8 *mask;
struct list_head list;
} RSignItem;
typedef struct r_sign_t {
int s_byte;
int s_anal;
int s_byte;
int s_head;
int s_func; // TODO: this must be an array count[N]
char prefix[32];
FunctionPrintf printf;
struct list_head items;

View File

@ -9,28 +9,25 @@ R_API RPrint *r_print_new() {
p = R_NEW (RPrint);
if (p) {
/* read callback */
strcpy (p->datefmt, "%Y:%m:%d %H:%M:%S %z");
p->user = NULL;
p->read_at = NULL;
p->printf = printf;
p->interrupt = 0;
strcpy (p->datefmt, "%Y:%m:%d %H:%M:%S %z");
/* setup prefs */
p->bigendian = 0;
p->width = 78;
p->cur_enabled = R_FALSE;
p->cur = p->ocur = -1;
p->addrmod = 4;
p->flags = \
R_PRINT_FLAGS_COLOR |
R_PRINT_FLAGS_HEADER |
R_PRINT_FLAGS_ADDRMOD;
R_PRINT_FLAGS_COLOR |
R_PRINT_FLAGS_HEADER |
R_PRINT_FLAGS_ADDRMOD;
}
return p;
}
// dummy setter
R_API void r_print_set_flags(RPrint *p, int _flags) {
p->flags = _flags;
}
@ -83,11 +80,21 @@ R_API void r_print_addr(RPrint *p, ut64 addr) {
}
// XXX: bad designed function :)
R_API char *r_print_hexpair(RPrint *p, const char *str) {
R_API char *r_print_hexpair(RPrint *p, const char *str, int n) {
const char *s;
int i=0;
char *d, *dst = (char *)malloc (1024); //(strlen (str)+2)*6);
for (s=str,d=dst; *s; s+=2, d+=2) {
// XXX: overflow here
for (s=str,d=dst; *s; s+=2, d+=2, i++) {
if (i-1==n) {
memcpy (d, "\x1b[0m", 4);
d += 4;
}
if (i==n) {
memcpy (d, "\x1b[7m", 4);
d += 4;
} else
if (s[0]=='0' && s[1]=='0') {
memcpy (d, "\x1b[31m", 5);
d += 5;

View File

@ -4,9 +4,7 @@
#include <r_anal.h>
R_API RSign *r_sign_new() {
RSign *sig;
sig = R_NEW (RSign);
RSign *sig = R_NEW (RSign);
if (sig) {
sig->s_byte = sig->s_anal = 0;
sig->prefix[0] = '\0';
@ -23,26 +21,40 @@ R_API void r_sign_prefix(RSign *sig, const char *str) {
R_API int r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const char *arg) {
int len, ret = R_FALSE;
char *data;
char *data, *ptr;
RSignItem *si; // TODO: like in r_search.. we need r_sign_item_new ()
// TODO: but..we need to use a pool here..
if (!name || !arg || !anal)
return R_FALSE;
if (!(si = R_NEW (RSignItem)))
return R_FALSE;
si->type = type;
snprintf (si->name, sizeof (si->name), "%s.%c.%s",
*sig->prefix?sig->prefix:"sign", type, name);
switch (type) {
case R_SIGN_BYTES:
case R_SIGN_FUNC:
si = R_NEW (RSignItem);
if (si == NULL)
case R_SIGN_FUNC: // function signature
sig->s_func++;
// FUNC FORMAT [addr] [function-signature]
ptr = strchr (arg, ' ');
if (ptr) {
// TODO. matching must be done by sym/flag/function name
// sig->addr =
}
list_add_tail (&(si->list), &(sig->items));
break;
case R_SIGN_HEAD: // function prefix (push ebp..)
case R_SIGN_BYTE: // function mask
if (type==R_SIGN_HEAD)
sig->s_head++;
else if (type==R_SIGN_BYTE)
sig->s_byte++;
if (!(data = r_anal_strmask (anal, arg))) {
free (si);
break;
si->type = type;
snprintf (si->name, sizeof (si->name), "%s.%s",
*sig->prefix?sig->prefix:"sign", name);
data = r_anal_strmask (anal, arg);
if (data == NULL)
break;
len = strlen (data);
}
len = strlen (data)+1;
si->bytes = (ut8 *)malloc (len);
si->mask = (ut8 *)malloc (len);
if (si->bytes == NULL || si->mask == NULL) {
@ -55,14 +67,14 @@ R_API int r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const
si->size = r_hex_str2binmask (data, si->bytes, si->mask);
if (si->size<1) {
free (si->bytes);
free (si->mask);
free (si);
} else list_add_tail (&(si->list), &(sig->items));
sig->s_byte++;
free (data);
break;
default:
case R_SIGN_ANAL:
eprintf ("r_sign_add: TODO\n");
eprintf ("r_sign_add: TODO. unsupported signature type %d\n", type);
break;
}
return ret;
@ -79,7 +91,8 @@ R_API void r_sign_list(RSign *sig, int rad) {
} else {
sig->printf ("Loaded %d signatures\n", sig->s_byte + sig->s_anal);
sig->printf (" %d byte signatures\n", sig->s_byte);
sig->printf (" %d anal signatures\n", sig->s_anal);
sig->printf (" %d head signatures\n", sig->s_head);
sig->printf (" %d func signatures\n", sig->s_func);
}
}
@ -103,7 +116,7 @@ R_API RSignItem *r_sign_check(RSign *sig, const ut8 *buf, int len) {
struct list_head *pos;
list_for_each (pos, &sig->items) {
RSignItem *si = list_entry (pos, RSignItem, list);
if (si->type == R_SIGN_BYTES) {
if (si->type == R_SIGN_BYTE) {
int l = (len>si->size)?si->size:len;
if (!r_mem_cmp_mask (buf, si->bytes, si->mask, l))
return si;