mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 05:40:10 +00:00
* 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:
parent
2b819bba83
commit
f343c4d74f
@ -13,7 +13,7 @@ R_API struct r_anal_t *r_anal_new()
|
||||
R_API struct r_anal_t *r_anal_free(struct r_anal_t *a)
|
||||
{
|
||||
/* TODO: Free a->anals here */
|
||||
free(a);
|
||||
free (a);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ R_API int r_anal_list(struct r_anal_t *anal)
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &anal->anals) {
|
||||
struct r_anal_handle_t *h = list_entry(pos, struct r_anal_handle_t, list);
|
||||
printf(" %s: %s\n", h->name, h->desc);
|
||||
printf (" %s: %s\n", h->name, h->desc);
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
@ -57,9 +57,9 @@ R_API int r_anal_list(struct r_anal_t *anal)
|
||||
R_API int r_anal_use(struct r_anal_t *anal, const char *name)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &anal->anals) {
|
||||
list_for_each_prev (pos, &anal->anals) {
|
||||
struct r_anal_handle_t *h = list_entry(pos, struct r_anal_handle_t, list);
|
||||
if (!strcmp(h->name, name)) {
|
||||
if (!strcmp (h->name, name)) {
|
||||
anal->cur = h;
|
||||
return R_TRUE;
|
||||
}
|
||||
@ -106,7 +106,7 @@ R_API struct r_anal_fcn_t *r_anal_funcions_get(struct r_anal_t *anal, ut8 *buf,
|
||||
|
||||
R_API struct r_anal_refline_t *r_anal_reflines_get(struct r_anal_t *anal, ut8 *buf, ut64 len, int nlines, int linesout)
|
||||
{
|
||||
struct r_anal_refline_t *list = MALLOC_STRUCT(struct r_anal_refline_t);
|
||||
struct r_anal_refline_t *list = MALLOC_STRUCT (struct r_anal_refline_t);
|
||||
struct r_anal_refline_t *list2;
|
||||
struct r_anal_aop_t aop;
|
||||
ut8 *ptr = buf;
|
||||
@ -117,7 +117,7 @@ R_API struct r_anal_refline_t *r_anal_reflines_get(struct r_anal_t *anal, ut8 *b
|
||||
INIT_LIST_HEAD(&(list->list));
|
||||
|
||||
/* analyze code block */
|
||||
while(ptr<end) {
|
||||
while (ptr<end) {
|
||||
if (nlines != -1 && --nlines == 0)
|
||||
break;
|
||||
#if 0
|
||||
@ -218,7 +218,7 @@ R_API int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *li
|
||||
}
|
||||
}
|
||||
|
||||
switch(dir) {
|
||||
switch (dir) {
|
||||
case 1: strcat(str, "-> "); break;
|
||||
case 2: strcat(str, "=< "); break;
|
||||
default: strcat(str, " "); break;
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
110
libr/core/cmd.c
110
libr/core/cmd.c
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +135,7 @@ static void r_core_cmd_bp (struct r_core_t *core, const char *input) {
|
||||
} else r_bp_handle_list (core->dbg.bp);
|
||||
break;
|
||||
case '?':
|
||||
r_cons_printf(
|
||||
r_cons_printf (
|
||||
"Usage: db [[-]addr] [len] [rwx] [condstring]\n"
|
||||
"db ; list breakpoints\n"
|
||||
"db sym.main ; add breakpoint into sym.main\n"
|
||||
@ -381,22 +378,22 @@ static int cmd_seek(void *data, const char *input) {
|
||||
ut64 off;
|
||||
char *cmd, *p;
|
||||
struct r_core_t *core = (struct r_core_t *)data;
|
||||
if (input[0]&&input[1]) {
|
||||
int delta = (input[1]==' ')?2:1;
|
||||
off = r_num_math(&core->num, input + delta);
|
||||
if (input[0] && input[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;
|
||||
switch(input[0]) {
|
||||
switch (input[0]) {
|
||||
case ' ':
|
||||
r_core_seek(core, off, 1);
|
||||
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;
|
||||
@ -409,7 +406,7 @@ static int cmd_seek(void *data, const char *input) {
|
||||
}
|
||||
cmd[0]='s';
|
||||
// perform real seek if provided
|
||||
r_cmd_call(&core->cmd, cmd);
|
||||
r_cmd_call (&core->cmd, cmd);
|
||||
free(cmd);
|
||||
}
|
||||
r_core_seek_align(core, off, 0);
|
||||
@ -425,7 +422,7 @@ static int cmd_seek(void *data, const char *input) {
|
||||
" sa [[+-]a] [asz] ; seek asz (or bsize) aligned to addr\n");
|
||||
break;
|
||||
}
|
||||
} else r_cons_printf("0x%llx\n", core->offset);
|
||||
} else r_cons_printf ("0x%llx\n", core->offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -434,45 +431,45 @@ static int cmd_help(void *data, const char *input)
|
||||
struct r_core_t *core = (struct r_core_t *)data;
|
||||
ut64 n;
|
||||
|
||||
switch(input[0]) {
|
||||
switch (input[0]) {
|
||||
case ' ':
|
||||
n = r_num_math(&core->num, input+1);
|
||||
r_cons_printf("%lld 0x%llx\n", n,n);
|
||||
n = r_num_math (&core->num, input+1);
|
||||
r_cons_printf ("%lld 0x%llx\n", n,n);
|
||||
break;
|
||||
case '=':
|
||||
r_num_math(&core->num, input+1);
|
||||
r_num_math (&core->num, input+1);
|
||||
break;
|
||||
case '+':
|
||||
if (input[1]) {
|
||||
if (core->num.value & UT64_GT0)
|
||||
r_core_cmd (core, input+1, 0);
|
||||
} else r_cons_printf("0x%llx\n", core->num.value);
|
||||
} else r_cons_printf ("0x%llx\n", core->num.value);
|
||||
break;
|
||||
case '-':
|
||||
if (input[1]) {
|
||||
if (core->num.value & UT64_LT0)
|
||||
r_core_cmd(core, input+1, 0);
|
||||
} else r_cons_printf("0x%llx\n", core->num.value);
|
||||
r_core_cmd (core, input+1, 0);
|
||||
} else r_cons_printf ("0x%llx\n", core->num.value);
|
||||
break;
|
||||
case '!': // ??
|
||||
if (input[1]) {
|
||||
if (&core->num.value != UT64_MIN)
|
||||
r_core_cmd(core, input+1, 0);
|
||||
} else r_cons_printf("0x%llx\n", core->num.value);
|
||||
r_core_cmd (core, input+1, 0);
|
||||
} else r_cons_printf ("0x%llx\n", core->num.value);
|
||||
break;
|
||||
case '$':
|
||||
return cmd_help(data, " $?");
|
||||
return cmd_help (data, " $?");
|
||||
case 'z':
|
||||
for(input=input+1;input[0]==' ';input=input+1);
|
||||
for (input=input+1;input[0]==' ';input=input+1);
|
||||
core->num.value = strlen(input);
|
||||
break;
|
||||
case 't': {
|
||||
struct r_prof_t prof;
|
||||
r_prof_start(&prof);
|
||||
r_core_cmd(core, input+1, 0);
|
||||
r_prof_end(&prof);
|
||||
r_prof_start (&prof);
|
||||
r_core_cmd (core, input+1, 0);
|
||||
r_prof_end (&prof);
|
||||
core->num.value = (ut64)prof.result;
|
||||
eprintf("%lf\n", prof.result);
|
||||
eprintf ("%lf\n", prof.result);
|
||||
} break;
|
||||
case '?': // ???
|
||||
if (input[1]=='?') {
|
||||
@ -501,12 +498,12 @@ static int cmd_help(void *data, const char *input)
|
||||
} else
|
||||
if (input[1]) {
|
||||
if (&core->num.value == UT64_MIN)
|
||||
r_core_cmd(core, input+1, 0);
|
||||
} else r_cons_printf("0x%llx\n", core->num.value);
|
||||
r_core_cmd (core, input+1, 0);
|
||||
} else r_cons_printf ("0x%llx\n", core->num.value);
|
||||
break;
|
||||
case '\0':
|
||||
default:
|
||||
r_cons_printf(
|
||||
r_cons_printf (
|
||||
"Usage:\n"
|
||||
" a ; perform analysis of code\n"
|
||||
" b [bsz] ; get or change block size\n"
|
||||
@ -541,13 +538,13 @@ static int cmd_help(void *data, const char *input)
|
||||
static int cmd_bsize(void *data, const char *input)
|
||||
{
|
||||
struct r_core_t *core = (struct r_core_t *)data;
|
||||
switch(input[0]) {
|
||||
switch (input[0]) {
|
||||
case '\0':
|
||||
r_cons_printf("0x%x\n", core->blocksize);
|
||||
r_cons_printf ("0x%x\n", core->blocksize);
|
||||
break;
|
||||
default:
|
||||
//input = r_str_clean(input);
|
||||
r_core_block_size(core, r_num_math(NULL, input));
|
||||
r_core_block_size (core, r_num_math (NULL, input));
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
@ -557,7 +554,7 @@ static int cmd_info(void *data, const char *input)
|
||||
{
|
||||
struct r_core_t *core = (struct r_core_t *)data;
|
||||
char buf[1024];
|
||||
switch(input[0]) {
|
||||
switch (input[0]) {
|
||||
case 's':
|
||||
case 'i':
|
||||
case 'I':
|
||||
@ -567,10 +564,10 @@ 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(
|
||||
r_cons_printf (
|
||||
"Usage: i[eiIsSz]* ; get info from opened file (rabin2)\n"
|
||||
"; Append a '*' to get the output in radare commands\n"
|
||||
" ii ; imports\n"
|
||||
@ -1160,7 +1157,7 @@ static int cmd_search(void *data, const char *input)
|
||||
break;
|
||||
}
|
||||
}
|
||||
r_cons_break_end();
|
||||
r_cons_break_end ();
|
||||
}
|
||||
return R_TRUE;
|
||||
}
|
||||
@ -1178,14 +1175,14 @@ static int cmd_eval(void *data, const char *input)
|
||||
eprintf ("r_config: '%s' is not a boolean variable.\n", input);
|
||||
break;
|
||||
case '-':
|
||||
r_core_config_init(core);
|
||||
eprintf("BUG: 'e-' command locks the eval hashtable. patches are welcome :)\n");
|
||||
r_core_config_init (core);
|
||||
eprintf ("BUG: 'e-' command locks the eval hashtable. patches are welcome :)\n");
|
||||
break;
|
||||
case '*':
|
||||
r_config_list(&core->config, NULL, 1);
|
||||
r_config_list (&core->config, NULL, 1);
|
||||
break;
|
||||
case '?':
|
||||
r_cons_printf(
|
||||
r_cons_printf (
|
||||
"Usage: e[?] [var[=value]]\n"
|
||||
" e ; list config vars\n"
|
||||
" e- ; reset config vars\n"
|
||||
@ -1196,7 +1193,7 @@ static int cmd_eval(void *data, const char *input)
|
||||
//r_cmd_help(&core->cmd, "e");
|
||||
break;
|
||||
default:
|
||||
r_config_eval(&core->config, input);
|
||||
r_config_eval (&core->config, input);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1228,11 +1225,12 @@ static int cmd_hash(void *data, const char *input)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
ptr = strchr(input, ' ');
|
||||
sscanf(input, "%31s", algo);
|
||||
ptr = strchr (input, ' ');
|
||||
sscanf (input, "%31s", algo);
|
||||
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);
|
||||
|
@ -11,11 +11,9 @@ static ut64 num_callback(void *userptr, const char *str, int *ok)
|
||||
|
||||
if (str[0]=='$') {
|
||||
/* analyze opcode */
|
||||
switch(str[1]) {
|
||||
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':
|
||||
@ -26,7 +24,7 @@ static ut64 num_callback(void *userptr, const char *str, int *ok)
|
||||
}
|
||||
|
||||
/* return value */
|
||||
switch(str[1]) {
|
||||
switch (str[1]) {
|
||||
case '{':
|
||||
{
|
||||
char *ptr, *bptr = strdup(str+2);
|
||||
@ -50,13 +48,10 @@ 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;
|
||||
flag = r_flag_get (&(core->flags), str);
|
||||
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;
|
||||
|
@ -483,9 +483,9 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
|
||||
case 'a':
|
||||
r_cons_printf("Enter assembler opcodes separated with ';':\n");
|
||||
r_cons_flush();
|
||||
r_cons_set_raw(0);
|
||||
strcpy(buf, "wa ");
|
||||
if (r_cons_fgets(buf+3, 1000, 0, NULL) <0) buf[0]='\0';
|
||||
r_cons_set_raw (0);
|
||||
strcpy (buf, "wa ");
|
||||
if (r_cons_fgets (buf+3, 1000, 0, NULL) <0) buf[0]='\0';
|
||||
if (buf[0]) {
|
||||
if (curset) r_core_seek(core, core->offset + cursor, 0);
|
||||
r_core_cmd(core, buf, 1);
|
||||
@ -494,11 +494,11 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
|
||||
r_cons_set_raw(1);
|
||||
break;
|
||||
case 'w':
|
||||
r_cons_printf("Enter hexpair string to write:\n");
|
||||
r_cons_flush();
|
||||
r_cons_set_raw(0);
|
||||
strcpy(buf, "wx ");
|
||||
if (r_cons_fgets(buf+3, 1000, 0, NULL) <0) buf[0]='\0';
|
||||
r_cons_printf ("Enter hexpair string to write:\n");
|
||||
r_cons_flush ();
|
||||
r_cons_set_raw (0);
|
||||
strcpy (buf, "wx ");
|
||||
if (r_cons_fgets (buf+3, 1000, 0, NULL) <0) buf[0]='\0';
|
||||
if (buf[0]) {
|
||||
if (curset) r_core_seek(core, core->offset + cursor, 0);
|
||||
r_core_cmd(core, buf, 1);
|
||||
@ -509,10 +509,9 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
|
||||
/* select */
|
||||
case 'H':
|
||||
if (curset) {
|
||||
if (ocursor ==-1) ocursor=cursor;
|
||||
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);
|
||||
@ -522,60 +521,57 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
|
||||
break;
|
||||
case 'J':
|
||||
if (curset) {
|
||||
if (ocursor ==-1) ocursor=cursor;
|
||||
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);
|
||||
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);
|
||||
if (ocursor==-1) ocursor=cursor;
|
||||
cursor -= 16;
|
||||
} else r_core_cmd (core, "s--", 0);
|
||||
break;
|
||||
case 'L':
|
||||
if (curset) {
|
||||
if (ocursor ==-1) ocursor=cursor;
|
||||
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':
|
||||
if (curset) {
|
||||
cursor--;
|
||||
ocursor=-1;
|
||||
} else r_core_cmd(core, "s-1", 0);
|
||||
} else r_core_cmd (core, "s-1", 0);
|
||||
break;
|
||||
case 'l':
|
||||
if (curset) {
|
||||
cursor++;
|
||||
ocursor=-1;
|
||||
} else r_core_cmd(core, "s+1", 0);
|
||||
} else r_core_cmd (core, "s+1", 0);
|
||||
break;
|
||||
case 'j':
|
||||
if (curset) {
|
||||
cursor+=16;
|
||||
ocursor=-1;
|
||||
} else r_core_cmd(core, "s+16", 0);
|
||||
} else r_core_cmd (core, "s+16", 0);
|
||||
break;
|
||||
case 'k':
|
||||
if (curset) {
|
||||
cursor-=16;
|
||||
ocursor=-1;
|
||||
} else r_core_cmd(core, "s- 16", 0);
|
||||
} else r_core_cmd (core, "s- 16", 0);
|
||||
break;
|
||||
case 's':
|
||||
r_core_cmd(core, "ds", 0);
|
||||
r_core_cmd(core, ".dr", 0);
|
||||
r_core_cmd (core, "ds", 0);
|
||||
r_core_cmd (core, ".dr", 0);
|
||||
//r_core_cmd(core, "s eip", 0);
|
||||
break;
|
||||
case 'p':
|
||||
@ -585,64 +581,65 @@ R_API int r_core_visual_cmd(struct r_core_t *core, int ch)
|
||||
printidx--;
|
||||
break;
|
||||
case '-':
|
||||
r_core_block_size( core, core->blocksize-1);
|
||||
r_core_block_size (core, core->blocksize-1);
|
||||
break;
|
||||
case 'm':
|
||||
r_core_visual_mark(core, r_cons_readchar());
|
||||
r_core_visual_mark (core, r_cons_readchar());
|
||||
break;
|
||||
case '\'':
|
||||
r_core_visual_mark_seek(core, r_cons_readchar());
|
||||
r_core_visual_mark_seek (core, r_cons_readchar());
|
||||
break;
|
||||
case '+':
|
||||
r_core_block_size(core, core->blocksize+1);
|
||||
r_core_block_size (core, core->blocksize+1);
|
||||
break;
|
||||
case '/':
|
||||
r_core_block_size(core, core->blocksize-=16);
|
||||
r_core_block_size (core, core->blocksize-=16);
|
||||
break;
|
||||
case '*':
|
||||
r_core_block_size(core, core->blocksize+=16);
|
||||
r_core_block_size (core, core->blocksize+=16);
|
||||
break;
|
||||
case '>':
|
||||
r_core_seek_align(core, core->blocksize, 1);
|
||||
r_core_seek_align (core, core->blocksize, 1);
|
||||
break;
|
||||
case '<':
|
||||
r_core_seek_align(core, core->blocksize, -1);
|
||||
r_core_seek_align (core, core->blocksize, -1);
|
||||
break;
|
||||
case '.':
|
||||
r_core_cmd(core, ".dr* && s eip", 0); // XXX
|
||||
r_core_cmd (core, ".dr* && s eip", 0); // XXX
|
||||
break;
|
||||
case ':':
|
||||
r_cons_fgets(buf, 1023, 0, NULL);
|
||||
r_core_cmd(core, buf, 0);
|
||||
r_cons_fgets (buf, 1023, 0, NULL);
|
||||
r_core_cmd (core, buf, 0);
|
||||
break;
|
||||
case ';':
|
||||
r_cons_printf("Enter a comment: (prefix it with '-' to remove)\n");
|
||||
r_cons_flush();
|
||||
r_cons_set_raw(0);
|
||||
strcpy(buf, "CC ");
|
||||
if (r_cons_fgets(buf+3, 1000, 0, NULL) <0)
|
||||
r_cons_printf ("Enter a comment: (prefix it with '-' to remove)\n");
|
||||
r_cons_flush ();
|
||||
r_cons_set_raw (0);
|
||||
strcpy (buf, "CC ");
|
||||
if (r_cons_fgets (buf+3, 1000, 0, NULL) <0)
|
||||
buf[0]='\0';
|
||||
if (buf[0]) {
|
||||
if (curset) r_core_seek(core, core->offset + cursor, 0);
|
||||
r_core_cmd(core, buf, 1);
|
||||
if (curset) r_core_seek(core, core->offset - cursor, 1);
|
||||
if (curset) r_core_seek (core, core->offset + cursor, 0);
|
||||
r_core_cmd (core, buf, 1);
|
||||
if (curset) r_core_seek (core, core->offset - cursor, 1);
|
||||
}
|
||||
r_cons_set_raw(1);
|
||||
r_cons_set_raw (1);
|
||||
break;
|
||||
case '?':
|
||||
r_cons_clear00();
|
||||
r_cons_printf(
|
||||
r_cons_clear00 ();
|
||||
r_cons_printf (
|
||||
"\nVisual mode help:\n\n"
|
||||
" >||< - seek aligned to block size\n"
|
||||
" hjkl - move around\n"
|
||||
" 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");
|
||||
r_cons_flush();
|
||||
r_cons_any_key();
|
||||
r_cons_flush ();
|
||||
r_cons_any_key ();
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
@ -666,22 +663,22 @@ R_API int r_core_visual(struct r_core_t *core, const char *input)
|
||||
vi = r_config_get(&core->config, "cmd.visual");
|
||||
if (vi) r_core_cmd(core, vi, 0);
|
||||
|
||||
while(input[0]) {
|
||||
if (!r_core_visual_cmd(core, input[0])) {
|
||||
r_cons_clear00();
|
||||
r_core_cmd(core, printfmt[printidx%NPF], 0);
|
||||
r_cons_flush();
|
||||
r_cons_any_key();
|
||||
while (input[0]) {
|
||||
if (!r_core_visual_cmd (core, input[0])) {
|
||||
r_cons_clear00 ();
|
||||
r_core_cmd (core, printfmt[printidx%NPF], 0);
|
||||
r_cons_flush ();
|
||||
r_cons_any_key ();
|
||||
return 0;
|
||||
}
|
||||
input = input + 1;
|
||||
}
|
||||
|
||||
color = r_config_get_i(&core->config, "scr.color");
|
||||
debug = r_config_get_i(&core->config, "cfg.debug");
|
||||
color = r_config_get_i (&core->config, "scr.color");
|
||||
debug = r_config_get_i (&core->config, "cfg.debug");
|
||||
do {
|
||||
scrseek = r_num_math(&core->num,
|
||||
r_config_get(&core->config, "scr.seek"));
|
||||
scrseek = r_num_math (&core->num,
|
||||
r_config_get (&core->config, "scr.seek"));
|
||||
if (scrseek != 0LL) {
|
||||
r_core_seek (core, scrseek, 1);
|
||||
// TODO: read?
|
||||
|
@ -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]
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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(®s, 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, ®s, size);
|
||||
return sizeof(regs);
|
||||
}
|
||||
break;
|
||||
//r_reg_set_bytes(reg, ®s, sizeof(struct user_regs));
|
||||
}
|
||||
#else
|
||||
#warning dbg-ptrace not supported for this platform
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009 */
|
||||
/* radare - LGPL - Copyright 2009-2010 */
|
||||
/* nibble<.ds@gmail.com> */
|
||||
/* pancake<nopcode.org> */
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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..
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
11
libr/io/io.c
11
libr/io/io.c
@ -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 :) */
|
||||
r_io_cache_write(io, io->seek, buf, len);
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 ();
|
||||
}
|
||||
|
@ -7,13 +7,12 @@
|
||||
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
|
||||
ut8 * buf = malloc(1);
|
||||
for(i=0;i<R_REG_TYPE_LAST;i++) {
|
||||
for (i=0;i<R_REG_TYPE_LAST;i++) {
|
||||
arena = reg->regset[type].arena;
|
||||
sz += arena->size;
|
||||
buf = realloc(buf, sz);
|
||||
@ -25,7 +24,7 @@ R_API ut8* r_reg_get_bytes(struct r_reg_t *reg, int type, int *size)
|
||||
return buf;
|
||||
}
|
||||
|
||||
if (type < 0 || type > R_REG_TYPE_LAST)
|
||||
if (type<0 || type>R_REG_TYPE_LAST)
|
||||
return NULL;
|
||||
if (size)
|
||||
*size = reg->regset[type].arena->size;
|
||||
@ -58,9 +57,9 @@ R_API int r_reg_set_bytes(struct r_reg_t *reg, int type, const ut8* buf, int len
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (type >= 0 && type <= R_REG_TYPE_LAST) {
|
||||
if (type>=0 && type<=R_REG_TYPE_LAST) {
|
||||
regset = ®->regset[type];
|
||||
if (len <= regset->arena->size) {
|
||||
if (len<=regset->arena->size) {
|
||||
memcpy (regset->arena->bytes, buf, len);
|
||||
ret = R_TRUE;
|
||||
}
|
||||
|
@ -102,6 +102,9 @@ myclean:
|
||||
clean: myclean
|
||||
-rm -f ${OBJ} ${BIN}
|
||||
|
||||
install:
|
||||
cd ../.. && ${MAKE} install
|
||||
|
||||
.PHONY: all clean myclean
|
||||
|
||||
endif
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
11
libr/vapi/r_anal.vapi
Normal file
@ -0,0 +1,11 @@
|
||||
class Radare.RAnalysis {
|
||||
struct Refline {
|
||||
uint64 from;
|
||||
uint64 to;
|
||||
int index;
|
||||
}
|
||||
/* XXX dupped in r_asm ?? */
|
||||
struct Aop {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user