rizin/librz/include/rz_parse.h
Riccardo Schirone c4767cf1ac
Fix plugin removal and clean code (#3277)
* cmd: Fix summary of few "L" sub-commands
* util: start decluttering plugins handling

- Add Doxygen docs
- Remove unused API functions and make others internal only
- Use RzLibType enum for plugin type instead of int

* util: move dlopen/dlsym/dlclose to rz_sys
* util: make rz_lib_open/close return bool
* util: simplify rz_lib_add_handler and rz_lib_open*
* libs: implement rz_*_plugin_del to remove a plugin
* core: remove commands from RzCmd when removing plugins
* librz: call plugins 'fini' method when removing a plugin
* core/cmd: do not fail if the hashmap removal fails

When removing a group command, the inner command might have the same
name, thus it would result in trying to remove the same name twice.
Ignore it, as it is fine.

* librz: make RzCrypto plugins handling like the others
* librz/crypto: add rz_crypto_reset and use it
* librz: allocate the plugin structures before adding them
2023-01-16 13:32:46 +01:00

95 lines
3.6 KiB
C

// SPDX-FileCopyrightText: 2009-2018 pancake <pancake@nopcode.org>
// SPDX-FileCopyrightText: 2009-2018 nibble <nibble.ds@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only
#ifndef RZ_PARSE_H
#define RZ_PARSE_H
#include <rz_types.h>
#include <rz_flag.h>
#include <rz_analysis.h>
#ifdef __cplusplus
extern "C" {
#endif
RZ_LIB_VERSION_HEADER(rz_parse);
typedef struct rz_parse_t {
void *user;
RzSpace *flagspace;
RzSpace *notin_flagspace;
bool pseudo;
bool subreg; // replace registers with their respective alias/role name (rdi=A0, ...)
bool subrel; // replace rip relative expressions in instruction
bool subtail; // replace any immediate relative to current address with .. prefix syntax
bool localvar_only; // if true use only the local variable name (e.g. [local_10h] instead of [ebp + local10h])
ut64 subrel_addr;
int maxflagnamelen;
int minval;
char *retleave_asm;
struct rz_parse_plugin_t *cur;
// RzAnalysis *analysis; // weak analysis ref XXX do not use. use analb.anal
RzList /*<RzParsePlugin *>*/ *parsers;
RZ_OWN char *(*var_expr_for_reg_access)(RzAnalysisFunction *fcn, ut64 addr, const char *reg, st64 reg_addend);
RzAnalysisBind analb;
RzFlagGetAtAddr flag_get; // XXX
RzAnalysisLabelAt label_get;
} RzParse;
typedef struct rz_parse_plugin_t {
char *name;
char *desc;
bool (*init)(RzParse *p, void *user);
int (*fini)(RzParse *p, void *user);
bool (*parse)(RzParse *p, const char *data, RzStrBuf *sb);
bool (*assemble)(RzParse *p, char *data, char *str);
int (*filter)(RzParse *p, ut64 addr, RzFlag *f, char *data, char *str, int len, bool big_endian);
bool (*subvar)(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *data, char *str, int len);
int (*replace)(int argc, const char *argv[], char *newstr);
} RzParsePlugin;
#ifdef RZ_API
/* lifecycle */
RZ_API RzParse *rz_parse_new(void);
RZ_API void rz_parse_free(RzParse *p);
/* plugins */
RZ_API void rz_parse_set_user_ptr(RzParse *p, void *user);
RZ_API bool rz_parse_plugin_add(RzParse *p, RZ_NONNULL RzParsePlugin *plugin);
RZ_API bool rz_parse_plugin_del(RzParse *p, RZ_NONNULL RzParsePlugin *plugin);
RZ_API bool rz_parse_use(RzParse *p, const char *name);
/* action */
RZ_API char *rz_parse_pseudocode(RzParse *p, const char *data);
RZ_API bool rz_parse_assemble(RzParse *p, char *data, char *str); // XXX deprecate, unused and probably useless, related to write-hack
RZ_API bool rz_parse_filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian);
RZ_API bool rz_parse_subvar(RzParse *p, RZ_NULLABLE RzAnalysisFunction *f, RZ_NONNULL RzAnalysisOp *op, RZ_NONNULL RZ_IN char *data, RZ_BORROW RZ_NONNULL RZ_OUT char *str, int len);
RZ_API char *rz_parse_immtrim(char *opstr);
/* plugin pointers */
extern RzParsePlugin rz_parse_plugin_6502_pseudo;
extern RzParsePlugin rz_parse_plugin_arm_pseudo;
extern RzParsePlugin rz_parse_plugin_att2intel;
extern RzParsePlugin rz_parse_plugin_avr_pseudo;
extern RzParsePlugin rz_parse_plugin_chip8_pseudo;
extern RzParsePlugin rz_parse_plugin_dalvik_pseudo;
extern RzParsePlugin rz_parse_plugin_dummy;
extern RzParsePlugin rz_parse_plugin_m68k_pseudo;
extern RzParsePlugin rz_parse_plugin_mips_pseudo;
extern RzParsePlugin rz_parse_plugin_ppc_pseudo;
extern RzParsePlugin rz_parse_plugin_sh_pseudo;
extern RzParsePlugin rz_parse_plugin_wasm_pseudo;
extern RzParsePlugin rz_parse_plugin_riscv_pseudo;
extern RzParsePlugin rz_parse_plugin_x86_pseudo;
extern RzParsePlugin rz_parse_plugin_z80_pseudo;
extern RzParsePlugin rz_parse_plugin_tms320_pseudo;
extern RzParsePlugin rz_parse_plugin_v850_pseudo;
#endif
#ifdef __cplusplus
}
#endif
#endif