Remove Global/Static variables in path.c to make it thread safe (#5148)
This commit is contained in:
parent
643622098c
commit
93d914bd81
63 changed files with 559 additions and 289 deletions
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
|
|
@ -107,6 +107,16 @@ jobs:
|
|||
enabled: ${{ needs.changes.outputs.edited == 'true' }}
|
||||
timeout: 120
|
||||
allow_failure: false
|
||||
- name: linux-gcc-tests-portable
|
||||
os: ubuntu-24.04
|
||||
build_system: meson
|
||||
compiler: gcc
|
||||
cflags: "-DRZ_ASSERT_STDOUT=1"
|
||||
meson_options: --buildtype=debug --default-library=static -Dstatic_runtime=true -Dportable=true
|
||||
run_tests: false
|
||||
enabled: ${{ needs.changes.outputs.edited == 'true' }}
|
||||
timeout: 120
|
||||
allow_failure: false
|
||||
- name: linux-clang-tests-asan
|
||||
os: ubuntu-24.04
|
||||
build_system: meson
|
||||
|
|
|
|||
|
|
@ -231,9 +231,14 @@ int rz_test_main(int argc, const char **argv) {
|
|||
if (quiet) {
|
||||
printf(RZ_VERSION "\n");
|
||||
} else {
|
||||
char *s = rz_version_str("rz-test");
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
goto beach;
|
||||
}
|
||||
char *s = rz_version_str(sys_path, "rz-test");
|
||||
printf("%s\n", s);
|
||||
free(s);
|
||||
rz_path_free(sys_path);
|
||||
}
|
||||
ret = 0;
|
||||
goto beach;
|
||||
|
|
|
|||
|
|
@ -67,11 +67,26 @@ static void meta_item_free(void *item) {
|
|||
free(it);
|
||||
}
|
||||
|
||||
RZ_API RzAnalysis *rz_analysis_new(void) {
|
||||
RZ_API RzAnalysis *rz_analysis_new(RZ_NULLABLE const char *sdb_types_path) {
|
||||
RzAnalysis *analysis = RZ_NEW0(RzAnalysis);
|
||||
if (!analysis) {
|
||||
return NULL;
|
||||
}
|
||||
if (!sdb_types_path) {
|
||||
RzPath *path = rz_path_new();
|
||||
if (!path) {
|
||||
free(analysis);
|
||||
return NULL;
|
||||
}
|
||||
analysis->sdb_types_path = rz_path_system(path, RZ_SDB_TYPES);
|
||||
rz_path_free(path);
|
||||
if (!analysis->sdb_types_path) {
|
||||
free(analysis);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
analysis->sdb_types_path = rz_str_dup(sdb_types_path);
|
||||
}
|
||||
if (!rz_str_constpool_init(&analysis->constpool)) {
|
||||
free(analysis);
|
||||
return NULL;
|
||||
|
|
@ -194,6 +209,7 @@ RZ_API RzAnalysis *rz_analysis_free(RzAnalysis *a) {
|
|||
ht_up_free(a->ht_rop_semantics);
|
||||
ht_sp_free(a->plugins);
|
||||
rz_analysis_debug_info_free(a->debug_info);
|
||||
free(a->sdb_types_path);
|
||||
free(a);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -295,10 +311,8 @@ static bool analysis_set_os(RzAnalysis *analysis, const char *os) {
|
|||
}
|
||||
free(analysis->os);
|
||||
analysis->os = rz_str_dup(os);
|
||||
char *types_dir = rz_path_system(RZ_SDB_TYPES);
|
||||
rz_type_db_set_os(analysis->typedb, os);
|
||||
rz_type_db_reload(analysis->typedb, types_dir);
|
||||
free(types_dir);
|
||||
rz_type_db_reload(analysis->typedb, analysis->sdb_types_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -344,9 +358,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);
|
||||
rz_type_db_reload(analysis->typedb, types_dir);
|
||||
free(types_dir);
|
||||
rz_type_db_reload(analysis->typedb, analysis->sdb_types_path);
|
||||
}
|
||||
rz_analysis_set_reg_profile(analysis);
|
||||
}
|
||||
|
|
@ -386,9 +398,7 @@ RZ_API void rz_analysis_set_cpu(RzAnalysis *analysis, const char *cpu) {
|
|||
}
|
||||
|
||||
rz_type_db_set_cpu(analysis->typedb, cpu);
|
||||
char *types_dir = rz_path_system(RZ_SDB_TYPES);
|
||||
rz_type_db_reload(analysis->typedb, types_dir);
|
||||
free(types_dir);
|
||||
rz_type_db_reload(analysis->typedb, analysis->sdb_types_path);
|
||||
}
|
||||
|
||||
RZ_API int rz_analysis_set_big_endian(RzAnalysis *analysis, int bigend) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <rz_util/rz_strbuf.h>
|
||||
#include <rz_util/rz_regex.h>
|
||||
#include <rz_util/rz_assert.h>
|
||||
#include <rz_util/rz_path.h>
|
||||
#include <rz_list.h>
|
||||
#include <stdio.h>
|
||||
#include <rz_core.h>
|
||||
|
|
@ -283,6 +284,11 @@ RZ_API RzAsm *rz_asm_new(void) {
|
|||
a->bits = RZ_SYS_BITS;
|
||||
a->bitshift = 0;
|
||||
a->syntax = RZ_ASM_SYNTAX_INTEL;
|
||||
a->sdb_opcodes_path = rz_path_new();
|
||||
if (!a->sdb_opcodes_path) {
|
||||
free(a);
|
||||
return NULL;
|
||||
}
|
||||
a->plugins = ht_sp_new(HT_STR_DUP, NULL, NULL);
|
||||
if (!a->plugins) {
|
||||
free(a);
|
||||
|
|
@ -346,6 +352,7 @@ RZ_API void rz_asm_free(RzAsm *a) {
|
|||
free(a->features);
|
||||
sdb_free(a->pair);
|
||||
ht_ss_free(a->flags);
|
||||
rz_path_free(a->sdb_opcodes_path);
|
||||
a->pair = NULL;
|
||||
free(a);
|
||||
}
|
||||
|
|
@ -466,7 +473,11 @@ RZ_API bool rz_asm_use(RzAsm *a, RZ_NULLABLE 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(a->sdb_opcodes_path, RZ_SDB_OPCODES);
|
||||
if (!opcodes_dir) {
|
||||
rz_iterator_free(iter);
|
||||
return false;
|
||||
}
|
||||
char *file = rz_str_newf("%s/%s.sdb", opcodes_dir, h->arch);
|
||||
if (file) {
|
||||
rz_asm_set_cpu(a, NULL);
|
||||
|
|
@ -1103,11 +1114,11 @@ RZ_API RzAsmCode *rz_asm_massemble(RzAsm *a, const char *assembly) {
|
|||
} else if (!strncmp(ptr, ".fill ", 6)) {
|
||||
ret = rz_asm_pseudo_fill(&op, ptr + 6);
|
||||
} else if (!strncmp(ptr, ".kernel ", 8)) {
|
||||
rz_syscall_setup(a->syscall, a->cur->arch, a->bits, asmcpu, ptr + 8);
|
||||
rz_syscall_setup(a->syscall, a->sdb_opcodes_path, a->cur->arch, a->bits, asmcpu, ptr + 8);
|
||||
} else if (!strncmp(ptr, ".cpu ", 5)) {
|
||||
rz_asm_set_cpu(a, ptr + 5);
|
||||
} else if (!strncmp(ptr, ".os ", 4)) {
|
||||
rz_syscall_setup(a->syscall, a->cur->arch, a->bits, asmcpu, ptr + 4);
|
||||
rz_syscall_setup(a->syscall, a->sdb_opcodes_path, a->cur->arch, a->bits, asmcpu, ptr + 4);
|
||||
} else if (!strncmp(ptr, ".hex ", 5)) {
|
||||
ret = rz_asm_op_set_hex(&op, ptr + 5);
|
||||
} else if ((!strncmp(ptr, ".int16 ", 7)) || !strncmp(ptr, ".short ", 7)) {
|
||||
|
|
|
|||
|
|
@ -52,8 +52,12 @@ static char *__read_nonnull_str_at(RzBuffer *buf, ut64 offset) {
|
|||
return str;
|
||||
}
|
||||
|
||||
static char *__func_name_from_ord(char *module, ut16 ordinal) {
|
||||
char *formats_dir = rz_path_system(RZ_SDB_FORMAT);
|
||||
static char *__func_name_from_ord(RZ_BORROW RZ_NONNULL RzPath *sys_path, char *module, ut16 ordinal) {
|
||||
rz_return_val_if_fail(sys_path, NULL);
|
||||
char *formats_dir = rz_path_system(sys_path, RZ_SDB_FORMAT);
|
||||
if (!formats_dir) {
|
||||
return NULL;
|
||||
}
|
||||
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);
|
||||
|
|
@ -540,6 +544,12 @@ RzPVector /*<RzBinReloc *>*/ *rz_bin_ne_get_relocs(rz_bin_ne_obj_t *bin) {
|
|||
free(modref);
|
||||
return NULL;
|
||||
}
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
free(relocs);
|
||||
free(modref);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ut64 bufsz = rz_buf_size(bin->buf);
|
||||
void **it;
|
||||
|
|
@ -595,7 +605,7 @@ RzPVector /*<RzBinReloc *>*/ *rz_bin_ne_get_relocs(rz_bin_ne_obj_t *bin) {
|
|||
}
|
||||
if (rel.flags & IMPORTED_ORD) {
|
||||
imp->ordinal = rel.func_ord;
|
||||
imp->name = rz_str_newf("%s.%s", name, __func_name_from_ord(name, rel.func_ord));
|
||||
imp->name = rz_str_newf("%s.%s", name, __func_name_from_ord(sys_path, name, rel.func_ord));
|
||||
} else {
|
||||
offset = bin->header_offset + bin->ne_header->ImportNameTable + rel.name_off;
|
||||
char *func = __read_nonnull_str_at(bin->buf, offset);
|
||||
|
|
@ -663,6 +673,7 @@ RzPVector /*<RzBinReloc *>*/ *rz_bin_ne_get_relocs(rz_bin_ne_obj_t *bin) {
|
|||
}
|
||||
}
|
||||
free(modref);
|
||||
rz_path_free(sys_path);
|
||||
return relocs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,11 +52,13 @@ static char *resolveModuleOrdinal(Sdb *sdb, const char *module, int ordinal) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int bin_pe_parse_imports(RzBinPEObj *bin,
|
||||
static int bin_pe_parse_imports(RZ_BORROW RZ_NONNULL RzPath *sys_path,
|
||||
RzBinPEObj *bin,
|
||||
struct rz_bin_pe_import_t **importp, int *nimp,
|
||||
const char *dll_name,
|
||||
PE_DWord OriginalFirstThunk,
|
||||
PE_DWord FirstThunk) {
|
||||
rz_return_val_if_fail(sys_path, 0);
|
||||
char import_name[PE_NAME_LENGTH + 1];
|
||||
char name[PE_NAME_LENGTH + 1];
|
||||
PE_Word import_hint, import_ordinal = 0;
|
||||
|
|
@ -114,8 +116,11 @@ 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);
|
||||
free(filename);
|
||||
char *formats_dir = rz_path_system(sys_path, RZ_SDB_FORMAT);
|
||||
if (!formats_dir) {
|
||||
goto error;
|
||||
}
|
||||
filename = rz_str_newf(RZ_JOIN_3_PATHS("%s", "dll", "%s.sdb"), formats_dir, symdllname);
|
||||
free(formats_dir);
|
||||
if (rz_file_exists(filename)) {
|
||||
|
|
@ -219,19 +224,27 @@ struct rz_bin_pe_import_t *PE_(rz_bin_pe_get_imports)(RzBinPEObj *bin) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
off = bin->import_directory_offset;
|
||||
if (off < bin->size && off > 0) {
|
||||
ut64 last;
|
||||
int idi = 0;
|
||||
if (off + sizeof(PE_(image_import_directory)) > bin->size) {
|
||||
rz_path_free(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
int r = PE_(read_image_import_directory)(bin->b, bin->import_directory_offset + idi * sizeof(curr_import_dir), &curr_import_dir);
|
||||
if (r < 0) {
|
||||
rz_path_free(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (bin->import_directory_size < 1) {
|
||||
rz_path_free(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
if (off + bin->import_directory_size > bin->size) {
|
||||
|
|
@ -260,7 +273,7 @@ struct rz_bin_pe_import_t *PE_(rz_bin_pe_get_imports)(RzBinPEObj *bin) {
|
|||
}
|
||||
dll_name[PE_NAME_LENGTH] = '\0';
|
||||
}
|
||||
if (!bin_pe_parse_imports(bin, &imports, &nimp, dll_name,
|
||||
if (!bin_pe_parse_imports(sys_path, bin, &imports, &nimp, dll_name,
|
||||
curr_import_dir.Characteristics,
|
||||
curr_import_dir.FirstThunk)) {
|
||||
break;
|
||||
|
|
@ -269,6 +282,7 @@ struct rz_bin_pe_import_t *PE_(rz_bin_pe_get_imports)(RzBinPEObj *bin) {
|
|||
r = PE_(read_image_import_directory)(bin->b, bin->import_directory_offset + idi * sizeof(curr_import_dir), &curr_import_dir);
|
||||
if (r < 0) {
|
||||
free(imports);
|
||||
rz_path_free(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -303,13 +317,14 @@ struct rz_bin_pe_import_t *PE_(rz_bin_pe_get_imports)(RzBinPEObj *bin) {
|
|||
goto beach;
|
||||
}
|
||||
dll_name[PE_NAME_LENGTH] = '\0';
|
||||
if (!bin_pe_parse_imports(bin, &imports, &nimp, dll_name, import_func_name_offset,
|
||||
if (!bin_pe_parse_imports(sys_path, bin, &imports, &nimp, dll_name, import_func_name_offset,
|
||||
curr_delay_import_dir.DelayImportAddressTable)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
beach:
|
||||
rz_path_free(sys_path);
|
||||
if (nimp) {
|
||||
imps = realloc(imports, (nimp + 1) * sizeof(struct rz_bin_pe_import_t));
|
||||
if (!imps) {
|
||||
|
|
|
|||
|
|
@ -15,9 +15,19 @@ static char *get_filetype(RzBuffer *b) {
|
|||
if (!ck) {
|
||||
return NULL;
|
||||
}
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
rz_magic_free(ck);
|
||||
return NULL;
|
||||
}
|
||||
const char *tmp = NULL;
|
||||
// TODO: dir.magic not honored here
|
||||
char *m = rz_path_system(RZ_SDB_MAGIC);
|
||||
char *m = rz_path_system(sys_path, RZ_SDB_MAGIC);
|
||||
if (!m) {
|
||||
rz_magic_free(ck);
|
||||
rz_path_free(sys_path);
|
||||
return NULL;
|
||||
}
|
||||
rz_magic_load(ck, m);
|
||||
free(m);
|
||||
rz_buf_read_at(b, 0, buf, sizeof(buf));
|
||||
|
|
@ -26,6 +36,7 @@ static char *get_filetype(RzBuffer *b) {
|
|||
res = rz_str_dup(tmp);
|
||||
}
|
||||
rz_magic_free(ck);
|
||||
rz_path_free(sys_path);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1364,7 +1364,12 @@ static RzList /*<RzBinSymbol *>*/ *resolve_syscalls(RzXNUKernelCacheObj *obj, ut
|
|||
if (!syscall) {
|
||||
goto beach;
|
||||
}
|
||||
rz_syscall_setup(syscall, "arm", 64, NULL, "ios");
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
goto beach;
|
||||
}
|
||||
rz_syscall_setup(syscall, sys_path, "arm", 64, NULL, "ios");
|
||||
rz_path_free(sys_path);
|
||||
if (!syscall->db) {
|
||||
goto beach;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4223,7 +4223,11 @@ RZ_API RZ_OWN RzList /*<RzSigDBEntry *>*/ *rz_core_analysis_sigdb_list(RZ_NONNUL
|
|||
}
|
||||
|
||||
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(core->sys_path, RZ_SIGDB);
|
||||
if (!system_sigdb) {
|
||||
rz_sign_sigdb_free(sigs);
|
||||
return rz_list_new();
|
||||
}
|
||||
analysis_sigdb_add(sigs, system_sigdb, with_details);
|
||||
free(system_sigdb);
|
||||
}
|
||||
|
|
@ -4877,8 +4881,10 @@ RZ_API void rz_core_analysis_type_init(RzCore *core) {
|
|||
int bits = core->rasm->bits;
|
||||
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(core->sys_path, RZ_SDB_TYPES);
|
||||
if (!types_dir) {
|
||||
return;
|
||||
}
|
||||
rz_type_db_init(core->analysis->typedb, types_dir, analysis_arch, bits, os);
|
||||
free(types_dir);
|
||||
}
|
||||
|
|
@ -4938,7 +4944,10 @@ RZ_API void rz_core_analysis_cc_init_by_path(RzCore *core, RZ_NULLABLE const cha
|
|||
}
|
||||
|
||||
RZ_API void rz_core_analysis_cc_init(RzCore *core) {
|
||||
char *types_dir = rz_path_system(RZ_SDB_TYPES);
|
||||
char *types_dir = rz_path_system(core->sys_path, RZ_SDB_TYPES);
|
||||
if (!types_dir) {
|
||||
return;
|
||||
}
|
||||
char *home_types_dir = rz_path_home_prefix(RZ_SDB_TYPES);
|
||||
rz_core_analysis_cc_init_by_path(core, types_dir, home_types_dir);
|
||||
free(types_dir);
|
||||
|
|
|
|||
|
|
@ -603,7 +603,10 @@ 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(r->sys_path, RZ_SDB_TYPES);
|
||||
if (!types_dir) {
|
||||
return false;
|
||||
}
|
||||
char *spath = rz_file_path_join(types_dir, "spec.sdb");
|
||||
free(types_dir);
|
||||
if (spath && rz_file_exists(spath)) {
|
||||
|
|
@ -697,7 +700,10 @@ RZ_API bool rz_core_bin_apply_dwarf(RzCore *core, RzBinFile *binfile) {
|
|||
}
|
||||
|
||||
rz_type_db_purge(core->analysis->typedb);
|
||||
char *types_dir = rz_path_system(RZ_SDB_TYPES);
|
||||
char *types_dir = rz_path_system(core->sys_path, RZ_SDB_TYPES);
|
||||
if (!types_dir) {
|
||||
return false;
|
||||
}
|
||||
rz_type_db_reload(core->analysis->typedb, types_dir);
|
||||
free(types_dir);
|
||||
|
||||
|
|
@ -1206,8 +1212,11 @@ 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);
|
||||
free(filename);
|
||||
char *formats_dir = rz_path_system(r->sys_path, RZ_SDB_FORMAT);
|
||||
if (!formats_dir) {
|
||||
return;
|
||||
}
|
||||
filename = rz_str_newf(RZ_JOIN_3_PATHS("%s", "dll", "%s.sdb"), formats_dir, module);
|
||||
free(formats_dir);
|
||||
if (rz_file_exists(filename)) {
|
||||
|
|
|
|||
|
|
@ -425,11 +425,17 @@ 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(core->sys_path, RZ_SDB_ARCH_CPUS);
|
||||
if (!cpus_dir) {
|
||||
return false;
|
||||
}
|
||||
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(core->sys_path, RZ_SDB_ARCH_PLATFORMS);
|
||||
if (!platforms_dir) {
|
||||
return false;
|
||||
}
|
||||
rz_platform_target_index_init(core->analysis->platform_target, rz_config_get(core->config, "asm.arch"), node->value, platform, platforms_dir);
|
||||
free(platforms_dir);
|
||||
|
||||
|
|
@ -580,10 +586,17 @@ static bool cb_asmarch(void *user, void *data) {
|
|||
const char *asmcpu = rz_config_get(core->config, "asm.cpu");
|
||||
const char *platform = rz_config_get(core->config, "asm.platform");
|
||||
rz_config_set(core->config, "analysis.cpu", asmcpu);
|
||||
rz_syscall_setup(core->analysis->syscall, node->value, core->analysis->bits, asmcpu, asmos);
|
||||
rz_syscall_setup(core->analysis->syscall, core->sys_path, 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(core->sys_path, RZ_SDB_ARCH_PLATFORMS);
|
||||
if (!platforms_dir) {
|
||||
return false;
|
||||
}
|
||||
char *cpus_dir = rz_path_system(core->sys_path, RZ_SDB_ARCH_CPUS);
|
||||
if (!cpus_dir) {
|
||||
free(platforms_dir);
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
|
|
@ -625,8 +638,15 @@ static bool cb_asmarch(void *user, void *data) {
|
|||
|
||||
const char *platform = rz_config_get(core->config, "asm.platform");
|
||||
if (asm_cpu_node) {
|
||||
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(core->sys_path, RZ_SDB_ARCH_PLATFORMS);
|
||||
if (!platforms_dir) {
|
||||
return false;
|
||||
}
|
||||
char *cpus_dir = rz_path_system(core->sys_path, RZ_SDB_ARCH_CPUS);
|
||||
if (!cpus_dir) {
|
||||
free(platforms_dir);
|
||||
return false;
|
||||
}
|
||||
rz_platform_target_index_init(core->analysis->platform_target, node->value, asm_cpu_node->value, platform, platforms_dir);
|
||||
rz_platform_profiles_init(core->analysis->arch_target, asm_cpu_node->value, node->value, cpus_dir);
|
||||
free(cpus_dir);
|
||||
|
|
@ -684,7 +704,7 @@ static bool cb_asmbits(void *user, void *data) {
|
|||
const char *asmcpu = rz_config_get(core->config, "asm.cpu");
|
||||
if (core->analysis) {
|
||||
rz_config_set(core->config, "analysis.cpu", asmcpu);
|
||||
if (!rz_syscall_setup(core->analysis->syscall, asmarch, bits, asmcpu, asmos)) {
|
||||
if (!rz_syscall_setup(core->analysis->syscall, core->sys_path, asmarch, bits, asmcpu, asmos)) {
|
||||
// eprintf ("asm.arch: Cannot setup syscall '%s/%s' from '%s'\n",
|
||||
// node->value, asmos, RZ_LIBDIR"/rizin/"RZ_VERSION"/syscall");
|
||||
}
|
||||
|
|
@ -776,7 +796,10 @@ 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(core->sys_path, RZ_SDB_ARCH_PLATFORMS);
|
||||
if (!platforms_dir) {
|
||||
return false;
|
||||
}
|
||||
rz_platform_target_index_init(core->analysis->platform_target, asmarch, asmcpu, node->value, platforms_dir);
|
||||
free(platforms_dir);
|
||||
return 1;
|
||||
|
|
@ -857,7 +880,7 @@ static bool cb_asmos(void *user, void *data) {
|
|||
asmarch = rz_config_node_get(core->config, "asm.arch");
|
||||
if (asmarch) {
|
||||
const char *asmcpu = rz_config_get(core->config, "asm.cpu");
|
||||
rz_syscall_setup(core->analysis->syscall, asmarch->value, core->analysis->bits, asmcpu, node->value);
|
||||
rz_syscall_setup(core->analysis->syscall, core->sys_path, asmarch->value, core->analysis->bits, asmcpu, node->value);
|
||||
update_syscall_ns(core);
|
||||
__setsegoff(core->config, asmarch->value, asmbits);
|
||||
}
|
||||
|
|
@ -3009,10 +3032,12 @@ RZ_API int rz_core_config_init(RzCore *core) {
|
|||
{
|
||||
char *pfx = rz_sys_getenv("RZ_PREFIX");
|
||||
if (!pfx) {
|
||||
pfx = rz_path_prefix(NULL);
|
||||
const char *pfx_const = rz_path_prefix(core->sys_path);
|
||||
SETCB("dir.prefix", pfx_const, NULL, "Default prefix rizin was compiled for");
|
||||
} else {
|
||||
SETCB("dir.prefix", pfx, NULL, "Default prefix rizin was compiled for");
|
||||
free(pfx);
|
||||
}
|
||||
SETCB("dir.prefix", pfx, NULL, "Default prefix rizin was compiled for");
|
||||
free(pfx);
|
||||
}
|
||||
#if __ANDROID__
|
||||
{ // use dir.home and also adjust check for permissions in directory before choosing a home
|
||||
|
|
@ -3443,10 +3468,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(core->sys_path, RZ_SDB_MAGIC);
|
||||
SETPREF("dir.magic", path, "Path to rz_magic files");
|
||||
free(path);
|
||||
path = rz_path_system(RZ_PLUGINS);
|
||||
path = rz_path_system(core->sys_path, RZ_PLUGINS);
|
||||
SETPREF("dir.plugins", path, "Path to plugin files to be loaded at startup");
|
||||
free(path);
|
||||
}
|
||||
|
|
@ -3611,7 +3636,7 @@ RZ_API int rz_core_config_init(RzCore *core) {
|
|||
#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(core->sys_path, RZ_WWWROOT);
|
||||
SETPREF("http.root", wwwroot, "http root directory");
|
||||
free(wwwroot);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -768,7 +768,7 @@ static bool try_loadlib(RzCore *core, const char *lib, ut64 addr) {
|
|||
|
||||
RZ_API bool rz_core_file_loadlib(RzCore *core, const char *lib, ut64 libaddr) {
|
||||
const char *dirlibs = rz_config_get(core->config, "dir.libs");
|
||||
char *libdir = rz_path_libdir();
|
||||
char *libdir = rz_path_libdir(core->sys_path);
|
||||
if (!dirlibs || !*dirlibs) {
|
||||
dirlibs = "." RZ_SYS_DIR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ RZ_API bool rz_core_theme_load(RzCore *core, const char *name) {
|
|||
|
||||
char *tmp = NULL;
|
||||
char *home_themes = rz_path_home_prefix(RZ_THEMES);
|
||||
char *system_themes = rz_path_system(RZ_THEMES);
|
||||
char *system_themes = rz_path_system(core->sys_path, RZ_THEMES);
|
||||
char *extra_themes = rz_path_extra(RZ_THEMES);
|
||||
char *home_file = rz_file_path_join(home_themes, name);
|
||||
char *system_file = rz_file_path_join(system_themes, name);
|
||||
|
|
@ -116,7 +116,7 @@ RZ_API RZ_OWN RzPVector /*<char *>*/ *rz_core_get_themes(RZ_NONNULL RzCore *core
|
|||
RZ_FREE(path);
|
||||
}
|
||||
|
||||
path = rz_path_system(RZ_THEMES);
|
||||
path = rz_path_system(core->sys_path, RZ_THEMES);
|
||||
if (path) {
|
||||
list_themes_in_path(themes, path);
|
||||
RZ_FREE(path);
|
||||
|
|
|
|||
|
|
@ -6376,7 +6376,7 @@ RZ_IPI RzCmdStatus rz_cmd_print_format_file_handler(RzCore *core, int argc, cons
|
|||
rz_list_free(files);
|
||||
free(home);
|
||||
}
|
||||
char *path = rz_path_system(RZ_SDB_FORMAT);
|
||||
char *path = rz_path_system(core->sys_path, RZ_SDB_FORMAT);
|
||||
if (path) {
|
||||
files = rz_sys_dir(path);
|
||||
rz_list_foreach (files, iter, fn) {
|
||||
|
|
@ -6392,7 +6392,7 @@ RZ_IPI RzCmdStatus rz_cmd_print_format_file_handler(RzCore *core, int argc, cons
|
|||
char *home_formats = rz_path_home_prefix(RZ_SDB_FORMAT);
|
||||
char *home = rz_file_path_join(home_formats, argv[1]);
|
||||
free(home_formats);
|
||||
char *system_formats = rz_path_system(RZ_SDB_FORMAT);
|
||||
char *system_formats = rz_path_system(core->sys_path, RZ_SDB_FORMAT);
|
||||
char *path = rz_file_path_join(system_formats, argv[1]);
|
||||
free(system_formats);
|
||||
if (rz_str_endswith(argv[1], ".h")) {
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ RZ_IPI RzCmdStatus rz_calculate_command_time_handler(RzCore *core, int argc, con
|
|||
RZ_IPI RzCmdStatus rz_show_version_info_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
|
||||
switch (state->mode) {
|
||||
case RZ_OUTPUT_MODE_STANDARD: {
|
||||
char *v = rz_version_str(NULL);
|
||||
char *v = rz_version_str(core->sys_path, NULL);
|
||||
rz_cons_printf("%s\n", v);
|
||||
free(v);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1641,7 +1641,13 @@ RZ_API bool rz_core_init(RzCore *core) {
|
|||
core->rasm = rz_asm_new();
|
||||
core->rasm->num = core->num;
|
||||
core->rasm->core = core;
|
||||
core->analysis = rz_analysis_new();
|
||||
// initialize path
|
||||
core->sys_path = rz_path_new();
|
||||
char *sdb_types_path = rz_path_system(core->sys_path, RZ_SDB_TYPES);
|
||||
core->analysis = rz_analysis_new(sdb_types_path);
|
||||
if (sdb_types_path) {
|
||||
free(sdb_types_path);
|
||||
}
|
||||
core->gadgets = rz_list_newf((RzListFree)rz_core_gadget_free);
|
||||
core->analysis->ev = core->ev;
|
||||
core->analysis->read_at = rz_core_analysis_read_at;
|
||||
|
|
@ -1749,7 +1755,7 @@ RZ_API bool rz_core_init(RzCore *core) {
|
|||
rz_config_set(core->config, "asm.arch", RZ_SYS_ARCH);
|
||||
update_sdb(core);
|
||||
{
|
||||
char *a = rz_path_system(RZ_FLAGS);
|
||||
char *a = rz_path_system(core->sys_path, RZ_FLAGS);
|
||||
if (a) {
|
||||
char *file = rz_file_path_join(a, "tags.rz");
|
||||
(void)rz_core_run_script(core, file);
|
||||
|
|
@ -1841,6 +1847,7 @@ RZ_API void rz_core_fini(RzCore *c) {
|
|||
RZ_FREE(c->curtheme);
|
||||
RZ_FREE_CUSTOM(c->visual, rz_core_visual_free);
|
||||
RZ_FREE_CUSTOM(c->warnings_after, rz_list_free);
|
||||
RZ_FREE_CUSTOM(c->sys_path, rz_path_free);
|
||||
}
|
||||
|
||||
RZ_API void rz_core_free(RzCore *c) {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,13 @@ static const char *fortunes[] = {
|
|||
"tips", "fun"
|
||||
};
|
||||
|
||||
static char *rizin_fortune_file(const char *type) {
|
||||
static char *rizin_fortune_file(RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *type) {
|
||||
rz_return_val_if_fail(sys_path, NULL);
|
||||
if (!strncmp(type, "tips", 4) || !strncmp(type, "fun", 3)) {
|
||||
char *fortunes_dir = rz_path_system(RZ_FORTUNES);
|
||||
char *fortunes_dir = rz_path_system(sys_path, RZ_FORTUNES);
|
||||
if (!fortunes_dir) {
|
||||
return NULL;
|
||||
}
|
||||
char buf[100];
|
||||
char *res = rz_file_path_join(fortunes_dir, rz_strf(buf, "fortunes.%s", type));
|
||||
free(fortunes_dir);
|
||||
|
|
@ -29,7 +33,7 @@ RZ_API void rz_core_fortune_list_types(void) {
|
|||
RZ_API void rz_core_fortune_list(RzCore *core) {
|
||||
const char *types = (char *)rz_config_get(core->config, "cfg.fortunes.file");
|
||||
|
||||
char *file = rizin_fortune_file(types);
|
||||
char *file = rizin_fortune_file(core->sys_path, types);
|
||||
char *str = rz_file_slurp(file, NULL);
|
||||
if (!str) {
|
||||
free(file);
|
||||
|
|
@ -51,7 +55,7 @@ RZ_API RZ_OWN char *rz_core_fortune_get_random(RzCore *core) {
|
|||
int lines = 0;
|
||||
const char *types = (char *)rz_config_get(core->config, "cfg.fortunes.file");
|
||||
|
||||
char *file = rizin_fortune_file(types);
|
||||
char *file = rizin_fortune_file(core->sys_path, types);
|
||||
char *line = rz_file_slurp_random_line_count(file, &lines);
|
||||
|
||||
free(file);
|
||||
|
|
|
|||
|
|
@ -89,7 +89,10 @@ static void loadSystemPlugins(RzCore *core, int where) {
|
|||
free(hpd);
|
||||
}
|
||||
if (where & RZ_CORE_LOADLIBS_SYSTEM) {
|
||||
char *spd = rz_path_system(RZ_PLUGINS);
|
||||
char *spd = rz_path_system(core->sys_path, RZ_PLUGINS);
|
||||
if (!spd) {
|
||||
return;
|
||||
}
|
||||
rz_lib_opendir(core->lib, spd, false);
|
||||
free(spd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
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(core->sys_path, RZ_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;
|
||||
|
|
|
|||
|
|
@ -3644,7 +3644,8 @@ int __help_cb(void *user) {
|
|||
}
|
||||
|
||||
int __version_cb(void *user) {
|
||||
char *v = rz_version_str(NULL);
|
||||
RzCore *core = (RzCore *)user;
|
||||
char *v = rz_version_str(core->sys_path, NULL);
|
||||
rz_cons_message(v);
|
||||
free(v);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ RZ_API RzEgg *rz_egg_new(void) {
|
|||
for (i = 0; i < RZ_ARRAY_SIZE(egg_static_plugins); i++) {
|
||||
rz_egg_plugin_add(egg, egg_static_plugins[i]);
|
||||
}
|
||||
egg->sys_path = rz_path_new();
|
||||
return egg;
|
||||
|
||||
beach:
|
||||
|
|
@ -111,6 +112,7 @@ RZ_API void rz_egg_free(RzEgg *egg) {
|
|||
if (!egg) {
|
||||
return;
|
||||
}
|
||||
rz_path_free(egg->sys_path);
|
||||
rz_buf_free(egg->src);
|
||||
rz_buf_free(egg->buf);
|
||||
rz_buf_free(egg->bin);
|
||||
|
|
@ -143,12 +145,12 @@ RZ_API bool rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, con
|
|||
egg->arch = RZ_SYS_ARCH_X86;
|
||||
switch (bits) {
|
||||
case 32:
|
||||
rz_syscall_setup(egg->syscall, arch, bits, asmcpu, os);
|
||||
rz_syscall_setup(egg->syscall, egg->sys_path, arch, bits, asmcpu, os);
|
||||
egg->remit = &emit_x86;
|
||||
egg->bits = bits;
|
||||
break;
|
||||
case 64:
|
||||
rz_syscall_setup(egg->syscall, arch, bits, asmcpu, os);
|
||||
rz_syscall_setup(egg->syscall, egg->sys_path, arch, bits, asmcpu, os);
|
||||
egg->remit = &emit_x64;
|
||||
egg->bits = bits;
|
||||
break;
|
||||
|
|
@ -159,7 +161,7 @@ RZ_API bool rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, con
|
|||
case 16:
|
||||
case 32:
|
||||
case 64:
|
||||
rz_syscall_setup(egg->syscall, arch, bits, asmcpu, os);
|
||||
rz_syscall_setup(egg->syscall, egg->sys_path, arch, bits, asmcpu, os);
|
||||
egg->remit = &emit_arm;
|
||||
egg->bits = bits;
|
||||
egg->endian = endian;
|
||||
|
|
@ -218,7 +220,7 @@ RZ_API bool rz_egg_load_file(RzEgg *egg, const char *file) {
|
|||
rz_str_sanitize(fileSanitized);
|
||||
const char *arch = rz_sys_arch_str(egg->arch);
|
||||
const char *os = rz_egg_os_as_string(egg->os);
|
||||
char *textFile = rz_egg_Cfile_parser(fileSanitized, arch, os, egg->bits);
|
||||
char *textFile = rz_egg_Cfile_parser(egg->sys_path, fileSanitized, arch, os, egg->bits);
|
||||
if (!textFile) {
|
||||
RZ_LOG_ERROR("egg: failure while parsing '%s'\n", fileSanitized);
|
||||
free(fileSanitized);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ static inline bool isXNU(const char *os) {
|
|||
return (!strcmp(os, "darwin") || !strcmp(os, "macos") || !strcmp(os, "tvos") || !strcmp(os, "watchos") || !strcmp(os, "ios"));
|
||||
}
|
||||
|
||||
static struct cEnv_t *rz_egg_Cfile_set_cEnv(const char *arch, const char *os, int bits) {
|
||||
static struct cEnv_t *rz_egg_Cfile_set_cEnv(RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *arch, const char *os, int bits) {
|
||||
rz_return_val_if_fail(sys_path, NULL);
|
||||
struct cEnv_t *cEnv = calloc(1, sizeof(struct cEnv_t));
|
||||
bool use_clang;
|
||||
char *buffer = NULL;
|
||||
|
|
@ -79,7 +80,7 @@ static struct cEnv_t *rz_egg_Cfile_set_cEnv(const char *arch, const char *os, in
|
|||
|
||||
cEnv->SFLIBPATH = rz_sys_getenv("SFLIBPATH");
|
||||
if (!cEnv->SFLIBPATH) {
|
||||
incdir = rz_path_incdir();
|
||||
incdir = rz_path_incdir(sys_path);
|
||||
|
||||
if (!(cEnv->SFLIBPATH = rz_str_newf("%s/sflib", incdir))) {
|
||||
goto fail;
|
||||
|
|
@ -238,10 +239,11 @@ fail:
|
|||
return false;
|
||||
}
|
||||
|
||||
RZ_API char *rz_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits) {
|
||||
RZ_API char *rz_egg_Cfile_parser(RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *file, const char *arch, const char *os, int bits) {
|
||||
rz_return_val_if_fail(sys_path, NULL);
|
||||
char *output = NULL;
|
||||
char *fileExt = NULL; // "file" with extension (.s, .text, ...)
|
||||
struct cEnv_t *cEnv = rz_egg_Cfile_set_cEnv(arch, os, bits);
|
||||
struct cEnv_t *cEnv = rz_egg_Cfile_set_cEnv(sys_path, arch, os, bits);
|
||||
|
||||
if (!cEnv) {
|
||||
goto fail;
|
||||
|
|
|
|||
|
|
@ -162,9 +162,8 @@ RZ_API void rz_egg_lang_include_path(RzEgg *egg, const char *path) {
|
|||
}
|
||||
|
||||
RZ_API void rz_egg_lang_include_init(RzEgg *egg) {
|
||||
char *prefix = rz_path_prefix(NULL);
|
||||
const char *prefix = rz_path_prefix(egg->sys_path);
|
||||
char *s = rz_str_newf(".:%s/%s", prefix, RZ_EGG_INCDIR_PATH);
|
||||
free(prefix);
|
||||
rz_sys_setenv(RZ_EGG_INCDIR_ENV, s);
|
||||
free(s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -540,6 +540,7 @@ typedef struct rz_analysis_t {
|
|||
RBTree global_var_tree; // global variables by address. must not overlap
|
||||
RzHash *hash;
|
||||
RzAnalysisDebugInfo *debug_info; ///< store all debug info parsed from DWARF, etc..
|
||||
char *sdb_types_path; ///< system path prefix, whether created in initialization or passed by RzCore.
|
||||
ut64 cmpval; ///< last compare value for jump table.
|
||||
ut64 lea_jmptbl_ip; ///< jump table x86 lea ip
|
||||
} RzAnalysis;
|
||||
|
|
@ -1592,7 +1593,7 @@ RZ_API bool rz_analysis_function_is_autonamed(RZ_NONNULL char *name);
|
|||
RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL char *name);
|
||||
|
||||
/* analysis.c */
|
||||
RZ_API RzAnalysis *rz_analysis_new(void);
|
||||
RZ_API RzAnalysis *rz_analysis_new(RZ_NULLABLE const char *sdb_types_path);
|
||||
RZ_API void rz_analysis_purge(RzAnalysis *analysis);
|
||||
RZ_API RzAnalysis *rz_analysis_free(RzAnalysis *r);
|
||||
RZ_API bool rz_analysis_plugin_add(RzAnalysis *analysis, RZ_NONNULL RzAnalysisPlugin *foo);
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ typedef struct rz_asm_t {
|
|||
Sdb *pair;
|
||||
RzSyscall *syscall;
|
||||
RzNum *num;
|
||||
RzPath *sdb_opcodes_path; ///< pointer to RzPath, contains path prefix of the system
|
||||
char *features;
|
||||
char *platforms;
|
||||
int invhex; // invalid instructions displayed in hex
|
||||
|
|
|
|||
|
|
@ -339,6 +339,7 @@ struct rz_core_t {
|
|||
RzCoreSeekHistory seek_history;
|
||||
RzHash *hash;
|
||||
RzList /*<char *>*/ *warnings_after;
|
||||
RzPath *sys_path; ///< pointer to RzPath, contains path prefix of the system
|
||||
|
||||
bool marks_init;
|
||||
ut64 marks[UT8_MAX + 1];
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ typedef struct rz_egg_t {
|
|||
Sdb *db;
|
||||
HtSP /*<RzEggPlugin *>*/ *plugins;
|
||||
RzList /*<struct egg_patch_t *>*/ *patches; // <RzBuffer>
|
||||
RzPath *sys_path; ///< pointer to RzPath, contains path prefix of the system
|
||||
struct rz_egg_emit_t *remit;
|
||||
int arch;
|
||||
int endian;
|
||||
|
|
@ -221,7 +222,7 @@ RZ_API bool rz_egg_patch_num(RzEgg *egg, int off, ut64 val, ut32 bits);
|
|||
RZ_API void rz_egg_finalize(RzEgg *egg);
|
||||
|
||||
/* rz_egg_Cfile.c */
|
||||
RZ_API char *rz_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits);
|
||||
RZ_API char *rz_egg_Cfile_parser(RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *file, const char *arch, const char *os, int bits);
|
||||
|
||||
/* lang.c */
|
||||
RZ_API char *rz_egg_mkvar(RzEgg *egg, char *out, const char *_str, int delta);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ typedef struct rz_lang_t {
|
|||
PrintfCallback cb_printf;
|
||||
RzCoreCmdStrCallback cmd_str;
|
||||
RzCoreCmdfCallback cmdf;
|
||||
RzPath *sys_path; ///< pointer to RzPath, contains path prefix of the system
|
||||
} RzLang;
|
||||
|
||||
typedef struct rz_lang_plugin_t {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ RZ_LIB_VERSION_HEADER(rz_main);
|
|||
typedef int (*RzMainCallback)(int argc, const char **argv);
|
||||
|
||||
RZ_API RzMainCallback rz_main_find(const char *name);
|
||||
RZ_API int rz_main_version_print(const char *program);
|
||||
RZ_API int rz_main_version_print(RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *program);
|
||||
RZ_API int rz_main_rz_ax(int argc, const char **argv);
|
||||
RZ_API int rz_main_rz_run(int argc, const char **argv);
|
||||
RZ_API int rz_main_rz_hash(int argc, const char **argv);
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ RZ_API RzSyscall *rz_syscall_new(void);
|
|||
RZ_API void rz_sysregs_db_free(RzSysregsDB *sysregdb);
|
||||
RZ_API void rz_syscall_free(RzSyscall *ctx);
|
||||
RZ_API RzSyscall *rz_syscall_ref(RzSyscall *sc);
|
||||
RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os);
|
||||
RZ_API bool rz_syscall_setup(RzSyscall *s, RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *arch, int bits, const char *cpu, const char *os);
|
||||
RZ_API RzSyscallItem *rz_syscall_get(RzSyscall *ctx, int num, int swi);
|
||||
RZ_API int rz_syscall_get_num(RzSyscall *ctx, const char *str);
|
||||
RZ_API const char *rz_syscall_get_i(RzSyscall *ctx, int num, int swi);
|
||||
|
|
|
|||
|
|
@ -2,23 +2,39 @@
|
|||
#define RZ_UTIL_PATH_H_
|
||||
|
||||
#include <rz_types.h>
|
||||
#include <rz_th.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
RZ_API void rz_path_set_prefix(RZ_NONNULL const char *path);
|
||||
RZ_API RZ_OWN char *rz_path_prefix(RZ_NULLABLE const char *path);
|
||||
RZ_API RZ_OWN char *rz_path_incdir(void);
|
||||
RZ_API RZ_OWN char *rz_path_bindir(void);
|
||||
RZ_API RZ_OWN char *rz_path_libdir(void);
|
||||
/**
|
||||
* \brief Holds Rizin's path prefix and synchronization utilities.
|
||||
*
|
||||
* This structure stores the computed prefix of Rizin's path, along with a flag
|
||||
* indicating whether the prefix has already been computed to avoid redundant work.
|
||||
* It also includes a mutex to ensure thread-safe access when computing or accessing the prefix.
|
||||
*/
|
||||
typedef struct rz_path_t {
|
||||
char *prefix; ///< the computed path prefix.
|
||||
bool prefix_searched; ///< flag indicating if the prefix has already been computed.
|
||||
RzThreadLock *prefix_mutex; ///< mutex to protect access to the prefix in multithreaded contexts.
|
||||
} RzPath;
|
||||
|
||||
RZ_API RZ_OWN char *rz_path_system(RZ_NULLABLE const char *path);
|
||||
#ifdef RZ_API
|
||||
|
||||
RZ_API void rz_path_set_prefix(RZ_BORROW RZ_NONNULL RzPath *sys_path, RZ_NONNULL const char *path);
|
||||
RZ_API const char *rz_path_prefix(RZ_BORROW RZ_NONNULL RzPath *sys_path);
|
||||
RZ_API RZ_OWN char *rz_path_incdir(RZ_BORROW RZ_NULLABLE RzPath *sys_path);
|
||||
RZ_API RZ_OWN char *rz_path_bindir(RZ_BORROW RZ_NULLABLE RzPath *sys_path);
|
||||
RZ_API RZ_OWN char *rz_path_libdir(RZ_BORROW RZ_NULLABLE RzPath *sys_path);
|
||||
|
||||
RZ_API RZ_OWN char *rz_path_system(RZ_BORROW RZ_NULLABLE RzPath *sys_path, RZ_NULLABLE const char *path);
|
||||
RZ_API RZ_OWN char *rz_path_extra(RZ_NULLABLE const char *path);
|
||||
RZ_API RZ_OWN char *rz_path_home_prefix(RZ_NULLABLE const char *path);
|
||||
RZ_API RZ_OWN char *rz_path_home(RZ_NULLABLE const char *path);
|
||||
|
||||
RZ_API RZ_OWN char *rz_path_system_rc(void);
|
||||
RZ_API RZ_OWN char *rz_path_system_rc(RZ_BORROW RZ_NULLABLE RzPath *sys_path);
|
||||
RZ_API RZ_OWN char *rz_path_home_rc(void);
|
||||
RZ_API RZ_OWN char *rz_path_home_config_rc(void);
|
||||
RZ_API RZ_OWN char *rz_path_home_config_rcdir(void);
|
||||
|
|
@ -30,6 +46,11 @@ RZ_API RZ_OWN char *rz_path_home_expand(RZ_NULLABLE const char *path);
|
|||
|
||||
RZ_API RZ_OWN char *rz_path_realpath(RZ_NULLABLE const char *path);
|
||||
|
||||
RZ_API RZ_OWN RzPath *rz_path_new(void);
|
||||
RZ_API void rz_path_free(RZ_OWN RZ_NULLABLE RzPath *p);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
RZ_API RZ_OWN char *rz_version_gittip();
|
||||
RZ_API RZ_OWN char *rz_version_str(const char *program);
|
||||
RZ_API RZ_OWN char *rz_version_gittip(RZ_BORROW RZ_NONNULL RzPath *sys_path);
|
||||
RZ_API RZ_OWN char *rz_version_str(RZ_BORROW RZ_NONNULL RzPath *sys_path, RZ_NULLABLE const char *program);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ RZ_API RzLang *rz_lang_new(void) {
|
|||
if (!lang) {
|
||||
return NULL;
|
||||
}
|
||||
lang->sys_path = rz_path_new();
|
||||
if (!lang->sys_path) {
|
||||
free(lang);
|
||||
return NULL;
|
||||
}
|
||||
lang->user = NULL;
|
||||
lang->langs = rz_list_new();
|
||||
if (!lang->langs) {
|
||||
|
|
@ -57,6 +62,7 @@ RZ_API void rz_lang_free(RzLang *lang) {
|
|||
rz_lang_undef(lang, NULL);
|
||||
rz_list_free(lang->langs);
|
||||
rz_list_free(lang->defs);
|
||||
rz_path_free(lang->sys_path);
|
||||
free(lang);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ static int lang_c_file(RzLang *lang, const char *file) {
|
|||
if (RZ_STR_ISEMPTY(cc)) {
|
||||
cc = rz_str_dup("gcc");
|
||||
}
|
||||
char *libdir = rz_path_libdir();
|
||||
char *libdir = rz_path_libdir(lang->sys_path);
|
||||
char *pkgconf_path = rz_file_path_join(libdir, "pkgconfig");
|
||||
char *file_esc = rz_str_escape_sh(file);
|
||||
char *libpath_esc = rz_str_escape_sh(libpath);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ static int lang_cpipe_file(RzLang *lang, const char *file) {
|
|||
free(cc);
|
||||
cc = rz_str_dup("gcc");
|
||||
}
|
||||
char *libdir = rz_path_libdir();
|
||||
char *libdir = rz_path_libdir(lang->sys_path);
|
||||
char *pkgconf_path = rz_file_path_join(libdir, "pkgconfig");
|
||||
char *file_esc = rz_str_escape_sh(file);
|
||||
char *libpath_esc = rz_str_escape_sh(libpath);
|
||||
|
|
|
|||
|
|
@ -36,8 +36,9 @@ RZ_API RzMainCallback rz_main_find(const char *name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
RZ_API int rz_main_version_print(const char *progname) {
|
||||
char *s = rz_version_str(progname);
|
||||
RZ_API int rz_main_version_print(RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *progname) {
|
||||
rz_return_val_if_fail(sys_path, -1);
|
||||
char *s = rz_version_str(sys_path, progname);
|
||||
printf("%s\n", s);
|
||||
free(s);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -86,8 +86,8 @@ static int rz_main_version_verify(int show) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int main_help(int line) {
|
||||
|
||||
static int main_help(RZ_BORROW RZ_NONNULL RzCore *core, int line) {
|
||||
rz_return_val_if_fail(core, 1);
|
||||
if (line < 2) {
|
||||
printf("%s%s", Color_CYAN, "Usage: ");
|
||||
printf(Color_RESET "rizin [-ACdfLMnNqStuvwzX] [-P patch] [-p prj] [-a arch] [-b bits] [-i file]\n"
|
||||
|
|
@ -161,21 +161,21 @@ static int main_help(int line) {
|
|||
}
|
||||
if (line == 2) {
|
||||
char *datahome = rz_path_home_prefix(RZ_DATADIR);
|
||||
char *incdir = rz_path_incdir();
|
||||
char *libdir = rz_path_libdir();
|
||||
char *incdir = rz_path_incdir(core->sys_path);
|
||||
char *libdir = rz_path_libdir(core->sys_path);
|
||||
char *home_rc = rz_path_home_rc();
|
||||
char *home_config_rc = rz_path_home_config_rc();
|
||||
char *home_config_rcdir = rz_path_home_config_rcdir();
|
||||
char *system_rc = rz_path_system_rc();
|
||||
char *system_rc = rz_path_system_rc(core->sys_path);
|
||||
char *binrc_dir = rz_path_home_prefix(RZ_BINRC);
|
||||
char *binrc = rz_file_path_join(binrc_dir, "bin-<format>");
|
||||
char *system_magic = rz_path_system(RZ_SDB_MAGIC);
|
||||
char *system_magic = rz_path_system(core->sys_path, RZ_SDB_MAGIC);
|
||||
char *home_plugins = rz_path_home_prefix(RZ_PLUGINS);
|
||||
char *system_plugins = rz_path_system(RZ_PLUGINS);
|
||||
char *system_plugins = rz_path_system(core->sys_path, RZ_PLUGINS);
|
||||
char *extra_plugins = rz_path_extra(RZ_PLUGINS);
|
||||
char *system_sigdb = rz_path_system(RZ_SIGDB);
|
||||
char *system_sigdb = rz_path_system(core->sys_path, RZ_SIGDB);
|
||||
char *extra_sigdb = rz_path_extra(RZ_SIGDB);
|
||||
char *dirPrefix = rz_path_prefix(NULL);
|
||||
const char *dirPrefix = rz_path_prefix(core->sys_path);
|
||||
char *extra_prefix = rz_path_extra(NULL);
|
||||
// clang-format off
|
||||
printf(
|
||||
|
|
@ -250,27 +250,27 @@ static int main_help(int line) {
|
|||
free(extra_plugins);
|
||||
free(system_sigdb);
|
||||
free(extra_sigdb);
|
||||
free(dirPrefix);
|
||||
free(extra_prefix);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int main_print_var(const char *var_name) {
|
||||
static int main_print_var(RZ_BORROW RZ_NONNULL RzCore *core, const char *var_name) {
|
||||
rz_return_val_if_fail(core, 1);
|
||||
int i = 0;
|
||||
char *prefix = rz_path_prefix(NULL);
|
||||
const char *prefix = rz_path_prefix(core->sys_path);
|
||||
char *extra_prefix = rz_path_extra(NULL);
|
||||
char *incdir = rz_path_incdir();
|
||||
char *libdir = rz_path_libdir();
|
||||
char *incdir = rz_path_incdir(core->sys_path);
|
||||
char *libdir = rz_path_libdir(core->sys_path);
|
||||
char *confighome = rz_path_home_config();
|
||||
char *datahome = rz_path_home_prefix(RZ_DATADIR);
|
||||
char *cachehome = rz_path_home_cache();
|
||||
char *homeplugins = rz_path_home_prefix(RZ_PLUGINS);
|
||||
char *sigdbdir = rz_path_system(RZ_SIGDB);
|
||||
char *sigdbdir = rz_path_system(core->sys_path, RZ_SIGDB);
|
||||
char *extrasigdbdir = rz_path_extra(RZ_SIGDB);
|
||||
char *plugins = rz_path_system(RZ_PLUGINS);
|
||||
char *plugins = rz_path_system(core->sys_path, RZ_PLUGINS);
|
||||
char *extraplugins = rz_path_extra(RZ_PLUGINS);
|
||||
char *magicpath = rz_path_system(RZ_SDB_MAGIC);
|
||||
char *magicpath = rz_path_system(core->sys_path, RZ_SDB_MAGIC);
|
||||
const char *is_portable = RZ_IS_PORTABLE ? "1" : "0";
|
||||
struct rizin_var_t {
|
||||
const char *name;
|
||||
|
|
@ -324,7 +324,6 @@ static int main_print_var(const char *var_name) {
|
|||
free(plugins);
|
||||
free(magicpath);
|
||||
free(extra_prefix);
|
||||
free(prefix);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -525,7 +524,7 @@ RZ_API int rz_main_rizin(int argc, const char **argv) {
|
|||
|
||||
// -H option without argument
|
||||
if (argc == 2 && !strcmp(argv[1], "-H")) {
|
||||
main_print_var(NULL);
|
||||
main_print_var(r, NULL);
|
||||
LISTS_FREE();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -629,7 +628,7 @@ RZ_API int rz_main_rizin(int argc, const char **argv) {
|
|||
help++;
|
||||
break;
|
||||
case 'H':
|
||||
main_print_var(opt.arg);
|
||||
main_print_var(r, opt.arg);
|
||||
LISTS_FREE();
|
||||
return 0;
|
||||
case 'i':
|
||||
|
|
@ -732,7 +731,7 @@ RZ_API int rz_main_rizin(int argc, const char **argv) {
|
|||
LISTS_FREE();
|
||||
RZ_FREE(debugbackend);
|
||||
free(customRarunProfile);
|
||||
return rz_main_version_print("rizin");
|
||||
return rz_main_version_print(r->sys_path, "rizin");
|
||||
}
|
||||
case 'V':
|
||||
return rz_main_version_verify(1);
|
||||
|
|
@ -838,7 +837,7 @@ RZ_API int rz_main_rizin(int argc, const char **argv) {
|
|||
LISTS_FREE();
|
||||
free(pfile);
|
||||
RZ_FREE(debugbackend);
|
||||
return main_help(help > 1 ? 2 : 0);
|
||||
return main_help(r, help > 1 ? 2 : 0);
|
||||
}
|
||||
if (customRarunProfile) {
|
||||
char *tfn = rz_file_temp(".rz-run");
|
||||
|
|
@ -1384,7 +1383,7 @@ RZ_API int rz_main_rizin(int argc, const char **argv) {
|
|||
}
|
||||
}
|
||||
{
|
||||
char *global_rc = rz_path_system_rc();
|
||||
char *global_rc = rz_path_system_rc(r->sys_path);
|
||||
if (rz_file_exists(global_rc)) {
|
||||
(void)rz_core_run_script(r, global_rc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ static RzAsmState *__as_new(void) {
|
|||
if (as->a) {
|
||||
as->a->num = rz_num_new(NULL, NULL, NULL);
|
||||
}
|
||||
as->analysis = rz_analysis_new();
|
||||
as->analysis = rz_analysis_new(NULL);
|
||||
__load_plugins(as);
|
||||
__as_set_archbits(as);
|
||||
}
|
||||
|
|
@ -541,7 +541,7 @@ static void __load_plugins(RzAsmState *as) {
|
|||
}
|
||||
|
||||
char *homeplugindir = rz_path_home_prefix(RZ_PLUGINS);
|
||||
char *sysplugindir = rz_path_system(RZ_PLUGINS);
|
||||
char *sysplugindir = rz_path_system(as->a->sdb_opcodes_path, RZ_PLUGINS);
|
||||
char *extraplugindir = rz_path_extra(RZ_PLUGINS);
|
||||
rz_lib_opendir(as->l, homeplugindir, false);
|
||||
rz_lib_opendir(as->l, sysplugindir, false);
|
||||
|
|
@ -717,13 +717,19 @@ RZ_API int rz_main_rz_asm(int argc, const char *argv[]) {
|
|||
rz_asm_set_syntax(as->a, syntax);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
case 'v': {
|
||||
if (as->quiet) {
|
||||
printf("%s\n", RZ_VERSION);
|
||||
} else {
|
||||
ret = rz_main_version_print("rz-asm");
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
goto beach;
|
||||
}
|
||||
ret = rz_main_version_print(sys_path, "rz-asm");
|
||||
rz_path_free(sys_path);
|
||||
}
|
||||
goto beach;
|
||||
}
|
||||
case 'w':
|
||||
whatsop = true;
|
||||
break;
|
||||
|
|
@ -764,7 +770,7 @@ RZ_API int rz_main_rz_asm(int argc, const char *argv[]) {
|
|||
rz_asm_set_bits(as->a, (env_bits && *env_bits) ? atoi(env_bits) : bits);
|
||||
rz_analysis_set_bits(as->analysis, (env_bits && *env_bits) ? atoi(env_bits) : bits);
|
||||
as->a->syscall = rz_syscall_new();
|
||||
rz_syscall_setup(as->a->syscall, arch, bits, cpu, kernel);
|
||||
rz_syscall_setup(as->a->syscall, as->a->sdb_opcodes_path, arch, bits, cpu, kernel);
|
||||
{
|
||||
bool canbebig = rz_asm_set_big_endian(as->a, isbig);
|
||||
if (isbig && !canbebig) {
|
||||
|
|
|
|||
|
|
@ -296,7 +296,15 @@ static int rax(RzNum *num, char *str, int len, int last, ut64 *_flags, int *fm)
|
|||
case 'I': flags ^= RZ_AX_FLAG_IPADDR_TO_LONG; break;
|
||||
case 'm': flags ^= RZ_AX_FLAG_DOS_TIMESTAMP_TO_STR; break;
|
||||
case 'W': flags ^= RZ_AX_FLAG_WIN_TIMESTAMP_TO_STR; break;
|
||||
case 'v': return rz_main_version_print("rz-ax");
|
||||
case 'v': {
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
break;
|
||||
}
|
||||
size_t print_val = rz_main_version_print(sys_path, "rz-ax");
|
||||
rz_path_free(sys_path);
|
||||
return print_val;
|
||||
}
|
||||
case '\0':
|
||||
*_flags = flags;
|
||||
return !use_stdin(num, _flags, fm);
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ RZ_API int rz_main_rz_bin(int argc, const char **argv) {
|
|||
bin = core.bin;
|
||||
if (!(tmp = rz_sys_getenv("RZ_NOPLUGINS"))) {
|
||||
char *homeplugindir = rz_path_home_prefix(RZ_PLUGINS);
|
||||
char *plugindir = rz_path_system(RZ_PLUGINS);
|
||||
char *plugindir = rz_path_system(core.sys_path, RZ_PLUGINS);
|
||||
char *extraplugindir = rz_path_extra(RZ_PLUGINS);
|
||||
RzLib *l = rz_lib_new(NULL, NULL);
|
||||
rz_lib_add_handler(l, RZ_LIB_TYPE_DEMANGLER, "demangler plugins",
|
||||
|
|
@ -960,9 +960,11 @@ RZ_API int rz_main_rz_bin(int argc, const char **argv) {
|
|||
case 'o': output = opt.arg; break;
|
||||
case 'p': core.io->va = false; break;
|
||||
case 'r': out_mode = RZ_MODE_RIZINCMD; break;
|
||||
case 'v':
|
||||
case 'v': {
|
||||
size_t print_val = rz_main_version_print(core.sys_path, "rz-bin");
|
||||
rz_core_fini(&core);
|
||||
return rz_main_version_print("rz-bin");
|
||||
return print_val;
|
||||
}
|
||||
case 'L':
|
||||
set_action(RZ_BIN_REQ_LISTPLUGINS);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -3094,10 +3094,17 @@ RZ_API int rz_main_rz_diff(int argc, const char **argv) {
|
|||
case DIFF_OPT_HEX_VISUAL:
|
||||
success = rz_diff_hex_visual(&ctx);
|
||||
break;
|
||||
case DIFF_OPT_VERSION:
|
||||
rz_main_version_print("rz-diff");
|
||||
case DIFF_OPT_VERSION: {
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
rz_diff_show_help(false);
|
||||
break;
|
||||
}
|
||||
rz_main_version_print(sys_path, "rz-diff");
|
||||
rz_path_free(sys_path);
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
case DIFF_OPT_USAGE:
|
||||
rz_diff_show_help(true);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -631,8 +631,15 @@ RZ_API int rz_main_rz_find(int argc, const char **argv) {
|
|||
case 'q':
|
||||
ro.quiet = true;
|
||||
break;
|
||||
case 'v':
|
||||
return rz_main_version_print("rz-find");
|
||||
case 'v': {
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
return show_help(argv[0], 1);
|
||||
}
|
||||
size_t print_val = rz_main_version_print(sys_path, "rz-find");
|
||||
rz_path_free(sys_path);
|
||||
return print_val;
|
||||
}
|
||||
case 'h':
|
||||
return show_help(argv[0], 0);
|
||||
case 'z':
|
||||
|
|
|
|||
|
|
@ -331,10 +331,12 @@ RZ_API int rz_main_rz_gg(int argc, const char **argv) {
|
|||
rz_egg_free(egg);
|
||||
free(sequence);
|
||||
return usage(1);
|
||||
case 'v':
|
||||
case 'v': {
|
||||
size_t print_val = rz_main_version_print(egg->sys_path, "rz-gg");
|
||||
free(sequence);
|
||||
rz_egg_free(egg);
|
||||
return rz_main_version_print("rz-gg");
|
||||
return print_val;
|
||||
}
|
||||
case 'z':
|
||||
show_str = 1;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1223,15 +1223,22 @@ static void hash_load_plugins(RzHashContext *ctx) {
|
|||
if (!RZ_STR_ISEMPTY(path)) {
|
||||
rz_lib_opendir(rl, path, false);
|
||||
}
|
||||
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
free(path);
|
||||
rz_lib_free(rl);
|
||||
free(tmp);
|
||||
return;
|
||||
}
|
||||
char *homeplugindir = rz_path_home_prefix(RZ_PLUGINS);
|
||||
char *sysplugindir = rz_path_system(RZ_PLUGINS);
|
||||
char *extraplugindir = rz_path_system(RZ_PLUGINS);
|
||||
char *sysplugindir = rz_path_system(sys_path, RZ_PLUGINS);
|
||||
char *extraplugindir = rz_path_system(sys_path, RZ_PLUGINS);
|
||||
rz_lib_opendir(rl, homeplugindir, false);
|
||||
rz_lib_opendir(rl, sysplugindir, false);
|
||||
if (extraplugindir) {
|
||||
rz_lib_opendir(rl, extraplugindir, false);
|
||||
}
|
||||
rz_path_free(sys_path);
|
||||
free(homeplugindir);
|
||||
free(sysplugindir);
|
||||
free(extraplugindir);
|
||||
|
|
@ -1274,9 +1281,15 @@ RZ_API int rz_main_rz_hash(int argc, const char **argv) {
|
|||
goto rz_main_rz_hash_end;
|
||||
}
|
||||
break;
|
||||
case RZ_HASH_OP_VERSION:
|
||||
rz_main_version_print("rz-hash");
|
||||
case RZ_HASH_OP_VERSION: {
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
goto rz_main_rz_hash_end;
|
||||
}
|
||||
rz_main_version_print(sys_path, "rz-hash");
|
||||
rz_path_free(sys_path);
|
||||
break;
|
||||
}
|
||||
case RZ_HASH_OP_USAGE:
|
||||
rz_hash_show_help(true);
|
||||
goto rz_main_rz_hash_end;
|
||||
|
|
|
|||
|
|
@ -157,21 +157,6 @@ static void rz_run_help(int v) {
|
|||
RZ_API int rz_main_rz_run(int argc, const char **argv) {
|
||||
RzRunProfile *p;
|
||||
int i, ret;
|
||||
if (argc == 1 || !strcmp(argv[1], "-h")) {
|
||||
rz_run_help(0);
|
||||
return 1;
|
||||
}
|
||||
if (!strcmp(argv[1], "-v")) {
|
||||
return rz_main_version_print("rz-run");
|
||||
}
|
||||
if (!strcmp(argv[1], "-t")) {
|
||||
rz_run_help(1);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(argv[1], "-l")) {
|
||||
rz_run_help(2);
|
||||
return 0;
|
||||
}
|
||||
const char *file = argv[1];
|
||||
if (!strcmp(file, "-w")) {
|
||||
#if __UNIX__
|
||||
|
|
@ -213,6 +198,31 @@ RZ_API int rz_main_rz_run(int argc, const char **argv) {
|
|||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
if (argc == 1 || !strcmp(argv[1], "-h")) {
|
||||
rz_run_help(0);
|
||||
ret = 1;
|
||||
goto finish;
|
||||
}
|
||||
if (!strcmp(argv[1], "-v")) {
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if(!sys_path){
|
||||
ret = 1;
|
||||
goto finish;
|
||||
}
|
||||
ret = rz_main_version_print(sys_path, "rz-run");
|
||||
rz_path_free(sys_path);
|
||||
goto finish;
|
||||
}
|
||||
if (!strcmp(argv[1], "-t")) {
|
||||
rz_run_help(1);
|
||||
ret = 0;
|
||||
goto finish;
|
||||
}
|
||||
if (!strcmp(argv[1], "-l")) {
|
||||
rz_run_help(2);
|
||||
ret = 0;
|
||||
goto finish;
|
||||
}
|
||||
ret = rz_run_config_env(p);
|
||||
if (ret) {
|
||||
printf("error while configuring the environment.\n");
|
||||
|
|
@ -220,6 +230,7 @@ RZ_API int rz_main_rz_run(int argc, const char **argv) {
|
|||
return 1;
|
||||
}
|
||||
ret = rz_run_start(p);
|
||||
finish:
|
||||
rz_run_free(p);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,8 +120,16 @@ RZ_API int rz_main_rz_sign(int argc, const char **argv) {
|
|||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'v':
|
||||
return rz_main_version_print("rz-sign");
|
||||
case 'v': {
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
ret = -1;
|
||||
goto rz_sign_end;
|
||||
}
|
||||
size_t print_val = rz_main_version_print(sys_path, "rz-sign");
|
||||
rz_path_free(sys_path);
|
||||
return print_val;
|
||||
}
|
||||
case 'h':
|
||||
rz_sign_show_help();
|
||||
goto rz_sign_end;
|
||||
|
|
|
|||
|
|
@ -999,7 +999,9 @@ RZ_API int rz_run_config_env(RzRunProfile *p) {
|
|||
RZ_LOG_WARN("rz-run: only one library can be opened at a time\n");
|
||||
free(p->_preload);
|
||||
}
|
||||
char *libdir = rz_path_libdir();
|
||||
RzPath *sys_path = rz_path_new();
|
||||
char *libdir = rz_path_libdir(sys_path);
|
||||
rz_path_free(sys_path);
|
||||
p->_preload = rz_file_path_join(libdir, "librz." RZ_LIB_EXT);
|
||||
free(libdir);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,9 +100,12 @@ RZ_API void rz_sysreg_item_free(RzSysregItem *s) {
|
|||
free(s);
|
||||
}
|
||||
|
||||
static bool load_sdb(Sdb **db, const char *name) {
|
||||
rz_return_val_if_fail(db, false);
|
||||
char *sdb_path = rz_path_system(RZ_SDB);
|
||||
static bool load_sdb(Sdb **db, RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *name) {
|
||||
rz_return_val_if_fail(db && sys_path, false);
|
||||
char *sdb_path = rz_path_system(sys_path, RZ_SDB);
|
||||
if (!sdb_path) {
|
||||
return false;
|
||||
}
|
||||
char *file_name = rz_str_newf("%s.sdb", name);
|
||||
char *file = rz_file_path_join(sdb_path, file_name);
|
||||
free(file_name);
|
||||
|
|
@ -226,7 +229,8 @@ RZ_API bool rz_sysreg_set_arch(RzSyscall *s, RZ_NONNULL const char *arch, RZ_NON
|
|||
}
|
||||
|
||||
// TODO: should be renamed to rz_syscall_use();
|
||||
RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os) {
|
||||
RZ_API bool rz_syscall_setup(RzSyscall *s, RZ_BORROW RZ_NONNULL RzPath *sys_path, const char *arch, int bits, const char *cpu, const char *os) {
|
||||
rz_return_val_if_fail(sys_path, false);
|
||||
bool syscall_changed, sysregs_changed;
|
||||
|
||||
if (!os || !*os) {
|
||||
|
|
@ -262,7 +266,7 @@ RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const cha
|
|||
char *dbName = rz_str_newf(RZ_JOIN_2_PATHS("syscall", "%s-%s-%d"),
|
||||
os, arch, bits);
|
||||
if (dbName) {
|
||||
if (!load_sdb(&s->db, dbName)) {
|
||||
if (!load_sdb(&s->db, sys_path, dbName)) {
|
||||
sdb_free(s->db);
|
||||
s->db = NULL;
|
||||
}
|
||||
|
|
@ -271,7 +275,11 @@ RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const cha
|
|||
}
|
||||
|
||||
if (sysregs_changed) {
|
||||
char *regs_dir = rz_path_system(RZ_SDB_REG);
|
||||
char *regs_dir = rz_path_system(sys_path, RZ_SDB_REG);
|
||||
if (!regs_dir) {
|
||||
free(regs_dir);
|
||||
return false;
|
||||
}
|
||||
rz_sysreg_set_arch(s, arch, regs_dir);
|
||||
free(regs_dir);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,31 +9,8 @@
|
|||
#include <rz_windows.h>
|
||||
|
||||
#if RZ_IS_PORTABLE
|
||||
#include <rz_constructor.h>
|
||||
#include <rz_th.h>
|
||||
|
||||
static char *portable_prefix = NULL;
|
||||
static bool portable_prefix_searched = false;
|
||||
static RzThreadLock *portable_prefix_mutex = NULL;
|
||||
|
||||
#ifdef RZ_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
||||
#pragma RZ_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(init_portable_prefix)
|
||||
#endif
|
||||
RZ_DEFINE_CONSTRUCTOR(init_portable_prefix)
|
||||
static void init_portable_prefix(void) {
|
||||
portable_prefix_mutex = rz_th_lock_new(false);
|
||||
}
|
||||
|
||||
#ifdef RZ_DEFINE_DESTRUCTOR_NEEDS_PRAGMA
|
||||
#pragma RZ_DEFINE_DESTRUCTOR_PRAGMA_ARGS(fini_portable_prefix)
|
||||
#endif
|
||||
RZ_DEFINE_DESTRUCTOR(fini_portable_prefix)
|
||||
static void fini_portable_prefix(void) {
|
||||
RZ_FREE(portable_prefix);
|
||||
portable_prefix_searched = false;
|
||||
RZ_FREE_CUSTOM(portable_prefix_mutex, rz_th_lock_free);
|
||||
}
|
||||
|
||||
static char *set_portable_prefix(void) {
|
||||
char *pid_to_path = rz_sys_pid_to_path(rz_sys_getpid());
|
||||
if (!pid_to_path) {
|
||||
|
|
@ -42,7 +19,6 @@ static char *set_portable_prefix(void) {
|
|||
|
||||
const char *filename = rz_file_basename(pid_to_path);
|
||||
char *it = rz_file_dirname(pid_to_path);
|
||||
free(pid_to_path);
|
||||
|
||||
for (int i = 0; i < RZ_BINDIR_DEPTH && it; i++) {
|
||||
char *tmp = it;
|
||||
|
|
@ -50,6 +26,7 @@ static char *set_portable_prefix(void) {
|
|||
free(tmp);
|
||||
}
|
||||
if (!it) {
|
||||
free(pid_to_path);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +42,7 @@ static char *set_portable_prefix(void) {
|
|||
}
|
||||
|
||||
char *exe_path = rz_file_path_join(bindir_real, filename);
|
||||
free(pid_to_path);
|
||||
free(bindir_real);
|
||||
char *exe_path_real = rz_path_realpath(exe_path);
|
||||
free(exe_path);
|
||||
|
|
@ -83,24 +61,23 @@ err:
|
|||
/**
|
||||
* \brief Return \p path prefixed by the Rizin install prefix
|
||||
*
|
||||
* The install prefix is taken from the build-time configuration RZ_PREFIX,
|
||||
* unless Rizin was compiled as "portable". In such a case the prefix is either
|
||||
* provided via the path argument or discovered from the path of the executable
|
||||
* calling this function.
|
||||
*
|
||||
* The install prefix is taken from \p path unless path is empty. In such a case the portable prefix is
|
||||
* computed.
|
||||
* \param sys_path RzPath* contains install prefix and mutex.
|
||||
* \param path Path to use when prefixing or NULL to use the executable location
|
||||
*/
|
||||
RZ_API void rz_path_set_prefix(RZ_NONNULL const char *path) {
|
||||
RZ_API void rz_path_set_prefix(RZ_BORROW RZ_NONNULL RzPath *sys_path, RZ_NONNULL const char *path) {
|
||||
#if RZ_IS_PORTABLE
|
||||
rz_th_lock_enter(portable_prefix_mutex);
|
||||
free(portable_prefix);
|
||||
rz_return_if_fail(sys_path && sys_path->prefix_mutex);
|
||||
rz_th_lock_enter(sys_path->prefix_mutex);
|
||||
free(sys_path->prefix);
|
||||
if (RZ_STR_ISNOTEMPTY(path)) {
|
||||
portable_prefix = rz_str_dup(path);
|
||||
sys_path->prefix = rz_str_dup(path);
|
||||
} else {
|
||||
portable_prefix = set_portable_prefix();
|
||||
sys_path->prefix = set_portable_prefix();
|
||||
}
|
||||
portable_prefix_searched = true;
|
||||
rz_th_lock_leave(portable_prefix_mutex);
|
||||
sys_path->prefix_searched = true;
|
||||
rz_th_lock_leave(sys_path->prefix_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -109,54 +86,57 @@ RZ_API void rz_path_set_prefix(RZ_NONNULL const char *path) {
|
|||
*
|
||||
* The install prefix is taken from the build-time configuration RZ_PREFIX,
|
||||
* unless Rizin was compiled as "portable". In such a case the prefix is
|
||||
* discovered from the path of the executable calling this function.
|
||||
*
|
||||
* \param path Path to put in the install prefix context or NULL to just get the install prefix
|
||||
* \return \p path prefixed by the Rizin install prefix or just the install prefix
|
||||
* provided via \p sys_path->prefix
|
||||
* \param sys_path RzPath* contains install prefix and mutex.
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_path_prefix(RZ_NULLABLE const char *path) {
|
||||
RZ_API const char *rz_path_prefix(RZ_BORROW RZ_NONNULL RzPath *sys_path) {
|
||||
#if RZ_IS_PORTABLE
|
||||
rz_th_lock_enter(portable_prefix_mutex);
|
||||
if (!portable_prefix_searched) {
|
||||
portable_prefix = set_portable_prefix();
|
||||
portable_prefix_searched = true;
|
||||
rz_return_val_if_fail(sys_path && sys_path->prefix_mutex, RZ_PREFIX);
|
||||
rz_th_lock_enter(sys_path->prefix_mutex);
|
||||
if (!sys_path->prefix_searched) {
|
||||
sys_path->prefix = set_portable_prefix();
|
||||
sys_path->prefix_searched = true;
|
||||
}
|
||||
rz_th_lock_leave(portable_prefix_mutex);
|
||||
rz_th_lock_leave(sys_path->prefix_mutex);
|
||||
|
||||
if (portable_prefix) {
|
||||
return rz_file_path_join(portable_prefix, path);
|
||||
if (sys_path->prefix) {
|
||||
return sys_path->prefix;
|
||||
}
|
||||
|
||||
#endif
|
||||
return rz_file_path_join(RZ_PREFIX, path);
|
||||
return RZ_PREFIX;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return the directory where include files are placed
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_path_incdir(void) {
|
||||
return rz_path_prefix(RZ_INCDIR);
|
||||
RZ_API RZ_OWN char *rz_path_incdir(RZ_BORROW RZ_NULLABLE RzPath *sys_path) {
|
||||
const char *prefix = rz_path_prefix(sys_path);
|
||||
return rz_file_path_join(prefix, RZ_INCDIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return the directory where the Rizin binaries are placed
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_path_bindir(void) {
|
||||
return rz_path_prefix(RZ_BINDIR);
|
||||
RZ_API RZ_OWN char *rz_path_bindir(RZ_BORROW RZ_NULLABLE RzPath *sys_path) {
|
||||
const char *prefix = rz_path_prefix(sys_path);
|
||||
return rz_file_path_join(prefix, RZ_BINDIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return the directory where the Rizin libraries are placed
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_path_libdir(void) {
|
||||
return rz_path_prefix(RZ_LIBDIR);
|
||||
RZ_API RZ_OWN char *rz_path_libdir(RZ_BORROW RZ_NULLABLE RzPath *sys_path) {
|
||||
const char *prefix = rz_path_prefix(sys_path);
|
||||
return rz_file_path_join(prefix, RZ_LIBDIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return the full system path of the given subpath \p path
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_path_system(RZ_NULLABLE const char *path) {
|
||||
return rz_path_prefix(path);
|
||||
RZ_API RZ_OWN char *rz_path_system(RZ_BORROW RZ_NULLABLE RzPath *sys_path, RZ_NULLABLE const char *path) {
|
||||
const char *prefix = rz_path_prefix(sys_path);
|
||||
return rz_file_path_join(prefix, path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -174,9 +154,11 @@ RZ_API RZ_OWN char *rz_path_extra(RZ_NULLABLE const char *path) {
|
|||
|
||||
/**
|
||||
* \brief Return the system path of the global rizinrc file
|
||||
* \param sys_path RzPath* contains mutex and install prefix.
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_path_system_rc(void) {
|
||||
return rz_path_prefix(RZ_GLOBAL_RC);
|
||||
RZ_API RZ_OWN char *rz_path_system_rc(RZ_BORROW RZ_NULLABLE RzPath *sys_path) {
|
||||
const char *prefix = rz_path_prefix(sys_path);
|
||||
return rz_file_path_join(prefix, RZ_GLOBAL_RC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -318,3 +300,30 @@ RZ_API RZ_OWN char *rz_path_realpath(RZ_NULLABLE const char *path) {
|
|||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return new RzPath pointer
|
||||
*/
|
||||
RZ_API RZ_OWN RzPath *rz_path_new(void) {
|
||||
RzPath *p = RZ_NEW0(RzPath);
|
||||
if (!p) {
|
||||
return NULL;
|
||||
}
|
||||
p->prefix = NULL;
|
||||
p->prefix_searched = false;
|
||||
p->prefix_mutex = rz_th_lock_new(false);
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deallocate memory that the RzPath* \p p is pointing to.
|
||||
* \param p RzPath* contains install prefix and mutex.
|
||||
*/
|
||||
RZ_API void rz_path_free(RZ_OWN RZ_NULLABLE RzPath *p) {
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
free(p->prefix);
|
||||
rz_th_lock_free(p->prefix_mutex);
|
||||
free(p);
|
||||
}
|
||||
|
|
@ -19,8 +19,9 @@
|
|||
*
|
||||
* \return The saved git commit hash as a string, or NULL if it's not available.
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_version_gittip() {
|
||||
char *datadir = rz_path_system(RZ_DATADIR);
|
||||
RZ_API RZ_OWN char *rz_version_gittip(RZ_BORROW RZ_NONNULL RzPath *sys_path) {
|
||||
rz_return_val_if_fail(sys_path, NULL);
|
||||
char *datadir = rz_path_system(sys_path, RZ_DATADIR);
|
||||
if (!datadir) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -44,11 +45,12 @@ RZ_API RZ_OWN char *rz_version_gittip() {
|
|||
* Returns a version string containing the program version and the OS that the
|
||||
* program is compiled against, and the program name, packager information and
|
||||
* git commit hash if available.
|
||||
*
|
||||
* \param sys_path RzPath *
|
||||
* \param program The program name, or NULL if it's not needed.
|
||||
* \return The version string.
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_version_str(const char *program) {
|
||||
RZ_API RZ_OWN char *rz_version_str(RZ_BORROW RZ_NONNULL RzPath *sys_path, RZ_NULLABLE const char *program) {
|
||||
rz_return_val_if_fail(sys_path, NULL);
|
||||
RzStrBuf *sb = rz_strbuf_new(NULL);
|
||||
if (program) {
|
||||
rz_strbuf_appendf(sb, "%s ", program);
|
||||
|
|
@ -58,7 +60,7 @@ RZ_API RZ_OWN char *rz_version_str(const char *program) {
|
|||
if (RZ_STR_ISNOTEMPTY(RZ_STR_PKG_VERSION_STRING)) {
|
||||
rz_strbuf_append(sb, RZ_STR_PKG_VERSION_STRING);
|
||||
}
|
||||
char *gittip = rz_version_gittip();
|
||||
char *gittip = rz_version_gittip(sys_path);
|
||||
if (gittip) {
|
||||
rz_strbuf_append(sb, "\n");
|
||||
rz_strbuf_appendf(sb, "commit: %s", gittip);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ static bool test_parse_dwarf_types(void) {
|
|||
// TODO fix, how to correctly promote binary info to the RzAnalysis in unit tests?
|
||||
rz_analysis_set_cpu(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 32);
|
||||
char *types_dir = rz_path_system(RZ_SDB_TYPES);
|
||||
char *types_dir = rz_path_system(core->sys_path, RZ_SDB_TYPES);
|
||||
mu_assert_notnull(types_dir, "couldn't allocate types_dir");
|
||||
rz_type_db_init(analysis->typedb, types_dir, "x86", 32, "linux");
|
||||
free(types_dir);
|
||||
|
||||
|
|
@ -214,7 +215,8 @@ static bool test_dwarf_function_parsing_rust(void) {
|
|||
// TODO fix, how to correctly promote binary info to the RzAnalysis in unit tests?
|
||||
rz_analysis_set_cpu(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 64);
|
||||
char *types_dir = rz_path_system(RZ_SDB_TYPES);
|
||||
char *types_dir = rz_path_system(core->sys_path, RZ_SDB_TYPES);
|
||||
mu_assert_notnull(types_dir, "couldn't allocate types_dir");
|
||||
rz_type_db_init(analysis->typedb, types_dir, "x86", 64, "linux");
|
||||
free(types_dir);
|
||||
|
||||
|
|
|
|||
|
|
@ -346,10 +346,8 @@ bool test_pdb_tpi_rust(void) {
|
|||
}
|
||||
|
||||
bool test_pdb_type_save(void) {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
char *types_dir = rz_path_system(RZ_SDB_TYPES);
|
||||
rz_type_db_init(analysis->typedb, types_dir, "x86", 32, "windows");
|
||||
free(types_dir);
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_type_db_init(analysis->typedb, analysis->sdb_types_path, "x86", 32, "windows");
|
||||
|
||||
mu_assert_true(pdb_info_save_types(analysis, "bins/pdb/Project1.pdb"), "pdb parsing failed");
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ static size_t blocks_count(RzAnalysis *analysis) {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_create() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
mu_assert_eq(blocks_count(analysis), 0, "initial count");
|
||||
|
|
@ -72,7 +72,7 @@ bool test_rz_analysis_block_contains() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_sp() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
ut64 base = 0xfa1afe1;
|
||||
|
|
@ -220,7 +220,7 @@ bool test_rz_analysis_block_sp() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_split() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisBlock *block = rz_analysis_create_block(analysis, 0x1337, 42);
|
||||
|
|
@ -294,7 +294,7 @@ bool test_rz_analysis_block_split() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_split_in_function() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisFunction *fcn = rz_analysis_create_function(analysis, "bbowner", 0x1337, RZ_ANALYSIS_FCN_TYPE_NULL);
|
||||
|
|
@ -328,7 +328,7 @@ bool test_rz_analysis_block_split_in_function() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_merge() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisBlock *first = rz_analysis_create_block(analysis, 0x1337, 42);
|
||||
|
|
@ -376,7 +376,7 @@ bool test_rz_analysis_block_merge() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_merge_in_function() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisFunction *fcn = rz_analysis_create_function(analysis, "bbowner", 0x1337, RZ_ANALYSIS_FCN_TYPE_NULL);
|
||||
|
|
@ -409,7 +409,7 @@ bool test_rz_analysis_block_merge_in_function() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_delete() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisFunction *fcn = rz_analysis_create_function(analysis, "bbowner", 0x1337, RZ_ANALYSIS_FCN_TYPE_NULL);
|
||||
|
|
@ -437,7 +437,7 @@ bool test_rz_analysis_block_delete() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_set_size() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisFunction *fcn = rz_analysis_create_function(analysis, "bbowner", 0x1337, RZ_ANALYSIS_FCN_TYPE_NULL);
|
||||
|
|
@ -476,7 +476,7 @@ bool test_rz_analysis_block_set_size() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_relocate() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisFunction *fcn = rz_analysis_create_function(analysis, "bbowner", 0x1337, RZ_ANALYSIS_FCN_TYPE_NULL);
|
||||
|
|
@ -541,7 +541,7 @@ bool test_rz_analysis_block_relocate() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_query() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
#define N 200
|
||||
|
|
@ -658,7 +658,7 @@ bool addr_list_cb(ut64 addr, void *user) {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_successors() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisBlock *blocks[10];
|
||||
|
|
@ -741,7 +741,7 @@ bool test_rz_analysis_block_successors() {
|
|||
bool test_rz_analysis_block_automerge() {
|
||||
size_t i;
|
||||
for (i = 0; i < SAMPLES; i++) {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisBlock *a = rz_analysis_create_block(analysis, 0x100, 0x10);
|
||||
|
|
@ -818,7 +818,7 @@ bool test_rz_analysis_block_automerge() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_block_chop_noreturn(void) {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_block_invariants(analysis);
|
||||
|
||||
RzAnalysisBlock *a = rz_analysis_create_block(analysis, 0x100, 0x10);
|
||||
|
|
@ -851,7 +851,7 @@ static const uint8_t example_code[0x18] = {
|
|||
};
|
||||
|
||||
bool test_rz_analysis_block_analyze_ops(void) {
|
||||
RzAnalysis *a = rz_analysis_new();
|
||||
RzAnalysis *a = rz_analysis_new(NULL);
|
||||
rz_analysis_use(a, "x86");
|
||||
rz_analysis_set_bits(a, 64);
|
||||
IOMock io;
|
||||
|
|
@ -928,7 +928,7 @@ static const uint8_t example_code_sp[0xa] = {
|
|||
};
|
||||
|
||||
bool test_rz_analysis_block_analyze_ops_sp(void) {
|
||||
RzAnalysis *a = rz_analysis_new();
|
||||
RzAnalysis *a = rz_analysis_new(NULL);
|
||||
rz_analysis_use(a, "x86");
|
||||
rz_analysis_set_bits(a, 64);
|
||||
IOMock io;
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ static Sdb *ref_db_self_err() {
|
|||
}
|
||||
|
||||
static RzAnalysis *ref_analysis() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_cc_set(analysis, "rax sectarian(rdx, rcx, stack)");
|
||||
return analysis;
|
||||
}
|
||||
|
||||
static RzAnalysis *ref_analysis_self_err() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_cc_set(analysis, "rax sectarian(rdx, rcx, stack)");
|
||||
rz_analysis_cc_set_self(analysis, "sectarian", "rsi");
|
||||
rz_analysis_cc_set_error(analysis, "sectarian", "rdi");
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ static bool function_check_invariants(RzAnalysis *analysis) {
|
|||
} while (0)
|
||||
|
||||
bool test_rz_analysis_function_relocate() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
assert_invariants(analysis);
|
||||
|
||||
RzAnalysisFunction *fa = rz_analysis_create_function(analysis, "do_something", 0x1337, RZ_ANALYSIS_FCN_TYPE_NULL);
|
||||
|
|
@ -117,7 +117,7 @@ bool test_rz_analysis_function_relocate() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_function_labels() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
RzAnalysisFunction *f = rz_analysis_create_function(analysis, "do_something", 0x1337, RZ_ANALYSIS_FCN_TYPE_NULL);
|
||||
|
||||
|
|
@ -325,7 +325,7 @@ bool test_initial_underscore(void) {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_function_set_type() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_use(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 32);
|
||||
rz_analysis_cc_set(analysis, "eax sectarian(ecx, edx, stack)");
|
||||
|
|
@ -434,7 +434,7 @@ bool test_rz_analysis_function_set_type() {
|
|||
}
|
||||
|
||||
bool test_noreturn_functions_list() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_analysis_noreturn_add(analysis, NULL, 0x800800);
|
||||
|
||||
|
|
@ -470,7 +470,7 @@ bool test_noreturn_functions_list() {
|
|||
}
|
||||
|
||||
bool test_analysis_function_rename() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
// we know b does not exist, rename a to b
|
||||
RzAnalysisFunction *a = rz_analysis_create_function(analysis, "a", 0xcafe, RZ_ANALYSIS_FCN_TYPE_FCN);
|
||||
|
|
@ -488,7 +488,7 @@ bool test_analysis_function_rename() {
|
|||
}
|
||||
|
||||
bool test_analysis_function_force_rename() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
RzAnalysisFunction *a = rz_analysis_create_function(analysis, "a", 0xcafe, RZ_ANALYSIS_FCN_TYPE_FCN);
|
||||
rz_analysis_create_function(analysis, "b", 0xbabe, RZ_ANALYSIS_FCN_TYPE_FCN);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ bool hint_equals(const RzAnalysisHint *a, const RzAnalysisHint *b) {
|
|||
} while (0)
|
||||
|
||||
bool test_rz_analysis_addr_hints() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
RzAnalysisHint *hint = rz_analysis_hint_get(analysis, 0x1337);
|
||||
assert_hint_eq(hint, &empty_hint);
|
||||
rz_analysis_hint_free(hint);
|
||||
|
|
@ -221,7 +221,7 @@ bool test_rz_analysis_addr_hints() {
|
|||
|
||||
#define RANGED_TEST(name, val, resetval, assert_val) \
|
||||
bool test_rz_analysis_hints_##name() { \
|
||||
RzAnalysis *analysis = rz_analysis_new(); \
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL); \
|
||||
\
|
||||
ut64 hint_addr = 0xdead; \
|
||||
assert_val(rz_analysis_hint_##name##_at(analysis, 0x1337, &hint_addr), resetval, "no " #name ""); \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "minunit.h"
|
||||
|
||||
bool test_meta_set() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "summer of love");
|
||||
|
|
@ -134,7 +134,7 @@ bool test_meta_set() {
|
|||
}
|
||||
|
||||
bool test_meta_get_at() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "vera gemini");
|
||||
|
|
@ -172,7 +172,7 @@ bool test_meta_get_at() {
|
|||
}
|
||||
|
||||
bool test_meta_get_in() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "vera gemini");
|
||||
|
|
@ -213,7 +213,7 @@ bool test_meta_get_in() {
|
|||
}
|
||||
|
||||
bool test_meta_get_all_at() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "vera gemini");
|
||||
|
|
@ -253,7 +253,7 @@ bool test_meta_get_all_at() {
|
|||
}
|
||||
|
||||
bool test_meta_get_all_in() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "vera gemini");
|
||||
|
|
@ -315,7 +315,7 @@ bool test_meta_get_all_in() {
|
|||
}
|
||||
|
||||
bool test_meta_get_all_intersect() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "vera gemini");
|
||||
|
|
@ -379,7 +379,7 @@ bool test_meta_get_all_intersect() {
|
|||
}
|
||||
|
||||
bool test_meta_del() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "vera gemini");
|
||||
|
|
@ -444,7 +444,7 @@ bool test_meta_del() {
|
|||
}
|
||||
|
||||
bool test_meta_rebase() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x200, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x200, "summer of love");
|
||||
|
|
@ -494,7 +494,7 @@ bool test_meta_rebase() {
|
|||
}
|
||||
|
||||
bool test_meta_spaces() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x100, 4, NULL);
|
||||
rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, 0x100, "summer of love");
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
rz_analysis_set_bits(analysis, bits);
|
||||
|
||||
bool test_rz_analysis_op_val() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
RzAnalysisOp op;
|
||||
SWITCH_TO_ARCH_BITS("x86", 64);
|
||||
// mov rax, [rbx+rcx+4]
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ static RzAnalysisVar *set_var_str(RzAnalysisFunction *fcn, RzAnalysisVarStorage
|
|||
}
|
||||
|
||||
bool test_rz_analysis_var() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_use(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 64);
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ bool test_rz_analysis_var() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_function_get_stack_var_in() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_use(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 64);
|
||||
|
||||
|
|
@ -288,7 +288,7 @@ bool test_rz_analysis_function_get_stack_var_in() {
|
|||
}
|
||||
|
||||
bool test_rz_analysis_function_var_expr_for_reg_access_at() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_use(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 64);
|
||||
rz_type_db_init(analysis->typedb, TEST_BUILD_TYPES_DIR, NULL, 64, NULL);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "minunit.h"
|
||||
|
||||
bool test_rz_analysis_xrefs_count() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
mu_assert_eq(rz_analysis_xrefs_count(analysis), 0, "xrefs count");
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ Sdb *blocks_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_block_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_analysis_create_block(analysis, 1337, 42);
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ bool test_analysis_block_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_block_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
Sdb *db = blocks_ref_db();
|
||||
bool succ = rz_serialize_analysis_blocks_load(db, analysis, NULL);
|
||||
|
|
@ -161,7 +161,7 @@ bool test_analysis_block_load() {
|
|||
mu_assert_ptreq(b->cmpreg, rz_str_constpool_get(&analysis->constpool, "rax"), "cmpreg from pool");
|
||||
|
||||
rz_analysis_free(analysis);
|
||||
analysis = rz_analysis_new();
|
||||
analysis = rz_analysis_new(NULL);
|
||||
// This could lead to a buffer overflow if unchecked:
|
||||
sdb_set(db, "0x539", "{\"size\":42,\"ninstr\":4,\"op_pos\":[4,7]}");
|
||||
succ = rz_serialize_analysis_blocks_load(db, analysis, NULL);
|
||||
|
|
@ -191,7 +191,7 @@ Sdb *functions_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_function_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
RzAnalysisBlock *ba = rz_analysis_create_block(analysis, 1337, 42);
|
||||
RzAnalysisBlock *bb = rz_analysis_create_block(analysis, 1234, 32);
|
||||
|
|
@ -243,7 +243,7 @@ bool test_analysis_function_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_function_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
Sdb *db = functions_ref_db();
|
||||
|
||||
|
|
@ -377,7 +377,7 @@ static Sdb *noreturn_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_function_noreturn_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_analysis_noreturn_add(analysis, NULL, 0x800800);
|
||||
bool has = sdb_bool_get(analysis->sdb_noret, "addr.800800.noreturn");
|
||||
|
|
@ -402,7 +402,7 @@ bool test_analysis_function_noreturn_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_function_noreturn_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
Sdb *db = noreturn_ref_db();
|
||||
bool succ = rz_serialize_analysis_function_noreturn_load(db, analysis, NULL);
|
||||
sdb_free(db);
|
||||
|
|
@ -457,7 +457,7 @@ static RzAnalysisVarStorage *composite_stor(RzAnalysisVarStorage *stor) {
|
|||
}
|
||||
|
||||
bool test_analysis_var_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_use(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 64);
|
||||
const char *types_dir = TEST_BUILD_TYPES_DIR;
|
||||
|
|
@ -525,7 +525,7 @@ bool test_analysis_var_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_var_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
rz_analysis_use(analysis, "x86");
|
||||
rz_analysis_set_bits(analysis, 64);
|
||||
const char *types_dir = TEST_BUILD_TYPES_DIR;
|
||||
|
|
@ -640,7 +640,7 @@ Sdb *xrefs_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_xrefs_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_analysis_xrefs_set(analysis, 0x1337, 4242, RZ_ANALYSIS_XREF_TYPE_NULL);
|
||||
rz_analysis_xrefs_set(analysis, 0x1337, 4243, RZ_ANALYSIS_XREF_TYPE_CODE);
|
||||
|
|
@ -660,7 +660,7 @@ bool test_analysis_xrefs_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_xrefs_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
Sdb *db = xrefs_ref_db();
|
||||
|
||||
|
|
@ -742,7 +742,7 @@ Sdb *meta_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_meta_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_meta_set(analysis, RZ_META_TYPE_DATA, 0x1337, 0x10, NULL);
|
||||
rz_meta_set(analysis, RZ_META_TYPE_CODE, 0x1337, 0x11, NULL);
|
||||
|
|
@ -778,7 +778,7 @@ bool test_analysis_meta_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_meta_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
Sdb *db = meta_ref_db();
|
||||
|
||||
|
|
@ -1004,7 +1004,7 @@ static int all_optypes[] = {
|
|||
#define ALL_OPTYPES_COUNT (sizeof(all_optypes) / sizeof(int))
|
||||
|
||||
bool test_analysis_hints_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_analysis_hint_set_arch(analysis, 0x100, "arm");
|
||||
rz_analysis_hint_set_bits(analysis, 0x100, 16);
|
||||
|
|
@ -1059,7 +1059,7 @@ static bool bits_hints_count_cb(ut64 addr, int bits, void *user) {
|
|||
}
|
||||
|
||||
bool test_analysis_hints_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
Sdb *db = hints_ref_db();
|
||||
|
||||
|
|
@ -1145,7 +1145,7 @@ Sdb *classes_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_classes_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_analysis_class_create(analysis, "Aeropause");
|
||||
RzAnalysisMethod crystal = {
|
||||
|
|
@ -1198,7 +1198,7 @@ bool test_analysis_classes_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_classes_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
Sdb *db = classes_ref_db();
|
||||
bool succ = rz_serialize_analysis_classes_load(db, analysis, NULL);
|
||||
sdb_free(db);
|
||||
|
|
@ -1269,7 +1269,7 @@ static Sdb *cc_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_cc_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
rz_analysis_cc_set(analysis, "rax sectarian(rdx, rcx, stack)");
|
||||
rz_analysis_cc_set_self(analysis, "sectarian", "rsi");
|
||||
|
|
@ -1287,7 +1287,7 @@ bool test_analysis_cc_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_cc_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
Sdb *db = cc_ref_db();
|
||||
bool succ = rz_serialize_analysis_cc_load(db, analysis, NULL);
|
||||
sdb_free(db);
|
||||
|
|
@ -1362,7 +1362,7 @@ Sdb *analysis_ref_db() {
|
|||
}
|
||||
|
||||
bool test_analysis_save() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
RzAnalysisBlock *ba = rz_analysis_create_block(analysis, 1337, 42);
|
||||
RzAnalysisBlock *bb = rz_analysis_create_block(analysis, 1234, 32);
|
||||
|
|
@ -1421,7 +1421,7 @@ bool test_analysis_save() {
|
|||
}
|
||||
|
||||
bool test_analysis_load() {
|
||||
RzAnalysis *analysis = rz_analysis_new();
|
||||
RzAnalysis *analysis = rz_analysis_new(NULL);
|
||||
|
||||
const char *types_dir = TEST_BUILD_TYPES_DIR;
|
||||
rz_type_db_init(analysis->typedb, types_dir, "x86", 64, "linux");
|
||||
|
|
|
|||
|
|
@ -42,21 +42,21 @@ static RzAsm *setup_x86_asm(ut32 bits) {
|
|||
}
|
||||
|
||||
static RzAnalysis *setup_x86_analysis(ut32 bits) {
|
||||
RzAnalysis *a = rz_analysis_new();
|
||||
RzAnalysis *a = rz_analysis_new(NULL);
|
||||
rz_analysis_use(a, "x86");
|
||||
rz_analysis_set_bits(a, bits);
|
||||
return a;
|
||||
}
|
||||
|
||||
static RzAnalysis *setup_arm_analysis(ut32 bits) {
|
||||
RzAnalysis *a = rz_analysis_new();
|
||||
RzAnalysis *a = rz_analysis_new(NULL);
|
||||
rz_analysis_use(a, "arm");
|
||||
rz_analysis_set_bits(a, bits);
|
||||
return a;
|
||||
}
|
||||
|
||||
static RzAnalysis *setup_hexagon_analysis() {
|
||||
RzAnalysis *a = rz_analysis_new();
|
||||
RzAnalysis *a = rz_analysis_new(NULL);
|
||||
rz_analysis_use(a, "hexagon");
|
||||
rz_analysis_set_bits(a, 32);
|
||||
return a;
|
||||
|
|
@ -79,7 +79,7 @@ static ut32 hexagon_set_next_pc(RZ_BORROW RzAsm *a) {
|
|||
}
|
||||
|
||||
static RzAnalysis *setup_tms_analysis(const char *cpu) {
|
||||
RzAnalysis *a = rz_analysis_new();
|
||||
RzAnalysis *a = rz_analysis_new(NULL);
|
||||
rz_analysis_use(a, "tms320");
|
||||
rz_analysis_set_bits(a, 32);
|
||||
rz_analysis_set_cpu(a, cpu);
|
||||
|
|
|
|||
|
|
@ -62,9 +62,23 @@ bool test_leading_zeros(void) {
|
|||
mu_end;
|
||||
}
|
||||
|
||||
bool test_path_prefix(void) {
|
||||
size_t equal;
|
||||
RzPath *sys_path = rz_path_new();
|
||||
if (!sys_path) {
|
||||
mu_assert_eq(1, 0, "initialization error");
|
||||
}
|
||||
const char *output = rz_path_prefix(sys_path);
|
||||
equal = strcmp(output, RZ_PREFIX);
|
||||
mu_assert_eq(equal, 0, "not equal");
|
||||
rz_path_free(sys_path);
|
||||
mu_end;
|
||||
}
|
||||
|
||||
int all_tests() {
|
||||
mu_run_test(test_file_slurp);
|
||||
mu_run_test(test_leading_zeros);
|
||||
mu_run_test(test_path_prefix);
|
||||
return tests_passed != tests_run;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue