Skip to content

Commit

Permalink
build: allow packager to specify absolute system paths outside prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ret2libc committed Feb 22, 2023
1 parent 0e8828c commit dd6ca70
Show file tree
Hide file tree
Showing 28 changed files with 183 additions and 152 deletions.
6 changes: 3 additions & 3 deletions librz/analysis/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static bool analysis_set_os(RzAnalysis *analysis, const char *os) {
}
free(analysis->os);
analysis->os = strdup(os);
char *types_dir = rz_path_system(RZ_SDB_TYPES);
char *types_dir = rz_path_system(RZ_SYSTEM_SDB_TYPES);
rz_type_db_set_os(analysis->typedb, os);
rz_type_db_reload(analysis->typedb, types_dir);
free(types_dir);
Expand Down Expand Up @@ -297,7 +297,7 @@ RZ_API bool rz_analysis_set_bits(RzAnalysis *analysis, int bits) {
rz_type_db_set_bits(analysis->typedb, bits);
rz_type_db_set_address_bits(analysis->typedb, rz_analysis_get_address_bits(analysis));
if (!is_hack) {
char *types_dir = rz_path_system(RZ_SDB_TYPES);
char *types_dir = rz_path_system(RZ_SYSTEM_SDB_TYPES);
rz_type_db_reload(analysis->typedb, types_dir);
free(types_dir);
}
Expand Down Expand Up @@ -332,7 +332,7 @@ RZ_API void rz_analysis_set_cpu(RzAnalysis *analysis, const char *cpu) {
}
rz_analysis_set_reg_profile(analysis);
rz_type_db_set_cpu(analysis->typedb, cpu);
char *types_dir = rz_path_system(RZ_SDB_TYPES);
char *types_dir = rz_path_system(RZ_SYSTEM_SDB_TYPES);
rz_type_db_reload(analysis->typedb, types_dir);
free(types_dir);
}
Expand Down
2 changes: 1 addition & 1 deletion librz/asm/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ RZ_API bool rz_asm_use(RzAsm *a, const char *name) {
if (h->arch && h->name && !strcmp(h->name, name)) {
if (!a->cur || (a->cur && strcmp(a->cur->arch, h->arch))) {
plugin_fini(a);
char *opcodes_dir = rz_path_system(RZ_SDB_OPCODES);
char *opcodes_dir = rz_path_system(RZ_SYSTEM_SDB_OPCODES);
char *file = rz_str_newf("%s/%s.sdb", opcodes_dir, h->arch);
if (file) {
rz_asm_set_cpu(a, NULL);
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/format/ne/ne.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static char *__read_nonnull_str_at(RzBuffer *buf, ut64 offset) {
}

static char *__func_name_from_ord(char *module, ut16 ordinal) {
char *formats_dir = rz_path_system(RZ_SDB_FORMAT);
char *formats_dir = rz_path_system(RZ_SYSTEM_SDB_FORMAT);
char *path = rz_str_newf(RZ_JOIN_3_PATHS("%s", "dll", "%s.sdb"), formats_dir, module);
free(formats_dir);
char *ord = rz_str_newf("%d", ordinal);
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/format/pe/pe_imports.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static int bin_pe_parse_imports(RzBinPEObj *bin,
if (filename && rz_file_exists(filename)) {
db = sdb_new(NULL, filename, 0);
} else {
char *formats_dir = rz_path_system(RZ_SDB_FORMAT);
char *formats_dir = rz_path_system(RZ_SYSTEM_SDB_FORMAT);
free(filename);
filename = rz_str_newf(RZ_JOIN_3_PATHS("%s", "dll", "%s.sdb"), formats_dir, symdllname);
free(formats_dir);
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/p/bin_any.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static char *get_filetype(RzBuffer *b) {
}
const char *tmp = NULL;
// TODO: dir.magic not honored here
char *m = rz_path_system(RZ_SDB_MAGIC);
char *m = rz_path_system(RZ_SYSTEM_SDB_MAGIC);
rz_magic_load(ck, m);
free(m);
rz_buf_read_at(b, 0, buf, sizeof(buf));
Expand Down
14 changes: 7 additions & 7 deletions librz/core/canalysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -4904,8 +4904,8 @@ static void analysis_sigdb_add(RzSigDb *sigs, const char *path, bool with_detail
* \brief Returns all the signatures found in the default path.
*
* Scans for signature in the following paths:
* - home path + RZ_SIGDB
* - system install prefix path + RZ_SIGDB
* - home path + RZ_HOME_SIGDB
* - RZ_SYSTEM_SIGDB
* - flirt.sigdb.path user custom sigdb path
*
* \param core The RzCore to use.
Expand All @@ -4921,13 +4921,13 @@ RZ_API RZ_OWN RzList /*<RzSigDBEntry *>*/ *rz_core_analysis_sigdb_list(RZ_NONNUL
}

if (rz_config_get_b(core->config, "flirt.sigdb.load.home")) {
char *home_sigdb = rz_path_home_prefix(RZ_SIGDB);
char *home_sigdb = rz_path_home_prefix(RZ_HOME_SIGDB);
analysis_sigdb_add(sigs, home_sigdb, with_details);
free(home_sigdb);
}

if (rz_config_get_b(core->config, "flirt.sigdb.load.system")) {
char *system_sigdb = rz_path_system(RZ_SIGDB);
char *system_sigdb = rz_path_system(RZ_SYSTEM_SIGDB);
analysis_sigdb_add(sigs, system_sigdb, with_details);
free(system_sigdb);
}
Expand Down Expand Up @@ -5520,7 +5520,7 @@ RZ_API void rz_core_analysis_type_init(RzCore *core) {
const char *analysis_arch = rz_config_get(core->config, "analysis.arch");
const char *os = rz_config_get(core->config, "asm.os");

char *types_dir = rz_path_system(RZ_SDB_TYPES);
char *types_dir = rz_path_system(RZ_SYSTEM_SDB_TYPES);
rz_type_db_init(core->analysis->typedb, types_dir, analysis_arch, bits, os);
free(types_dir);
}
Expand All @@ -5542,8 +5542,8 @@ RZ_API void rz_core_analysis_cc_init(RzCore *core) {
}

int bits = core->analysis->bits;
char *types_dir = rz_path_system(RZ_SDB_TYPES);
char *home_types_dir = rz_path_home_prefix(RZ_SDB_TYPES);
char *types_dir = rz_path_system(RZ_SYSTEM_SDB_TYPES);
char *home_types_dir = rz_path_home_prefix(RZ_HOME_SDB_TYPES);
char buf[40];
char *dbpath = rz_file_path_join(types_dir, rz_strf(buf, "cc-%s-%d.sdb", analysis_arch, bits));
char *dbhomepath = rz_file_path_join(home_types_dir, rz_strf(buf, "cc-%s-%d.sdb", analysis_arch, bits));
Expand Down
4 changes: 2 additions & 2 deletions librz/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ RZ_API bool rz_core_bin_apply_config(RzCore *r, RzBinFile *binfile) {
if (info->default_cc && rz_analysis_cc_exist(r->analysis, info->default_cc)) {
rz_config_set(r->config, "analysis.cc", info->default_cc);
}
char *types_dir = rz_path_system(RZ_SDB_TYPES);
char *types_dir = rz_path_system(RZ_SYSTEM_SDB_TYPES);
char *spath = rz_file_path_join(types_dir, "spec.sdb");
free(types_dir);
if (spath && rz_file_exists(spath)) {
Expand Down Expand Up @@ -1170,7 +1170,7 @@ static void set_bin_relocs(RzCore *r, RzBinObject *o, RzBinReloc *reloc, bool va
if (rz_file_exists(filename)) {
*db = sdb_new(NULL, filename, 0);
} else {
char *formats_dir = rz_path_system(RZ_SDB_FORMAT);
char *formats_dir = rz_path_system(RZ_SYSTEM_SDB_FORMAT);
free(filename);
filename = rz_str_newf(RZ_JOIN_3_PATHS("%s", "dll", "%s.sdb"), formats_dir, module);
free(formats_dir);
Expand Down
26 changes: 13 additions & 13 deletions librz/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ static bool cb_asmcpu(void *user, void *data) {
rz_asm_set_cpu(core->rasm, node->value);
rz_config_set(core->config, "analysis.cpu", node->value);

char *cpus_dir = rz_path_system(RZ_SDB_ARCH_CPUS);
char *cpus_dir = rz_path_system(RZ_SYSTEM_SDB_ARCH_CPUS);
rz_platform_profiles_init(core->analysis->arch_target, node->value, rz_config_get(core->config, "asm.arch"), cpus_dir);
free(cpus_dir);
const char *platform = rz_config_get(core->config, "asm.platform");
char *platforms_dir = rz_path_system(RZ_SDB_ARCH_PLATFORMS);
char *platforms_dir = rz_path_system(RZ_SYSTEM_SDB_ARCH_PLATFORMS);
rz_platform_target_index_init(core->analysis->platform_target, rz_config_get(core->config, "asm.arch"), node->value, platform, platforms_dir);
free(platforms_dir);

Expand Down Expand Up @@ -570,8 +570,8 @@ static bool cb_asmarch(void *user, void *data) {
const char *platform = rz_config_get(core->config, "asm.platform");
rz_syscall_setup(core->analysis->syscall, node->value, core->analysis->bits, asmcpu, asmos);
update_syscall_ns(core);
char *platforms_dir = rz_path_system(RZ_SDB_ARCH_PLATFORMS);
char *cpus_dir = rz_path_system(RZ_SDB_ARCH_CPUS);
char *platforms_dir = rz_path_system(RZ_SYSTEM_SDB_ARCH_PLATFORMS);
char *cpus_dir = rz_path_system(RZ_SYSTEM_SDB_ARCH_CPUS);
rz_platform_target_index_init(core->analysis->platform_target, node->value, asmcpu, platform, platforms_dir);
rz_platform_profiles_init(core->analysis->arch_target, asmcpu, node->value, cpus_dir);
free(platforms_dir);
Expand Down Expand Up @@ -615,8 +615,8 @@ static bool cb_asmarch(void *user, void *data) {

const char *platform = rz_config_get(core->config, "asm.platform");
if (asmcpu) {
char *platforms_dir = rz_path_system(RZ_SDB_ARCH_PLATFORMS);
char *cpus_dir = rz_path_system(RZ_SDB_ARCH_CPUS);
char *platforms_dir = rz_path_system(RZ_SYSTEM_SDB_ARCH_PLATFORMS);
char *cpus_dir = rz_path_system(RZ_SYSTEM_SDB_ARCH_CPUS);
rz_platform_target_index_init(core->analysis->platform_target, node->value, asmcpu->value, platform, platforms_dir);
rz_platform_profiles_init(core->analysis->arch_target, asmcpu->value, node->value, cpus_dir);
free(cpus_dir);
Expand Down Expand Up @@ -768,7 +768,7 @@ static bool cb_asmplatform(void *user, void *data) {
}
const char *asmcpu = rz_config_get(core->config, "asm.cpu");
const char *asmarch = rz_config_get(core->config, "asm.arch");
char *platforms_dir = rz_path_system(RZ_SDB_ARCH_PLATFORMS);
char *platforms_dir = rz_path_system(RZ_SYSTEM_SDB_ARCH_PLATFORMS);
rz_platform_target_index_init(core->analysis->platform_target, asmarch, asmcpu, node->value, platforms_dir);
free(platforms_dir);
return 1;
Expand Down Expand Up @@ -2861,7 +2861,7 @@ RZ_API int rz_core_config_init(RzCore *core) {
/* pdb */
SETPREF("pdb.server", "https://msdl.microsoft.com/download/symbols", "Semi-colon separated list of base URLs for Microsoft symbol servers");
{
char *pdb_path = rz_path_home_prefix(RZ_PDB);
char *pdb_path = rz_path_home_prefix(RZ_HOME_PDB);
SETPREF("pdb.symstore", pdb_path, "Path to downstream symbol store");
RZ_FREE(pdb_path);
}
Expand Down Expand Up @@ -3261,10 +3261,10 @@ RZ_API int rz_core_config_init(RzCore *core) {
/* dir */
SETI("dir.depth", 10, "Maximum depth when searching recursively for files");
{
char *path = rz_path_system(RZ_SDB_MAGIC);
char *path = rz_path_system(RZ_SYSTEM_SDB_MAGIC);
SETPREF("dir.magic", path, "Path to rz_magic files");
free(path);
path = rz_path_system(RZ_PLUGINS);
path = rz_path_system(RZ_SYSTEM_PLUGINS);
SETPREF("dir.plugins", path, "Path to plugin files to be loaded at startup");
free(path);
}
Expand All @@ -3280,7 +3280,7 @@ RZ_API int rz_core_config_init(RzCore *core) {
#if __ANDROID__
SETPREF("dir.projects", "/data/data/org.rizin.rizininstaller/rizin/projects", "Default path for projects");
#else
char *projects_dir = rz_path_home_prefix(RZ_PROJECTS);
char *projects_dir = rz_path_home_prefix(RZ_HOME_PROJECTS);
SETPREF("dir.projects", projects_dir, "Default path for projects");
free(projects_dir);
#endif
Expand Down Expand Up @@ -3422,13 +3422,13 @@ RZ_API int rz_core_config_init(RzCore *core) {
SETI("http.maxsize", 0, "Maximum file size for upload");
SETPREF("http.index", "index.html", "Main html file to check in directory");
SETPREF("http.bind", "localhost", "Server address");
char *wwwroot_dir = rz_path_home_prefix(RZ_WWWROOT);
char *wwwroot_dir = rz_path_home_prefix(RZ_HOME_WWWROOT);
SETPREF("http.homeroot", wwwroot_dir, "http home root directory");
free(wwwroot_dir);
#if __ANDROID__
SETPREF("http.root", "/data/data/org.rizin.rizininstaller/www", "http root directory");
#else
char *wwwroot = rz_path_system(RZ_WWWROOT);
char *wwwroot = rz_path_system(RZ_SYSTEM_WWWROOT);
SETPREF("http.root", wwwroot, "http root directory");
free(wwwroot);
#endif
Expand Down
2 changes: 1 addition & 1 deletion librz/core/cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ RZ_API int rz_core_bin_rebase(RzCore *core, ut64 baddr) {
static void load_scripts_for(RzCore *core, const char *name) {
char *file;
RzListIter *iter;
char *binrc = rz_path_home_prefix(RZ_BINRC);
char *binrc = rz_path_home_prefix(RZ_HOME_BINRC);
char tmp[50];
char *hdir = rz_file_path_join(binrc, rz_strf(tmp, "bin-%s", name));
free(binrc);
Expand Down
8 changes: 4 additions & 4 deletions librz/core/cmd/cmd_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ RZ_API bool rz_core_theme_load(RzCore *core, const char *name) {
return true;
}

char *home_themes = rz_path_home_prefix(RZ_THEMES);
char *system_themes = rz_path_system(RZ_THEMES);
char *home_themes = rz_path_home_prefix(RZ_HOME_THEMES);
char *system_themes = rz_path_system(RZ_SYSTEM_THEMES);
char *home_file = rz_file_path_join(home_themes, name);
char *system_file = rz_file_path_join(system_themes, name);
free(system_themes);
Expand Down Expand Up @@ -124,13 +124,13 @@ RZ_API RZ_OWN RzList /*<char *>*/ *rz_core_theme_list(RZ_NONNULL RzCore *core) {
return NULL;
}

char *path = rz_path_home_prefix(RZ_THEMES);
char *path = rz_path_home_prefix(RZ_HOME_THEMES);
if (path) {
list_themes_in_path(themes, path);
RZ_FREE(path);
}

path = rz_path_system(RZ_THEMES);
path = rz_path_system(RZ_SYSTEM_THEMES);
if (path) {
list_themes_in_path(themes, path);
RZ_FREE(path);
Expand Down
20 changes: 11 additions & 9 deletions librz/core/cmd/cmd_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,19 +1082,21 @@ static void cmd_print_format(RzCore *core, const char *_input, const ut8 *block,
case 'o': // "pfo"
if (_input[2] == '?') {
char *prefix = rz_path_prefix(NULL);
char *sdb_format = rz_path_home_prefix(RZ_SDB_FORMAT);
char *sdb_format = rz_path_home_prefix(RZ_HOME_SDB_FORMAT);
char *system_sdb_format = rz_path_system(RZ_SYSTEM_SDB_FORMAT);
eprintf("|Usage: pfo [format-file]\n"
" %s\n"
" " RZ_JOIN_3_PATHS("%s", RZ_SDB_FORMAT, "") "\n",
sdb_format, prefix);
" %s\n",
sdb_format, system_sdb_format);
free(system_sdb_format);
free(sdb_format);
free(prefix);
} else if (_input[2] == ' ') {
const char *fname = rz_str_trim_head_ro(_input + 3);
char *home_formats = rz_path_home_prefix(RZ_SDB_FORMAT);
char *home_formats = rz_path_home_prefix(RZ_HOME_SDB_FORMAT);
char *home = rz_file_path_join(home_formats, fname);
free(home_formats);
char *system_formats = rz_path_system(RZ_SDB_FORMAT);
char *system_formats = rz_path_system(RZ_SYSTEM_SDB_FORMAT);
char *path = rz_file_path_join(system_formats, fname);
free(system_formats);
if (rz_str_endswith(_input, ".h")) {
Expand All @@ -1120,7 +1122,7 @@ static void cmd_print_format(RzCore *core, const char *_input, const ut8 *block,
RzList *files;
RzListIter *iter;
const char *fn;
char *home = rz_path_home_prefix(RZ_SDB_FORMAT);
char *home = rz_path_home_prefix(RZ_HOME_SDB_FORMAT);
if (home) {
files = rz_sys_dir(home);
rz_list_foreach (files, iter, fn) {
Expand All @@ -1131,7 +1133,7 @@ static void cmd_print_format(RzCore *core, const char *_input, const ut8 *block,
rz_list_free(files);
free(home);
}
char *path = rz_path_system(RZ_SDB_FORMAT);
char *path = rz_path_system(RZ_SYSTEM_SDB_FORMAT);
if (path) {
files = rz_sys_dir(path);
rz_list_foreach (files, iter, fn) {
Expand Down Expand Up @@ -3077,8 +3079,8 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) {
"| foo@ 0x40 # use 'foo' magic file on address 0x40\n"
"| @ 0x40 # use current magic file on address 0x40\n"
"| \\n # append newline\n"
"| e dir.magic # defaults to " RZ_JOIN_2_PATHS("{RZ_PREFIX}", RZ_SDB_MAGIC) "\n"
"| /m # search for magic signatures\n");
"| e dir.magic # defaults to " RZ_JOIN_2_PATHS("{RZ_PREFIX}", RZ_SYSTEM_SDB_MAGIC) "\n"
"| /m # search for magic signatures\n");
} else if (input[1] == 'j') { // "pmj"
const char *filename = rz_str_trim_head_ro(input + 2);
PJ *pj = pj_new();
Expand Down
2 changes: 1 addition & 1 deletion librz/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,7 @@ RZ_API bool rz_core_init(RzCore *core) {
rz_bp_use(core->dbg->bp, RZ_SYS_ARCH);
update_sdb(core);
{
char *a = rz_path_system(RZ_FLAGS);
char *a = rz_path_system(RZ_SYSTEM_FLAGS);
if (a) {
char *file = rz_file_path_join(a, "tags.rz");
(void)rz_core_run_script(core, file);
Expand Down
2 changes: 1 addition & 1 deletion librz/core/fortune.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static const char *fortunes[] = {

static char *rizin_fortune_file(const char *type) {
if (!strncmp(type, "tips", 4) || !strncmp(type, "fun", 3)) {
char *fortunes_dir = rz_path_system(RZ_FORTUNES);
char *fortunes_dir = rz_path_system(RZ_SYSTEM_FORTUNES);
char buf[100];
char *res = rz_file_path_join(fortunes_dir, rz_strf(buf, "fortunes.%s", type));
free(fortunes_dir);
Expand Down
6 changes: 3 additions & 3 deletions librz/core/libs.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ static void loadSystemPlugins(RzCore *core, int where) {
free(p);
}
if (where & RZ_CORE_LOADLIBS_HOME) {
char *hpd = rz_path_home_prefix(RZ_PLUGINS);
char *hpd = rz_path_home_prefix(RZ_HOME_PLUGINS);
rz_lib_opendir(core->lib, hpd, false);
free(hpd);
}
if (where & RZ_CORE_LOADLIBS_SYSTEM) {
char *spd = rz_path_system(RZ_PLUGINS);
char *spd = rz_path_system(RZ_SYSTEM_PLUGINS);
rz_lib_opendir(core->lib, spd, false);
free(spd);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ RZ_API int rz_core_loadlibs(RzCore *core, int where) {
return false;
}
// load script plugins
char *homeplugindir = rz_path_home_prefix(RZ_PLUGINS);
char *homeplugindir = rz_path_home_prefix(RZ_HOME_PLUGINS);
RzList *files = rz_sys_dir(homeplugindir);
RzListIter *iter;
char *file;
Expand Down
4 changes: 2 additions & 2 deletions librz/core/tui/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

RZ_IPI bool rz_core_visual_hud(RzCore *core) {
const char *c = rz_config_get(core->config, "hud.path");
char *system_hud_dir = rz_path_system(RZ_HUD);
char *system_hud_dir = rz_path_system(RZ_SYSTEM_HUD);
char *f = rz_file_path_join(system_hud_dir, "main");
free(system_hud_dir);
int use_color = core->print->flags & RZ_PRINT_FLAGS_COLOR;
char *homehud = rz_path_home_prefix(RZ_HUD);
char *homehud = rz_path_home_prefix(RZ_HOME_HUD);
char *res = NULL;
char *p = 0;
rz_cons_singleton()->context->color_mode = use_color;
Expand Down
2 changes: 1 addition & 1 deletion librz/core/tui/panels.c
Original file line number Diff line number Diff line change
Expand Up @@ -5248,7 +5248,7 @@ void __restore_panel_pos(RzPanel *panel) {
}

char *__get_panels_config_dir_path(void) {
char *home_datadir = rz_path_home_prefix(RZ_DATADIR);
char *home_datadir = rz_path_home_prefix(RZ_HOME_DATADIR);
char *res = rz_file_path_join(home_datadir, ".rzpanels");
free(home_datadir);
return res;
Expand Down
Loading

0 comments on commit dd6ca70

Please sign in to comment.