2011-01-26 20:54:39 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2011 // 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_
|
|
|
|
|
2010-02-26 12:08:42 +00:00
|
|
|
#include <r_types.h>
|
|
|
|
#include <list.h>
|
2011-02-02 23:20:39 +00:00
|
|
|
#include <r_io.h>
|
2010-06-16 07:42:46 +00:00
|
|
|
#include <r_reg.h>
|
2010-02-26 12:08:42 +00:00
|
|
|
#include <r_list.h>
|
2010-05-24 09:15:32 +00:00
|
|
|
#include <r_util.h>
|
2011-02-02 12:05:48 +00:00
|
|
|
#include <r_syscall.h>
|
2009-02-15 23:57:03 +00:00
|
|
|
|
2011-02-11 10:22:43 +00:00
|
|
|
#define VERBOSE_ANAL if(0)
|
|
|
|
|
2011-03-01 23:02:50 +00:00
|
|
|
/* meta */
|
|
|
|
typedef struct r_meta_item_t {
|
|
|
|
ut64 from;
|
|
|
|
ut64 to;
|
|
|
|
ut64 size;
|
|
|
|
int type;
|
|
|
|
char *str;
|
|
|
|
} RMetaItem;
|
|
|
|
|
|
|
|
typedef struct r_meta_t {
|
|
|
|
RList *data;
|
|
|
|
PrintfCallback printf;
|
|
|
|
} RMeta;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
R_META_WHERE_PREV = -1,
|
|
|
|
R_META_WHERE_HERE = 0,
|
|
|
|
R_META_WHERE_NEXT = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
R_META_TYPE_ANY = -1,
|
|
|
|
R_META_TYPE_DATA = 'd',
|
|
|
|
R_META_TYPE_CODE = 'c',
|
|
|
|
R_META_TYPE_STRING = 's',
|
|
|
|
R_META_TYPE_FORMAT = 'f',
|
|
|
|
R_META_TYPE_MAGIC = 'm',
|
|
|
|
R_META_TYPE_COMMENT = 'C',
|
|
|
|
};
|
|
|
|
|
|
|
|
// anal
|
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 {
|
2010-09-05 19:20:56 +00:00
|
|
|
R_ANAL_OP_TYPE_NULL = 0x0,
|
|
|
|
R_ANAL_OP_TYPE_JMP = 0x1, /* mandatory jump */
|
|
|
|
R_ANAL_OP_TYPE_UJMP = 0x2, /* unknown jump (register or so) */
|
|
|
|
R_ANAL_OP_TYPE_CJMP = 0x4, /* conditional jump */
|
|
|
|
R_ANAL_OP_TYPE_CALL = 0x8, /* call to subroutine (branch+link) */
|
|
|
|
R_ANAL_OP_TYPE_UCALL = 0x10, /* unknown call (register or so) */
|
|
|
|
R_ANAL_OP_TYPE_REP = 0x20, /* repeats next instruction N times */
|
|
|
|
R_ANAL_OP_TYPE_RET = 0x40, /* returns from subrutine */
|
2010-07-02 00:01:51 +00:00
|
|
|
R_ANAL_OP_TYPE_ILL = 0x80, /* illegal instruction // trap */
|
|
|
|
R_ANAL_OP_TYPE_UNK = 0x100, /* unknown opcode type */
|
|
|
|
R_ANAL_OP_TYPE_NOP = 0x200, /* does nothing */
|
|
|
|
R_ANAL_OP_TYPE_MOV = 0x400, /* register move */
|
|
|
|
R_ANAL_OP_TYPE_TRAP = 0x800, /* it's a trap! */
|
|
|
|
R_ANAL_OP_TYPE_SWI = 0x1000, /* syscall, software interrupt */
|
2010-05-24 15:51:51 +00:00
|
|
|
R_ANAL_OP_TYPE_UPUSH = 0x2000, /* unknown push of data into stack */
|
2010-07-02 00:01:51 +00:00
|
|
|
R_ANAL_OP_TYPE_PUSH = 0x4000, /* push value into stack */
|
|
|
|
R_ANAL_OP_TYPE_POP = 0x8000, /* pop value from stack to register */
|
|
|
|
R_ANAL_OP_TYPE_CMP = 0x10000, /* copmpare something */
|
|
|
|
R_ANAL_OP_TYPE_ADD = 0x20000,
|
|
|
|
R_ANAL_OP_TYPE_SUB = 0x40000,
|
|
|
|
R_ANAL_OP_TYPE_MUL = 0x100000,
|
|
|
|
R_ANAL_OP_TYPE_DIV = 0x200000,
|
|
|
|
R_ANAL_OP_TYPE_SHR = 0x400000,
|
|
|
|
R_ANAL_OP_TYPE_SHL = 0x800000,
|
|
|
|
R_ANAL_OP_TYPE_OR = 0x1000000,
|
|
|
|
R_ANAL_OP_TYPE_AND = 0x2000000,
|
|
|
|
R_ANAL_OP_TYPE_XOR = 0x4000000,
|
|
|
|
R_ANAL_OP_TYPE_NOT = 0x8000000,
|
2010-09-05 19:20:56 +00:00
|
|
|
R_ANAL_OP_TYPE_STORE = 0x10000000, /* store from register to memory */
|
2010-05-24 15:51:51 +00:00
|
|
|
R_ANAL_OP_TYPE_LOAD = 0x20000000, /* load from memory to register */
|
2011-03-01 18:16:29 +00:00
|
|
|
R_ANAL_OP_TYPE_LEA = 0x40000000,
|
|
|
|
R_ANAL_OP_TYPE_LEAVE = 0x80000000,
|
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 {
|
2010-06-16 07:42:46 +00:00
|
|
|
R_ANAL_COND_EQ = 0,
|
|
|
|
R_ANAL_COND_NE,
|
|
|
|
R_ANAL_COND_GE,
|
|
|
|
R_ANAL_COND_GT,
|
|
|
|
R_ANAL_COND_LE,
|
|
|
|
R_ANAL_COND_LT,
|
2009-08-19 16:38:35 +00:00
|
|
|
};
|
|
|
|
|
2010-03-11 16:19:33 +00:00
|
|
|
enum {
|
2010-12-03 12:52:11 +00:00
|
|
|
R_ANAL_VAR_TYPE_NULL = 0,
|
|
|
|
R_ANAL_VAR_TYPE_GLOBAL = 0x01,
|
|
|
|
R_ANAL_VAR_TYPE_LOCAL = 0x02,
|
|
|
|
R_ANAL_VAR_TYPE_ARG = 0x04,
|
|
|
|
R_ANAL_VAR_TYPE_ARGREG = 0x08,
|
|
|
|
R_ANAL_VAR_TYPE_RET = 0x10,
|
2010-03-11 16:19:33 +00:00
|
|
|
};
|
2010-12-06 15:26:21 +00:00
|
|
|
|
2010-12-03 12:52:11 +00:00
|
|
|
typedef enum {
|
|
|
|
R_ANAL_VAR_DIR_NONE = 0,
|
|
|
|
R_ANAL_VAR_DIR_IN = 0x100,
|
|
|
|
R_ANAL_VAR_DIR_OUT = 0x200
|
|
|
|
} _RAnalVarDir;
|
2010-03-11 16:19:33 +00:00
|
|
|
|
2010-05-21 15:35:05 +00:00
|
|
|
typedef enum {
|
2009-02-06 17:22:27 +00:00
|
|
|
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
|
2010-10-28 10:10:21 +00:00
|
|
|
} _RAnalData;
|
2009-02-06 17:22:27 +00:00
|
|
|
|
2010-05-21 15:35:05 +00:00
|
|
|
typedef enum {
|
2010-02-26 12:08:42 +00:00
|
|
|
R_ANAL_BB_TYPE_NULL = 0,
|
2010-05-21 17:20:42 +00:00
|
|
|
R_ANAL_BB_TYPE_HEAD = 0x1, /* first block */
|
|
|
|
R_ANAL_BB_TYPE_BODY = 0x2, /* conditional jump */
|
|
|
|
R_ANAL_BB_TYPE_LAST = 0x4, /* ret */
|
2010-11-23 16:15:33 +00:00
|
|
|
R_ANAL_BB_TYPE_FOOT = 0x8, /* unknown jump */
|
|
|
|
R_ANAL_BB_TYPE_SWITCH = 0x10 /* TODO: switch */
|
2010-10-28 10:10:21 +00:00
|
|
|
} _RAnalBlockType;
|
2009-02-06 17:22:27 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
R_ANAL_STACK_NULL = 0,
|
2009-02-08 23:19:06 +00:00
|
|
|
R_ANAL_STACK_NOP,
|
|
|
|
R_ANAL_STACK_INCSTACK,
|
2010-05-14 21:04:10 +00:00
|
|
|
R_ANAL_STACK_GET,
|
|
|
|
R_ANAL_STACK_SET,
|
2009-02-06 17:22:27 +00:00
|
|
|
};
|
|
|
|
|
2011-06-14 02:49:10 +00:00
|
|
|
enum {
|
2010-10-27 22:55:07 +00:00
|
|
|
R_ANAL_REFLINE_TYPE_STYLE = 1,
|
|
|
|
R_ANAL_REFLINE_TYPE_WIDE = 2,
|
2011-06-14 02:49:10 +00:00
|
|
|
};
|
2009-04-01 22:41:10 +00:00
|
|
|
|
2010-03-01 15:50:37 +00:00
|
|
|
enum {
|
|
|
|
R_ANAL_RET_ERROR = -1,
|
2010-03-05 17:55:39 +00:00
|
|
|
R_ANAL_RET_DUP = -2,
|
|
|
|
R_ANAL_RET_NEW = -3,
|
|
|
|
R_ANAL_RET_END = -4
|
2010-03-01 15:50:37 +00:00
|
|
|
};
|
|
|
|
|
2010-03-19 12:51:28 +00:00
|
|
|
typedef struct r_anal_t {
|
2010-02-26 12:08:42 +00:00
|
|
|
int bits;
|
2011-02-03 08:31:50 +00:00
|
|
|
int lineswidth;
|
2010-02-26 12:08:42 +00:00
|
|
|
int big_endian;
|
2010-11-20 15:47:15 +00:00
|
|
|
int split;
|
2010-02-26 12:08:42 +00:00
|
|
|
void *user;
|
2010-03-03 11:08:27 +00:00
|
|
|
RList *fcns;
|
2010-09-28 11:58:03 +00:00
|
|
|
RList *refs;
|
2010-03-11 18:52:05 +00:00
|
|
|
RList *vartypes;
|
2011-03-01 23:02:50 +00:00
|
|
|
RMeta *meta;
|
2010-09-18 00:51:17 +00:00
|
|
|
RReg *reg;
|
2011-02-02 12:05:48 +00:00
|
|
|
RSyscall *syscall;
|
2011-03-28 08:24:01 +00:00
|
|
|
struct r_anal_op_t *queued;
|
2011-02-02 23:20:39 +00:00
|
|
|
RIOBind iob;
|
2010-02-26 12:08:42 +00:00
|
|
|
struct r_anal_ctx_t *ctx;
|
2010-05-25 23:42:22 +00:00
|
|
|
struct r_anal_plugin_t *cur;
|
2011-02-03 08:31:50 +00:00
|
|
|
struct list_head anals; // TODO: Reimplement with RList
|
2010-03-19 11:00:04 +00:00
|
|
|
} RAnal;
|
2009-02-15 23:57:03 +00:00
|
|
|
|
2010-06-16 19:44:19 +00:00
|
|
|
// mul*value+regbase+regidx+delta
|
|
|
|
typedef struct r_anal_value_t {
|
2010-06-17 00:22:50 +00:00
|
|
|
int absolute; // if true, unsigned cast is used
|
2010-06-16 23:48:51 +00:00
|
|
|
int memref; // is memory reference? which size? 1, 2 ,4, 8
|
2010-06-16 19:44:19 +00:00
|
|
|
ut64 base ; // numeric address
|
2010-09-22 16:31:15 +00:00
|
|
|
st64 delta; // numeric delta
|
2010-09-23 11:25:46 +00:00
|
|
|
st64 imm; // immediate value
|
2010-06-16 19:44:19 +00:00
|
|
|
int mul; // multiplier (reg*4+base)
|
2010-09-22 16:31:15 +00:00
|
|
|
ut16 sel; // segment selector
|
2010-09-18 00:51:17 +00:00
|
|
|
RRegItem *reg; // register index used (-1 if no reg)
|
|
|
|
RRegItem *regdelta; // register index used (-1 if no reg)
|
2010-06-16 19:44:19 +00:00
|
|
|
} RAnalValue;
|
|
|
|
|
2011-02-24 13:06:49 +00:00
|
|
|
typedef struct r_anal_op_t {
|
2010-06-16 07:42:46 +00:00
|
|
|
char *mnemonic; /* mnemonic */
|
|
|
|
ut64 addr; /* address */
|
|
|
|
int type; /* type of opcode */
|
|
|
|
int stackop; /* operation on stack? */
|
|
|
|
int cond; /* condition type */
|
|
|
|
int length; /* length in bytes of opcode */
|
2010-06-23 15:30:16 +00:00
|
|
|
int nopcode; /* number of bytes representing the opcode (not the arguments) */
|
2010-06-16 07:42:46 +00:00
|
|
|
int family; /* family of opcode */
|
|
|
|
int eob; /* end of block (boolean) */
|
2011-03-28 08:24:01 +00:00
|
|
|
/* Run N instructions before executing the current one */
|
|
|
|
int delay; /* delay N slots (mips, ..)*/
|
2010-06-16 07:42:46 +00:00
|
|
|
ut64 jump; /* true jmp */
|
|
|
|
ut64 fail; /* false jmp */
|
2010-09-05 19:20:56 +00:00
|
|
|
ut32 selector; /* segment selector */
|
2010-06-16 07:42:46 +00:00
|
|
|
st64 ref; /* reference to memory */ /* XXX signed? */
|
|
|
|
ut64 value; /* reference to value */ /* XXX signed? */
|
|
|
|
st64 stackptr; /* stack pointer */
|
2010-06-16 19:44:19 +00:00
|
|
|
RAnalValue *src[3];
|
|
|
|
RAnalValue *dst;
|
2010-06-02 21:36:05 +00:00
|
|
|
int refptr;
|
2011-03-28 08:24:01 +00:00
|
|
|
struct r_anal_op_t *next;
|
2010-05-20 23:46:26 +00:00
|
|
|
} RAnalOp;
|
2009-02-06 17:22:27 +00:00
|
|
|
|
2010-06-16 07:42:46 +00:00
|
|
|
#define R_ANAL_COND_SINGLE(x) (!x->arg[1] || x->arg[0]==x->arg[1])
|
2010-06-14 14:20:54 +00:00
|
|
|
|
|
|
|
typedef struct r_anal_cond_t {
|
2010-06-16 07:42:46 +00:00
|
|
|
int type; // filled by CJMP opcode
|
|
|
|
RAnalValue *arg[2]; // filled by CMP opcode
|
2010-06-14 14:20:54 +00:00
|
|
|
} RAnalCond;
|
|
|
|
|
2010-12-05 07:46:56 +00:00
|
|
|
enum {
|
|
|
|
R_ANAL_DIFF_TYPE_NULL = 0,
|
|
|
|
R_ANAL_DIFF_TYPE_MATCH = 'm',
|
|
|
|
R_ANAL_DIFF_TYPE_UNMATCH = 'u'
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct r_anal_diff_t {
|
|
|
|
int type;
|
|
|
|
ut64 addr;
|
|
|
|
char *name;
|
|
|
|
} RAnalDiff;
|
|
|
|
|
2010-02-26 12:08:42 +00:00
|
|
|
typedef struct r_anal_bb_t {
|
|
|
|
ut64 addr;
|
|
|
|
ut64 size;
|
|
|
|
ut64 jump;
|
|
|
|
ut64 fail;
|
2010-05-21 16:23:01 +00:00
|
|
|
int type;
|
2010-05-23 10:51:37 +00:00
|
|
|
int ninstr;
|
2011-02-11 10:22:43 +00:00
|
|
|
int returnbb;
|
2010-11-22 14:14:54 +00:00
|
|
|
int conditional;
|
2010-06-18 09:09:19 +00:00
|
|
|
int traced;
|
2010-12-04 14:14:53 +00:00
|
|
|
ut8 *fingerprint;
|
2010-12-05 07:46:56 +00:00
|
|
|
RAnalDiff *diff;
|
2011-02-24 13:06:49 +00:00
|
|
|
RList *ops;
|
2010-06-14 22:46:18 +00:00
|
|
|
RAnalCond *cond;
|
2010-05-20 23:46:26 +00:00
|
|
|
} RAnalBlock;
|
2009-03-31 22:32:26 +00:00
|
|
|
|
2011-01-26 20:54:39 +00:00
|
|
|
enum {
|
|
|
|
R_ANAL_CC_TYPE_CDECL,
|
|
|
|
R_ANAL_CC_TYPE_STDCALL,
|
|
|
|
R_ANAL_CC_TYPE_FASTCALL,
|
|
|
|
R_ANAL_CC_TYPE_PASCAL,
|
|
|
|
R_ANAL_CC_TYPE_MSFASTCALL, // microsoft fastcall
|
|
|
|
R_ANAL_CC_TYPE_BOFASTCALL, // borland fastcall
|
|
|
|
R_ANAL_CC_TYPE_WAFASTCALL, // wacom fastcall
|
|
|
|
R_ANAL_CC_TYPE_CLARION,
|
|
|
|
R_ANAL_CC_TYPE_SYSV,
|
|
|
|
};
|
|
|
|
|
2011-02-02 23:20:39 +00:00
|
|
|
#define R_ANAL_CC_ARGS 16
|
2011-01-26 20:54:39 +00:00
|
|
|
typedef struct r_anal_cc_t {
|
|
|
|
int type;
|
|
|
|
int bits;
|
|
|
|
int rel; // relative or absolute?
|
|
|
|
ut64 off; // offset of the call instruction (caller)
|
2011-02-02 12:05:48 +00:00
|
|
|
ut64 jump; // offset of the call instruction (caller)
|
|
|
|
int nargs;
|
2011-02-02 23:20:39 +00:00
|
|
|
ut64 args[R_ANAL_CC_ARGS];
|
2011-01-26 20:54:39 +00:00
|
|
|
// TODO: Store arguments someway
|
|
|
|
} RAnalCC;
|
|
|
|
|
|
|
|
typedef struct r_anal_cc_type_t {
|
|
|
|
int rtl; // right-to-left? if false use left-to-right
|
|
|
|
int alignstack;
|
|
|
|
//
|
|
|
|
//const char **reglist; //
|
|
|
|
} RAnalCCType;
|
2010-06-17 15:55:39 +00:00
|
|
|
|
2010-11-23 16:15:33 +00:00
|
|
|
enum {
|
|
|
|
R_ANAL_FCN_TYPE_NULL = 0,
|
2011-02-07 16:43:50 +00:00
|
|
|
R_ANAL_FCN_TYPE_FCN = 1,
|
|
|
|
R_ANAL_FCN_TYPE_LOC = 2,
|
|
|
|
R_ANAL_FCN_TYPE_SYM = 4,
|
|
|
|
R_ANAL_FCN_TYPE_IMP = 8
|
2010-12-06 15:26:21 +00:00
|
|
|
};
|
2010-11-23 16:15:33 +00:00
|
|
|
|
2011-02-26 18:16:08 +00:00
|
|
|
#define R_ANAL_VARSUBS 32
|
2011-02-26 13:58:54 +00:00
|
|
|
typedef struct r_anal_varsub_t {
|
|
|
|
char pat[1024];
|
|
|
|
char sub[1024];
|
|
|
|
} RAnalVarSub;
|
2011-02-23 14:17:06 +00:00
|
|
|
|
2010-03-03 11:08:27 +00:00
|
|
|
typedef struct r_anal_fcn_t {
|
|
|
|
char *name;
|
|
|
|
ut64 addr;
|
2010-03-18 21:22:21 +00:00
|
|
|
ut64 size;
|
2010-11-23 16:15:33 +00:00
|
|
|
int type;
|
2011-01-26 20:54:39 +00:00
|
|
|
int calltype; /* See R_ANAL_CC_TYPE_ */
|
2010-05-19 00:39:01 +00:00
|
|
|
int stack;
|
2010-05-23 10:51:37 +00:00
|
|
|
int ninstr;
|
2010-12-03 12:52:11 +00:00
|
|
|
int nargs;
|
2011-02-26 18:16:08 +00:00
|
|
|
RAnalVarSub varsubs[R_ANAL_VARSUBS];
|
2010-12-04 14:14:53 +00:00
|
|
|
ut8 *fingerprint;
|
2010-12-05 07:46:56 +00:00
|
|
|
RAnalDiff *diff;
|
2010-12-24 12:27:20 +00:00
|
|
|
RList *bbs;
|
2010-03-07 13:00:26 +00:00
|
|
|
RList *vars;
|
2010-03-03 11:08:27 +00:00
|
|
|
RList *refs;
|
|
|
|
RList *xrefs;
|
2010-03-19 11:00:04 +00:00
|
|
|
} RAnalFcn;
|
2010-03-03 11:08:27 +00:00
|
|
|
|
2010-07-02 00:01:51 +00:00
|
|
|
typedef struct r_anal_var_access_t {
|
|
|
|
ut64 addr;
|
|
|
|
int set;
|
|
|
|
} RAnalVarAccess;
|
|
|
|
|
2010-03-07 13:00:26 +00:00
|
|
|
typedef struct r_anal_var_t {
|
2010-07-12 19:37:40 +00:00
|
|
|
char *name; /* name of the variable */
|
2010-08-22 16:41:57 +00:00
|
|
|
ut64 addr; // not used correctly?
|
|
|
|
ut64 eaddr; // not used correctly?
|
2010-07-12 19:37:40 +00:00
|
|
|
int delta; /* delta offset inside stack frame */
|
2010-12-03 12:52:11 +00:00
|
|
|
int type; /* global, local... | in, out... */
|
2010-07-12 19:37:40 +00:00
|
|
|
int array; /* array size */
|
|
|
|
char *vartype; /* float, int... */
|
2010-07-02 00:01:51 +00:00
|
|
|
/* probably dupped or so */
|
|
|
|
RList/*RAnalVarAccess*/ *accesses; /* list of accesses for this var */
|
|
|
|
RList/*RAnalValue*/ *stores; /* where this */
|
2010-03-19 11:00:04 +00:00
|
|
|
} RAnalVar;
|
2010-03-11 16:19:33 +00:00
|
|
|
|
2010-03-11 18:52:05 +00:00
|
|
|
typedef struct r_anal_var_type_t {
|
|
|
|
char *name;
|
|
|
|
char *fmt;
|
2011-02-07 16:43:50 +00:00
|
|
|
ut32 size;
|
2010-03-19 11:00:04 +00:00
|
|
|
} RAnalVarType;
|
2010-03-11 16:19:33 +00:00
|
|
|
|
2011-06-14 02:49:10 +00:00
|
|
|
typedef enum {
|
2010-11-23 13:05:23 +00:00
|
|
|
R_ANAL_REF_TYPE_NULL = 0,
|
2010-07-02 00:01:51 +00:00
|
|
|
R_ANAL_REF_TYPE_CODE = 'c', // code ref
|
2010-11-23 13:05:23 +00:00
|
|
|
R_ANAL_REF_TYPE_CALL = 'C', // code ref (call)
|
2011-02-07 23:15:12 +00:00
|
|
|
R_ANAL_REF_TYPE_DATA = 'd' // mem ref
|
2010-06-13 22:57:40 +00:00
|
|
|
} RAnalRefType;
|
|
|
|
|
|
|
|
typedef struct r_anal_ref_t {
|
|
|
|
int type;
|
|
|
|
ut64 addr;
|
2010-09-28 11:58:03 +00:00
|
|
|
ut64 at;
|
2010-06-13 22:57:40 +00:00
|
|
|
} RAnalRef;
|
2009-10-12 15:41:52 +00:00
|
|
|
|
2010-02-26 12:08:42 +00:00
|
|
|
typedef struct r_anal_refline_t {
|
|
|
|
ut64 from;
|
|
|
|
ut64 to;
|
|
|
|
int index;
|
|
|
|
struct list_head list;
|
2010-03-19 11:00:04 +00:00
|
|
|
} RAnalRefline;
|
2010-02-22 03:02:13 +00:00
|
|
|
|
2011-02-24 13:06:49 +00:00
|
|
|
typedef int (*RAnalOpCallback)(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *data, int len);
|
2011-02-18 12:08:09 +00:00
|
|
|
typedef int (*RAnalRegProfCallback)(RAnal *a);
|
2011-03-06 14:21:13 +00:00
|
|
|
typedef int (*RAnalFPBBCallback)(RAnal *a, RAnalBlock *bb);
|
|
|
|
typedef int (*RAnalFPFcnCallback)(RAnal *a, RAnalFcn *fcn);
|
|
|
|
typedef int (*RAnalDiffBBCallback)(RAnal *anal, RAnalFcn *fcn, RAnalFcn *fcn2);
|
|
|
|
typedef int (*RAnalDiffFcnCallback)(RAnal *anal, RList *fcns, RList *fcns2);
|
|
|
|
typedef int (*RAnalDiffEvalCallback)(RAnal *anal);
|
2010-07-02 00:01:51 +00:00
|
|
|
|
2010-05-25 23:42:22 +00:00
|
|
|
typedef struct r_anal_plugin_t {
|
2009-02-16 01:12:02 +00:00
|
|
|
char *name;
|
|
|
|
char *desc;
|
2011-05-06 17:56:16 +00:00
|
|
|
int arch;
|
|
|
|
int bits;
|
2009-02-16 01:12:02 +00:00
|
|
|
int (*init)(void *user);
|
|
|
|
int (*fini)(void *user);
|
2011-02-24 13:06:49 +00:00
|
|
|
RAnalOpCallback op;
|
2011-02-18 12:08:09 +00:00
|
|
|
RAnalRegProfCallback set_reg_profile;
|
2011-03-06 14:21:13 +00:00
|
|
|
RAnalFPBBCallback fingerprint_bb;
|
|
|
|
RAnalFPFcnCallback fingerprint_fcn;
|
|
|
|
RAnalDiffBBCallback diff_bb;
|
|
|
|
RAnalDiffFcnCallback diff_fcn;
|
|
|
|
RAnalDiffEvalCallback diff_eval;
|
2009-02-16 01:12:02 +00:00
|
|
|
struct list_head list;
|
2010-05-25 23:42:22 +00:00
|
|
|
} RAnalPlugin;
|
2009-02-16 01:12:02 +00:00
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
#ifdef R_API
|
2010-03-12 02:05:20 +00:00
|
|
|
/* anal.c */
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API RAnal *r_anal_new();
|
2010-03-19 11:23:14 +00:00
|
|
|
R_API RAnal *r_anal_free(RAnal *r);
|
|
|
|
R_API void r_anal_set_user_ptr(RAnal *anal, void *user);
|
2010-05-25 23:42:22 +00:00
|
|
|
R_API int r_anal_add(RAnal *anal, struct r_anal_plugin_t *foo);
|
2010-03-19 11:23:14 +00:00
|
|
|
R_API int r_anal_list(RAnal *anal);
|
|
|
|
R_API int r_anal_use(RAnal *anal, const char *name);
|
2011-02-18 12:08:09 +00:00
|
|
|
R_API int r_anal_set_reg_profile(RAnal *anal);
|
2010-03-19 11:23:14 +00:00
|
|
|
R_API int r_anal_set_bits(RAnal *anal, int bits);
|
|
|
|
R_API int r_anal_set_big_endian(RAnal *anal, int boolean);
|
2010-05-16 12:04:08 +00:00
|
|
|
R_API char *r_anal_strmask (RAnal *anal, const char *data);
|
2011-02-11 10:22:43 +00:00
|
|
|
R_API void r_anal_trace_bb(RAnal *anal, ut64 addr);
|
|
|
|
R_API RAnalFcn *r_anal_get_fcn_at(RAnal *anal, ut64 addr);
|
|
|
|
R_API RList *r_anal_get_fcns(RAnal *anal);
|
2010-03-12 02:05:20 +00:00
|
|
|
|
|
|
|
/* bb.c */
|
2010-05-20 23:46:26 +00:00
|
|
|
R_API RAnalBlock *r_anal_bb_new();
|
2010-03-12 02:05:20 +00:00
|
|
|
R_API RList *r_anal_bb_list_new();
|
|
|
|
R_API void r_anal_bb_free(void *bb);
|
2010-05-21 16:23:01 +00:00
|
|
|
R_API int r_anal_bb(RAnal *anal, RAnalBlock *bb,
|
|
|
|
ut64 addr, ut8 *buf, ut64 len, int head);
|
2011-02-28 12:07:41 +00:00
|
|
|
R_API RAnalBlock *r_anal_bb_from_offset(RAnal *anal, ut64 off);
|
2010-03-12 02:05:20 +00:00
|
|
|
|
2011-02-24 13:06:49 +00:00
|
|
|
/* op.c */
|
|
|
|
R_API RAnalOp *r_anal_op_new();
|
|
|
|
R_API void r_anal_op_free(void *op);
|
|
|
|
R_API RList *r_anal_op_list_new();
|
|
|
|
R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr,
|
2010-11-23 16:15:33 +00:00
|
|
|
const ut8 *data, int len);
|
2011-02-24 13:06:49 +00:00
|
|
|
R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op);
|
2010-03-12 02:05:20 +00:00
|
|
|
|
|
|
|
/* fcn.c */
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API RAnalFcn *r_anal_fcn_new();
|
2010-11-23 18:55:31 +00:00
|
|
|
R_API RAnalFcn *r_anal_fcn_find(RAnal *anal, ut64 addr, int type);
|
2010-03-12 02:05:20 +00:00
|
|
|
R_API RList *r_anal_fcn_list_new();
|
|
|
|
R_API void r_anal_fcn_free(void *fcn);
|
2010-11-23 16:15:33 +00:00
|
|
|
R_API int r_anal_fcn(RAnal *anal, RAnalFcn *fcn, ut64 addr,
|
|
|
|
ut8 *buf, ut64 len, int reftype);
|
2010-05-24 11:57:49 +00:00
|
|
|
R_API int r_anal_fcn_add(RAnal *anal, ut64 addr, ut64 size,
|
2010-12-05 07:46:56 +00:00
|
|
|
const char *name, int type, RAnalDiff *diff);
|
2010-04-07 11:43:50 +00:00
|
|
|
R_API int r_anal_fcn_del(RAnal *anal, ut64 addr);
|
2011-02-11 10:22:43 +00:00
|
|
|
R_API int r_anal_fcn_add_bb(RAnalFcn *fcn, ut64 addr, ut64 size,
|
|
|
|
ut64 jump, ut64 fail, int type, RAnalDiff *diff);
|
|
|
|
R_API int r_anal_fcn_cc(RAnalFcn *fcn);
|
|
|
|
R_API int r_anal_fcn_split_bb(RAnalFcn *fcn, RAnalBlock *bb, ut64 addr);
|
|
|
|
R_API int r_anal_fcn_overlap_bb(RAnalFcn *fcn, RAnalBlock *bb);
|
2010-07-12 19:37:40 +00:00
|
|
|
R_API RAnalVar *r_anal_fcn_get_var(RAnalFcn *fs, int num, int dir);
|
|
|
|
R_API char *r_anal_fcn_to_string(RAnal *a, RAnalFcn* fs);
|
2010-08-12 10:19:25 +00:00
|
|
|
R_API int r_anal_fcn_from_string(RAnal *a, RAnalFcn *f, const char *_str);
|
2010-03-12 02:05:20 +00:00
|
|
|
|
|
|
|
/* ref.c */
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API RAnalRef *r_anal_ref_new();
|
2010-03-12 02:05:20 +00:00
|
|
|
R_API RList *r_anal_ref_list_new();
|
|
|
|
R_API void r_anal_ref_free(void *ref);
|
2010-09-28 11:58:03 +00:00
|
|
|
R_API int r_anal_ref_add(RAnal *anal, ut64 addr, ut64 at, int type);
|
|
|
|
R_API int r_anal_ref_del(RAnal *anal, ut64 at);
|
2010-09-28 16:05:31 +00:00
|
|
|
R_API RList *r_anal_xref_get(RAnal *anal, ut64 addr);
|
2010-02-26 12:08:42 +00:00
|
|
|
|
2010-03-11 16:19:33 +00:00
|
|
|
/* var.c */
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API RAnalVar *r_anal_var_new();
|
|
|
|
R_API RAnalVarType *r_anal_var_type_new();
|
|
|
|
R_API RAnalVarAccess *r_anal_var_access_new();
|
2010-03-11 18:52:05 +00:00
|
|
|
R_API RList *r_anal_var_list_new();
|
|
|
|
R_API RList *r_anal_var_type_list_new();
|
|
|
|
R_API RList *r_anal_var_access_list_new();
|
|
|
|
R_API void r_anal_var_free(void *var);
|
|
|
|
R_API void r_anal_var_type_free(void *vartype);
|
|
|
|
R_API void r_anal_var_access_free(void *access);
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API int r_anal_var_type_add(RAnal *anal, const char *name, int size, const char *fmt);
|
|
|
|
R_API int r_anal_var_type_del(RAnal *anal, const char *name);
|
|
|
|
R_API RAnalVarType *r_anal_var_type_get(RAnal *anal, const char *name);
|
|
|
|
R_API int r_anal_var_add(RAnal *anal, RAnalFcn *fcn, ut64 from, int delta, int type,
|
2010-12-03 12:52:11 +00:00
|
|
|
const char *vartype, const char *name, int set);
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API int r_anal_var_del(RAnal *anal, RAnalFcn *fcn, int delta, int type);
|
|
|
|
R_API RAnalVar *r_anal_var_get(RAnal *anal, RAnalFcn *fcn, int delta, int type);
|
|
|
|
R_API const char *r_anal_var_type_to_str (RAnal *anal, int type);
|
|
|
|
R_API int r_anal_var_access_add(RAnal *anal, RAnalVar *var, ut64 from, int set);
|
|
|
|
R_API int r_anal_var_access_del(RAnal *anal, RAnalVar *var, ut64 from);
|
|
|
|
R_API RAnalVarAccess *r_anal_var_access_get(RAnal *anal, RAnalVar *var, ut64 from);
|
2010-03-11 16:19:33 +00:00
|
|
|
|
2011-03-06 14:21:13 +00:00
|
|
|
#define R_ANAL_THRESHOLDFCN 0.7F
|
|
|
|
#define R_ANAL_THRESHOLDBB 0.7F
|
2010-12-05 07:46:56 +00:00
|
|
|
/* diff.c */
|
|
|
|
R_API RAnalDiff *r_anal_diff_new();
|
|
|
|
R_API void* r_anal_diff_free(RAnalDiff *diff);
|
2011-03-06 14:21:13 +00:00
|
|
|
R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb);
|
|
|
|
R_API int r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFcn *fcn);
|
|
|
|
R_API int r_anal_diff_bb(RAnal *anal, RAnalFcn *fcn, RAnalFcn *fcn2);
|
|
|
|
R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2);
|
|
|
|
R_API int r_anal_diff_eval(RAnal *anal);
|
2010-12-05 07:46:56 +00:00
|
|
|
|
2011-03-06 14:21:13 +00:00
|
|
|
/* value.c */
|
2010-06-16 19:44:19 +00:00
|
|
|
R_API RAnalValue *r_anal_value_new();
|
2011-03-28 08:24:01 +00:00
|
|
|
R_API RAnalValue *r_anal_value_copy (RAnalValue *ov);
|
2010-06-16 19:44:19 +00:00
|
|
|
R_API RAnalValue *r_anal_value_new_from_string(const char *str);
|
|
|
|
R_API st64 r_anal_value_eval(RAnalValue *value);
|
|
|
|
R_API char *r_anal_value_to_string (RAnalValue *value);
|
2010-06-17 22:53:47 +00:00
|
|
|
R_API ut64 r_anal_value_to_ut64(RAnal *anal, RAnalValue *val);
|
2011-02-02 23:20:39 +00:00
|
|
|
R_API int r_anal_value_set_ut64(RAnal *anal, RAnalValue *val, ut64 num);
|
2010-06-16 19:44:19 +00:00
|
|
|
R_API void r_anal_value_free(RAnalValue *value);
|
|
|
|
|
2010-06-14 22:46:18 +00:00
|
|
|
R_API RAnalCond *r_anal_cond_new();
|
2011-02-24 13:06:49 +00:00
|
|
|
R_API RAnalCond *r_anal_cond_new_from_op(RAnalOp *op);
|
2010-06-14 22:46:18 +00:00
|
|
|
#define r_anal_cond_free(x) free(x);
|
2010-06-16 07:42:46 +00:00
|
|
|
R_API char *r_anal_cond_to_string(RAnalCond *cond);
|
2010-06-17 22:53:47 +00:00
|
|
|
R_API int r_anal_cond_eval (RAnal *anal, RAnalCond *cond);
|
2010-06-16 07:42:46 +00:00
|
|
|
R_API RAnalCond *r_anal_cond_new_from_string(const char *str);
|
2010-06-14 22:46:18 +00:00
|
|
|
|
2010-02-26 12:08:42 +00:00
|
|
|
/* reflines.c */
|
2010-03-19 11:23:14 +00:00
|
|
|
R_API struct r_anal_refline_t *r_anal_reflines_get(RAnal *anal,
|
2010-06-17 00:22:50 +00:00
|
|
|
ut64 addr, ut8 *buf, ut64 len, int nlines, int linesout, int linescall);
|
2010-04-08 16:29:46 +00:00
|
|
|
R_API char* r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *list,
|
|
|
|
ut64 addr, int opts);
|
2010-03-19 11:23:14 +00:00
|
|
|
R_API int r_anal_reflines_middle(RAnal *anal, RAnalRefline *list, ut64 addr, int len);
|
2010-03-10 14:15:50 +00:00
|
|
|
|
2011-02-18 09:08:24 +00:00
|
|
|
/* TODO move to r_core */
|
|
|
|
R_API void r_anal_var_list_show(RAnal *anal, RAnalFcn *fcn, ut64 addr);
|
|
|
|
R_API void r_anal_var_list(RAnal *anal, RAnalFcn *fcn, ut64 addr, int delta);
|
2010-08-22 16:41:57 +00:00
|
|
|
|
2011-02-02 12:05:48 +00:00
|
|
|
// calling conventions API
|
|
|
|
R_API RAnalCC* r_anal_cc_new ();
|
|
|
|
R_API void r_anal_cc_init (RAnalCC *cc);
|
|
|
|
R_API RAnalCC* r_anal_cc_new_from_string (const char *str, int type);
|
|
|
|
R_API void r_anal_cc_free (RAnalCC* cc);
|
|
|
|
R_API void r_anal_cc_reset (RAnalCC *cc);
|
|
|
|
R_API char *r_anal_cc_to_string (RAnal *anal, RAnalCC* cc);
|
|
|
|
R_API boolt r_anal_cc_update (RAnal *anal, RAnalCC *cc, RAnalOp *op);
|
|
|
|
//R_API int r_anal_cc_register (RAnal *anal, RAnalCC *cc);
|
|
|
|
//R_API int r_anal_cc_unregister (RAnal *anal, RAnalCC *cc);
|
|
|
|
|
2011-03-01 18:06:22 +00:00
|
|
|
R_API RMeta *r_meta_new();
|
|
|
|
R_API void r_meta_free(RMeta *m);
|
|
|
|
R_API int r_meta_count(RMeta *m, int type, ut64 from, ut64 to);
|
|
|
|
R_API char *r_meta_get_string(RMeta *m, int type, ut64 addr);
|
2011-05-21 12:27:46 +00:00
|
|
|
R_API int r_meta_set_string(RMeta *m, int type, ut64 addr, const char *s);
|
2011-03-01 18:06:22 +00:00
|
|
|
R_API int r_meta_del(RMeta *m, int type, ut64 from, ut64 size, const char *str);
|
|
|
|
R_API int r_meta_add(RMeta *m, int type, ut64 from, ut64 size, const char *str);
|
|
|
|
R_API struct r_meta_item_t *r_meta_find(RMeta *m, ut64 off, int type, int where);
|
|
|
|
R_API int r_meta_cleanup(RMeta *m, ut64 from, ut64 to);
|
|
|
|
R_API const char *r_meta_type_to_string(int type);
|
|
|
|
R_API int r_meta_list(RMeta *m, int type);
|
|
|
|
R_API void r_meta_item_free(void *_item);
|
|
|
|
R_API RMetaItem *r_meta_item_new(int type);
|
|
|
|
|
2010-03-10 14:15:50 +00:00
|
|
|
/* plugin pointers */
|
2010-05-25 23:42:22 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_csr;
|
2011-01-26 20:54:39 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_avr;
|
2010-05-25 23:42:22 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_arm;
|
|
|
|
extern RAnalPlugin r_anal_plugin_x86;
|
2010-11-20 15:47:15 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_x86_simple;
|
2010-05-25 23:42:22 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_ppc;
|
|
|
|
extern RAnalPlugin r_anal_plugin_java;
|
2010-06-23 02:02:57 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_mips;
|
2011-02-18 00:43:31 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_dalvik;
|
2011-03-29 12:55:41 +00:00
|
|
|
extern RAnalPlugin r_anal_plugin_sh;
|
2010-03-10 14:15:50 +00:00
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
#endif
|
2009-02-06 17:22:27 +00:00
|
|
|
#endif
|