cleanup and add new cbs for esilvm

This commit is contained in:
condret 2014-06-20 18:01:33 +02:00 committed by pancake
parent 6227c12bfe
commit 1407d499b5
2 changed files with 48 additions and 45 deletions

View File

@ -46,13 +46,13 @@ static int esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
return ret;
}
static int internal_esil_mem_write (THIS *esil, ut64 addr, const ut8 *buf, int len) {
static int internal_esil_mem_write (ESIL *esil, ut64 addr, const ut8 *buf, int len) {
if (!esil || !esil->anal || !esil->anal->iob.io)
return 0;
return esil->anal->iob.write_at (esil->anal->iob.io, addr, buf, len);
}
static int esil_mem_write (THIS *esil, ut64 addr, const ut8 *buf, int len) {
static int esil_mem_write (ESIL *esil, ut64 addr, const ut8 *buf, int len) {
int i, ret = 0;
if (!buf || !esil)
return 0;

View File

@ -742,6 +742,45 @@ typedef struct r_anal_cycle_hook_t { //rename ?
int cycles;
} RAnalCycleHook;
typedef struct r_anal_esil_word_t {
int type;
const char *str;
} RAnalEsilWord;
// only flags that affect control flow
enum {
R_ANAL_ESIL_FLAG_ZERO = 1,
R_ANAL_ESIL_FLAG_CARRY = 2,
R_ANAL_ESIL_FLAG_OVERFLOW = 4,
R_ANAL_ESIL_FLAG_PARITY = 8,
// ...
};
#define ESIL struct r_anal_esil_t
typedef struct r_anal_esil_t {
void *user;
RAnal *anal;
char *stack[32];
int stackptr;
int skip;
int repeat;
int debug;
ut64 flags;
/* callbacks */
int (*hook_mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len);
int (*mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len);
int (*hook_mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len);
int (*mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len);
int (*hook_reg_read)(ESIL *esil, const char *name, ut64 *res);
int (*reg_read)(ESIL *esil, const char *name, ut64 *res);
int (*hook_reg_write)(ESIL *esil, const char *name, ut64 val);
int (*reg_write)(ESIL *esil, const char *name, ut64 val);
} RAnalEsil;
struct r_anal_esil_op_t {
const char *str;
int (*run)(RAnalEsil *esil);
};
typedef int (*RAnalCmdExt)(/* Rcore */RAnal *anal, const char* input);
typedef int (*RAnalAnalyzeFunctions)(RAnal *a, ut64 at, ut64 from, int reftype, int depth);
typedef int (*RAnalExCallback)(RAnal *a, struct r_anal_state_type_t *state, ut64 addr);
@ -762,6 +801,9 @@ typedef int (*RAnalDiffBBCallback)(RAnal *anal, RAnalFunction *fcn, RAnalFunctio
typedef int (*RAnalDiffFcnCallback)(RAnal *anal, RList *fcns, RList *fcns2);
typedef int (*RAnalDiffEvalCallback)(RAnal *anal);
typedef int (*RAnalEsilCB)(RAnalEsil *esil);
typedef int (*RAnalEsilLoopCB)(RAnalEsil *esil, RAnalOp *op);
typedef struct r_anal_plugin_t {
char *name;
char *desc;
@ -831,6 +873,10 @@ typedef struct r_anal_plugin_t {
RAnalDiffFcnCallback diff_fcn;
RAnalDiffEvalCallback diff_eval;
struct list_head list;
RAnalEsilCB esil_init;
RAnalEsilLoopCB esil_post_loop; //cycle-counting, firing interrupts, ...
RAnalEsilCB esil_fini;
} RAnalPlugin;
@ -901,45 +947,6 @@ R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr,
const char *hexstr);
R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op);
#if NEW_ESIL
typedef struct r_anal_esil_word_t {
int type;
const char *str;
} RAnalEsilWord;
// only flags that affect control flow
enum {
R_ANAL_ESIL_FLAG_ZERO = 1,
R_ANAL_ESIL_FLAG_CARRY = 2,
R_ANAL_ESIL_FLAG_OVERFLOW = 4,
R_ANAL_ESIL_FLAG_PARITY = 8,
// ...
};
#define THIS struct r_anal_esil_t
typedef struct r_anal_esil_t {
void *user;
RAnal *anal;
char *stack[32];
int stackptr;
int skip;
int repeat;
int debug;
ut64 flags;
/* callbacks */
int (*hook_mem_read)(THIS *esil, ut64 addr, ut8 *buf, int len);
int (*mem_read)(THIS *esil, ut64 addr, ut8 *buf, int len);
int (*hook_mem_write)(THIS *esil, ut64 addr, const ut8 *buf, int len);
int (*mem_write)(THIS *esil, ut64 addr, const ut8 *buf, int len);
int (*hook_reg_read)(THIS *esil, const char *name, ut64 *res);
int (*reg_read)(THIS *esil, const char *name, ut64 *res);
int (*hook_reg_write)(THIS *esil, const char *name, ut64 val);
int (*reg_write)(THIS *esil, const char *name, ut64 val);
} RAnalEsil;
struct r_anal_esil_op_t {
const char *str;
int (*run)(RAnalEsil *esil);
};
R_API RAnalEsil *r_anal_esil_new();
R_API int r_anal_esil_setup (RAnalEsil *esil, RAnal *anal);
@ -949,10 +956,6 @@ R_API int r_anal_esil_dumpstack (RAnalEsil *esil);
R_API int r_anal_esil_pushnum(RAnalEsil *esil, ut64 num);
R_API int r_anal_esil_push(RAnalEsil *esil, const char *str);
R_API char *r_anal_esil_pop(RAnalEsil *esil);
#else
R_API const char *r_anal_op_to_esil_string(RAnal *anal, RAnalOp *op);
R_API char *r_anal_esil_to_sdb(char *str);
#endif
/* fcn.c */
R_API RAnalFunction *r_anal_fcn_new();