Rizin
unix-like reverse engineering framework and cli tools
rz_lib.h
Go to the documentation of this file.
1 #ifndef RZ_LIB_H
2 #define RZ_LIB_H
3 
4 #include "rz_types.h"
5 #include "rz_list.h"
6 #include <ht_pu.h>
7 
8 #if __UNIX__
9 #include <dlfcn.h>
10 #endif
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
17 
18 // rename to '.' ??
19 #define RZ_LIB_SEPARATOR "."
20 #define RZ_LIB_SYMNAME "rizin_plugin"
21 #define RZ_LIB_SYMFUNC "rizin_plugin_function"
22 
23 #define RZ_LIB_ENV "RZ_LIBR_PLUGINS"
24 
25 /* TODO: This must depend on HOST_OS, and maybe move into rz_types */
26 #if __WINDOWS__
27 #define RZ_LIB_EXT "dll"
28 #elif __APPLE__
29 #define RZ_LIB_EXT "dylib"
30 #else
31 #define RZ_LIB_EXT "so"
32 #endif
33 
34 /* store list of loaded plugins */
35 typedef struct rz_lib_plugin_t {
36  int type;
37  char *file;
38  void *data; /* user pointer */
40  void *dl_handler; // DL HANDLER
41  char *author;
42  char *version;
43  void (*free)(void *data);
45 
46 /* store list of initialized plugin handlers */
47 typedef struct rz_lib_handler_t {
48  int type;
49  char desc[128]; // TODO: use char *
50  void *user; /* user pointer */
51  int (*constructor)(RzLibPlugin *, void *user, void *data);
52  int (*destructor)(RzLibPlugin *, void *user, void *data);
54 
55 /* this structure should be pointed by the 'rizin_plugin' symbol
56  found in the loaded .so */
57 typedef struct rz_lib_struct_t {
58  int type;
59  void *data; /* pointer to data handled by plugin handler */
60  const char *version; /* rizin version */
61  void (*free)(void *data);
62  const char *pkgname; /* pkgname associated to this plugin */
64 
65 typedef RzLibStruct *(*RzLibStructFunc)(void);
66 
67 // order matters because of librz/util/lib.c
68 typedef enum {
69  RZ_LIB_TYPE_IO, /* io layer */
70  RZ_LIB_TYPE_DBG, /* debugger */
71  RZ_LIB_TYPE_LANG, /* language */
72  RZ_LIB_TYPE_ASM, /* assembler */
73  RZ_LIB_TYPE_ANALYSIS, /* analysis */
74  RZ_LIB_TYPE_PARSE, /* parsers */
75  RZ_LIB_TYPE_BIN, /* bin headers */
76  RZ_LIB_TYPE_BIN_XTR, /* bin extractors */
77  RZ_LIB_TYPE_BIN_LDR, /* bin loaders */
78  RZ_LIB_TYPE_BP, /* breakpoint */
79  RZ_LIB_TYPE_SYSCALL, /* syscall */
80  RZ_LIB_TYPE_FASTCALL, /* fastcall */
81  RZ_LIB_TYPE_CRYPTO, /* cryptography */
82  RZ_LIB_TYPE_HASH, /* hashes / message digests */
83  RZ_LIB_TYPE_CORE, /* RzCore commands */
84  RZ_LIB_TYPE_EGG, /* rz_egg plugin */
85  RZ_LIB_TYPE_DEMANGLER, /* demanglers */
88 
89 typedef struct rz_lib_t {
90  /* linked list with all the plugin handler */
91  /* only one handler per handler-id allowed */
92  /* this is checked in add_handler function */
93  char *symname;
94  char *symnamefunc;
95  RzList /*RzLibPlugin*/ *plugins;
96  RzList /*RzLibHandler*/ *handlers;
97  HtPU *opened_dirs;
99 
100 #ifdef RZ_API
101 /* low level api */
102 RZ_API void *rz_lib_dl_open(const char *libname);
103 
104 RZ_API void *rz_lib_dl_sym(void *handler, const char *name);
105 RZ_API int rz_lib_dl_close(void *handler);
106 
107 /* high level api */
108 typedef int (*RzLibCallback)(RzLibPlugin *, void *, void *);
109 RZ_API RzLib *rz_lib_new(const char *symname, const char *symnamefunc);
110 RZ_API void rz_lib_free(RzLib *lib);
111 RZ_API int rz_lib_run_handler(RzLib *lib, RzLibPlugin *plugin, RzLibStruct *symbol);
113 RZ_API int rz_lib_open(RzLib *lib, const char *file);
114 RZ_API bool rz_lib_opendir(RzLib *lib, const char *path, bool force);
115 RZ_API int rz_lib_open_ptr(RzLib *lib, const char *file, void *handler, RzLibStruct *stru);
116 RZ_API char *rz_lib_path(const char *libname);
117 RZ_API void rz_lib_list(RzLib *lib);
118 RZ_API bool rz_lib_add_handler(RzLib *lib, int type, const char *desc, RzLibCallback ct, RzLibCallback dt, void *user);
119 RZ_API bool rz_lib_del_handler(RzLib *lib, int type);
120 RZ_API int rz_lib_close(RzLib *lib, const char *file);
121 
122 RZ_API int rz_lib_types_get_i(const char *str);
123 #endif
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif
const char * desc
Definition: bin_vsf.c:19
#define RZ_API
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
int type
Definition: mipsasm.c:17
RZ_API void rz_lib_free(RzLib *lib)
Definition: lib.c:189
struct rz_lib_plugin_t RzLibPlugin
RZ_API bool rz_lib_del_handler(RzLib *lib, int type)
Definition: lib.c:528
RZ_API int rz_lib_run_handler(RzLib *lib, RzLibPlugin *plugin, RzLibStruct *symbol)
Definition: lib.c:206
RZ_API int rz_lib_close(RzLib *lib, const char *file)
Definition: lib.c:227
RZ_API int rz_lib_open_ptr(RzLib *lib, const char *file, void *handler, RzLibStruct *stru)
Definition: lib.c:343
RZ_API RzLibHandler * rz_lib_get_handler(RzLib *lib, int type)
Definition: lib.c:216
RZ_API int rz_lib_types_get_i(const char *str)
Definition: lib.c:45
struct rz_lib_handler_t RzLibHandler
RZ_API void * rz_lib_dl_sym(void *handler, const char *name)
Definition: lib.c:90
RZ_API void rz_lib_list(RzLib *lib)
Definition: lib.c:543
RZ_API RzLib * rz_lib_new(const char *symname, const char *symnamefunc)
Definition: lib.c:176
RZ_API char * rz_lib_path(const char *libname)
Definition: lib.c:112
RZ_API int rz_lib_open(RzLib *lib, const char *file)
Definition: lib.c:281
RZ_LIB_VERSION_HEADER(rz_lib)
struct rz_lib_t RzLib
struct rz_lib_struct_t RzLibStruct
RZ_API void * rz_lib_dl_open(const char *libname)
Definition: lib.c:54
RzLibType
Definition: rz_lib.h:68
@ RZ_LIB_TYPE_SYSCALL
Definition: rz_lib.h:79
@ RZ_LIB_TYPE_EGG
Definition: rz_lib.h:84
@ RZ_LIB_TYPE_UNKNOWN
Definition: rz_lib.h:86
@ RZ_LIB_TYPE_FASTCALL
Definition: rz_lib.h:80
@ RZ_LIB_TYPE_HASH
Definition: rz_lib.h:82
@ RZ_LIB_TYPE_BIN_LDR
Definition: rz_lib.h:77
@ RZ_LIB_TYPE_BIN
Definition: rz_lib.h:75
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
@ RZ_LIB_TYPE_CRYPTO
Definition: rz_lib.h:81
@ RZ_LIB_TYPE_ANALYSIS
Definition: rz_lib.h:73
@ RZ_LIB_TYPE_DBG
Definition: rz_lib.h:70
@ RZ_LIB_TYPE_IO
Definition: rz_lib.h:69
@ RZ_LIB_TYPE_PARSE
Definition: rz_lib.h:74
@ RZ_LIB_TYPE_BIN_XTR
Definition: rz_lib.h:76
@ RZ_LIB_TYPE_LANG
Definition: rz_lib.h:71
@ RZ_LIB_TYPE_BP
Definition: rz_lib.h:78
@ RZ_LIB_TYPE_CORE
Definition: rz_lib.h:83
@ RZ_LIB_TYPE_DEMANGLER
Definition: rz_lib.h:85
RZ_API bool rz_lib_opendir(RzLib *lib, const char *path, bool force)
Open all the libraries in the given directory, if it wasn't already opened.
Definition: lib.c:417
int(* RzLibCallback)(RzLibPlugin *, void *, void *)
Definition: rz_lib.h:108
RZ_API bool rz_lib_add_handler(RzLib *lib, int type, const char *desc, RzLibCallback ct, RzLibCallback dt, void *user)
RZ_API int rz_lib_dl_close(void *handler)
Definition: lib.c:104
static int
Definition: sfsocketcall.h:114
Definition: gzappend.c:170
Definition: z80asm.h:102
char desc[128]
Definition: rz_lib.h:49
void * user
Definition: rz_lib.h:50
int(* constructor)(RzLibPlugin *, void *user, void *data)
Definition: rz_lib.h:51
int(* destructor)(RzLibPlugin *, void *user, void *data)
Definition: rz_lib.h:52
void * dl_handler
Definition: rz_lib.h:40
void(* free)(void *data)
Definition: rz_lib.h:43
char * version
Definition: rz_lib.h:42
char * author
Definition: rz_lib.h:41
char * file
Definition: rz_lib.h:37
void * data
Definition: rz_lib.h:38
struct rz_lib_handler_t * handler
Definition: rz_lib.h:39
const char * version
Definition: rz_lib.h:60
const char * pkgname
Definition: rz_lib.h:62
void * data
Definition: rz_lib.h:59
void(* free)(void *data)
Definition: rz_lib.h:61
char * symname
Definition: rz_lib.h:93
HtPU * opened_dirs
Hashtable to keep track of already opened directories.
Definition: rz_lib.h:97
RzList * handlers
Definition: rz_lib.h:96
char * symnamefunc
Definition: rz_lib.h:94
RzList * plugins
Definition: rz_lib.h:95