Rizin
unix-like reverse engineering framework and cli tools
lib.c File Reference
#include <rz_lib.h>
#include <rz_core.h>
#include <rz_lang.h>

Go to the source code of this file.

Functions

static int lang_lib_init (RzLang *user)
 
static int lang_lib_file_run (RzLang *user, const char *file)
 

Variables

RzLangPlugin rz_lang_plugin_lib
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ lang_lib_file_run()

static int lang_lib_file_run ( RzLang user,
const char *  file 
)
static

Definition at line 12 of file lib.c.

12  {
13  char *libpath;
14  void *lib;
15  if (!(libpath = rz_str_new(file))) {
16  return -1;
17  }
18  if (!rz_str_startswith(libpath, "/") && !rz_str_startswith(libpath, "./")) {
19  libpath = rz_str_prepend(libpath, "./");
20  }
21  if (!rz_file_exists(libpath)) {
22  if (!rz_str_endswith(libpath, RZ_LIB_EXT)) {
23  libpath = rz_str_appendf(libpath, ".%s", RZ_LIB_EXT);
24  }
25  }
26  if (!rz_file_exists(libpath)) {
27  free(libpath);
28  return -1;
29  }
30 
31  lib = rz_lib_dl_open(libpath);
32  if (lib) {
33  void (*fcn)(RzCore *);
34  fcn = rz_lib_dl_sym(lib, "entry");
35  if (fcn) {
36  fcn(user->user);
37  } else {
38  eprintf("Cannot find 'entry' symbol in library\n");
39  }
40  rz_lib_dl_close(lib);
41  }
42  free(libpath);
43  return 0;
44 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void * rz_lib_dl_sym(void *handler, const char *name)
Definition: lib.c:90
RZ_API void * rz_lib_dl_open(const char *libname)
Definition: lib.c:54
RZ_API int rz_lib_dl_close(void *handler)
Definition: lib.c:104
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
#define RZ_LIB_EXT
Definition: rz_lib.h:31
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_new(const char *str)
Definition: str.c:865
RZ_API char * rz_str_prepend(char *ptr, const char *string)
Definition: str.c:1027
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
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
Definition: gzappend.c:170
void * user
Definition: rz_lang.h:19

References eprintf, free(), rz_file_exists(), rz_lib_dl_close(), rz_lib_dl_open(), rz_lib_dl_sym(), RZ_LIB_EXT, rz_str_appendf(), rz_str_endswith(), rz_str_new(), rz_str_prepend(), rz_str_startswith(), and rz_lang_t::user.

◆ lang_lib_init()

static int lang_lib_init ( RzLang user)
static

Definition at line 8 of file lib.c.

8  {
9  return true;
10 }

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.version = RZ_VERSION
}
RzLangPlugin rz_lang_plugin_lib
Definition: lib.c:46
@ RZ_LIB_TYPE_LANG
Definition: rz_lib.h:71
#define RZ_VERSION
Definition: rz_version.h:8

Definition at line 56 of file lib.c.

◆ rz_lang_plugin_lib

RzLangPlugin rz_lang_plugin_lib
Initial value:
= {
.name = "lib",
.ext = RZ_LIB_EXT,
.desc = "Load libs directly into rizin",
.license = "LGPL",
.init = lang_lib_init,
.run_file = lang_lib_file_run,
}
static int lang_lib_file_run(RzLang *user, const char *file)
Definition: lib.c:12
static int lang_lib_init(RzLang *user)
Definition: lib.c:8

Definition at line 46 of file lib.c.