* Add constructor/destructor for r_anal and r_sign

- Add rasign test program for r_sign
* Minor code cleanup in cons
* Cleanup and sort commands in help message
* Make oobi input work as command interpreter
  - Add r_core_cmd_buffer
* Some basic design workup for xrefs search engine
This commit is contained in:
pancake 2009-03-14 11:39:37 +00:00
parent 9526a34445
commit 1d90ad7143
13 changed files with 173 additions and 110 deletions

2
TODO
View File

@ -1,4 +1,6 @@
* Add maxrows option for r_print (fix visual problem)
* Drop #if conditionals to use #ifdef ones
- fits better with plan9 compiler
* Add test for config.c with _set_cb
* Rename __UNIX__ as __POSIX__
* Strip non input symbols in plugins (speed up loading)

View File

@ -3,6 +3,19 @@
#include <r_anal.h>
#include <r_util.h>
struct r_anal_t *r_anal_new()
{
struct r_anal_t *r = MALLOC_STRUCT(struct r_anal_t);
r_anal_init(r);
return r;
}
struct r_anal_t *r_anal_free(struct r_anal_t *r)
{
free(r);
return NULL;
}
int r_anal_init(struct r_anal_t *anal)
{
anal->user = NULL;

View File

@ -2,9 +2,10 @@
#include <r_cons.h>
#include <string.h>
const char *nullstr="";
static const char *nullstr="";
const char *r_cons_palette_default = "7624 6646 2378 6824 3623";
char r_cons_palette[CONS_PALETTE_SIZE][8] = {
/* PROMPT */
/* ADDRESS */
@ -33,28 +34,9 @@ char r_cons_palette[CONS_PALETTE_SIZE][8] = {
};
const char *r_cons_color_names[CONS_COLORS_SIZE+1] = {
"black",
"gray",
"white",
"red",
"magenta",
"blue",
"green",
"yellow",
"turqoise",
"bblack",
"bgray",
"bwhite",
"bred",
"bmagenta",
"bblue",
"bgreen",
"byellow",
"bturqoise",
"reset",
"bgblack",
"bgred",
NULL
"black", "gray", "white", "red", "magenta", "blue", "green", "yellow",
"turqoise", "bblack", "bgray", "bwhite", "bred", "bmagenta", "bblue",
"bgreen", "byellow", "bturqoise", "reset", "bgblack", "bgred", NULL
};
void r_cons_invert(int set, int color)
@ -96,26 +78,9 @@ const char *r_cons_colors[CONS_COLORS_SIZE+1] = {
};
const char *pal_names[CONS_PALETTE_SIZE]={
"prompt",
"address",
"default",
"changed",
"jumps",
"calls",
"push",
"trap",
"cmp",
"ret",
"nop",
"metadata",
"header",
"printable",
"lines0",
"lines1",
"lines2",
"00",
"7f",
"ff",
"prompt", "address", "default", "changed", "jumps", "calls",
"push", "trap", "cmp", "ret", "nop", "metadata", "header",
"printable", "lines0", "lines1", "lines2", "00", "7f", "ff",
NULL
};

View File

@ -273,7 +273,7 @@ void r_cons_flush()
// XXX merge grepstr with r_cons_lines loop //
r_cons_lines += r_str_nchr(buf, '\n');
// XXX major cleanup here!
// XXX buggy! this needs a major cleanup here!
if (grepstr != NULL) {
int line, len;
char *one = r_cons_buffer;
@ -410,8 +410,7 @@ void r_cons_flush()
r_cons_buffer_len = strlen(buf);
r_cons_print_real(buf);
}
//r_cons_buffer_sz=0;
r_cons_buffer_len=0;
r_cons_buffer_len = 0;
}
/* stream is ignored */

View File

@ -7,59 +7,12 @@
#define CMDS 54
static const char *radare_argv[CMDS] ={
NULL, // padding
"? ",
"!step ",
"!stepo ",
"!cont ",
"!signal ",
"!fd ",
"!maps ",
".!maps*",
"!bp ",
"!!",
"#md5",
"#sha1",
"#crc32",
"#entropy",
"Visual",
"ad",
"ac",
"ag",
"emenu ",
"eval ",
"seek ",
"info ",
"help ",
"move ",
"quit ",
"flag ",
"Po ",
"Ps ",
"Pi ",
"H ",
"H no ",
"H nj ",
"H fj ",
"H lua ",
"x ",
"b ",
"y ",
"yy ",
"y? ",
"wx ",
"ww ",
"wf ",
"w?",
"pD ",
"pG ",
"pb ",
"px ",
"pX ",
"po ",
"pm ",
"pz ",
"pr > ",
"p? "
"? ", "!step ", "!stepo ", "!cont ", "!signal ", "!fd ", "!maps ", ".!maps*",
"!bp ", "!!", "#md5", "#sha1", "#crc32", "#entropy", "Visual", "ad", "ac",
"ag", "emenu ", "eval ", "seek ", "info ", "help ", "move ", "quit ", "flag ",
"Po ", "Ps ", "Pi ", "H ", "H no ", "H nj ", "H fj ", "H lua ", "x ", "b ",
"y ", "yy ", "y? ", "wx ", "ww ", "wf ", "w?", "pD ", "pG ", "pb ", "px ",
"pX ", "po ", "pm ", "pz ", "pr > ", "p? "
};
char *dl_readline(int argc, const char **argv);

View File

@ -258,18 +258,17 @@ static int cmd_help(void *data, const char *input)
"Usage:\n"
" a ; perform analysis of code\n"
" b [bsz] ; get or change block size\n"
" d[hrscb] ; debugger commands\n"
" C[CFf..] ; Code metadata management\n"
" d[hrscb] ; debugger commands\n"
" e [a[=b]] ; list/get/set config evaluable vars\n"
" i ; get info of the current file\n"
" f [name][sz][at] ; set flag at current address\n"
" s [addr] ; seek to address\n"
" i [file] ; get info about opened file\n"
" p?[len] ; print current block with format and length\n"
" V[vcmds] ; enter visual mode (vcmds=visualvisual keystrokes)\n"
" w[mode] [arg] ; multiple write operations\n"
" x [len] ; alias for 'px' (print hexadecimal\n"
" y [len] [off] ; yank/paste bytes from/to memory\n"
" w[mode] [arg] ; multiple write operations\n"
" V[vcmds] ; enter visual mode (vcmds=visualvisual keystrokes)\n"
" ? [expr] ; help or evaluate math expression\n"
" /[xmp/] ; search for bytes, regexps, patterns, ..\n"
" |[cmd] ; run this command thru the io pipe (no args=list)\n"
@ -972,7 +971,7 @@ static int r_core_cmd_subst(struct r_core_t *core, char *cmd, int *rs, int *rfd,
ptr = strchr(cmd+1, '|');
if (ptr) {
ptr[0] = '\0';
fprintf(stderr, "System pipes not yet supported.\n");
eprintf("System pipes not yet supported.\n");
}
/* Out Of Band Input */
@ -986,7 +985,7 @@ static int r_core_cmd_subst(struct r_core_t *core, char *cmd, int *rs, int *rfd,
char *oprompt = r_line_prompt;
oprompt = ">";
for(str=ptr+2;str[0]== ' ';str=str+1);
fprintf(stderr, "==> Reading from stdin until '%s'\n", str);
eprintf("==> Reading from stdin until '%s'\n", str);
free(core->oobi);
core->oobi = malloc(1);
core->oobi[0] = '\0';
@ -1009,11 +1008,12 @@ static int r_core_cmd_subst(struct r_core_t *core, char *cmd, int *rs, int *rfd,
r_line_prompt = oprompt;
} else {
for(str=ptr+1;str[0]== ' ';str=str+1);
printf("SLURPING FILE '%s'\n", str);
eprintf("SLURPING FILE '%s'\n", str);
core->oobi = r_file_slurp(str, &core->oobi_len);
if (core->oobi == NULL) {
printf("Cannot open file\n");
}
if (core->oobi == NULL)
eprintf("Cannot open file\n");
else if (ptr == cmd)
return r_core_cmd_buffer(core, core->oobi);
}
}
/* Pipe console to file */
@ -1186,7 +1186,7 @@ static int cmd_debug(void *data, const char *input)
else r_debug_handle_list(&core->dbg, "");
break;
default:
r_cons_printf("Usage: d[sbc] [arg]\n"
r_cons_printf("Usage: d[sbhcrbo] [arg]\n"
" dh [handler] ; list or set debugger handler\n"
" ds ; perform one step\n"
" ds 3 ; perform 3 steps\n"
@ -1207,6 +1207,22 @@ static int cmd_debug(void *data, const char *input)
return 0;
}
int r_core_cmd_buffer(void *user, const char *buf)
{
char *str = strdup(buf);
char *ptr = strchr(str, '\n');
char *optr = str;
while(ptr) {
ptr[0]='\0';
r_core_cmd(user, optr, 0);
optr = ptr+1;
ptr = strchr(str,'\n');
}
r_core_cmd(user, optr, 0);
free(str);
return R_TRUE;
}
int r_core_cmdf(void *user, const char *fmt, ...)
{
char string[1024];

View File

@ -99,6 +99,8 @@ struct r_anal_handle_t {
/* anal.c */
int r_anal_init(struct r_anal_t *anal);
struct r_anal_t *r_anal_free(struct r_anal_t *r);
struct r_anal_t *r_anal_new();
void r_anal_set_user_ptr(struct r_anal_t *anal, void *user);
int r_anal_add(struct r_anal_t *anal, struct r_anal_handle_t *foo);
int r_anal_list(struct r_anal_t *anal);

View File

@ -4,3 +4,8 @@
- r_vm : to properly setup the per-architecture register configuration
- r_debug : to get/set register values
- r_core : to display register values in 'd' (debug) command. dr
---------------------------------
We will have to split up every arch into a plugin
- define an API to access to registers and get information about the type of regs.
- we can base this stuff as in r_vm is done

View File

@ -7,6 +7,7 @@ static char *x86_regs[] = {
"ax", "bx", "cx", "dx", "si", "di", "sp", "bp", "ip", // 16 tits
"ah","al", "bh", "bl", "ch","cl", "dh","dl", // 8 tits
NULL };
#if 0
// XXX
- we need size of register

View File

@ -13,3 +13,31 @@ int r_search_xrefs_update(struct r_search_t *s, u64 from, const u8 *buf, int len
//}
return count;
}
#if 0
struct r_xrefs_arch_t {
int align; // if arch requires align we can skip invalid addresses
int bigendian;
u64 baseaddr;
u64 targetaddr; // the addr we are looking for
};
the xrefs plugin will have a callback:
- size of opcode to skip in bytes (mips/arm=4 f.ex)
int r_xrefs_x86(u64 addr, int bigendian, u64 baseaddr)
{
// check for calls, branches..and calculate target address
}
Options we need to configure xrefs search plugin:
- endian
- base address
- target address
- from/to (defined as max for the maximum branch distance)
- architecture profile ()
- TODO: ensure we are pointing to a function if following a 'call'
- we need per-arch plugins
#endif

View File

@ -2,6 +2,19 @@
#include <r_sign.h>
struct r_sign_t *r_sign_new()
{
struct r_sign_t *s = MALLOC_STRUCT(struct r_sign_t);
r_sign_init(s);
return s;
}
struct r_sign_t *r_sign_free(struct r_sign_t *s)
{
free(s);
return NULL;
}
int r_sign_init(struct r_sign_t *sig)
{
sig->count = 0;

5
libr/sign/t/Makefile Normal file
View File

@ -0,0 +1,5 @@
OBJ=rasign.o
BIN=rasign
BINDEPS=r_io r_sign
include ../../rules.mk

61
libr/sign/t/rasign.c Normal file
View File

@ -0,0 +1,61 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include "r_sign.h"
int rasign_show_help()
{
printf("Usage: rasign [options] [file]\n"
" -r : show output in radare commands\n"
" -s [sigfile] : specify one or more signature files\n"
"Examples:\n"
" rasign libc.so.6 > libc.sig\n"
" rasign -s libc.sig ls.static\n");
return 0;
}
int main(int argc, char **argv)
{
int c;
int action = 0;
int rad = 0;
struct r_sign_t sig;
r_sign_init(&sig);
while((c=getopt(argc, argv, "o:hrs:i")) !=-1) {
switch(c) {
case 'o':
r_sign_option(&sig, optarg);
break;
case 's':
action = c;
r_sign_load_file(&sig, optarg);
break;
case 'r':
rad = 1;
break;
default:
return rasign_show_help();
}
}
if (argv[optind]==NULL)
return rasign_show_help();
r_sign_info(&sig);
switch(action) {
case 's':
/* check sigfiles in optarg file */
r_sign_check(&sig, argv[optind]);
break;
default:
/* generate signature file */
r_sign_generate(&sig, argv[optind], stdout);
break;
}
return 0;
}