2018-09-30 15:41:19 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */
|
2009-02-24 14:58:21 +00:00
|
|
|
|
2014-03-27 15:34:17 +00:00
|
|
|
#ifndef R2_PARSE_H
|
|
|
|
#define R2_PARSE_H
|
2009-02-24 14:58:21 +00:00
|
|
|
|
|
|
|
#include <r_types.h>
|
2016-10-26 23:02:26 +00:00
|
|
|
#include <r_flag.h>
|
2011-02-23 14:17:06 +00:00
|
|
|
#include <r_anal.h>
|
2009-02-24 14:58:21 +00:00
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-06-14 00:51:33 +00:00
|
|
|
R_LIB_VERSION_HEADER(r_parse);
|
|
|
|
|
2014-12-14 01:10:55 +00:00
|
|
|
typedef RList* (*RAnalVarList)(RAnal *anal, RAnalFunction *fcn, int kind);
|
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
typedef struct r_parse_t {
|
2009-02-24 14:58:21 +00:00
|
|
|
void *user;
|
2019-02-03 15:06:45 +00:00
|
|
|
RSpace *flagspace;
|
|
|
|
RSpace *notin_flagspace;
|
2018-05-11 07:40:25 +00:00
|
|
|
bool pseudo;
|
2019-03-09 09:21:04 +00:00
|
|
|
bool regsub; // replace registers with their respective alias/role name (rdi=A0, ...)
|
2015-11-19 22:12:08 +00:00
|
|
|
bool relsub; // replace rip relative expressions in instruction
|
2018-09-30 15:41:19 +00:00
|
|
|
bool tailsub; // replace any immediate relative to current address with .. prefix syntax
|
2017-03-17 10:54:34 +00:00
|
|
|
bool localvar_only; // if true use only the local variable name (e.g. [local_10h] instead of [ebp + local10h])
|
2018-10-11 13:51:13 +00:00
|
|
|
ut64 relsub_addr;
|
2019-04-24 00:16:54 +00:00
|
|
|
int maxflagnamelen;
|
2017-06-27 23:29:04 +00:00
|
|
|
int minval;
|
2017-12-09 12:14:37 +00:00
|
|
|
char *retleave_asm;
|
2010-05-25 23:42:22 +00:00
|
|
|
struct r_parse_plugin_t *cur;
|
2019-04-25 09:22:06 +00:00
|
|
|
// RAnal *anal; // weak anal ref XXX do not use. use analb.anal
|
2012-11-12 23:53:52 +00:00
|
|
|
RList *parsers;
|
2014-12-14 01:10:55 +00:00
|
|
|
RAnalVarList varlist;
|
2018-11-02 17:27:45 +00:00
|
|
|
char* (*get_op_ireg)(void *user, ut64 addr);
|
2016-09-01 20:50:28 +00:00
|
|
|
RAnalBind analb;
|
2019-04-25 09:22:06 +00:00
|
|
|
RFlagGetAtAddr flag_get; // XXX
|
2010-01-26 00:28:33 +00:00
|
|
|
} RParse;
|
2009-02-24 14:58:21 +00:00
|
|
|
|
2010-05-25 23:42:22 +00:00
|
|
|
typedef struct r_parse_plugin_t {
|
2009-02-24 14:58:21 +00:00
|
|
|
char *name;
|
|
|
|
char *desc;
|
2019-06-17 00:23:58 +00:00
|
|
|
bool (*init)(RParse *p, void *user);
|
|
|
|
int (*fini)(RParse *p, void *user);
|
2011-10-05 10:40:16 +00:00
|
|
|
int (*parse)(RParse *p, const char *data, char *str);
|
2019-06-17 00:23:58 +00:00
|
|
|
bool (*assemble)(RParse *p, char *data, char *str);
|
2018-09-30 15:41:19 +00:00
|
|
|
int (*filter)(RParse *p, ut64 addr, RFlag *f, char *data, char *str, int len, bool big_endian);
|
2015-11-19 22:12:08 +00:00
|
|
|
bool (*varsub)(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len);
|
2015-01-16 01:34:35 +00:00
|
|
|
int (*replace)(int argc, const char *argv[], char *newstr);
|
2010-05-25 23:42:22 +00:00
|
|
|
} RParsePlugin;
|
2009-02-24 14:58:21 +00:00
|
|
|
|
2010-10-28 00:51:01 +00:00
|
|
|
#ifdef R_API
|
2019-06-17 00:23:58 +00:00
|
|
|
|
|
|
|
/* lifecycle */
|
2015-01-13 02:40:01 +00:00
|
|
|
R_API struct r_parse_t *r_parse_new(void);
|
2010-10-27 22:55:07 +00:00
|
|
|
R_API void r_parse_free(RParse *p);
|
2019-06-17 00:23:58 +00:00
|
|
|
|
|
|
|
/* plugins */
|
2010-10-27 22:55:07 +00:00
|
|
|
R_API void r_parse_set_user_ptr(RParse *p, void *user);
|
2019-06-17 00:23:58 +00:00
|
|
|
R_API bool r_parse_add(RParse *p, RParsePlugin *foo);
|
|
|
|
R_API bool r_parse_use(RParse *p, const char *name);
|
|
|
|
|
|
|
|
/* action */
|
2019-06-15 11:24:00 +00:00
|
|
|
R_API bool r_parse_parse(RParse *p, const char *data, char *str);
|
2019-06-17 00:23:58 +00:00
|
|
|
R_API bool r_parse_assemble(RParse *p, char *data, char *str); // XXX deprecate, unused and probably useless, related to write-hack
|
|
|
|
R_API bool r_parse_filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian);
|
2015-11-19 22:12:08 +00:00
|
|
|
R_API bool r_parse_varsub(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len);
|
2019-06-17 00:23:58 +00:00
|
|
|
R_API char *r_parse_immtrim(char *opstr);
|
|
|
|
|
|
|
|
/* c */
|
|
|
|
// why we have anal scoped things in rparse
|
2019-02-10 00:56:28 +00:00
|
|
|
R_API char *r_parse_c_string(RAnal *anal, const char *code, char **error_msg);
|
2019-05-15 06:46:44 +00:00
|
|
|
R_API char *r_parse_c_file(RAnal *anal, const char *path, const char *dir, char **error_msg);
|
2019-06-17 00:23:58 +00:00
|
|
|
R_API void r_parse_c_reset(RParse *p);
|
2010-03-19 01:49:30 +00:00
|
|
|
|
2019-07-20 10:50:27 +00:00
|
|
|
/* ctype */
|
|
|
|
// Parses strings like "const char * [0x42] const * [23]" to RParseCTypeType
|
|
|
|
|
|
|
|
typedef struct r_parse_ctype_t RParseCType;
|
|
|
|
|
|
|
|
typedef struct r_parse_ctype_type_t RParseCTypeType;
|
|
|
|
struct r_parse_ctype_type_t {
|
|
|
|
enum {
|
|
|
|
R_PARSE_CTYPE_TYPE_KIND_IDENTIFIER,
|
|
|
|
R_PARSE_CTYPE_TYPE_KIND_POINTER,
|
|
|
|
R_PARSE_CTYPE_TYPE_KIND_ARRAY
|
|
|
|
} kind;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
2019-07-25 19:57:14 +00:00
|
|
|
enum {
|
|
|
|
R_PARSE_CTYPE_IDENTIFIER_KIND_UNSPECIFIED,
|
|
|
|
R_PARSE_CTYPE_IDENTIFIER_KIND_STRUCT,
|
|
|
|
R_PARSE_CTYPE_IDENTIFIER_KIND_UNION,
|
|
|
|
R_PARSE_CTYPE_IDENTIFIER_KIND_ENUM
|
|
|
|
} kind;
|
2019-07-20 10:50:27 +00:00
|
|
|
char *name;
|
|
|
|
bool is_const;
|
|
|
|
} identifier;
|
|
|
|
struct {
|
|
|
|
RParseCTypeType *type;
|
|
|
|
bool is_const;
|
|
|
|
} pointer;
|
|
|
|
struct {
|
|
|
|
RParseCTypeType *type;
|
|
|
|
ut64 count;
|
|
|
|
} array;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
R_API RParseCType *r_parse_ctype_new();
|
|
|
|
R_API void r_parse_ctype_free(RParseCType *ctype);
|
|
|
|
R_API RParseCTypeType *r_parse_ctype_parse(RParseCType *ctype, const char *str, char **error);
|
|
|
|
R_API void r_parse_ctype_type_free(RParseCTypeType *type);
|
|
|
|
|
2010-03-19 01:49:30 +00:00
|
|
|
/* plugin pointers */
|
2019-01-18 10:29:51 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_6502_pseudo;
|
2017-07-20 19:36:26 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_arm_pseudo;
|
2019-01-18 10:29:51 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_att2intel;
|
|
|
|
extern RParsePlugin r_parse_plugin_avr_pseudo;
|
2019-03-16 19:48:27 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_chip8_pseudo;
|
2017-07-20 19:36:26 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_dalvik_pseudo;
|
2019-01-18 10:29:51 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_dummy;
|
|
|
|
extern RParsePlugin r_parse_plugin_m68k_pseudo;
|
|
|
|
extern RParsePlugin r_parse_plugin_mips_pseudo;
|
2017-07-20 19:36:26 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_ppc_pseudo;
|
|
|
|
extern RParsePlugin r_parse_plugin_sh_pseudo;
|
2019-01-18 10:29:51 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_wasm_pseudo;
|
|
|
|
extern RParsePlugin r_parse_plugin_x86_pseudo;
|
2017-12-06 07:06:06 +00:00
|
|
|
extern RParsePlugin r_parse_plugin_z80_pseudo;
|
2010-10-28 00:51:01 +00:00
|
|
|
#endif
|
2009-08-14 01:44:12 +00:00
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-24 14:58:21 +00:00
|
|
|
#endif
|