* Fix return value of bin_meta_elf

* Added 'dsl' command to step until next meta information
  line is reached.
* Display file:line with context 5 with 'CL' command
  - Fix r_file_slurp_line
* Added 'dcu' command to continue until an address
  - bp,dc,bp-
* Added dbg.swstep to configure stepping debugger algorithm
* Add file.type. fixes warning. Defined by rabin2
* Load rabin2 in va format when debug or va modes are enabled
* Ask to kill the child before quitting
* cmd_quit is no longer calling 'exit'.
  - Returns R_CORE_CMD_EXIT (-2)
  - Return value can be captured at core->num.value
* Implement native kill as a debugger callback
* cmd.visual is now cmd.vprompt
* Add r_debug_reg_{get|set}
  - Handle register name aliases
  - Works only with ut64 type
* 'dr:eax' is now 'dr?eax'
* Lot of random syntax cleanups
This commit is contained in:
pancake 2010-02-28 22:58:21 +01:00
parent cbb5fe143b
commit 9c0636e5ca
18 changed files with 419 additions and 383 deletions

2
TODO
View File

@ -21,8 +21,6 @@
- commands can be listed like in a tree
* 'Vc' cursor mode makes color toggle
* Add maxrows option for r_print (fix visual problem)
* Add test for config.c with _set_cb
* Strip non input symbols in plugins (speed up loading)
* Specify binmask in hexpairs

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
#include <r_types.h>
#include <r_util.h>
@ -9,4 +9,3 @@ R_API int r_bin_meta_get_line(RBin *bin, ut64 addr, char *file, int len, int *li
return bin->cur->meta->get_line (bin, addr, file, len, line);
return R_FALSE;
}

View File

@ -23,17 +23,19 @@ static int cmd_to_str(const char *cmd, char *out, int len)
static int get_line(RBin *bin, ut64 addr, char *file, int len, int *line) {
char *p, buf[1024];
snprintf(buf, 1023, "addr2line -e '%s' 0x%08llx", bin->file, addr);
snprintf (buf, 1023, "addr2line -e '%s' 0x%08llx", bin->file, addr);
memset(file,'\0', len);
if (!cmd_to_str(buf, file, len))
memset (file,'\0', len);
if (!cmd_to_str (buf, file, len))
return R_FALSE;
p = strchr(file, ':');
p = strchr (file, ':');
if (p) {
*p='\0';
*line = atoi(p+1);
}
} else return R_FALSE;
if (*file=='?')
return R_FALSE;
return R_TRUE;
}

View File

@ -35,12 +35,20 @@ static int cmd_iopipe(void *data, const char *input) {
static void cmd_reg (struct r_core_t *core, const char *str) {
struct r_reg_item_t *r;
const char *name;
char *arg;
int size, i, type = R_REG_TYPE_GPR;
switch (str[0]) {
case '?':
if (str[1]) {
r_debug_reg_sync (&core->dbg, R_REG_TYPE_GPR, R_FALSE);
r = r_reg_get (core->dbg.reg, str+1, R_REG_TYPE_GPR);
if (r == NULL) eprintf ("Unknown register (%s)\n", str+1);
else r_cons_printf ("0x%08llx\n", r_reg_get_value (core->dbg.reg, r));
} else
eprintf ("Usage: dr[*] [type] [size] - get/set registers\n"
" dr? display this help message\n"
" dr?eax show value of eax register\n"
" .dr* include common register values in flags\n"
" .dr- unflag all registers\n"
" drp [file] load register metadata file\n"
@ -52,7 +60,6 @@ static void cmd_reg (struct r_core_t *core, const char *str) {
" dr flg 1 show flag registers ('flg' is type, see drt)\n"
" dr 16 show 16 bit registers\n"
" dr 32 show 32 bit registers\n"
" dr:eax show value of eax register\n"
" dr eax=33 set register value. eax = 33\n");
break;
case 'p':
@ -64,26 +71,14 @@ static void cmd_reg (struct r_core_t *core, const char *str) {
} else r_reg_set_profile (core->dbg.reg, str+2);
break;
case 't':
{
const char *type;
for (i=0;(type=r_reg_get_type(i));i++)
r_cons_printf ("%s\n", type);
}
break;
case ':':
r_debug_reg_sync (&core->dbg, R_REG_TYPE_GPR, R_FALSE);
r = r_reg_get (core->dbg.reg, str+1, R_REG_TYPE_GPR);
if (r == NULL) eprintf ("Unknown register (%s)\n", str+1);
else r_cons_printf ("0x%08llx\n", r_reg_get_value (core->dbg.reg, r));
for (i=0; (name=r_reg_get_type (i));i++)
r_cons_printf ("%s\n", name);
break;
case 'n':
{
const char *reg = r_reg_get_name (
core->dbg.reg, r_reg_get_name_idx (str+2));
if (reg && *reg)
r_cons_printf ("%s\n", reg);
else eprintf ("Oops. try dn [pc|sp|bp|a0|a1|a2|a3]\n");
}
name = r_reg_get_name (core->dbg.reg, r_reg_get_name_idx (str+2));
if (name && *name)
r_cons_printf ("%s\n", name);
else eprintf ("Oops. try dn [pc|sp|bp|a0|a1|a2|a3]\n");
break;
case '*':
r_debug_reg_sync (&core->dbg, R_REG_TYPE_GPR, R_FALSE);
@ -171,20 +166,21 @@ static void r_core_cmd_bp (struct r_core_t *core, const char *input) {
/* TODO: this should be moved to the core->yank api */
static int cmd_yank_to(struct r_core_t *core, char *arg) {
ut64 src = core->offset;
ut64 len = 0;
ut64 len = 0;
ut64 pos = -1;
char *str;
ut8 *buf;
while (*arg==' ')arg=arg+1;
str = strchr(arg, ' ');
while (*arg==' ')
arg = arg+1;
str = strchr (arg, ' ');
if (str) {
str[0]='\0';
len = r_num_math (&core->num, arg);
pos = r_num_math (&core->num, str+1);
str[0]=' ';
}
if ( (str == NULL) || (pos == -1) || (len == 0) ) {
if ((str == NULL) || (pos == -1) || (len == 0)) {
eprintf("Usage: yt [len] [dst-addr]\n");
return 1;
}
@ -206,7 +202,7 @@ static int cmd_yank_to(struct r_core_t *core, char *arg) {
static int cmd_yank(void *data, const char *input) {
struct r_core_t *core = (struct r_core_t *)data;
switch(input[0]) {
switch (input[0]) {
case ' ':
r_core_yank(core, core->offset, atoi(input+1));
break;
@ -231,7 +227,7 @@ static int cmd_yank(void *data, const char *input) {
} else eprintf ("No buffer yanked already\n");
break;
default:
r_cons_printf(
r_cons_printf (
"Usage: y[y] [len] [[@]addr]\n"
" y ; show yank buffer information (srcoff len bytes)\n"
" y 16 ; copy 16 bytes into clipboard\n"
@ -260,10 +256,13 @@ static int cmd_quit(void *data, const char *input) {
// TODO
default:
r_line_hist_save (".radare2_history");
exit (*input?r_num_math (&core->num, input+1):0);
break;
if (input[1])
r_num_math (&core->num, input+1);
else core->num.value = 0LL;
//exit (*input?r_num_math (&core->num, input+1):0);
return -2;
}
return 0;
return R_FALSE;
}
static int cmd_interpret(void *data, const char *input) {
@ -279,7 +278,7 @@ static int cmd_interpret(void *data, const char *input) {
r_core_cmd_command (core, input+1);
break;
case '(':
//fprintf(stderr, "macro call (%s)\n", input+1);
//eprintf ("macro call (%s)\n", input+1);
r_macro_call (&core->macro, input+1);
break;
case '?':
@ -334,10 +333,10 @@ static int cmd_section(void *data, const char *input) {
ut64 size = 0LL;
ut64 vsize = 0LL;
i = r_str_word_set0(ptr);
i = r_str_word_set0 (ptr);
switch(i) {
case 5: // get name
name = r_str_word_get0(ptr, 4);
name = r_str_word_get0 (ptr, 4);
case 4: // get vsize
vsize = r_num_math (&core->num, r_str_word_get0 (ptr, 3));
case 3: // get size
@ -394,14 +393,14 @@ static int cmd_seek(void *data, const char *input) {
p = strchr (cmd+2, ' ');
if (p) {
off = r_num_math (&core->num, p+1);;
*p='\0';
*p = '\0';
}
cmd[0]='s';
cmd[0] = 's';
// perform real seek if provided
r_cmd_call (&core->cmd, cmd);
free(cmd);
free (cmd);
}
r_core_seek_align(core, off, 0);
r_core_seek_align (core, off, 0);
break;
case '?':
r_cons_printf (
@ -625,7 +624,7 @@ static int cmd_cmp(void *data, const char *input) {
}
static int cmd_info(void *data, const char *input) {
struct r_core_t *core = (struct r_core_t *)data;
RCore *core = (RCore *)data;
char buf[1024];
switch (*input) {
case 's':
@ -664,7 +663,7 @@ static int cmd_print(void *data, const char *input) {
RCore *core = (RCore *)data;
int l, len = core->blocksize;
ut32 tbs = core->blocksize;
int show_offset = r_config_get_i (&core->config, "asm.offset");
int show_offset = r_config_get_i (&core->config, "asm.offset");
int show_bytes = r_config_get_i (&core->config, "asm.bytes");
int show_lines = r_config_get_i (&core->config, "asm.reflines");
int linesout = r_config_get_i (&core->config, "asm.reflinesout");
@ -728,7 +727,7 @@ static int cmd_print(void *data, const char *input) {
r_anal_aop (&core->anal, &analop, addr, buf+idx, (int)(len-idx));
if (show_lines) r_cons_strcat(line);
if (show_offset) r_cons_printf("0x%08llx ", core->offset + idx);
if (show_offset) r_cons_printf("0x%08llx ", core->offset + idx);
if (show_bytes) {
struct r_flag_item_t *flag = r_flag_get_i(&core->flags, core->offset+idx);
if (flag) r_cons_printf("*[ %10s] ", flag->name);
@ -749,36 +748,35 @@ static int cmd_print(void *data, const char *input) {
}
break;
case 's':
r_print_string(&core->print, core->offset, core->block, len, 0, 1, 0); //, 78, 1);
r_print_string (&core->print, core->offset, core->block, len, 0, 1, 0); //, 78, 1);
break;
case 'S':
r_print_string(&core->print, core->offset, core->block, len, 1, 1, 0); //, 78, 1);
r_print_string (&core->print, core->offset, core->block, len, 1, 1, 0); //, 78, 1);
break;
case 'u':
r_print_string(&core->print, core->offset, core->block, len, 0, 1, 1); //, 78, 1);
r_print_string (&core->print, core->offset, core->block, len, 0, 1, 1); //, 78, 1);
break;
case 'U':
r_print_string(&core->print, core->offset, core->block, len, 1, 1, 1); //, 78, 1);
r_print_string (&core->print, core->offset, core->block, len, 1, 1, 1); //, 78, 1);
break;
case 'c':
r_print_code(&core->print, core->offset, core->block, len); //, 78, 1);
r_print_code (&core->print, core->offset, core->block, len); //, 78, 1);
break;
case 'r':
r_print_raw(&core->print, core->block, len);
r_print_raw (&core->print, core->block, len);
break;
case 'o':
r_print_hexdump(&core->print, core->offset, core->block, len, 8, 1); //, 78, !(input[1]=='-'));
r_print_hexdump (&core->print, core->offset, core->block, len, 8, 1); //, 78, !(input[1]=='-'));
break;
case 'x':
r_print_hexdump(&core->print, core->offset, core->block, len, 16, 1); //, 78, !(input[1]=='-'));
r_print_hexdump (&core->print, core->offset, core->block, len, 16, 1); //, 78, !(input[1]=='-'));
break;
case '8':
r_print_bytes(&core->print, core->block, len, "%02x");
r_print_bytes (&core->print, core->block, len, "%02x");
break;
default:
//r_cons_printf("Unknown subcommand '%c'\n", input[0]);
r_cons_printf(
"Usage: p[8] [len] ; '%c' is unknown\n"
r_cons_printf (
"Usage: p[fmt] [len]\n"
" p8 [len] 8bit hexpair list of bytes\n"
" px [len] hexdump of N bytes\n"
" po [len] octal dump of N bytes\n"
@ -789,8 +787,7 @@ static int cmd_print(void *data, const char *input) {
" pD [len] disassemble N bytes\n"
" pr [len] print N raw bytes\n"
" pu [len] print N url encoded bytes\n"
" pU [len] print N wide url encoded bytes\n",
input[0]);
" pU [len] print N wide url encoded bytes\n");
break;
}
if (tbs != core->blocksize)
@ -799,24 +796,24 @@ static int cmd_print(void *data, const char *input) {
}
static int cmd_hexdump(void *data, const char *input) {
return cmd_print(data, input-1);
return cmd_print (data, input-1);
}
static int cmd_flag(void *data, const char *input) {
struct r_core_t *core = (struct r_core_t *)data;
int len = strlen(input)+1;
char *str = alloca(len);
memcpy(str, input+1, len);
RCore *core = (RCore *)data;
int len = strlen (input)+1;
char *str = alloca (len);
memcpy (str, input+1, len);
switch(input[0]) {
switch (input[0]) {
case '+':
r_flag_set(&core->flags, str, core->offset, core->blocksize, 1);
r_flag_set (&core->flags, str, core->offset, core->blocksize, 1);
break;
case ' ': {
char *s = NULL, *s2 = NULL;
ut64 seek = core->offset;
ut32 bsze = core->blocksize;
s = strchr(str, ' ');
s = strchr (str, ' ');
if (s) {
*s = '\0';
s2 = strchr(s+1, ' ');
@ -835,27 +832,26 @@ static int cmd_flag(void *data, const char *input) {
r_flag_unset (&core->flags, input+1);
break;
case 's':
if (input[1]==' ')
r_flag_space_set(&core->flags, input+2);
else r_flag_space_list(&core->flags);
if (input[1]==' ') r_flag_space_set (&core->flags, input+2);
else r_flag_space_list (&core->flags);
break;
case 'o':
{
char *file = PREFIX"/share/doc/radare2/fortunes";
char *line = r_file_slurp_random_line (file);
r_cons_printf(" -- %s\n", line);
free(line);
r_cons_printf (" -- %s\n", line);
free (line);
}
break;
case '*':
r_flag_list(&core->flags, 1);
r_flag_list (&core->flags, 1);
break;
case '\0':
r_flag_list(&core->flags, 0);
r_flag_list (&core->flags, 0);
break;
case '?':
r_cons_printf (
"Usage: f[ ] [flagname]\n"
"Usage: f[?] [flagname]\n"
" f name 12 @ 33 ; set flag 'name' with size 12 at 33\n"
" f name 12 33 ; same as above\n"
" f+name 12 @ 33 ; like above but creates new one if doesnt exist\n"
@ -885,7 +881,7 @@ static int cmd_anal(void *data, const char *input) {
case 'h':
if (input[1]) {
if (!r_anal_use (&core->anal, input+2))
eprintf("Cannot use '%s' anal plugin.\n", input+2);
eprintf ("Cannot use '%s' anal plugin.\n", input+2);
} else r_anal_list (&core->anal);
break;
case 'o':
@ -906,7 +902,7 @@ static int cmd_anal(void *data, const char *input) {
break;
case 'c':
r_core_anal_bb (core, core->offset,
r_config_get_i(&core->config, "anal.depth"));
r_config_get_i (&core->config, "anal.depth"));
break;
case 'g':
r_core_anal_graph (core);
@ -921,7 +917,7 @@ static int cmd_anal(void *data, const char *input) {
break;
}
if (tbs != core->blocksize)
r_core_block_size(core, tbs);
r_core_block_size (core, tbs);
return 0;
}
@ -934,40 +930,40 @@ static int cmd_write(void *data, const char *input) {
switch(input[0]) {
case ' ':
/* write string */
len = r_str_escape(str);
r_io_set_fd(&core->io, core->file->fd);
r_io_write_at(&core->io, core->offset, (const ut8*)str, len);
r_core_block_read(core, 0);
len = r_str_escape (str);
r_io_set_fd (&core->io, core->file->fd);
r_io_write_at (&core->io, core->offset, (const ut8*)str, len);
r_core_block_read (core, 0);
break;
case 't': {
/* TODO: Support user defined size? */
int len = core->blocksize;
const char *arg = (const char *)(input+(input[1]==' ')?2:1);
const ut8 *buf = core->block;
r_file_dump(arg, buf, len);
r_file_dump (arg, buf, len);
} break;
case 'T':
fprintf(stderr, "TODO\n");
eprintf ("TODO\n");
break;
case 'f': {
int size;
const char *arg = (const char *)(input+(input[1]==' ')?2:1);
ut8 *buf = (ut8*) r_file_slurp(arg, &size);
ut8 *buf = (ut8*) r_file_slurp (arg, &size);
if (buf) {
r_io_set_fd(&core->io, core->file->fd);
r_io_write_at(&core->io, core->offset, buf, size);
r_io_set_fd (&core->io, core->file->fd);
r_io_write_at (&core->io, core->offset, buf, size);
free(buf);
} else eprintf("Cannot open file '%s'\n", arg);
} else eprintf ("Cannot open file '%s'\n", arg);
} break;
case 'F': {
int size;
const char *arg = (const char *)(input+(input[1]==' ')?2:1);
ut8 *buf = r_file_slurp_hexpairs(arg, &size);
ut8 *buf = r_file_slurp_hexpairs (arg, &size);
if (buf == NULL) {
r_io_set_fd(&core->io, core->file->fd);
r_io_write_at(&core->io, core->offset, buf, size);
free(buf);
} else eprintf("Cannot open file '%s'\n", arg);
r_io_set_fd (&core->io, core->file->fd);
r_io_write_at (&core->io, core->offset, buf, size);
free (buf);
} else eprintf ("Cannot open file '%s'\n", arg);
} break;
case 'w':
str = str+1;
@ -981,17 +977,17 @@ static int cmd_write(void *data, const char *input) {
str = tmp;
// write strifng
r_io_set_fd(&core->io, core->file->fd);
r_io_write_at(&core->io, core->offset, (const ut8*)str, len);
r_core_block_read(core, 0);
r_io_set_fd (&core->io, core->file->fd);
r_io_write_at (&core->io, core->offset, (const ut8*)str, len);
r_core_block_read (core, 0);
break;
case 'x':
{
int len = strlen(input);
ut8 *buf = alloca(len);
len = r_hex_str2bin(input+1, buf);
r_core_write_at(core, core->offset, buf, len);
r_core_block_read(core, 0);
int len = strlen (input);
ut8 *buf = alloca (len);
len = r_hex_str2bin (input+1, buf);
r_core_write_at (core, core->offset, buf, len);
r_core_block_read (core, 0);
}
// write hexpairs
break;
@ -999,33 +995,33 @@ static int cmd_write(void *data, const char *input) {
{
struct r_asm_code_t *acode;
/* XXX ULTRAUGLY , needs fallback support in rasm */
r_asm_use(&core->assembler, "x86.olly");
r_asm_set_pc(&core->assembler, core->offset);
if (input[1]==' ')input=input+1;
acode = r_asm_massemble(&core->assembler, input+1);
eprintf("Written %d bytes (%s)=wx %s\n", acode->len, input+1, acode->buf_hex);
r_core_write_at(core, core->offset, acode->buf, acode->len);
r_asm_code_free(acode);
r_core_block_read(core, 0);
r_asm_use(&core->assembler, "x86"); /* XXX */
r_asm_use (&core->assembler, "x86.olly");
r_asm_set_pc (&core->assembler, core->offset);
if (input[1]==' ') input=input+1;
acode = r_asm_massemble (&core->assembler, input+1);
eprintf ("Written %d bytes (%s)=wx %s\n", acode->len, input+1, acode->buf_hex);
r_core_write_at (core, core->offset, acode->buf, acode->len);
r_asm_code_free (acode);
r_core_block_read (core, 0);
r_asm_use (&core->assembler, "x86"); /* XXX */
}
break;
case 'b':
{
int len = strlen(input);
ut8 *buf = alloca(len);
len = r_hex_str2bin(input+1, buf);
r_mem_copyloop(core->block, buf, core->blocksize, len);
r_core_write_at(core, core->offset, core->block, core->blocksize);
r_core_block_read(core, 0);
int len = strlen (input);
ut8 *buf = alloca (len);
len = r_hex_str2bin (input+1, buf);
r_mem_copyloop (core->block, buf, core->blocksize, len);
r_core_write_at (core, core->offset, core->block, core->blocksize);
r_core_block_read (core, 0);
}
break;
case 'm':
{
int len = r_hex_str2bin(input+1, (ut8*)str);
switch(input[1]) {
int len = r_hex_str2bin (input+1, (ut8*)str);
switch (input[1]) {
case '\0':
fprintf(stderr, "Current write mask: TODO\n");
eprintf ("Current write mask: TODO\n");
// TODO
break;
case '?':
@ -1052,8 +1048,8 @@ static int cmd_write(void *data, const char *input) {
case 'v':
{
ut64 off = r_num_math(&core->num, input+1);
r_io_set_fd(&core->io, core->file->fd);
r_io_seek(&core->io, core->offset, R_IO_SEEK_SET);
r_io_set_fd (&core->io, core->file->fd);
r_io_seek (&core->io, core->offset, R_IO_SEEK_SET);
if (off&UT64_32U) {
/* 8 byte addr */
ut64 addr8;
@ -1065,14 +1061,14 @@ static int cmd_write(void *data, const char *input) {
ut32 addr4, addr4_ = (ut32)off;
//drop_endian((ut8*)&addr4_, (ut8*)&addr4, 4); /* addr4_ = addr4 */
//endian_memcpy((ut8*)&addr4, (ut8*)&addr4_, 4); /* addr4 = addr4_ */
memcpy((ut8*)&addr4, (ut8*)&addr4_, 4); // XXX needs endian here too
r_io_write(&core->io, (const ut8 *)&addr4, 4);
memcpy ((ut8*)&addr4, (ut8*)&addr4_, 4); // XXX needs endian here too
r_io_write (&core->io, (const ut8 *)&addr4, 4);
}
r_core_block_read(core, 0);
r_core_block_read (core, 0);
}
break;
case 'o':
switch(input[1]) {
switch (input[1]) {
case 'a':
case 's':
case 'A':
@ -1083,7 +1079,7 @@ static int cmd_write(void *data, const char *input) {
case 'd':
case 'o':
if (input[2]!=' ') {
fprintf(stderr, "Usage: 'wo%c 00 11 22'\n", input[1]);
eprintf ("Usage: 'wo%c 00 11 22'\n", input[1]);
return 0;
}
case '2':
@ -1116,9 +1112,9 @@ static int cmd_write(void *data, const char *input) {
default:
case '?':
if (core->oobi) {
fprintf(stderr, "Writing oobi buffer!\n");
r_io_set_fd(&core->io, core->file->fd);
r_io_write(&core->io, core->oobi, core->oobi_len);
eprintf ("Writing oobi buffer!\n");
r_io_set_fd (&core->io, core->file->fd);
r_io_write (&core->io, core->oobi, core->oobi_len);
} else
r_cons_printf(
"Usage: w[x] [str] [<file] [<<EOF] [@addr]\n"
@ -1141,8 +1137,7 @@ static int cmd_write(void *data, const char *input) {
}
static const char *cmdhit = NULL;
static int __cb_hit(struct r_search_kw_t *kw, void *user, ut64 addr)
{
static int __cb_hit(struct r_search_kw_t *kw, void *user, ut64 addr) {
struct r_core_t *core = (struct r_core_t *)user;
r_cons_printf ("f hit%d_%d %d 0x%08llx\n",
@ -1413,17 +1408,23 @@ static int cmd_open(void *data, const char *input) {
static int cmd_meta(void *data, const char *input) {
RCore *core = (RCore*)data;
int ret, line = 0;
int i, ret, line = 0;
char file[1024];
switch(input[0]) {
switch (input[0]) {
case '*':
r_meta_list(&core->meta, R_META_ANY);
r_meta_list (&core->meta, R_META_ANY);
break;
case 'L': // debug information of current offset
ret = r_bin_meta_get_line(
&core->bin, core->offset, file, 1023, &line);
if (ret)
r_cons_printf("file %s\nline %d\n", file, line);
ret = r_bin_meta_get_line (&core->bin, core->offset, file, 1023, &line);
if (ret) {
r_cons_printf ("file %s\nline %d\n", file, line);
ret = (line<5)? 5-line: 5;
line -= 2;
for (i = 0; i<ret; i++) {
char *row = r_file_slurp_line (file, line+i, 0);
r_cons_printf ("%c %.3x %s\n", (i==2)?'>':' ', line+i, row);
}
} else eprintf ("Cannot find meta information at 0x%08llx\n", core->offset);
break;
case 'C': /* add comment */
// TODO: do we need to get the size? or the offset?
@ -1447,7 +1448,7 @@ static int cmd_meta(void *data, const char *input) {
char *t, *p = strchr (input+1, ' ');
if (p) {
t = strdup (p+1);
eprintf ("T=(%s)\n", t);
//eprintf ("T=(%s)\n", t);
p = strchr(t, ' ');
if (p) {
*p='\0';
@ -1549,8 +1550,7 @@ static int r_core_cmd_pipe(struct r_core_t *core, char *radare_cmd, char *shell_
#endif
}
static int r_core_cmd_subst(struct r_core_t *core, char *cmd)
{
static int r_core_cmd_subst(struct r_core_t *core, char *cmd) {
char *ptr, *ptr2, *str;
int i, len = strlen(cmd), pipefd, ret;
@ -1609,12 +1609,12 @@ static int r_core_cmd_subst(struct r_core_t *core, char *cmd)
ptr[0] = '\0';
if (ptr[1]=='<') {
/* this is a bit mess */
const char *oprompt = r_line_singleton()->prompt;
const char *oprompt = r_line_singleton ()->prompt;
oprompt = ">";
for(str=ptr+2;str[0]== ' ';str=str+1);
eprintf("==> Reading from stdin until '%s'\n", str);
free(core->oobi);
core->oobi = malloc(1);
for (str=ptr+2; str[0]==' '; str=str+1);
eprintf ("==> Reading from stdin until '%s'\n", str);
free (core->oobi);
core->oobi = malloc (1);
core->oobi[0] = '\0';
core->oobi_len = 0;
for (;;) {
@ -1645,14 +1645,14 @@ static int r_core_cmd_subst(struct r_core_t *core, char *cmd)
}
/* pipe console to file */
ptr = strchr(cmd, '>');
ptr = strchr (cmd, '>');
if (ptr) {
ptr[0] = '\0';
str = r_str_trim_head_tail(ptr+1+(ptr[1]=='>'));
pipefd = r_cons_pipe_open(str, ptr[1]=='>');
ret = r_core_cmd_subst(core, cmd);
r_cons_flush();
r_cons_pipe_close(pipefd);
str = r_str_trim_head_tail (ptr+1+(ptr[1]=='>'));
pipefd = r_cons_pipe_open (str, ptr[1]=='>');
ret = r_core_cmd_subst (core, cmd);
r_cons_flush ();
r_cons_pipe_close (pipefd);
return ret;
}
@ -1701,9 +1701,7 @@ static int r_core_cmd_subst(struct r_core_t *core, char *cmd)
return ret;
}
r_cmd_call (&core->cmd, r_str_trim_head(cmd));
return 0;
return r_cmd_call (&core->cmd, r_str_trim_head (cmd));
}
R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
@ -1714,14 +1712,14 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
struct list_head *pos;
ut64 oseek, addr;
for(;*each==' ';each=each+1);
for(;*cmd==' ';cmd=cmd+1);
for (; *each==' '; each++);
for (; *cmd==' '; cmd++);
oseek = core->offset;
ostr = str = strdup(each);
//radare_controlc();
switch(each[0]) {
switch (each[0]) {
case '?':
r_cons_printf (
"Foreach '@@' iterator command:\n"
@ -1791,7 +1789,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
break;
default:
core->macro.counter = 0;
//while(str[i]) && !core->interrupted) {
//while(str[i]) && !core->interrupted) {
while (str[i]) {
j = i;
for (;str[j]&&str[j]==' ';j++); // skip spaces
@ -1884,11 +1882,8 @@ R_API int r_core_cmd(struct r_core_t *core, const char *command, int log) {
cmd++;
while (rep--) {
ret = r_core_cmd_subst (core, cmd);
if (ret == -1) {
eprintf ("r_core_cmd: Invalid command\n");
ret = R_FALSE;
if (ret<0)
break;
}
}
}
@ -1904,12 +1899,12 @@ R_API int r_core_cmd(struct r_core_t *core, const char *command, int log) {
R_API int r_core_cmd_file(struct r_core_t *core, const char *file) {
char buf[1024];
FILE *fd = fopen(file, "r");
FILE *fd = fopen (file, "r");
if (fd == NULL) {
eprintf ("r_core_cmd_file: Cannot open '%s'\n", file);
return -1;
}
while (!feof(fd)) {
while (!feof (fd)) {
if (fgets (buf, 1023, fd) != NULL) {
buf[strlen (buf)-1]='\0';
if (r_core_cmd (core, buf, 0) == -1) {
@ -1918,7 +1913,7 @@ R_API int r_core_cmd_file(struct r_core_t *core, const char *file) {
}
}
}
fclose(fd);
fclose (fd);
return 0;
}
@ -1963,10 +1958,45 @@ static void cmd_dm(RCore *core, const char *input) {
}
}
static int step_line(RCore *core, int times) {
char file[512], file2[512];
int find_meta, line, line2;
ut64 off;
off = r_debug_reg_get (&core->dbg, "pc");
if (off == 0LL) {
eprintf ("Cannot 'drn pc'\n");
return R_FALSE;
}
if (r_bin_meta_get_line (&core->bin, off, file, sizeof (file), &line)) {
eprintf ("--> 0x%08llx %s : %d\n", off, file, line);
eprintf ("--> %s\n", r_file_slurp_line (file, line, 0));
find_meta = R_FALSE;
} else {
eprintf ("--> Stepping until dwarf line\n");
find_meta = R_TRUE;
}
do {
r_debug_step (&core->dbg, 1);
off = r_debug_reg_get (&core->dbg, "pc");
if (!r_bin_meta_get_line (&core->bin, off, file2, sizeof (file2), &line2)) {
if (find_meta)
continue;
eprintf ("Cannot retrieve dwarf info at 0x%08llx\n", off);
return R_FALSE;
}
} while (!strcmp (file, file2) && line == line2);
eprintf ("--> 0x%08llx %s : %d\n", off, file2, line2);
eprintf ("--> %s\n", r_file_slurp_line (file2, line2, 0));
return R_TRUE;
}
static int cmd_debug(void *data, const char *input) {
int pid, sig;
struct r_core_t *core = (struct r_core_t *)data;
RCore *core = (RCore *)data;
int times, pid, sig;
ut64 addr;
char *ptr;
switch (input[0]) {
case 'x':
r_debug_execute (&core->dbg, (ut8*)
@ -1976,9 +2006,9 @@ static int cmd_debug(void *data, const char *input) {
case 'k':
/* XXX: not for threads? signal is for a whole process!! */
/* XXX: but we want fine-grained access to process resources */
pid = atoi(input);
ptr = strchr(input, ' ');
if (ptr) sig = atoi(ptr+1);
pid = atoi (input);
ptr = strchr (input, ' ');
if (ptr) sig = atoi (ptr+1);
if (pid > 0) {
eprintf ("Sending signal '%d' to pid '%d'\n",
sig, pid);
@ -1986,17 +2016,19 @@ static int cmd_debug(void *data, const char *input) {
} else eprintf ("Invalid arguments\n");
break;
case 's':
eprintf ("step\n");
r_debug_step (&core->dbg, 1);
times = atoi (input+2);
if (times<1) times = 1;
if (input[1]=='l') step_line (core, times);
else r_debug_step (&core->dbg, times);
break;
case 'b':
r_core_cmd_bp (core, input);
break;
case 't':
fprintf(stderr, "TODO: list/select thread\n");
eprintf ("TODO: list/select thread\n");
break;
case 'H':
fprintf(stderr, "TODO: transplant process\n");
eprintf ("TODO: transplant process\n");
break;
case 'c':
switch (input[1]) {
@ -2004,6 +2036,7 @@ static int cmd_debug(void *data, const char *input) {
eprintf("Usage: dc[?] -- continue execution\n"
" dc? show this help\n"
" dc continue execution of all childs\n"
" dcu [addr] continue until address\n"
" dck [sig] [pid] continue sending kill 9 to process\n"
" dc [pid] continue execution of pid\n"
" dc[-pid] stop execution of pid\n"
@ -2021,6 +2054,13 @@ static int cmd_debug(void *data, const char *input) {
r_debug_select (&core->dbg, old_pid, old_pid);
} else r_debug_continue_kill (&core->dbg, atoi (input+2));
break;
case 'u':
addr = r_num_math (&core->num, input+2);
eprintf ("Continue until 0x%08llx\n", addr);
r_bp_add_sw (core->dbg.bp, addr, 1, R_BP_PROT_EXEC);
r_debug_continue (&core->dbg);
r_bp_del (core->dbg.bp, addr);
break;
case ' ':
do {
int old_pid = core->dbg.pid;
@ -2046,25 +2086,27 @@ static int cmd_debug(void *data, const char *input) {
// TODO: Support PID and Thread
if (input[1]==' ')
//r_debug_select(&core->dbg, core->dbg.pid, atoi(input+2));
r_debug_select(&core->dbg, atoi(input+2), atoi(input+2));
else fprintf(stderr, "TODO: List processes..\n");
r_debug_select (&core->dbg, atoi(input+2), atoi(input+2));
else eprintf ("TODO: List processes..\n");
break;
case 'h':
if (input[1]==' ')
r_debug_use(&core->dbg, input+2);
else r_debug_handle_list(&core->dbg);
r_debug_use (&core->dbg, input+2);
else r_debug_handle_list (&core->dbg);
break;
default:
r_cons_printf("Usage: d[sbhcrbo] [arg]\n"
r_cons_printf ("Usage: d[sbhcrbo] [arg]\n"
" dh [handler] list or set debugger handler\n"
" dH [handler] transplant process to a new handler\n"
" ds perform one step\n"
" df file descriptors\n"
" ds 3 perform 3 steps\n"
" do 3 perform 3 steps overs\n"
" dsl step to next source line\n"
" df show frames (backtrace)\n"
" dp [pid] list or set pid\n"
" dt [tid] select thread id\n"
" dc continue execution\n"
" dc[?] continue execution. dc? for more\n"
" dr[?] cpu registers, dr? for extended help\n"
" db[?] breakpoints\n"
" dm show memory maps\n"
@ -2077,17 +2119,17 @@ static int cmd_debug(void *data, const char *input) {
}
R_API int r_core_cmd_buffer(void *user, const char *buf) {
char *str = strdup(buf);
char *ptr = strchr(str, '\n');
char *str = strdup (buf);
char *ptr = strchr (str, '\n');
char *optr = str;
while(ptr) {
while (ptr) {
ptr[0]='\0';
r_core_cmd(user, optr, 0);
r_core_cmd (user, optr, 0);
optr = ptr+1;
ptr = strchr(str,'\n');
ptr = strchr (str,'\n');
}
r_core_cmd(user, optr, 0);
free(str);
r_core_cmd (user, optr, 0);
free (str);
return R_TRUE;
}
@ -2109,8 +2151,7 @@ R_API int r_core_cmd0(void *user, const char *cmd) {
/*
* return: pointer to a buffer with the output of the command.
*/
R_API char *r_core_cmd_str(struct r_core_t *core, const char *cmd)
{
R_API char *r_core_cmd_str(struct r_core_t *core, const char *cmd) {
char *retstr = NULL;
r_cons_reset ();
if (r_core_cmd (core, cmd, 0) == -1) {

View File

@ -23,6 +23,13 @@ static int config_iova_callback(void *user, void *data) {
return R_TRUE;
}
static int config_swstep_callback(void *user, void *data) {
struct r_core_t *core = (struct r_core_t *) user;
struct r_config_node_t *node = (struct r_config_node_t *) data;
core->dbg.swstep = node->i_value;
return R_TRUE;
}
static int config_asm_arch_callback(void *user, void *data) {
struct r_core_t *core = (struct r_core_t *) user;
struct r_config_node_t *node = (struct r_config_node_t *) data;
@ -44,42 +51,34 @@ static int config_asm_parser_callback(void *user, void *data)
return R_TRUE;
}
static int config_asm_bits_callback(void *user, void *data)
{
struct r_core_t *core = (struct r_core_t *) user;
struct r_config_node_t *node = (struct r_config_node_t *) data;
int ret = r_asm_set_bits(&core->assembler, node->i_value);
static int config_asm_bits_callback(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
int ret = r_asm_set_bits (&core->assembler, node->i_value);
if (ret == R_FALSE) {
struct r_asm_handle_t *h = core->assembler.cur;
if (h) {
eprintf("Cannot set bits %lld to '%s'\n",
eprintf ("Cannot set bits %lld to '%s'\n",
node->i_value, h->name);
} else {
IFDBG eprintf("e asm.bits: Cannot set value, no plugins defined yet\n");
eprintf ("e asm.bits: Cannot set value, no plugins defined yet\n");
ret = R_TRUE;
}
}
return ret;
}
static int config_color_callback(void *user, void *data)
{
struct r_core_t *core = (struct r_core_t *) user;
struct r_config_node_t *node =
(struct r_config_node_t *) data;
static int config_color_callback(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
if (node->i_value) {
core->print.flags|=R_PRINT_FLAGS_COLOR;
} else {
// XXX ??? sure
if (core->print.flags&R_PRINT_FLAGS_COLOR)
core->print.flags^=R_PRINT_FLAGS_COLOR;
}
core->print.flags |= R_PRINT_FLAGS_COLOR;
} else if (core->print.flags&R_PRINT_FLAGS_COLOR)
core->print.flags ^= R_PRINT_FLAGS_COLOR;
return R_TRUE;
}
R_API int r_core_config_init(struct r_core_t *core)
{
R_API int r_core_config_init(struct r_core_t *core) {
struct r_config_t *cfg = &core->config;
r_config_init(cfg, (void *)core);
cfg->printf = r_cons_printf;
@ -92,6 +91,8 @@ R_API int r_core_config_init(struct r_core_t *core)
&config_asm_parser_callback);
r_config_set(cfg, "dir.plugins", LIBDIR"/radare2/");
/* anal */
r_config_set_i (cfg, "anal.depth", 10);
r_config_set(cfg, "asm.syntax", "intel");
r_config_set_i_cb(cfg, "asm.bits", 32,
&config_asm_bits_callback);
@ -117,15 +118,14 @@ R_API int r_core_config_init(struct r_core_t *core)
r_config_set_cb (cfg, "io.ffio", "false", &config_ioffio_callback);
r_config_set_cb (cfg, "io.va", "false", &config_iova_callback);
r_config_set (cfg, "cfg.fortunes", "true");
/* anal */
r_config_set_i (cfg, "anal.depth", 10);
r_config_set (cfg, "file.type", "");
/* TODO cmd */
r_config_set(cfg, "cmd.prompt", "");
r_config_set(cfg, "cmd.visual", ""); //? eip && ?? s eip");
// r_config_set(cfg, "cmd.vprompt", "p%");
r_config_set(cfg, "cmd.vprompt2", "CFV");
r_config_set(cfg, "cmd.vprompt3", "");
r_config_set(cfg, "cmd.vprompt", ""); //? eip && ?? s eip");
//r_config_set(cfg, "cmd.vprompt2", "CFV");
//r_config_set(cfg, "cmd.vprompt3", "");
r_config_set(cfg, "cmd.bp", "");
r_config_set_cb(cfg, "dbg.swstep", "false", &config_swstep_callback);
#if 0
node = config_set("asm.profile", "default");
// node->callback = &config_asm_profile;
@ -145,7 +145,6 @@ R_API int r_core_config_init(struct r_core_t *core)
config_set("asm.comments", "true"); // show comments in disassembly
config_set_i("asm.cmtmargin", 10); // show comments in disassembly
config_set_i("asm.cmtlines", 0); // show comments in disassembly
config_set("asm.syntax", "intel");
config_set("asm.case", "false"); // uppercase = true
config_set("asm.objdump", "objdump -m i386 --target=binary -D");
config_set("asm.offset", "true"); // show offset
@ -202,7 +201,6 @@ R_API int r_core_config_init(struct r_core_t *core)
config_set("file.id", "false");
config_set("file.analyze", "false");
config_set("file.type", "");
config_set("file.flag", "false");
config_set("file.trace", "trace.log");
config_set("file.project", "");
@ -366,8 +364,6 @@ R_API int r_core_config_init(struct r_core_t *core)
node = config_set("zoom.byte", "head");
node->callback = &config_zoombyte_callback;
config_set_i("scr.accel", 0);
node = config_set("scr.palette", cons_palette_default);
node->callback = &config_palette_callback;
cons_palette_init(config_get("scr.palette"));
@ -405,7 +401,6 @@ R_API int r_core_config_init(struct r_core_t *core)
node->callback = &config_scrwidth;
node = config_set_i("scr.height", config.height);
node->callback = &config_scrheight;
r_config_set("vm.realio", "false");
#endif
r_config_lock (cfg, R_TRUE);
return R_TRUE;

View File

@ -3,8 +3,7 @@
#include <r_core.h>
#include "../config.h"
static ut64 num_callback(void *userptr, const char *str, int *ok)
{
static ut64 num_callback(void *userptr, const char *str, int *ok) {
struct r_core_t *core = userptr;
struct r_flag_item_t *flag;
struct r_anal_aop_t aop;
@ -54,8 +53,7 @@ static ut64 num_callback(void *userptr, const char *str, int *ok)
return (flag)?flag->offset:0LL;
}
R_API struct r_core_t *r_core_new()
{
R_API struct r_core_t *r_core_new() {
struct r_core_t *c = MALLOC_STRUCT (struct r_core_t);
r_core_init (c);
return c;
@ -72,8 +70,7 @@ static const char *radare_argv[CMDS] ={
"pX", "po", "pm", "pz", "pr >", "p?", NULL
};
static int myfgets(char *buf, int len)
{
static int myfgets(char *buf, int len) {
/* TODO: link against dietline if possible for autocompletion */
char *ptr;
RLine *rli = r_line_singleton ();
@ -105,8 +102,7 @@ static int __dbg_write(void *user, int pid, ut64 addr, const ut8 *buf, int len)
}
#endif
R_API int r_core_init(struct r_core_t *core)
{
R_API int r_core_init(struct r_core_t *core) {
core->ffio = 0;
core->oobi = NULL;
core->oobi_len = 0;
@ -184,22 +180,20 @@ R_API int r_core_init(struct r_core_t *core)
return 0;
}
R_API struct r_core_t *r_core_free(struct r_core_t *c)
{
R_API struct r_core_t *r_core_free(struct r_core_t *c) {
/* TODO: it leaks as shit */
free (c);
return NULL;
}
R_API int r_core_prompt(struct r_core_t *r)
{
R_API int r_core_prompt(struct r_core_t *r) {
int ret;
char line[1024];
char prompt[32];
const char *cmdprompt = r_config_get (&r->config, "cmd.prompt");
if (cmdprompt && cmdprompt[0])
r_core_cmd (r, cmdprompt, 0);
ret = r_core_cmd (r, cmdprompt, 0);
sprintf (prompt, "[0x%08llx]> ", r->offset);
r_line_singleton()->prompt = prompt;

View File

@ -1,10 +1,9 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
#include "r_core.h"
/* io callback */
static int __lib_io_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_io_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_io_handle_t *hand = (struct r_io_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added IO handler\n");
@ -15,8 +14,7 @@ static int __lib_io_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_io_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* cmd callback */
static int __lib_cmd_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_cmd_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_cmd_handle_t *hand = (struct r_cmd_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added CMD handler\n");
@ -27,8 +25,7 @@ static int __lib_cmd_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_cmd_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* debug callback */
static int __lib_dbg_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_dbg_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_debug_handle_t *hand = (struct r_debug_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added debugger handler\n");
@ -51,8 +48,7 @@ static int __lib_bp_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_bp_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* lang callback */
static int __lib_lng_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_lng_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_lang_handle_t *hand = (struct r_lang_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added language handler\n");
@ -63,8 +59,7 @@ static int __lib_lng_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_lng_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* anal callback */
static int __lib_anl_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_anl_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_anal_handle_t *hand = (struct r_anal_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added analysis handler\n");
@ -75,8 +70,7 @@ static int __lib_anl_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_anl_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* asm callback */
static int __lib_asm_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_asm_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_asm_handle_t *hand = (struct r_asm_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
@ -87,8 +81,7 @@ static int __lib_asm_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_asm_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* parse callback */
static int __lib_parse_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_parse_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_parse_handle_t *hand = (struct r_parse_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
@ -99,8 +92,7 @@ static int __lib_parse_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_parse_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
/* bin callback */
static int __lib_bin_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
static int __lib_bin_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_bin_handle_t *hand = (struct r_bin_handle_t *)data;
struct r_core_t *core = (struct r_core_t *)user;
//printf(" * Added (dis)assembly handler\n");
@ -110,27 +102,26 @@ static int __lib_bin_cb(struct r_lib_plugin_t *pl, void *user, void *data)
static int __lib_bin_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
R_API int r_core_loadlibs_init(struct r_core_t *core)
{
R_API int r_core_loadlibs_init(struct r_core_t *core) {
/* initialize handlers */
r_lib_init(&core->lib, "radare_plugin");
r_lib_add_handler(&core->lib, R_LIB_TYPE_IO, "io plugins",
r_lib_init (&core->lib, "radare_plugin");
r_lib_add_handler (&core->lib, R_LIB_TYPE_IO, "io plugins",
&__lib_io_cb, &__lib_io_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_CMD, "cmd plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_CMD, "cmd plugins",
&__lib_cmd_cb, &__lib_cmd_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_DBG, "debug plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_DBG, "debug plugins",
&__lib_dbg_cb, &__lib_dbg_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_BP, "breakpoint plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_BP, "breakpoint plugins",
&__lib_bp_cb, &__lib_bp_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_LANG, "language plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_LANG, "language plugins",
&__lib_lng_cb, &__lib_lng_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_ANAL, "analysis plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_ANAL, "analysis plugins",
&__lib_anl_cb, &__lib_anl_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_ASM, "(dis)assembly plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_ASM, "(dis)assembly plugins",
&__lib_asm_cb, &__lib_asm_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_PARSE, "parsing plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_PARSE, "parsing plugins",
&__lib_parse_cb, &__lib_parse_dt, core);
r_lib_add_handler(&core->lib, R_LIB_TYPE_BIN, "bin plugins",
r_lib_add_handler (&core->lib, R_LIB_TYPE_BIN, "bin plugins",
&__lib_bin_cb, &__lib_bin_dt, core);
return R_TRUE;
}
@ -138,16 +129,16 @@ R_API int r_core_loadlibs_init(struct r_core_t *core)
R_API int r_core_loadlibs(struct r_core_t *core)
{
/* TODO: all those default plugin paths should be defined in r_lib */
char *homeplugindir = r_str_home(".radare/plugins");
char *homeplugindir = r_str_home (".radare/plugins");
static int singleton = R_TRUE;
if (singleton) {
r_core_loadlibs_init(core);
r_core_loadlibs_init (core);
singleton = R_FALSE;
}
r_lib_opendir(&core->lib, r_config_get(&core->config, "dir.plugins"));
r_lib_opendir(&core->lib, getenv(R_LIB_ENV));
r_lib_opendir(&core->lib, homeplugindir);
r_lib_opendir(&core->lib, LIBDIR"/radare2/");
free(homeplugindir);
r_lib_opendir (&core->lib, r_config_get (&core->config, "dir.plugins"));
r_lib_opendir (&core->lib, getenv (R_LIB_ENV));
r_lib_opendir (&core->lib, homeplugindir);
r_lib_opendir (&core->lib, LIBDIR"/radare2/");
free (homeplugindir);
return R_TRUE;
}

View File

@ -32,7 +32,7 @@ static int main_version() {
int main(int argc, char **argv) {
struct r_core_file_t *fh;
int c, perms = R_IO_READ;
int ret, c, perms = R_IO_READ;
int run_rc = 1;
int debug = 0;
int fullfile = 0;
@ -150,9 +150,8 @@ int main(int argc, char **argv) {
r_core_cmdf (&r, "dp %d", r.file->fd);
r_core_cmd (&r, ".dr*", 0);
r_core_cmd (&r, "s eip", 0);
r_core_cmd (&r, "e cmd.prompt=.dr*",0);
r_core_cmd (&r, "\"e cmd.vprompt=.dr*\"",0);
r_core_cmd (&r, "\"e cmd.visual=.dr*\"",0);
r_config_set (&r.config, "cmd.prompt", ".dr*");
r_config_set (&r.config, "cmd.vprompt", ".dr*");
}
if (seek)
@ -167,7 +166,7 @@ int main(int argc, char **argv) {
// Load the binary information from rabin2
{
char *cmd = r_str_dup_printf (".!rabin2 -rSIeis%s %s",
r.io.va?"v":"", r.file->filename);
(debug||r.io.va)?"v":"", r.file->filename);
r_core_cmd (&r, cmd, 0);
r_str_free (cmd);
}
@ -178,7 +177,18 @@ int main(int argc, char **argv) {
r_cons_flush ();
}
while (r_core_prompt (&r) != -1);
do {
ret = r_core_prompt (&r);
if (ret == -1)
eprintf ("Invalid command\n");
} while (ret != R_CORE_CMD_EXIT);
return r_core_file_close (&r, fh);
if (debug)
if (r_cons_yesno ('y', "Do you want to kill the process? (Y/n)"))
r_debug_kill (&r.dbg, 9); // KILL
/* capture return value */
ret = r.num.value;
r_core_file_close (&r, fh);
return ret;
}

View File

@ -666,7 +666,7 @@ R_API int r_core_visual(struct r_core_t *core, const char *input)
ut64 scrseek;
int ch;
vi = r_config_get(&core->config, "cmd.visual");
vi = r_config_get(&core->config, "cmd.vprompt");
if (vi) r_core_cmd(core, vi, 0);
while (input[0]) {

View File

@ -40,7 +40,7 @@ R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg) {
R_API int r_debug_attach(struct r_debug_t *dbg, int pid) {
int ret = R_FALSE;
if (dbg && dbg->h && dbg->h->attach) {
ret = dbg->h->attach(pid);
ret = dbg->h->attach (pid);
if (ret) {
// TODO: get arch and set io pid
//int arch = dbg->h->get_arch();
@ -53,23 +53,6 @@ R_API int r_debug_attach(struct r_debug_t *dbg, int pid) {
return ret;
}
#if TODO
// TODO MOove to r_reg
R_API ut64 r_debug_reg_get(struct r_debug_t *dbg, char *name) {
RRegisterItem *ri;
ut64 ret = 0LL;
char *foo = r_reg_get_name (dbg->reg, name);
if (foo) {
} else {
//r_reg_get (dbg->reg, dbg->reg->name[
}
if (ri)
ret = r_reg_get_value (dbg->reg, ri);
return ret;
}
#endif
/*
* Save 4096 bytes from %esp
* TODO: Add support for reverse stack architectures
@ -139,16 +122,14 @@ R_API int r_debug_detach(struct r_debug_t *dbg, int pid) {
return R_FALSE;
}
R_API int r_debug_select(struct r_debug_t *dbg, int pid, int tid)
{
R_API int r_debug_select(struct r_debug_t *dbg, int pid, int tid) {
dbg->pid = pid;
dbg->tid = tid;
eprintf("PID: %d %d\n", pid, tid);
return R_TRUE;
}
R_API int r_debug_stop_reason(struct r_debug_t *dbg)
{
R_API int r_debug_stop_reason(struct r_debug_t *dbg) {
// TODO: return reason to stop debugging
// - new process
// - trap instruction
@ -158,8 +139,7 @@ R_API int r_debug_stop_reason(struct r_debug_t *dbg)
return R_TRUE;
}
R_API int r_debug_wait(struct r_debug_t *dbg)
{
R_API int r_debug_wait(struct r_debug_t *dbg) {
int ret = R_FALSE;
if (dbg && dbg->h && dbg->h->wait) {
ret = dbg->h->wait(dbg->pid);
@ -169,8 +149,7 @@ R_API int r_debug_wait(struct r_debug_t *dbg)
}
// TODO: count number of steps done to check if no error??
R_API int r_debug_step(struct r_debug_t *dbg, int steps)
{
R_API int r_debug_step(struct r_debug_t *dbg, int steps) {
int i, ret = R_FALSE;
if (dbg && dbg->h && dbg->h->step) {
for(i=0;i<steps;i++) {
@ -191,8 +170,7 @@ R_API void r_debug_io_bind(RDebug *dbg, RIO *io) {
r_io_bind (io, &dbg->iob);
}
R_API int r_debug_step_over(struct r_debug_t *dbg, int steps)
{
R_API int r_debug_step_over(struct r_debug_t *dbg, int steps) {
// TODO: analyze opcode if it is stepoverable
eprintf ("r_debug_step_over: TODO\n");
return r_debug_step(dbg, steps);
@ -217,8 +195,7 @@ static int r_debug_recoil(struct r_debug_t *dbg) {
return ret;
}
R_API int r_debug_continue_kill(struct r_debug_t *dbg, int sig)
{
R_API int r_debug_continue_kill(struct r_debug_t *dbg, int sig) {
int ret = R_FALSE;
if (dbg && dbg->h && dbg->h->cont) {
r_bp_restore (dbg->bp, R_FALSE); // set sw breakpoints
@ -231,13 +208,11 @@ R_API int r_debug_continue_kill(struct r_debug_t *dbg, int sig)
return ret;
}
R_API int r_debug_continue(struct r_debug_t *dbg)
{
R_API int r_debug_continue(struct r_debug_t *dbg) {
return r_debug_continue_kill (dbg, -1);
}
R_API int r_debug_continue_until(struct r_debug_t *dbg, ut64 addr)
{
R_API int r_debug_continue_until(struct r_debug_t *dbg, ut64 addr) {
//struct r_debug_bp_t *bp = r_debug_bp_add (dbg, addr);
//int ret = r_debug_continue(dbg);
/* TODO: check if the debugger stops at the right address */
@ -245,8 +220,7 @@ R_API int r_debug_continue_until(struct r_debug_t *dbg, ut64 addr)
return -1;
}
R_API int r_debug_continue_syscall(struct r_debug_t *dbg, int sc)
{
R_API int r_debug_continue_syscall(struct r_debug_t *dbg, int sc) {
int ret = R_FALSE;
if (dbg && dbg->h && dbg->h->contsc)
ret = dbg->h->contsc(dbg->pid, sc);
@ -254,36 +228,23 @@ R_API int r_debug_continue_syscall(struct r_debug_t *dbg, int sc)
}
// TODO: remove from here? this is code injection!
R_API int r_debug_syscall(struct r_debug_t *dbg, int num)
{
R_API int r_debug_syscall(struct r_debug_t *dbg, int num) {
eprintf ("TODO\n");
return R_FALSE;
}
// TODO: Move to pid.c ?
// 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 sig)
{
// XXX: use debugger handler backend here
#if __WINDOWS__
eprintf ("r_debug_kill: not implemented\n");
return R_FALSE;
#else
#include <signal.h>
int ret = kill(dbg->pid, sig);
if (ret == -1)
return R_FALSE;
return R_TRUE;
#endif
R_API int r_debug_kill(struct r_debug_t *dbg, int sig) {
int ret = R_FALSE;
if (dbg->h && dbg->h->kill)
ret = dbg->h->kill (dbg, sig);
else eprintf ("Backend does not implements kill()\n");
return ret;
}
// 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)
{
R_API int r_anal_backtrace(struct r_anal_t *anal, const ut8 *buf, ut64 esp) {
return R_FALSE;
}

View File

@ -5,6 +5,7 @@
#include <r_asm.h>
#include <r_reg.h>
#include <r_lib.h>
#include <signal.h>
#define DEBUGGER 1
@ -134,8 +135,7 @@ static int r_debug_native_step(int pid) {
ret = ptrace (PT_STEP, pid, (caddr_t)1, SIGTRAP); //SIGINT);
if (ret != 0) {
perror ("ptrace-step");
eprintf ("FUCK: %s\n", MACH_ERROR_STRING(ret));
eprintf ("debug_os_steps: %d\n", ret);
eprintf ("mach-error: %d, %s\n", ret, MACH_ERROR_STRING(ret));
/* DO NOT WAIT FOR EVENTS !!! */
ret = R_FALSE;
} else ret = R_TRUE;
@ -451,8 +451,7 @@ static int r_debug_native_reg_write(int pid, int type, const ut8* buf, int size)
return R_FALSE;
}
static RList *r_debug_native_map_get(struct r_debug_t *dbg)
{
static RList *r_debug_native_map_get(struct r_debug_t *dbg) {
char path[1024];
RList *list = NULL;
#if __sun
@ -598,6 +597,18 @@ const char *archlist[3] = { "mips", 0 };
const char *archlist[3] = { "arm", 0 };
#endif
static int r_debug_native_kill(struct r_debug_t *dbg, int sig) {
#if __WINDOWS__
TerminateProcess (WIN32_PI(hProcess), 1);
return R_FALSE;
#else
int ret = kill (dbg->pid, sig);
if (ret == -1)
return R_FALSE;
return R_TRUE;
#endif
}
// TODO: think on a way to define the program counter register name
struct r_debug_handle_t r_debug_plugin_native = {
.name = "native",
@ -607,6 +618,7 @@ struct r_debug_handle_t r_debug_plugin_native = {
.attach = &r_debug_native_attach,
.detach = &r_debug_native_detach,
.wait = &r_debug_native_wait,
.kill = &r_debug_native_kill,
.get_arch = &r_debug_get_arch,
.reg_profile = (void *)&r_debug_native_reg_profile,
.reg_read = &r_debug_native_reg_read,

View File

@ -3,8 +3,7 @@
#include <r_debug.h>
#include <r_reg.h>
R_API int r_debug_reg_sync(struct r_debug_t *dbg, int type, int write)
{
R_API int r_debug_reg_sync(struct r_debug_t *dbg, int type, int write) {
ut8 buf[4096]; // XXX hacky!
int size, ret = R_FALSE;
if (write) {
@ -25,23 +24,53 @@ R_API int r_debug_reg_sync(struct r_debug_t *dbg, int type, int write)
return ret;
}
R_API int r_debug_reg_list(struct r_debug_t *dbg, int type, int size, int rad)
{
R_API int r_debug_reg_list(struct r_debug_t *dbg, int type, int size, int rad) {
int n = 0;
struct list_head *pos, *head = r_reg_get_list(dbg->reg, type);
//printf("list type=%d size=%d\n", type, size);
list_for_each (pos, head) {
struct r_reg_item_t *item = list_entry(pos, struct r_reg_item_t, list);
struct r_reg_item_t *item = list_entry (pos, struct r_reg_item_t, list);
//printf("--> t=%d\n", item->type);
if (type != -1 && type != item->type)
continue;
if (size != 0 && size != item->size)
continue;
if (rad) dbg->printf("f %s @ 0x%08llx\n",
item->name, r_reg_get_value(dbg->reg, item));
else dbg->printf("%s = 0x%08llx\n",
item->name, r_reg_get_value(dbg->reg, item));
if (rad) dbg->printf ("f %s @ 0x%08llx\n",
item->name, r_reg_get_value (dbg->reg, item));
else dbg->printf ("%s = 0x%08llx\n",
item->name, r_reg_get_value (dbg->reg, item));
n++;
}
return n;
}
R_API int r_debug_reg_set(struct r_debug_t *dbg, const char *name, ut64 num) {
RRegisterItem *ri;
int role = r_reg_get_name_idx (name);
if (role != -1)
name = r_reg_get_name (dbg->reg, role);
ri = r_reg_get (dbg->reg, name, R_REG_TYPE_GPR);
if (ri) {
r_reg_set_value (dbg->reg, ri, num);
r_debug_reg_sync (dbg, R_REG_TYPE_GPR, R_TRUE);
}
return (ri!=NULL);
}
R_API ut64 r_debug_reg_get(struct r_debug_t *dbg, const char *name) {
RRegisterItem *ri = NULL;
ut64 ret = 0LL;
int role = r_reg_get_name_idx (name);
if (role != -1) {
name = r_reg_get_name (dbg->reg, role);
if (name == NULL && *name == '\0') {
eprintf ("Cannot resolve name for register role '%s'.\n", name);
}
}
ri = r_reg_get (dbg->reg, name, R_REG_TYPE_GPR);
if (ri) {
r_debug_reg_sync (dbg, R_REG_TYPE_GPR, R_FALSE);
ret = r_reg_get_value (dbg->reg, ri);
}
return ret;
}

View File

@ -20,6 +20,7 @@
#include "r_config.h"
#include "r_bin.h"
#define R_CORE_CMD_EXIT -2
#define R_CORE_BLOCKSIZE 64
#define R_CORE_BLOCKSIZE_MAX 0x40000 /* 4 MB */

View File

@ -75,6 +75,7 @@ typedef struct r_debug_handle_t {
int (*step)(int pid); // if step() is NULL; reimplement it with traps
int (*cont)(int pid, int sig);
int (*wait)(int pid);
int (*kill)(RDebug *dbg, int sig);
int (*contsc)(int pid, int sc);
/* registers */
RBreakpointCallback breakpoint;
@ -152,6 +153,8 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr);
/* registers */
R_API int r_debug_reg_sync(struct r_debug_t *dbg, int type, int write);
R_API int r_debug_reg_list(struct r_debug_t *dbg, int type, int size, int rad);
R_API int r_debug_reg_set(struct r_debug_t *dbg, const char *name, ut64 num);
R_API ut64 r_debug_reg_get(struct r_debug_t *dbg, const char *name);
R_API void r_debug_io_bind(RDebug *dbg, RIO *io);
R_API ut64 r_debug_execute(struct r_debug_t *dbg, ut8 *buf, int len);

View File

@ -73,11 +73,10 @@ R_API int r_reg_set_name(struct r_reg_t *reg, int role, const char *name) {
R_API const char *r_reg_get_name(struct r_reg_t *reg, int role) {
if (role>=0 && role<R_REG_NAME_LAST)
return reg->name[role];
return "";
return NULL;
}
R_API struct r_reg_t *r_reg_free(struct r_reg_t *reg)
{
R_API struct r_reg_t *r_reg_free(struct r_reg_t *reg) {
if (reg) {
// TODO: free more things here
free (reg);
@ -85,8 +84,7 @@ R_API struct r_reg_t *r_reg_free(struct r_reg_t *reg)
return NULL;
}
R_API struct r_reg_t *r_reg_init(struct r_reg_t *reg)
{
R_API struct r_reg_t *r_reg_init(struct r_reg_t *reg) {
int i;
if (!reg)
return NULL;
@ -110,8 +108,7 @@ static struct r_reg_item_t *r_reg_item_new() {
return item;
}
R_API int r_reg_type_by_name(const char *str)
{
R_API int r_reg_type_by_name(const char *str) {
int i;
for (i=0; types[i] && i<R_REG_TYPE_LAST; i++) {
if (!strcmp (types[i], str))
@ -157,8 +154,7 @@ static int r_reg_set_word(struct r_reg_item_t *item, int idx, char *word) {
}
/* TODO: make this parser better and cleaner */
R_API int r_reg_set_profile_string(struct r_reg_t *reg, const char *str)
{
R_API int r_reg_set_profile_string(struct r_reg_t *reg, const char *str) {
RRegisterItem *item;
int setname = -1;
int ret = R_FALSE;
@ -228,8 +224,7 @@ R_API int r_reg_set_profile_string(struct r_reg_t *reg, const char *str)
return ret;
}
R_API int r_reg_set_profile(struct r_reg_t *reg, const char *profile)
{
R_API int r_reg_set_profile(struct r_reg_t *reg, const char *profile) {
int ret = R_FALSE;
const char *base;
char *str, *file;
@ -250,8 +245,7 @@ R_API int r_reg_set_profile(struct r_reg_t *reg, const char *profile)
return ret;
}
R_API struct r_reg_item_t *r_reg_get(struct r_reg_t *reg, const char *name, int type)
{
R_API struct r_reg_item_t *r_reg_get(struct r_reg_t *reg, const char *name, int type) {
struct list_head *pos;
struct r_reg_item_t *r;
int i, e;
@ -265,17 +259,16 @@ R_API struct r_reg_item_t *r_reg_get(struct r_reg_t *reg, const char *name, int
}
for (; i<e; i++) {
list_for_each(pos, &reg->regset[i].regs) {
r = list_entry(pos, struct r_reg_item_t, list);
if (!strcmp(r->name, name))
list_for_each (pos, &reg->regset[i].regs) {
r = list_entry (pos, struct r_reg_item_t, list);
if (!strcmp (r->name, name))
return r;
}
}
return NULL;
}
R_API struct list_head *r_reg_get_list(struct r_reg_t *reg, int type)
{
R_API struct list_head *r_reg_get_list(struct r_reg_t *reg, int type) {
if (type < 0 || type > R_REG_TYPE_LAST)
return NULL;
return &reg->regset[type].regs;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2007-2010 pancake<nopcode.org> */
#include "r_types.h"
#include "r_util.h"
@ -9,8 +9,7 @@
#include <sys/stat.h>
#include <unistd.h>
R_API int r_file_mkdir(const char *path)
{
R_API int r_file_mkdir(const char *path) {
#if __WINDOWS__
return mkdir(path);
#else
@ -131,8 +130,7 @@ R_API char *r_file_slurp_range(const char *str, ut64 off, ut64 sz)
return ret;
}
R_API char *r_file_slurp_random_line(const char *file)
{
R_API char *r_file_slurp_random_line(const char *file) {
int i, lines = 0;
struct timeval tv;
int sz;
@ -156,24 +154,31 @@ R_API char *r_file_slurp_random_line(const char *file)
return ptr;
}
R_API char *r_file_slurp_line(const char *file, int line, int context)
{
R_API char *r_file_slurp_line(const char *file, int line, int context) {
int i, lines = 0;
int sz;
char *ptr, *str = r_file_slurp(file, &sz);
char *ptr, *str = r_file_slurp (file, &sz);
// TODO: Implement context
if (str) {
for(i=0;str[i];i++)
for (i=0;str[i];i++)
if (str[i]=='\n')
lines++;
if (line > lines) {
free (str);
return NULL;
}
lines = line;
for(i=0;str[i]&&lines;i++)
for (i=0;str[i]&&lines;i++)
if (str[i]=='\n')
lines--;
ptr = str+i;
for(i=0;ptr[i];i++) if (ptr[i]=='\n') { ptr[i]='\0'; break; }
ptr = strdup(ptr);
free(str);
for (i=0; ptr[i]; i++)
if (ptr[i]=='\n') {
ptr[i]='\0';
break;
}
ptr = strdup (ptr);
free (str);
}
return ptr;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2007-2010 pancake<nopcode.org> */
#include "r_types.h"
#include "r_util.h"

View File

@ -9,5 +9,7 @@ int main(int argc, char *argv[]) {
printf("r_str_trim_head('%s',): '%s'\n", " a", r_str_trim_head(head));fflush(stdout);
printf("r_str_trim_tail('%s',): '%s'\n", "a ", r_str_trim_tail(tail));fflush(stdout);
printf("r_str_trim_head_tail('%s',): '%s'\n", " a ", r_str_trim_head_tail(both));fflush(stdout);
printf ("%s\n", r_file_slurp_line ("/etc/fstab", 4, 0));
return 0;
}