Rizin
unix-like reverse engineering framework and cli tools
lib.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2008-2021 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_util.h>
5 #include <rz_lib.h>
6 #include <rz_windows.h>
7 
8 RZ_LIB_VERSION(rz_lib);
9 
10 typedef struct rz_lib_type_name_t {
12  const char *name;
14 
16  { RZ_LIB_TYPE_IO, "io" },
17  { RZ_LIB_TYPE_DBG, "dbg" },
18  { RZ_LIB_TYPE_LANG, "lang" },
19  { RZ_LIB_TYPE_ASM, "asm" },
20  { RZ_LIB_TYPE_ANALYSIS, "analysis" },
21  { RZ_LIB_TYPE_PARSE, "parse" },
22  { RZ_LIB_TYPE_BIN, "bin" },
23  { RZ_LIB_TYPE_BIN_XTR, "bin_xtr" },
24  { RZ_LIB_TYPE_BIN_LDR, "bin_ldr" },
25  { RZ_LIB_TYPE_BP, "bp" },
26  { RZ_LIB_TYPE_SYSCALL, "syscall" },
27  { RZ_LIB_TYPE_FASTCALL, "fastcall" },
28  { RZ_LIB_TYPE_CRYPTO, "crypto" },
29  { RZ_LIB_TYPE_HASH, "msgdigest" },
30  { RZ_LIB_TYPE_CORE, "core" },
31  { RZ_LIB_TYPE_EGG, "egg" },
32  { RZ_LIB_TYPE_DEMANGLER, "demangler" },
33  { RZ_LIB_TYPE_UNKNOWN, "unknown" },
34 };
35 
36 static const char *__lib_types_get(int id) {
37  for (int i = 0; i < RZ_ARRAY_SIZE(rz_lib_types); ++i) {
38  if (id == rz_lib_types[i].id) {
39  return rz_lib_types[i].name;
40  }
41  }
42  return "unk";
43 }
44 
45 RZ_API int rz_lib_types_get_i(const char *str) {
46  for (int i = 0; i < RZ_ARRAY_SIZE(rz_lib_types); ++i) {
47  if (!strcmp(str, rz_lib_types[i].name)) {
48  return rz_lib_types[i].id;
49  }
50  }
51  return RZ_LIB_TYPE_UNKNOWN;
52 }
53 
54 RZ_API void *rz_lib_dl_open(const char *libname) {
55  void *ret = NULL;
56 #if WANT_DYLINK
57 #if __UNIX__
58  if (libname) {
59  ret = dlopen(libname, RTLD_GLOBAL | RTLD_LAZY);
60  } else {
61  ret = dlopen(NULL, RTLD_NOW);
62  }
63  if (!ret) {
64  RZ_LOG_ERROR("rz_lib_dl_open: error: %s (%s)\n", libname, dlerror());
65  }
66 #elif __WINDOWS__
67  LPTSTR libname_;
68  if (libname && *libname) {
69  libname_ = rz_sys_conv_utf8_to_win(libname);
70  } else {
71  libname_ = calloc(MAX_PATH, sizeof(TCHAR));
72  if (!libname_) {
73  RZ_LOG_ERROR("lib/rz_lib_dl_open: Failed to allocate memory.\n");
74  return NULL;
75  }
76  if (!GetModuleFileName(NULL, libname_, MAX_PATH)) {
77  libname_[0] = '\0';
78  }
79  }
80  ret = LoadLibrary(libname_);
81  free(libname_);
82  if (!ret) {
83  RZ_LOG_ERROR("rz_lib_dl_open: error: %s\n", libname);
84  }
85 #endif
86 #endif
87  return ret;
88 }
89 
90 RZ_API void *rz_lib_dl_sym(void *handler, const char *name) {
91 #if WANT_DYLINK
92 #if __UNIX__
93  return dlsym(handler, name);
94 #elif __WINDOWS__
95  return GetProcAddress(handler, name);
96 #else
97  return NULL;
98 #endif
99 #else
100  return NULL;
101 #endif
102 }
103 
104 RZ_API int rz_lib_dl_close(void *handler) {
105 #if __UNIX__
106  return dlclose(handler);
107 #else
108  return handler ? 0 : -1;
109 #endif
110 }
111 
112 RZ_API char *rz_lib_path(const char *libname) {
113 #if __WINDOWS__
114  char *tmp = rz_str_newf("%s." RZ_LIB_EXT, libname);
115  if (!tmp) {
116  return NULL;
117  }
118  WCHAR *name = rz_utf8_to_utf16(tmp);
119  free(tmp);
120  WCHAR *path = NULL;
121  if (!name) {
122  goto err;
123  }
124 
125  int count;
126  if (!(count = SearchPathW(NULL, name, NULL, 0, NULL, NULL))) {
127  rz_sys_perror("SearchPath");
128  goto err;
129  }
130  path = malloc(count * sizeof(WCHAR));
131  if (!path) {
132  goto err;
133  }
134  if (!(count = SearchPathW(NULL, name, NULL, count, path, NULL))) {
135  RZ_FREE(path);
136  rz_sys_perror("SearchPath");
137  goto err;
138  }
139  tmp = rz_utf16_to_utf8(path);
140  free(name);
141  free(path);
142  return tmp;
143 err:
144  free(name);
145  return NULL;
146 #else
147 #if __APPLE__
148  char *env = rz_sys_getenv("DYLD_LIBRARY_PATH");
149  env = rz_str_append(env, ":/lib:/usr/lib:/usr/local/lib");
150 #elif __UNIX__
151  char *env = rz_sys_getenv("LD_LIBRARY_PATH");
152  env = rz_str_append(env, ":/lib:/usr/lib:/usr/local/lib");
153 #endif
154  if (!env) {
155  env = strdup(".");
156  }
157  char *next, *path0 = env;
158  do {
159  next = strchr(path0, ':');
160  if (next) {
161  *next = 0;
162  }
163  char *libpath = rz_str_newf("%s/%s." RZ_LIB_EXT, path0, libname);
164  if (rz_file_exists(libpath)) {
165  free(env);
166  return libpath;
167  }
168  free(libpath);
169  path0 = next + 1;
170  } while (next);
171  free(env);
172  return NULL;
173 #endif
174 }
175 
176 RZ_API RzLib *rz_lib_new(const char *symname, const char *symnamefunc) {
177  RzLib *lib = RZ_NEW(RzLib);
178  if (!lib) {
179  return NULL;
180  }
181  lib->handlers = rz_list_newf(free);
182  lib->plugins = rz_list_newf(free);
183  lib->symname = strdup(symname ? symname : RZ_LIB_SYMNAME);
184  lib->symnamefunc = strdup(symnamefunc ? symnamefunc : RZ_LIB_SYMFUNC);
185  lib->opened_dirs = ht_pu_new0();
186  return lib;
187 }
188 
190  if (!lib) {
191  return;
192  }
193  rz_lib_close(lib, NULL);
194  rz_list_free(lib->handlers);
195  rz_list_free(lib->plugins);
196  free(lib->symname);
197  free(lib->symnamefunc);
198  ht_pu_free(lib->opened_dirs);
199  free(lib);
200 }
201 
202 static bool __lib_dl_check_filename(const char *file) {
203  return rz_str_endswith(file, "." RZ_LIB_EXT);
204 }
205 
207  RzLibHandler *h = plugin->handler;
208  if (h && h->constructor) {
209  RZ_LOG_DEBUG("PLUGIN LOADED %p fcn %p\n", h, h->constructor);
210  return h->constructor(plugin, h->user, symbol->data);
211  }
212  RZ_LOG_WARN("Cannot find plugin constructor\n");
213  return -1;
214 }
215 
217  RzLibHandler *h;
218  RzListIter *iter;
219  rz_list_foreach (lib->handlers, iter, h) {
220  if (h->type == type) {
221  return h;
222  }
223  }
224  return NULL;
225 }
226 
227 RZ_API int rz_lib_close(RzLib *lib, const char *file) {
228  RzLibPlugin *p;
229  RzListIter *iter, *iter2;
230  rz_list_foreach_safe (lib->plugins, iter, iter2, p) {
231  if ((!file || !strcmp(file, p->file))) {
232  int ret = 0;
233  if (p->handler && p->handler->destructor) {
234  ret = p->handler->destructor(p, p->handler->user, p->data);
235  }
236  if (p->free) {
237  p->free(p->data);
238  }
239  free(p->file);
240  rz_list_delete(lib->plugins, iter);
241  if (file != NULL) {
242  return ret;
243  }
244  }
245  }
246  if (!file) {
247  return 0;
248  }
249  // delete similar plugin name
250  rz_list_foreach (lib->plugins, iter, p) {
251  if (strstr(p->file, file)) {
252  int ret = 0;
253  if (p->handler && p->handler->destructor) {
254  ret = p->handler->destructor(p,
255  p->handler->user, p->data);
256  }
257  RZ_LOG_INFO("Unloaded %s\n", p->file);
258  free(p->file);
259  rz_list_delete(lib->plugins, iter);
260  return ret;
261  }
262  }
263  return -1;
264 }
265 
266 static bool __already_loaded(RzLib *lib, const char *file) {
267  const char *fileName = rz_str_rstr(file, RZ_SYS_DIR);
268  RzLibPlugin *p;
269  RzListIter *iter;
270  if (fileName) {
271  rz_list_foreach (lib->plugins, iter, p) {
272  const char *pFileName = rz_str_rstr(p->file, RZ_SYS_DIR);
273  if (pFileName && !strcmp(fileName, pFileName)) {
274  return true;
275  }
276  }
277  }
278  return false;
279 }
280 
281 RZ_API int rz_lib_open(RzLib *lib, const char *file) {
282  /* ignored by filename */
284  RZ_LOG_ERROR("Invalid library extension: %s\n", file);
285  return -1;
286  }
287 
288  if (__already_loaded(lib, file)) {
289  RZ_LOG_INFO("Not loading library because it has already been loaded from somewhere else: '%s'\n", file);
290  return -1;
291  }
292 
293  // TODO: remove after 0.4.0 is released
294  if (strstr(file, RZ_HOME_OLD_PLUGINS)) {
295  char *oldhomeplugins = rz_path_home_prefix(RZ_HOME_OLD_PLUGINS);
296  char *homeplugins = rz_path_home_prefix(RZ_PLUGINS);
297  const char *basename = rz_file_basename(file);
298  RZ_LOG_WARN("Loading plugins from '%s' is deprecated, please install plugin '%s' in '%s' instead.\n", oldhomeplugins, basename, homeplugins);
299  free(homeplugins);
300  free(oldhomeplugins);
301  }
302 
303  void *handler = rz_lib_dl_open(file);
304  if (!handler) {
305  RZ_LOG_INFO("Cannot open library: '%s'\n", file);
306  return -1;
307  }
308 
310  RzLibStruct *stru = NULL;
311  if (strf) {
312  stru = strf();
313  }
314  if (!stru) {
315  stru = (RzLibStruct *)rz_lib_dl_sym(handler, lib->symname);
316  }
317  if (!stru) {
318  RZ_LOG_INFO("Cannot find symbol '%s' in library '%s'\n",
319  lib->symname, file);
320  rz_lib_dl_close(handler);
321  return -1;
322  }
323 
324  int res = rz_lib_open_ptr(lib, file, handler, stru);
325  if (strf) {
326  free(stru);
327  }
328  return res;
329 }
330 
331 static char *major_minor(const char *s) {
332  char *a = strdup(s);
333  char *p = strchr(a, '.');
334  if (p) {
335  p = strchr(p + 1, '.');
336  if (p) {
337  *p = 0;
338  }
339  }
340  return a;
341 }
342 
343 RZ_API int rz_lib_open_ptr(RzLib *lib, const char *file, void *handler, RzLibStruct *stru) {
344  rz_return_val_if_fail(lib && file && stru, -1);
345  if (stru->version) {
346  char *mm0 = major_minor(stru->version);
347  char *mm1 = major_minor(RZ_VERSION);
348  bool mismatch = strcmp(mm0, mm1);
349  free(mm0);
350  free(mm1);
351  if (mismatch) {
352  RZ_LOG_WARN("Module version mismatch %s (%s) vs (%s)\n",
353  file, stru->version, RZ_VERSION);
354  if (stru->pkgname) {
355  const char *dot = strchr(stru->version, '.');
356  int major = atoi(stru->version);
357  int minor = dot ? atoi(dot + 1) : 0;
358  // The pkgname member was introduced in 4.2.0
359  if (major > 4 || (major == 4 && minor >= 2)) {
360  printf("rz-pm -ci %s\n", stru->pkgname);
361  }
362  }
363  return -1;
364  }
365  }
366 
367  RzLibHandler *lib_handler = rz_lib_get_handler(lib, stru->type);
368  if (!lib_handler) {
369  // the handler was not assigned for this type therefore
370  // we skip this library (this happens when not loading
371  // all the plugins types, like rz-bin does).
372  RZ_LOG_DEBUG("rz_lib_open_ptr: no handler was defined for %s with type %d\n", file, stru->type);
373  rz_lib_dl_close(handler);
374  return -1;
375  }
376 
378  if (!p) {
379  RZ_LOG_ERROR("rz_lib_open_ptr: Cannot allocate RzLibPlugin\n");
380  rz_lib_dl_close(handler);
381  return -1;
382  }
383 
384  p->type = stru->type;
385  p->data = stru->data;
386  p->file = strdup(file);
387  p->dl_handler = handler;
388  p->handler = lib_handler;
389  p->free = stru->free;
390 
391  int ret = rz_lib_run_handler(lib, p, stru);
392  if (ret == -1) {
393  RZ_LOG_INFO("Library handler has failed for '%s'\n", file);
394  free(p->file);
395  free(p);
396  rz_lib_dl_close(handler);
397  } else {
398  rz_list_append(lib->plugins, p);
399  }
400 
401  return ret;
402 }
403 
417 RZ_API bool rz_lib_opendir(RzLib *lib, const char *path, bool force) {
418  rz_return_val_if_fail(lib && path, false);
419 
420  if (!force && ht_pu_find(lib->opened_dirs, path, NULL)) {
421  return false;
422  }
423 #if WANT_DYLINK
424  rz_return_val_if_fail(lib && path, false);
425 #if __WINDOWS__
426  wchar_t file[1024];
427  WIN32_FIND_DATAW dir;
428  HANDLE fh;
429  wchar_t directory[MAX_PATH];
430  wchar_t *wcpath;
431  char *wctocbuff;
432 #else
433  char file[1024];
434  struct dirent *de;
435  DIR *dh;
436 #endif
437 #ifdef RZ_LIBR_PLUGINS
438  if (!path) {
439  path = RZ_LIBR_PLUGINS;
440  }
441 #endif
442  if (!path) {
443  return false;
444  }
445 #if __WINDOWS__
446  wcpath = rz_utf8_to_utf16(path);
447  if (!wcpath) {
448  return false;
449  }
450  swprintf(directory, _countof(directory), L"%ls\\*.*", wcpath);
451  fh = FindFirstFileW(directory, &dir);
452  if (fh == INVALID_HANDLE_VALUE) {
453  RZ_LOG_INFO("Cannot open directory %ls\n", wcpath);
454  free(wcpath);
455  return false;
456  }
457  do {
458  swprintf(file, _countof(file), L"%ls/%ls", wcpath, dir.cFileName);
459  wctocbuff = rz_utf16_to_utf8(file);
460  if (wctocbuff) {
461  if (__lib_dl_check_filename(wctocbuff)) {
462  rz_lib_open(lib, wctocbuff);
463  } else {
464  RZ_LOG_INFO("Cannot open %ls\n", dir.cFileName);
465  }
466  free(wctocbuff);
467  }
468  } while (FindNextFileW(fh, &dir));
469  FindClose(fh);
470  free(wcpath);
471 #else
472  dh = opendir(path);
473  if (!dh) {
474  RZ_LOG_INFO("Cannot open directory '%s'\n", path);
475  return false;
476  }
477  while ((de = (struct dirent *)readdir(dh))) {
478  if (de->d_name[0] == '.' || strstr(de->d_name, ".dSYM")) {
479  continue;
480  }
481  snprintf(file, sizeof(file), "%s/%s", path, de->d_name);
483  RZ_LOG_INFO("Loading %s\n", file);
484  rz_lib_open(lib, file);
485  } else {
486  RZ_LOG_INFO("Cannot open %s\n", file);
487  }
488  }
489  closedir(dh);
490 #endif
491 #endif
492  ht_pu_insert(lib->opened_dirs, path, 1);
493  return true;
494 }
495 
497  int type, const char *desc,
498  int (*cb)(RzLibPlugin *, void *, void *), /* constructor */
499  int (*dt)(RzLibPlugin *, void *, void *), /* destructor */
500  void *user) {
501  RzLibHandler *h;
502  RzListIter *iter;
503  RzLibHandler *handler = NULL;
504 
505  rz_list_foreach (lib->handlers, iter, h) {
506  if (type == h->type) {
507  RZ_LOG_INFO("Redefining library handler constructor for %d\n", type);
508  handler = h;
509  break;
510  }
511  }
512  if (!handler) {
513  handler = RZ_NEW(RzLibHandler);
514  if (!handler) {
515  return false;
516  }
517  handler->type = type;
518  rz_list_append(lib->handlers, handler);
519  }
520  strncpy(handler->desc, desc, sizeof(handler->desc) - 1);
521  handler->user = user;
522  handler->constructor = cb;
523  handler->destructor = dt;
524 
525  return true;
526 }
527 
529  RzLibHandler *h;
530  RzListIter *iter;
531  // TODO: remove all handlers for that type? or only one?
532  /* No _safe loop necessary because we return immediately after the delete. */
533  rz_list_foreach (lib->handlers, iter, h) {
534  if (type == h->type) {
536  return true;
537  }
538  }
539  return false;
540 }
541 
542 // TODO _list methods should not exist.. only used in ../core/cmd_log.c: rz_lib_list (core->lib);
544  RzListIter *iter;
545  RzLibPlugin *p;
546  rz_list_foreach (lib->plugins, iter, p) {
547  printf(" %5s %p %s \n", __lib_types_get(p->type), p->dl_handler, p->file);
548  }
549 }
mm1
Definition: 3DNow.s.cs:2
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
const char * desc
Definition: bin_vsf.c:19
FILE * fh
Definition: cabinfo.c:52
#define RZ_API
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
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
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
#define minor(dev)
Definition: fsmagic.c:57
#define major(dev)
Definition: fsmagic.c:56
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define INVALID_HANDLE_VALUE
Definition: iowin32.c:21
snprintf
Definition: kernel.h:364
void * p
Definition: libc.cpp:67
#define basename
Definition: libiberty.h:109
RZ_API void rz_lib_free(RzLib *lib)
Definition: lib.c:189
static RzLibTypeName rz_lib_types[]
Definition: lib.c:15
RZ_API bool rz_lib_add_handler(RzLib *lib, int type, const char *desc, int(*cb)(RzLibPlugin *, void *, void *), int(*dt)(RzLibPlugin *, void *, void *), void *user)
Definition: lib.c:496
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_type_name_t RzLibTypeName
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
static const char * __lib_types_get(int id)
Definition: lib.c:36
RZ_LIB_VERSION(rz_lib)
static bool __lib_dl_check_filename(const char *file)
Definition: lib.c:202
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
static char * major_minor(const char *s)
Definition: lib.c:331
RZ_API void * rz_lib_dl_open(const char *libname)
Definition: lib.c:54
static bool __already_loaded(RzLib *lib, const char *file)
Definition: lib.c:266
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
RZ_API int rz_lib_dl_close(void *handler)
Definition: lib.c:104
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path static newfd static getpgrp static euid const sigset_t static mask const char static len const gid_t static list const char const char static newpath const char static library readdir
Definition: sflib.h:120
int type
Definition: mipsasm.c:17
directory
Definition: regress.py:17
static RzSocket * s
Definition: rtr.c:28
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API const char * rz_file_basename(const char *path)
Definition: file.c:83
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
#define RZ_LIB_SYMNAME
Definition: rz_lib.h:20
#define RZ_LIB_SYMFUNC
Definition: rz_lib.h:21
RzLibStruct *(* RzLibStructFunc)(void)
Definition: rz_lib.h:65
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
#define RZ_LIB_EXT
Definition: rz_lib.h:31
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API RZ_OWN char * rz_path_home_prefix(RZ_NULLABLE const char *path)
Return path prefixed by the home prefix.
Definition: path.c:182
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
RZ_API const char * rz_str_rstr(const char *base, const char *p)
Definition: str.c:814
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
Definition: sys.c:483
#define rz_sys_perror(x)
Definition: rz_types.h:336
#define RZ_SYS_DIR
Definition: rz_types.h:218
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NEW(x)
Definition: rz_types.h:285
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
#define RZ_FREE(x)
Definition: rz_types.h:369
#define RZ_PLUGINS
Definition: rz_userconf.h:72
#define RZ_HOME_OLD_PLUGINS
Definition: rz_userconf.h:100
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
Definition: sftypes.h:48
char d_name[256]
Definition: sftypes.h:52
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
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
const char * name
Definition: lib.c:12
RzLibType id
Definition: lib.c:11
static char ** env
Definition: sys.c:32
DWORD * HANDLE
static const char * cb[]
Definition: z80_tab.h:176
#define L
Definition: zip_err_str.c:7