Implement RFlagBind and use it from RAnal. Add 'ask' command

This commit is contained in:
pancake 2014-09-26 14:24:33 +02:00
parent a0e609e40d
commit bd618dccf2
8 changed files with 49 additions and 17 deletions

View File

@ -70,6 +70,7 @@ R_API RAnal *r_anal_new() {
anal->split = R_TRUE; // used from core
anal->syscall = r_syscall_new ();
r_io_bind_init (anal->iob);
r_flag_bind_init (anal->flb);
anal->reg = r_reg_new ();
anal->lineswidth = 0;
anal->fcns = r_anal_fcn_list_new ();

View File

@ -48,7 +48,7 @@ static void var_help(RCore *core, char ch) {
static int var_cmd(RCore *core, const char *str) {
RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, -1);
char *p, *ostr;
int scope, delta, type = *str;
int delta, type = *str;
ostr = p = strdup (str);
str = (const char *)ostr;
@ -65,16 +65,6 @@ static int var_cmd(RCore *core, const char *str) {
case 'a': // stack arg
case 'A': // fastcall arg
// XXX nested dup
switch (*str) {
case 'v': scope = R_ANAL_VAR_SCOPE_LOCAL|R_ANAL_VAR_DIR_NONE; break;
case 'a': scope = R_ANAL_VAR_SCOPE_ARG|R_ANAL_VAR_DIR_IN; break;
case 'A': scope = R_ANAL_VAR_SCOPE_ARGREG|R_ANAL_VAR_DIR_IN; break;
default:
eprintf ("Unknown type\n");
free (ostr);
return 0;
}
/* Variable access CFvs = set fun var */
switch (str[1]) {
case '\0':
@ -1450,6 +1440,15 @@ if (ret) {
case ' ':
cmd_syscall_do (core, (int)r_num_get (core->num, input+2));
break;
case 'k':
{
char *out = sdb_querys (core->anal->syscall->db, NULL, 0, input+3);
if (out) {
r_cons_printf ("%s\n", out);
free (out);
}
}
break;
default:
case '?':{
const char* help_msg[] = {
@ -1459,6 +1458,7 @@ if (ret) {
"asl", "", "list of syscalls by asm.os and asm.arch",
"asl", " close", "returns the syscall number for close",
"asl", " 4", "returns the name of the syscall number 4",
"ask", " [query]", "perform syscall/ queries",
NULL};
r_core_cmd_help (core, help_msg);
}

View File

@ -153,11 +153,10 @@ static int cb_asmarch(void *user, void *data) {
}
static int cb_dbgbpsize(void *user, void *data) {
const char *asmos, *asmarch;
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
core->dbg->bpsize = node->i_value;
int ret;
return R_TRUE;
}
static int cb_asmbits(void *user, void *data) {

View File

@ -661,6 +661,7 @@ R_API int r_core_init(RCore *core) {
r_io_bind (core->io, &(core->anal->iob));
r_io_bind (core->io, &(core->fs->iob));
r_io_bind (core->io, &(core->bin->iob));
r_flag_bind (core->flags, &(core->anal->flb));
core->file = NULL;
core->files = r_list_new ();

View File

@ -537,3 +537,13 @@ R_API const char *r_flag_color(RFlag *f, RFlagItem *it, const char *color) {
else it->color = NULL;
return it->color;
}
// BIND
R_API int r_flag_bind (RFlag *f, RFlagBind *fb) {
fb->f = f;
fb->get = r_flag_get;
fb->set = r_flag_set;
fb->set_fs = r_flag_space_set;
return 0;
}

View File

@ -31,18 +31,18 @@ void flag_space_init(struct r_flag_t *f) {
}
#endif
R_API void r_flag_space_set(RFlag *f, const char *name) {
R_API int r_flag_space_set(RFlag *f, const char *name) {
int i;
if (name == NULL || *name == '*') {
f->space_idx = -1;
return;
return f->space_idx;
}
for (i=0; i<R_FLAG_SPACES_MAX; i++) {
if (f->spaces[i] != NULL)
if (!strcmp (name, f->spaces[i])) {
f->space_idx = i;
return;
return f->space_idx;
}
}
/* not found */
@ -53,6 +53,7 @@ R_API void r_flag_space_set(RFlag *f, const char *name) {
break;
}
}
return f->space_idx;
}
R_API int r_flag_space_list(RFlag *f, int mode) {

View File

@ -18,6 +18,7 @@
#include <r_list.h>
#include <r_util.h>
#include <r_syscall.h>
#include <r_flags.h>
#include <r_bin.h>
#ifdef __cplusplus
@ -490,6 +491,7 @@ typedef struct r_anal_t {
double diff_thbb;
double diff_thfcn;
RIOBind iob;
RFlagBind flb;
int decode;
RList *types;
//struct r_anal_ctx_t *ctx;

View File

@ -56,6 +56,24 @@ typedef struct r_flag_t {
RList *flags;
} RFlag;
/* compile time dependency */
#include <r_flags.h> // compile time line, no linkage needed
typedef RFlagItem* (*RFlagGet)(RFlag *f, const char *name);
typedef RFlagItem* (*RFlagSet)(RFlag *f, const char *name, ut64 addr, ut32 size, int dup);
typedef int (*RFlagSetSpace)(RFlag *f, const char *name);
typedef struct r_flag_bind_t {
int init;
RFlag *f;
RFlagGet get;
RFlagSet set;
RFlagSetSpace set_fs;
} RFlagBind;
#define r_flag_bind_init(x) memset(&x,0,sizeof(x))
R_API int r_flag_bind(RFlag *io, RFlagBind *bnd);
#ifdef R_API
R_API RFlag * r_flag_new();
R_API RFlag * r_flag_free(RFlag *f);
@ -81,7 +99,7 @@ R_API const char *r_flag_color(RFlag *f, RFlagItem *it, const char *color);
/* spaces */
R_API int r_flag_space_get(RFlag *f, const char *name);
R_API const char *r_flag_space_get_i(RFlag *f, int idx);
R_API void r_flag_space_set(RFlag *f, const char *name);
R_API int r_flag_space_set(RFlag *f, const char *name);
R_API int r_flag_space_list(RFlag *f, int mode);
R_API int r_flag_space_rename (RFlag *f, const char *oname, const char *nname);
#endif