Rizin
unix-like reverse engineering framework and cli tools
libs.c File Reference
#include <rz_core.h>
#include <rz_demangler.h>
#include "config.h"

Go to the source code of this file.

Macros

#define CB(x, y)
 
#define rz_io_add   rz_io_plugin_add
 
#define rz_debug_add   rz_debug_plugin_add
 
#define rz_bp_add   rz_bp_plugin_add
 
#define rz_bin_add   rz_bin_plugin_add
 
#define rz_hash_add   rz_hash_plugin_add
 
#define DF(x, y, z)   rz_lib_add_handler(core->lib, RZ_LIB_TYPE_##x, y, &__lib_##z##_cb, &__lib_##z##_dt, core);
 

Functions

static int __lib_demangler_cb (RzLibPlugin *pl, void *user, void *data)
 
static int __lib_demangler_dt (RzLibPlugin *pl, void *p, void *u)
 
static int __lib_core_cb (RzLibPlugin *pl, void *user, void *data)
 
static int __lib_core_dt (RzLibPlugin *pl, void *p, void *u)
 
static void loadSystemPlugins (RzCore *core, int where)
 
RZ_API void rz_core_loadlibs_init (RzCore *core)
 
static bool __isScriptFilename (const char *name)
 
RZ_API int rz_core_loadlibs (RzCore *core, int where)
 

Macro Definition Documentation

◆ CB

#define CB (   x,
 
)
Value:
static int __lib_##x##_cb(RzLibPlugin *pl, void *user, void *data) { \
struct rz_##x##_plugin_t *hand = (struct rz_##x##_plugin_t *)data; \
RzCore *core = (RzCore *)user; \
pl->free = NULL; \
rz_##x##_add(core->y, hand); \
return true; \
} \
static int __lib_##x##_dt(RzLibPlugin *pl, void *p, void *u) { \
return true; \
}
#define NULL
Definition: cris-opc.c:27
void * p
Definition: libc.cpp:67
int x
Definition: mipsasm.c:20

Definition at line 8 of file libs.c.

◆ DF

#define DF (   x,
  y,
 
)    rz_lib_add_handler(core->lib, RZ_LIB_TYPE_##x, y, &__lib_##z##_cb, &__lib_##z##_dt, core);

◆ rz_bin_add

#define rz_bin_add   rz_bin_plugin_add

Definition at line 52 of file libs.c.

◆ rz_bp_add

#define rz_bp_add   rz_bp_plugin_add

Definition at line 46 of file libs.c.

◆ rz_debug_add

#define rz_debug_add   rz_debug_plugin_add

Definition at line 44 of file libs.c.

◆ rz_hash_add

#define rz_hash_add   rz_hash_plugin_add

Definition at line 55 of file libs.c.

◆ rz_io_add

#define rz_io_add   rz_io_plugin_add

Definition at line 42 of file libs.c.

Function Documentation

◆ __isScriptFilename()

static bool __isScriptFilename ( const char *  name)
static

Definition at line 108 of file libs.c.

108  {
109  const char *ext = rz_str_lchr(name, '.');
110  if (ext) {
111  ext++;
112  if (!strcmp(ext, "py") || !strcmp(ext, "js") || !strcmp(ext, "lua")) {
113  return true;
114  }
115  }
116  return false;
117 }
static const char ext[]
Definition: apprentice.c:1981
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
Definition: z80asm.h:102

References ext, and rz_str_lchr().

Referenced by rz_core_loadlibs().

◆ __lib_core_cb()

static int __lib_core_cb ( RzLibPlugin pl,
void *  user,
void *  data 
)
static

Definition at line 30 of file libs.c.

30  {
31  struct rz_core_plugin_t *hand = (struct rz_core_plugin_t *)data;
32  RzCore *core = (RzCore *)user;
33  pl->free = NULL;
34  rz_core_plugin_add(core, hand);
35  return true;
36 }
RZ_API bool rz_core_plugin_add(RzCore *core, RzCorePlugin *plugin)
Definition: cplugin.c:27

References NULL, pl, and rz_core_plugin_add().

◆ __lib_core_dt()

static int __lib_core_dt ( RzLibPlugin pl,
void *  p,
void *  u 
)
static

Definition at line 38 of file libs.c.

38  {
39  return true;
40 }

◆ __lib_demangler_cb()

static int __lib_demangler_cb ( RzLibPlugin pl,
void *  user,
void *  data 
)
static

Definition at line 20 of file libs.c.

20  {
21  RzCore *core = (RzCore *)user;
23  return true;
24 }
RZ_API bool rz_demangler_plugin_add(RZ_NONNULL RzDemangler *dem, RZ_NONNULL RzDemanglerPlugin *plugin)
Adds a new demangler plugin to the plugin list.
Definition: demangler.c:144
RzDemangler * demangler
Definition: rz_bin.h:364
RzBin * bin
Definition: rz_core.h:298

References rz_core_t::bin, rz_bin_t::demangler, and rz_demangler_plugin_add().

◆ __lib_demangler_dt()

static int __lib_demangler_dt ( RzLibPlugin pl,
void *  p,
void *  u 
)
static

Definition at line 26 of file libs.c.

26  {
27  return true;
28 }

◆ loadSystemPlugins()

static void loadSystemPlugins ( RzCore core,
int  where 
)
static

Definition at line 58 of file libs.c.

58  {
59 #if RZ_LOADLIBS
60  const char *dir_plugins = rz_config_get(core->config, "dir.plugins");
61  if (where & RZ_CORE_LOADLIBS_CONFIG) {
62  rz_lib_opendir(core->lib, dir_plugins, false);
63  }
64  if (where & RZ_CORE_LOADLIBS_ENV) {
65  char *p = rz_sys_getenv(RZ_LIB_ENV);
66  if (p && *p) {
67  rz_lib_opendir(core->lib, p, false);
68  }
69  free(p);
70  }
71  if (where & RZ_CORE_LOADLIBS_HOME) {
72  char *hpd = rz_path_home_prefix(RZ_PLUGINS);
73  rz_lib_opendir(core->lib, hpd, false);
74  free(hpd);
75 
76  // TODO: remove after 0.4.0 is released
78  rz_lib_opendir(core->lib, hpd, false);
79  free(hpd);
80  }
81  if (where & RZ_CORE_LOADLIBS_SYSTEM) {
82  char *spd = rz_path_system(RZ_PLUGINS);
83  rz_lib_opendir(core->lib, spd, false);
84  free(spd);
85  }
86 #endif
87 }
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define RZ_LIB_ENV
Definition: rz_lib.h:23
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 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 RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
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_PLUGINS
Definition: rz_userconf.h:72
#define RZ_HOME_OLD_PLUGINS
Definition: rz_userconf.h:100
RzLib * lib
Definition: rz_core.h:318
RzConfig * config
Definition: rz_core.h:300

References free(), p, rz_config_get(), RZ_HOME_OLD_PLUGINS, RZ_LIB_ENV, rz_lib_opendir(), rz_path_home_prefix(), rz_path_system(), RZ_PLUGINS, and rz_sys_getenv().

Referenced by rz_core_loadlibs().

◆ rz_core_loadlibs()

RZ_API int rz_core_loadlibs ( RzCore core,
int  where 
)

Definition at line 119 of file libs.c.

119  {
120  ut64 prev = rz_time_now_mono();
121  loadSystemPlugins(core, where);
122  /* TODO: all those default plugin paths should be defined in rz_lib */
123  if (!rz_config_get_i(core->config, "cfg.plugins")) {
124  core->times->loadlibs_time = 0;
125  return false;
126  }
127  // load script plugins
128  char *homeplugindir = rz_path_home_prefix(RZ_PLUGINS);
129  RzList *files = rz_sys_dir(homeplugindir);
130  RzListIter *iter;
131  char *file;
132  rz_list_foreach (files, iter, file) {
133  if (__isScriptFilename(file)) {
134  char *script_file = rz_str_newf("%s/%s", homeplugindir, file);
135  if (!rz_core_run_script(core, script_file)) {
136  eprintf("Cannot find script '%s'\n", script_file);
137  }
138  free(script_file);
139  }
140  }
141 
142  free(homeplugindir);
143  core->times->loadlibs_time = rz_time_now_mono() - prev;
145  return true;
146 }
RZ_API bool rz_core_run_script(RzCore *core, RZ_NONNULL const char *file)
Definition: cmd.c:457
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
Definition: file_opts.h:46
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
static void loadSystemPlugins(RzCore *core, int where)
Definition: libs.c:58
static bool __isScriptFilename(const char *name)
Definition: libs.c:108
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API RzList * rz_sys_dir(const char *path)
Definition: sys.c:216
RZ_API ut64 rz_time_now_mono(void)
Returns the current time in microseconds, using the monotonic clock.
Definition: time.c:102
Definition: gzappend.c:170
RzCoreTimes * times
Definition: rz_core.h:325
ut64 loadlibs_time
Definition: rz_core.h:179
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int file
Definition: z80asm.c:58

References __isScriptFilename(), rz_core_t::config, eprintf, file, files, free(), rz_core_times_t::loadlibs_time, loadSystemPlugins(), rz_config_get_i(), rz_core_run_script(), rz_list_free(), rz_path_home_prefix(), RZ_PLUGINS, rz_str_newf(), rz_sys_dir(), rz_time_now_mono(), rz_core_t::times, and ut64().

Referenced by rz_diff_load_file_with_core(), rz_main_rizin(), and rz_main_rz_sign().

◆ rz_core_loadlibs_init()

RZ_API void rz_core_loadlibs_init ( RzCore core)

Definition at line 89 of file libs.c.

89  {
90  ut64 prev = rz_time_now_mono();
91 #define DF(x, y, z) rz_lib_add_handler(core->lib, RZ_LIB_TYPE_##x, y, &__lib_##z##_cb, &__lib_##z##_dt, core);
92  core->lib = rz_lib_new(NULL, NULL);
93  DF(DEMANGLER, "demangler plugins", demangler);
94  DF(IO, "io plugins", io);
95  DF(CORE, "core plugins", core);
96  DF(DBG, "debugger plugins", debug);
97  DF(BP, "debugger breakpoint plugins", bp);
98  DF(LANG, "language plugins", lang);
99  DF(ANALYSIS, "analysis plugins", analysis);
100  DF(ASM, "(dis)assembler plugins", asm);
101  DF(PARSE, "parsing plugins", parse);
102  DF(BIN, "bin plugins", bin);
103  DF(EGG, "egg plugins", egg);
104  DF(HASH, "hash plugins", hash);
105  core->times->loadlibs_init_time = rz_time_now_mono() - prev;
106 }
#define CORE
Definition: aarch64-tbl.h:2166
#define DF(x, y, z)
RZ_API RzLib * rz_lib_new(const char *symname, const char *symnamefunc)
Definition: lib.c:176
Definition: malloc.c:26
Definition: regcomp.c:57
ut64 loadlibs_init_time
Definition: rz_core.h:178
static int debug
Definition: visual.c:21

References CORE, debug, DF, rz_core_t::lib, rz_core_times_t::loadlibs_init_time, NULL, rz_lib_new(), rz_time_now_mono(), rz_core_t::times, and ut64().

Referenced by rz_core_init().