* Fix delta seeking (do not allow seeks <0)

* Out of file reads (padding) filled by 0xff
* Added r_sys_cmd () to wrap r_system()
* Fix debug registers command to display segment and flag registers
  - Some draft changes in r_debug (signal handling and backtrace)
* Fix warnings in r_line
* Many more indentation fixes
  - Added st32 and st8 basic types
This commit is contained in:
pancake 2010-02-02 11:09:52 +01:00
parent 2b819bba83
commit f343c4d74f
24 changed files with 226 additions and 185 deletions

View File

@ -227,9 +227,3 @@ R_API int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *li
return R_TRUE;
}
// TODO: merge algorithms from r1 (do we need ebp?)
// TODO: must return a linked list or r_iter
R_API int r_anal_backtrace(struct r_anal_t *anal, const ut8 *buf, ut64 esp)
{
return R_FALSE;
}

View File

@ -24,7 +24,7 @@ RCons r_cons_instance;
static void break_signal(int sig)
{
I.breaked = 1;
I.breaked = R_TRUE;
if (I.break_cb)
I.break_cb (I.break_user);
}
@ -41,7 +41,7 @@ R_API void r_cons_break(void (*cb)(void *u), void *user)
R_API void r_cons_break_end()
{
I.breaked = 0;
I.breaked = R_FALSE;
#if __UNIX__
signal (SIGINT, SIG_IGN);
#endif
@ -68,7 +68,7 @@ R_API int r_cons_init()
I.noflush = R_FALSE;
I.fdin = stdin;
I.fdout = 1;
I.breaked = 0;
I.breaked = R_FALSE;
I.lines = 0;
I.buffer = NULL;
I.buffer_sz = 0;

View File

@ -82,11 +82,8 @@ static void r_core_cmd_reg (struct r_core_t *core, const char *str) {
if (arg) {
*arg = 0;
r = r_reg_get (core->dbg.reg, str+1, R_REG_TYPE_GPR);
if (r == NULL) {
eprintf ("Unknown register '%s'\n", str+1);
} else {
// TODO: does not works well :/
eprintf ("SET(%s)(%s)\n", str, arg+1);
if (r) {
//eprintf ("SET(%s)(%s)\n", str, arg+1);
r_cons_printf ("0x%08llx ->", str,
r_reg_get_value (core->dbg.reg, r));
r_reg_set_value (core->dbg.reg, r,
@ -94,7 +91,7 @@ static void r_core_cmd_reg (struct r_core_t *core, const char *str) {
r_debug_reg_sync (&core->dbg, R_REG_TYPE_GPR, R_TRUE);
r_cons_printf ("0x%08llx\n",
r_reg_get_value (core->dbg.reg, r));
}
} else eprintf ("Unknown register '%s'\n", str+1);
return;
}
size = atoi (str+1);
@ -111,7 +108,7 @@ static void r_core_cmd_reg (struct r_core_t *core, const char *str) {
if (type != R_REG_TYPE_LAST) {
r_debug_reg_sync (&core->dbg, type, R_FALSE);
r_debug_reg_list (&core->dbg, type, size, str[0]=='*');
} else eprintf("Unknown type\n");
} else eprintf ("r_core_cmd_reg: Unknown type\n");
}
}
@ -382,7 +379,7 @@ static int cmd_seek(void *data, const char *input) {
char *cmd, *p;
struct r_core_t *core = (struct r_core_t *)data;
if (input[0] && input[1]) {
int delta = (input[1]==' ')?2:1;
st32 delta = (input[1]==' ')?2:1;
off = r_num_math (&core->num, input + delta);
if (input[0]==' ' && (input[1]=='+'||input[1]=='-'))
input = input+1;
@ -391,12 +388,12 @@ static int cmd_seek(void *data, const char *input) {
r_core_seek (core, off, 1);
break;
case '+':
if (input[1]=='+') r_core_seek_delta (core, core->blocksize);
else r_core_seek_delta (core, off);
if (input[1]=='+') delta = core->blocksize; else delta = off;
r_core_seek_delta (core, delta);
break;
case '-':
if (input[1]=='-') r_core_seek_delta (core, -core->blocksize);
else r_core_seek_delta (core, -off);
if (input[1]=='-') delta = -core->blocksize; else delta = -off;
r_core_seek_delta (core, delta);
break;
case 'a':
off = core->blocksize;
@ -567,7 +564,7 @@ static int cmd_info(void *data, const char *input)
snprintf (buf, sizeof (buf), "rabin2 -%c%s '%s'", input[0],
input[1]=='*'?"r":"", core->file->filename);
eprintf ("(%s)\n", buf);
system(buf);
r_sys_cmd (buf);
break;
case '?':
r_cons_printf (
@ -1233,6 +1230,7 @@ static int cmd_hash(void *data, const char *input)
if (ptr != NULL)
len = r_num_math(&core->num, ptr+1);
/* TODO: support all hash algorithms and so */
if (!r_str_ccmp(input, "crc32", ' ')) {
r_cons_printf("%04x\n", r_hash_crc32(core->block, len));
} else
@ -1249,7 +1247,9 @@ static int cmd_hash(void *data, const char *input)
" #!python ; run python commandline\n"
" #!python < foo.py ; run foo.py python script\n"
" #!python <<EOF ; get python code until 'EOF' mark\n"
" #!python arg0 a1 <<q ; set arg0 and arg1 and read until 'q'\n");
" #!python arg0 a1 <<q ; set arg0 and arg1 and read until 'q'\n"
"Comments:\n"
" # this is a comment ; note the space after the sharp sign\n");
}
return 0;
@ -1283,7 +1283,7 @@ static int cmd_system(void *data, const char *input)
}
return WEXITSTATUS(st);
#else
return system(input);
return r_sys_cmd (input);
#endif
}
@ -1883,7 +1883,7 @@ static int cmd_debug(void *data, const char *input) {
if (pid > 0) {
eprintf ("Sending signal '%d' to pid '%d'\n",
sig, pid);
r_debug_kill (&core->dbg, pid, sig);
r_debug_kill (&core->dbg, sig);
} else eprintf ("Invalid arguments\n");
break;
case 's':
@ -1940,7 +1940,7 @@ static int cmd_debug(void *data, const char *input) {
// XXX: allow to allocate memory, show memory maps, ...
{char pid[16]; sprintf(pid, "%d", core->dbg.pid);
r_sys_setenv("PID", pid, 1);
system("cat /proc/$PID/maps"); }
r_sys_cmd ("cat /proc/$PID/maps"); }
break;
case 'r':
r_core_cmd_reg (core, input+1);

View File

@ -13,9 +13,7 @@ static ut64 num_callback(void *userptr, const char *str, int *ok)
/* analyze opcode */
switch (str[1]) {
case '$':
if (str[2]=='$')
return aop.length;
return core->offset;
return (str[2]=='$')? aop.length:core->offset;
case 'e':
case 'j':
case 'f':
@ -51,12 +49,9 @@ static ut64 num_callback(void *userptr, const char *str, int *ok)
}
flag = r_flag_get (&(core->flags), str);
if (flag != NULL) {
*ok = 1;
return flag->offset;
}
*ok = 0;
return 0LL;
if (flag) *ok = R_TRUE;
else *ok = R_FALSE;
return (flag)?flag->offset:0LL;
}
R_API struct r_core_t *r_core_new()
@ -232,6 +227,8 @@ R_API int r_core_seek_align(struct r_core_t *core, ut64 align, int times)
times -= inc;
diff += align*inc;
}
if (diff<0 && -diff>seek)
seek = diff = 0;
return r_core_seek (core, seek+diff, 1);
}
@ -247,7 +244,7 @@ R_API int r_core_seek_delta(struct r_core_t *core, st64 addr)
else addr += tmp;
} else {
/* check < 0 */
if (tmp+addr<0) addr = 0;
if (-addr > tmp) addr = 0;
else addr += tmp;
}
core->offset = addr;

View File

@ -511,8 +511,7 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
if (curset) {
if (ocursor==-1) ocursor=cursor;
cursor--;
} else
r_core_cmd(core, "s-2", 0);
} else r_core_cmd (core, "s-2", 0);
break;
case 'e':
r_core_visual_config(core);
@ -524,29 +523,26 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
if (curset) {
if (ocursor==-1) ocursor = cursor;
cursor+=16;
} else
r_core_cmd(core, "s++", 0);
} else r_core_cmd (core, "s++", 0);
break;
case 'g':
r_core_cmd (core, "s 0", 0);
break;
case 'G':
// TODO: seek to file size
r_core_seek (core, core->file->size-core->blocksize, 1);
//r_core_cmd(core, "s 0", 0);
break;
case 'K':
if (curset) {
if (ocursor==-1) ocursor=cursor;
cursor -= 16;
} else
r_core_cmd(core, "s--", 0);
} else r_core_cmd (core, "s--", 0);
break;
case 'L':
if (curset) {
if (ocursor==-1) ocursor=cursor;
cursor++;
} else
r_core_cmd(core, "s+2", 0);
} else r_core_cmd (core, "s+2", 0);
break;
/* move */
case 'h':
@ -638,6 +634,7 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
" HJKL - move around faster\n"
" P||p - rotate print modes\n"
" /*+- - change block size\n"
" cC - toggle cursor and colors\n"
" :cmd - run radare command\n"
" ;[-]cmt - add/remove comment\n"
" q - back to radare shell\n");

View File

@ -23,7 +23,7 @@ program from one engine to another (ptrace -> qemu).. we should
provide a way for all this operations between them.
[continue]
|--- check if bp api allows us to continue or we should step into..
|--- check if bp api allow us to continue or we should step into..
|--- check if debug plugin supports continue
[getregs]

View File

@ -191,7 +191,7 @@ R_API int r_debug_syscall(struct r_debug_t *dbg, int num)
// TODO: do we need tid/pid
// TODO: Do we need an intermediate signal representation for portability?
// TODO: STOP, CONTINUE, KILL, ...
R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig)
R_API int r_debug_kill(struct r_debug_t *dbg, int sig)
{
// XXX: use debugger handler backend here
#if __WINDOWS__
@ -199,9 +199,18 @@ R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig)
return R_FALSE;
#else
#include <signal.h>
int ret = kill(pid, sig);
int ret = kill(dbg->pid, sig);
if (ret == -1)
return R_FALSE;
return R_TRUE;
#endif
}
// TODO: move into r_debug
// TODO: we need to know the arch backend, frame size,
// TODO: merge algorithms from r1 (do we need ebp?)
// TODO: must return a linked list or r_iter
R_API int r_anal_backtrace(struct r_anal_t *anal, const ut8 *buf, ut64 esp)
{
return R_FALSE;
}

View File

@ -44,7 +44,7 @@ R_API int r_debug_handle_list(struct r_debug_t *dbg)
struct list_head *pos;
list_for_each_prev(pos, &dbg->handlers) {
struct r_debug_handle_t *h = list_entry(pos, struct r_debug_handle_t, list);
printf("dbg %d %s %s\n", count, h->name, ((h==dbg->h)?"*":""));
eprintf ("dbg %d %s %s\n", count, h->name, ((h==dbg->h)?"*":""));
count++;
}
return R_FALSE;

View File

@ -117,8 +117,6 @@ static const char *r_debug_ptrace_reg_profile()
"seg xss .32 52 0\n"
"gpr eflags .32 56 0\n"
"gpr flags .16 56 0\n"
"\n"
"# base address is 448bit\n"
"flg carry .1 .448 0\n"
"flg flag_p .1 .449 0\n"
"flg flag_a .1 .450 0\n"
@ -150,9 +148,13 @@ static int r_debug_ptrace_reg_read(struct r_debug_t *dbg, int type, ut8 *buf, in
{
int ret;
int pid = dbg->pid;
if (type == R_REG_TYPE_GPR) {
// XXX this must be defined somewhere else
#if __linux__ || __sun || __NetBSD__ || __FreeBSD__ || __OpenBSD__
switch (type) {
case R_REG_TYPE_SEG:
case R_REG_TYPE_FLG:
case R_REG_TYPE_GPR:
{
R_DEBUG_REG_T regs;
memset(&regs, 0, sizeof(regs));
memset(buf, 0, size);
@ -169,13 +171,13 @@ static int r_debug_ptrace_reg_read(struct r_debug_t *dbg, int type, ut8 *buf, in
return R_FALSE;
memcpy(buf, &regs, size);
return sizeof(regs);
}
break;
//r_reg_set_bytes(reg, &regs, sizeof(struct user_regs));
}
#else
#warning dbg-ptrace not supported for this platform
return 0;
#endif
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009 */
/* radare - LGPL - Copyright 2009-2010 */
/* nibble<.ds@gmail.com> */
/* pancake<nopcode.org> */

View File

@ -3,7 +3,7 @@
#define R_ITER_CPP 0
#define r_array_t void**
#define rArray void**
#define RArray void**
#define r_array_iterator(x) x
#define r_array_get(x) *(x++)
@ -21,7 +21,7 @@
#define r_array_prev(x) (--it==*it)?0:it
#define r_array_delete(x) for(;*x;x++)*x=*(x+1)
R_API void **r_array_new(int n);
R_API rArray r_array_init(rArray ptr, int n);
R_API RArray r_array_init(RArray ptr, int n);
R_API void **r_array_first(void **it);
R_API void r_array_foreach(void **it, int (*callback)(void *, void *), void *user);
R_API void **r_array_free(void **ptr);

View File

@ -119,12 +119,12 @@ typedef struct r_bin_field_t {
} RBinField;
typedef struct r_bin_obj_t {
rArray entrys;
rArray sections;
rArray symbols;
rArray imports;
rArray strings;
rArray fields;
RArray entrys;
RArray sections;
RArray symbols;
RArray imports;
RArray strings;
RArray fields;
RBinInfo info;
} RBinObject;

View File

@ -16,6 +16,15 @@ enum {
R_DBG_PROC_ZOMBIE,
};
// signal handling must support application and debugger level options
enum {
R_DBG_SIGNAL_IGNORE, // ignore signal handler
R_DBG_SIGNAL_BYPASS,
R_DBG_SIGNAL_HANDLE, //
R_DBG_SIGNAL_SETUP,
//..
};
typedef struct r_debug_t {
int pid; /* selected process id */
int tid; /* selected thread id */
@ -39,6 +48,13 @@ typedef struct r_debug_t {
*/
} RDebug;
typedef struct r_debug_memregion_t {
ut64 addr_start;
ut64 addr_end;
int perms;
char name[64];
} RDebugMemoryRegion;
/* TODO: pass dbg and user data pointer everywhere */
typedef struct r_debug_handle_t {
const char *name;
@ -48,6 +64,8 @@ typedef struct r_debug_handle_t {
int (*startv)(int argc, char **argv);
int (*attach)(int pid);
int (*detach)(int pid);
int (*select)(int pid, int tid);
RArray (*backtrace)(int count);
/* flow */
int (*step)(int pid); // if step() is NULL; reimplement it with traps
int (*cont)(int pid, int sig);
@ -87,7 +105,8 @@ R_API struct r_debug_t *r_debug_new();
R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg);
/* send signals */
R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig);
R_API int r_debug_kill(struct r_debug_t *dbg, int sig);
R_API int r_debug_kill_setup(struct r_debug_t *dbg, int sig, int action);
R_API int r_debug_step(struct r_debug_t *dbg, int steps);
R_API int r_debug_continue(struct r_debug_t *dbg);
R_API int r_debug_continue_kill(struct r_debug_t *dbg, int signal);
@ -120,7 +139,7 @@ Missing callbacks
=================
- alloc
- dealloc
- list maps
- list maps (memory regions)
- change memory protections
- touchtrace
- filedescriptor set/get/mod..

View File

@ -27,7 +27,7 @@ typedef int (*RLineCallback)(struct r_line_t *line);
typedef struct r_line_comp_t {
int argc;
char **argv;
const char **argv;
RLineCallback run;
} RLineCompletion;

View File

@ -45,8 +45,10 @@
#define ut64 unsigned long long
#define st64 long long
#define ut32 unsigned int
#define st32 int
#define ut16 unsigned short
#define ut8 unsigned char
#define st8 char
#define R_TRUE 1
#define R_FALSE 0

View File

@ -173,6 +173,7 @@ R_API int r_sys_usleep(int usecs);
R_API const char *r_sys_getenv(const char *key);
R_API int r_sys_setenv(const char *key, const char *value, int ow);
R_API char *r_sys_cmd_str_full(const char *cmd, const char *input, int *len, char **sterr);
R_API int r_sys_cmd(const char *cmd);
#define r_sys_cmd_str(cmd, input, len) r_sys_cmd_str_full(cmd, input, len, 0)
R_API int r_alloca_init();
R_API ut8 *r_alloca_bytes(int len);

View File

@ -153,14 +153,15 @@ R_API int r_io_read(struct r_io_t *io, ut8 *buf, int len)
if (io->plugin && io->plugin->read) {
if (io->plugin->read != NULL)
ret = io->plugin->read(io, io->fd, buf, len);
else fprintf(stderr, "IO handler for fd=%d has no read()\n", io->fd);
else eprintf ("IO handler for fd=%d has no read()\n", io->fd);
} else ret = read (io->fd, buf, len);
if (ret != -1 && ret != len)
memset (buf+ret, 0xff, len-ret);
}
if (ret != -1 && ret == len && io->cached_read) {
/* if read is cached. cache it :) */
if (ret != -1 && ret == len && io->cached_read)
r_io_cache_write (io, io->seek, buf, len);
}
return ret;
}

View File

@ -171,7 +171,7 @@ R_API int r_line_hist_chop(const char *file, int limit)
R_API void r_line_autocomplete()
{
int argc;
char **argv;
const char **argv;
int i, opt, len = 0;
/* prepare argc and argv */

View File

@ -22,7 +22,7 @@ R_API RLine *r_line_new () {
R_API void r_line_free () {
// XXX: prompt out of the heap?
free (I.prompt);
free ((void*)I.prompt);
I.prompt = NULL;
r_line_hist_free ();
}

View File

@ -7,8 +7,7 @@
R_API ut8* r_reg_get_bytes(struct r_reg_t *reg, int type, int *size)
{
struct r_reg_arena_t *arena;
int sz, osize = 0;
int i;
int i, sz, osize = 0;
if (type == -1) {
/* serialize ALL register types in a single buffer */
// owned buffer is returned

View File

@ -102,6 +102,9 @@ myclean:
clean: myclean
-rm -f ${OBJ} ${BIN}
install:
cd ../.. && ${MAKE} install
.PHONY: all clean myclean
endif

View File

@ -120,3 +120,9 @@ R_API char *r_sys_cmd_str_full(const char *cmd, const char *input, int *len, cha
return NULL;
#endif
}
R_API int r_sys_cmd (const char *str)
{
/* TODO: implement for other systems */
return system (str);
}

View File

@ -26,10 +26,10 @@ void test_array_new () {
void test_array_static () {
int i = 0;
void *data[10];
rArray iter;
rArray it = (rArray) &data;
RArray iter;
RArray it = (RArray) &data;
it = (rArray) r_array_init (it, 9);
it = (RArray) r_array_init (it, 9);
r_array_set (it, 0, "foo");
r_array_set (it, 1, "bar");

11
libr/vapi/r_anal.vapi Normal file
View File

@ -0,0 +1,11 @@
class Radare.RAnalysis {
struct Refline {
uint64 from;
uint64 to;
int index;
}
/* XXX dupped in r_asm ?? */
struct Aop {
}
}