2010-02-02 10:09:52 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2010 */
|
2009-03-31 20:05:18 +00:00
|
|
|
/* nibble<.ds@gmail.com> */
|
|
|
|
/* pancake<nopcode.org> */
|
2009-02-06 17:22:27 +00:00
|
|
|
|
|
|
|
#ifndef _INCLUDE_R_ANAL_H_
|
|
|
|
#define _INCLUDE_R_ANAL_H_
|
|
|
|
|
|
|
|
#include "r_types.h"
|
2009-02-15 23:57:03 +00:00
|
|
|
#include "list.h"
|
|
|
|
|
2010-01-31 01:30:59 +00:00
|
|
|
// deprecate this macro?
|
2009-05-01 23:08:57 +00:00
|
|
|
#define R_ANAL_MAXREG 16
|
|
|
|
|
2009-04-02 10:23:32 +00:00
|
|
|
enum {
|
2009-10-12 15:41:52 +00:00
|
|
|
R_ANAL_OP_FAMILY_UNKNOWN = 0,
|
|
|
|
R_ANAL_OP_FAMILY_CPU, /* normal cpu insturction */
|
|
|
|
R_ANAL_OP_FAMILY_FPU, /* fpu (floating point) */
|
|
|
|
R_ANAL_OP_FAMILY_MMX, /* multimedia instruction (packed data) */
|
|
|
|
R_ANAL_OP_FAMILY_PRIV, /* priviledged instruction */
|
|
|
|
R_ANAL_OP_FAMILY_LAST
|
2009-04-02 10:23:32 +00:00
|
|
|
};
|
|
|
|
|
2009-02-06 17:22:27 +00:00
|
|
|
enum {
|
2009-10-12 15:41:52 +00:00
|
|
|
R_ANAL_OP_TYPE_NULL = 0,
|
|
|
|
R_ANAL_OP_TYPE_JMP, /* mandatory jump */
|
|
|
|
R_ANAL_OP_TYPE_UJMP, /* unknown jump (register or so) */
|
|
|
|
R_ANAL_OP_TYPE_CJMP, /* conditional jump */
|
|
|
|
R_ANAL_OP_TYPE_CALL, /* call to subroutine (branch+link) */
|
|
|
|
R_ANAL_OP_TYPE_RCALL, /* call to register */
|
|
|
|
R_ANAL_OP_TYPE_REP, /* repeats next instruction N times */
|
|
|
|
R_ANAL_OP_TYPE_RET, /* returns from subrutine */
|
|
|
|
R_ANAL_OP_TYPE_ILL, /* illegal instruction // trap */
|
|
|
|
R_ANAL_OP_TYPE_UNK, /* unknown opcode type */
|
|
|
|
R_ANAL_OP_TYPE_NOP, /* does nothing */
|
|
|
|
R_ANAL_OP_TYPE_MOV, /* register move */
|
|
|
|
R_ANAL_OP_TYPE_TRAP, /* it's a trap! */
|
|
|
|
R_ANAL_OP_TYPE_SWI, /* syscall, software interrupt */
|
|
|
|
R_ANAL_OP_TYPE_UPUSH, /* unknown push of data into stack */
|
|
|
|
R_ANAL_OP_TYPE_PUSH, /* push value into stack */
|
|
|
|
R_ANAL_OP_TYPE_POP, /* pop value from stack to register */
|
|
|
|
R_ANAL_OP_TYPE_CMP, /* copmpare something */
|
|
|
|
R_ANAL_OP_TYPE_ADD,
|
|
|
|
R_ANAL_OP_TYPE_SUB,
|
|
|
|
R_ANAL_OP_TYPE_MUL,
|
|
|
|
R_ANAL_OP_TYPE_DIV,
|
|
|
|
R_ANAL_OP_TYPE_SHR,
|
|
|
|
R_ANAL_OP_TYPE_SHL,
|
|
|
|
R_ANAL_OP_TYPE_OR,
|
|
|
|
R_ANAL_OP_TYPE_AND,
|
|
|
|
R_ANAL_OP_TYPE_XOR,
|
|
|
|
R_ANAL_OP_TYPE_NOT,
|
|
|
|
R_ANAL_OP_TYPE_STORE, /* store from register to memory */
|
|
|
|
R_ANAL_OP_TYPE_LOAD, /* load from memory to register */
|
|
|
|
R_ANAL_OP_TYPE_LAST
|
2009-02-06 17:22:27 +00:00
|
|
|
};
|
|
|
|
|
2009-08-19 16:38:35 +00:00
|
|
|
/* TODO: what to do with signed/unsigned conditionals? */
|
|
|
|
enum {
|
2009-10-12 15:41:52 +00:00
|
|
|
R_ANAL_OP_COND_EQ,
|
|
|
|
R_ANAL_OP_COND_NE,
|
|
|
|
R_ANAL_OP_COND_GE,
|
|
|
|
R_ANAL_OP_COND_GT,
|
|
|
|
R_ANAL_OP_COND_LE,
|
|
|
|
R_ANAL_OP_COND_LT,
|
2009-08-19 16:38:35 +00:00
|
|
|
};
|
|
|
|
|
2009-02-06 17:22:27 +00:00
|
|
|
enum {
|
|
|
|
R_ANAL_DATA_NULL = 0,
|
|
|
|
R_ANAL_DATA_HEX, /* hex byte pairs */
|
|
|
|
R_ANAL_DATA_STR, /* ascii string */
|
|
|
|
R_ANAL_DATA_CODE, /* plain assembly code */
|
|
|
|
R_ANAL_DATA_FUN, /* plain assembly code */
|
2009-04-11 21:22:20 +00:00
|
|
|
R_ANAL_DATA_STRUCT, /* memory */
|
|
|
|
R_ANAL_DATA_LAST
|
2009-02-06 17:22:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
R_ANAL_BLK_TYPE_NULL = 0,
|
|
|
|
R_ANAL_BLK_TYPE_HEAD, /* first block */
|
|
|
|
R_ANAL_BLK_TYPE_BODY, /* conditional jump */
|
|
|
|
R_ANAL_BLK_TYPE_LAST, /* ret */
|
|
|
|
R_ANAL_BLK_TYPE_FOOT /* unknown jump */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
R_ANAL_STACK_NULL = 0,
|
2009-02-08 23:19:06 +00:00
|
|
|
R_ANAL_STACK_NOP,
|
|
|
|
R_ANAL_STACK_INCSTACK,
|
2009-02-06 17:22:27 +00:00
|
|
|
R_ANAL_STACK_LOCAL_GET,
|
|
|
|
R_ANAL_STACK_LOCAL_SET,
|
|
|
|
R_ANAL_STACK_ARG_GET,
|
|
|
|
R_ANAL_STACK_ARG_SET
|
|
|
|
};
|
|
|
|
|
2009-04-01 22:41:10 +00:00
|
|
|
enum {
|
2009-04-11 21:22:20 +00:00
|
|
|
R_ANAL_REFLINE_STYLE = 1,
|
|
|
|
R_ANAL_REFLINE_WIDE = 2,
|
2009-04-01 22:41:10 +00:00
|
|
|
};
|
|
|
|
|
2010-02-18 15:36:55 +00:00
|
|
|
typedef struct r_anal_refline_t {
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 from;
|
|
|
|
ut64 to;
|
2009-03-31 22:32:26 +00:00
|
|
|
int index;
|
|
|
|
struct list_head list;
|
2010-01-26 00:28:33 +00:00
|
|
|
} RAnalysisRefline;
|
2009-02-15 23:57:03 +00:00
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
typedef struct r_anal_aop_t {
|
2010-01-31 01:30:59 +00:00
|
|
|
int type; /* type of opcode */
|
|
|
|
int stackop; /* operation on stack? */
|
|
|
|
int cond; /* condition type */
|
|
|
|
int length; /* length in bytes of opcode */
|
|
|
|
int family; /* family of opcode */
|
|
|
|
int eob; /* end of block (boolean) */
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 jump; /* true jmp */
|
|
|
|
ut64 fail; /* false jmp */
|
|
|
|
ut64 ref; /* reference to memory */
|
|
|
|
ut64 value; /* reference to value */
|
2010-01-31 01:30:59 +00:00
|
|
|
int r_dst[R_ANAL_MAXREG]; /* register arguments */
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 i_dst[R_ANAL_MAXREG]; /* inmediate arguments */
|
2010-01-26 00:28:33 +00:00
|
|
|
} RAnalysisAop;
|
2009-02-06 17:22:27 +00:00
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
typedef struct r_anal_function_t {
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 from;
|
|
|
|
ut64 to;
|
2010-01-26 00:28:33 +00:00
|
|
|
} RAnalysisFunction;
|
2009-05-01 23:08:57 +00:00
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
typedef struct r_anal_t {
|
2009-03-31 22:32:26 +00:00
|
|
|
int bits;
|
|
|
|
int big_endian;
|
|
|
|
void *user;
|
2009-11-23 16:49:40 +00:00
|
|
|
struct r_anal_ctx_t *ctx;
|
2009-03-31 22:32:26 +00:00
|
|
|
struct r_anal_handle_t *cur;
|
|
|
|
struct list_head anals;
|
2010-01-26 00:28:33 +00:00
|
|
|
} RAnalysis;
|
2009-03-31 22:32:26 +00:00
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
typedef struct r_anal_ctx_t {
|
2009-10-12 15:41:52 +00:00
|
|
|
/* TODO: add more info here */
|
|
|
|
/* per opcode deep level */
|
|
|
|
/* per opcode stack size */
|
|
|
|
/* basic blocks */
|
|
|
|
int stacksize;
|
|
|
|
struct r_anal_t *anal;
|
2010-01-26 00:28:33 +00:00
|
|
|
} RAnalysisContext;
|
2009-10-12 15:41:52 +00:00
|
|
|
|
2010-02-22 03:02:13 +00:00
|
|
|
|
|
|
|
//TODO: typedef RAnalysisAopCallback
|
2010-01-26 00:28:33 +00:00
|
|
|
typedef struct r_anal_handle_t {
|
2009-02-16 01:12:02 +00:00
|
|
|
char *name;
|
|
|
|
char *desc;
|
|
|
|
int (*init)(void *user);
|
|
|
|
int (*fini)(void *user);
|
2010-02-22 03:02:13 +00:00
|
|
|
// TODO: typedef
|
|
|
|
int (*aop)(struct r_anal_t *a, struct r_anal_aop_t *aop, ut64 addr, const ut8 *data, int len);
|
2009-02-16 01:12:02 +00:00
|
|
|
struct list_head list;
|
2010-01-26 00:28:33 +00:00
|
|
|
} RAnalysisHandle;
|
2009-02-16 01:12:02 +00:00
|
|
|
|
2009-02-06 17:22:27 +00:00
|
|
|
/* anal.c */
|
2009-12-24 02:17:53 +00:00
|
|
|
#ifdef R_API
|
2010-01-31 01:30:59 +00:00
|
|
|
R_API struct r_anal_t *r_anal_init(struct r_anal_t *anal);
|
2009-12-24 02:17:53 +00:00
|
|
|
R_API struct r_anal_t *r_anal_free(struct r_anal_t *r);
|
|
|
|
R_API struct r_anal_t *r_anal_new();
|
|
|
|
R_API void r_anal_set_user_ptr(struct r_anal_t *anal, void *user);
|
|
|
|
R_API int r_anal_add(struct r_anal_t *anal, struct r_anal_handle_t *foo);
|
|
|
|
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);
|
|
|
|
R_API int r_anal_set_bits(struct r_anal_t *anal, int bits);
|
|
|
|
R_API int r_anal_set_big_endian(struct r_anal_t *anal, int boolean);
|
|
|
|
R_API int r_anal_set_pc(struct r_anal_t *a, ut64 pc);
|
2010-02-22 03:02:13 +00:00
|
|
|
R_API int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop,
|
|
|
|
ut64 addr, void *data, int len);
|
|
|
|
R_API struct r_anal_refline_t *r_anal_reflines_get(struct r_anal_t *anal,
|
|
|
|
ut64 addr, ut8 *buf, ut64 len, int nlines, int linesout);
|
|
|
|
R_API int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *list,
|
|
|
|
ut64 addr, char *str, int opts);
|
2009-12-24 02:17:53 +00:00
|
|
|
#endif
|
2009-02-06 17:22:27 +00:00
|
|
|
#endif
|