From 706a6bf6c20f089f56d21fbb1e89b5afa6e02253 Mon Sep 17 00:00:00 2001 From: pelijah Date: Sun, 12 May 2024 13:27:54 +0300 Subject: [PATCH] sdb: remove unused `cas` and `expire` features (#4487) --- librz/arch/analysis.c | 38 +- librz/arch/asm.c | 2 +- librz/arch/cc.c | 42 +-- librz/arch/class.c | 76 ++-- librz/arch/esil/esil_stats.c | 12 +- librz/arch/platform_profile.c | 4 +- librz/arch/platform_target_index.c | 4 +- librz/arch/serialize_analysis.c | 14 +- librz/bin/dwarf/dwarf.c | 2 +- librz/bin/format/elf/elf.c | 56 +-- librz/bin/format/elf/elf_info.c | 42 +-- librz/bin/format/java/class_bin.c | 22 +- librz/bin/format/mach0/mach0.c | 208 +++++------ librz/bin/format/mdmp/mdmp.c | 192 ++++------ librz/bin/format/mdmp/mdmp_pe.c | 6 +- librz/bin/format/mz/mz.c | 15 +- librz/bin/format/ne/ne.c | 2 +- librz/bin/format/objc/mach0_classes.c | 6 +- librz/bin/format/pe/pe_hdr.c | 41 +-- librz/bin/format/pe/pe_imports.c | 2 +- librz/bin/format/pe/pe_overlay.c | 4 +- librz/bin/format/pe/pe_rsrc.c | 48 +-- librz/bin/format/pe/pe_tls.c | 6 +- librz/bin/format/te/te.c | 21 +- librz/bin/p/bin_art.c | 22 +- librz/bin/p/bin_bootimg.c | 8 +- librz/bin/p/bin_mdmp.c | 4 +- librz/bin/p/bin_nro.c | 12 +- librz/bin/p/bin_nso.c | 12 +- librz/bin/p/bin_pe.inc | 44 +-- librz/bin/p/bin_qnx.c | 24 +- librz/bin/p/bin_te.c | 2 +- librz/bin/p/bin_vsf.c | 14 +- librz/bp/serialize_bp.c | 2 +- librz/config/config.c | 2 +- librz/config/serialize_config.c | 2 +- librz/core/agraph.c | 68 ++-- librz/core/analysis_tp.c | 2 +- librz/core/cagraph.c | 2 +- librz/core/cbin.c | 98 ++--- librz/core/cdebug.c | 6 +- librz/core/cil.c | 6 +- librz/core/cmd/cmd_debug.c | 4 +- librz/core/cmd/cmd_search.c | 2 +- librz/core/cmd/cmd_search_rop.c | 10 +- librz/core/disasm.c | 4 +- librz/core/project.c | 8 +- librz/core/project_migrate.c | 78 ++-- librz/core/serialize_core.c | 22 +- librz/debug/dsession.c | 10 +- librz/debug/dsignal.c | 6 +- .../debug/p/native/windows/windows_message.c | 4 +- librz/egg/egg.c | 4 +- librz/flag/serialize_flag.c | 8 +- librz/flag/tags.c | 4 +- librz/io/serialize_io.c | 2 +- librz/syscall/syscall.c | 20 +- librz/type/serialize_functions.c | 18 +- librz/type/serialize_types.c | 54 +-- librz/util/sdb/src/array.c | 205 +++++------ librz/util/sdb/src/diff.c | 2 +- librz/util/sdb/src/num.c | 67 ++-- librz/util/sdb/src/query.c | 77 ++-- librz/util/sdb/src/sdb.c | 173 ++------- librz/util/sdb/src/sdb.h | 109 +++--- librz/util/sdb/src/sdbht.c | 1 - librz/util/sdb/src/sdbht.h | 2 - librz/util/sdb/src/text.c | 2 +- librz/util/serialize_spaces.c | 10 +- test/integration/test_project_migrate.c | 96 ++--- test/unit/test_analysis_cc.c | 28 +- test/unit/test_analysis_function.c | 36 +- test/unit/test_debug_session.c | 11 +- test/unit/test_sdb_array.c | 38 +- test/unit/test_sdb_diff.c | 26 +- test/unit/test_sdb_sdb.c | 150 ++++---- test/unit/test_serialize_analysis.c | 338 +++++++++--------- test/unit/test_serialize_config.c | 8 +- test/unit/test_serialize_debug.c | 3 +- test/unit/test_serialize_flag.c | 30 +- test/unit/test_serialize_seek.c | 8 +- test/unit/test_serialize_spaces.c | 40 +-- test/unit/test_serialize_types.c | 50 +-- test/unit/test_type.c | 146 ++++---- 84 files changed, 1435 insertions(+), 1674 deletions(-) diff --git a/librz/arch/analysis.c b/librz/arch/analysis.c index 521fbbdc980..dc9d312c2ee 100644 --- a/librz/arch/analysis.c +++ b/librz/arch/analysis.c @@ -507,50 +507,50 @@ RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, RzAnalysisInfoType query) return value; } -static bool sdb_noret_addr_set(Sdb *db, ut64 addr, bool v, ut32 cas) { +static bool sdb_noret_addr_set(Sdb *db, ut64 addr, bool v) { char key[128]; rz_strf(key, "addr.%" PFMT64x ".noreturn", addr); - return sdb_bool_set(db, key, v, cas); + return sdb_bool_set(db, key, v); } -static bool sdb_noret_addr_get(Sdb *db, ut64 addr, ut32 *cas) { +static bool sdb_noret_addr_get(Sdb *db, ut64 addr) { char key[128]; rz_strf(key, "addr.%" PFMT64x ".noreturn", addr); - return sdb_bool_get(db, key, cas); + return sdb_bool_get(db, key); } -static int sdb_noret_addr_unset(Sdb *db, ut64 addr, ut32 cas) { +static int sdb_noret_addr_unset(Sdb *db, ut64 addr) { char key[128]; rz_strf(key, "addr.%" PFMT64x ".noreturn", addr); - return sdb_unset(db, key, cas); + return sdb_unset(db, key); } -static bool sdb_noret_func_set(Sdb *db, const char *name, bool v, ut32 cas) { +static bool sdb_noret_func_set(Sdb *db, const char *name, bool v) { char *key = rz_str_newf("func.%s.noreturn", name); if (!key) { return false; } - bool res = sdb_bool_set(db, key, v, cas); + bool res = sdb_bool_set(db, key, v); free(key); return res; } -static bool sdb_noret_func_get(Sdb *db, const char *name, ut32 *cas) { +static bool sdb_noret_func_get(Sdb *db, const char *name) { char *key = rz_str_newf("func.%s.noreturn", name); if (!key) { return false; } - bool res = sdb_bool_get(db, key, cas); + bool res = sdb_bool_get(db, key); free(key); return res; } -static int sdb_noret_func_unset(Sdb *db, const char *name, ut32 cas) { +static int sdb_noret_func_unset(Sdb *db, const char *name) { char *key = rz_str_newf("func.%s.noreturn", name); if (!key) { return false; } - int res = sdb_unset(db, key, cas); + int res = sdb_unset(db, key); free(key); return res; } @@ -560,7 +560,7 @@ RZ_API bool rz_analysis_noreturn_add(RzAnalysis *analysis, const char *name, ut6 Sdb *NDB = analysis->sdb_noret; char *fnl_name = NULL; if (addr != UT64_MAX) { - if (sdb_noret_addr_set(NDB, addr, true, 0)) { + if (sdb_noret_addr_set(NDB, addr, true)) { RzAnalysisFunction *fcn = rz_analysis_get_function_at(analysis, addr); if (fcn) { fcn->is_noreturn = true; @@ -587,7 +587,7 @@ RZ_API bool rz_analysis_noreturn_add(RzAnalysis *analysis, const char *name, ut6 } else if (!(fnl_name = rz_analysis_function_name_guess(analysis->typedb, (char *)tmp_name))) { if (addr == UT64_MAX) { if (name) { - sdb_noret_func_set(NDB, name, true, 0); + sdb_noret_func_set(NDB, name, true); } else { RZ_LOG_ERROR("Cannot find prototype for: %s\n", tmp_name); } @@ -597,7 +597,7 @@ RZ_API bool rz_analysis_noreturn_add(RzAnalysis *analysis, const char *name, ut6 // return false; } if (fnl_name) { - sdb_noret_func_set(NDB, fnl_name, true, 0); + sdb_noret_func_set(NDB, fnl_name, true); free(fnl_name); } return true; @@ -609,7 +609,7 @@ RZ_API bool rz_analysis_noreturn_drop(RzAnalysis *analysis, const char *expr) { const char *fcnname = NULL; if (!strncmp(expr, "0x", 2)) { ut64 n = rz_num_math(NULL, expr); - sdb_noret_addr_unset(NDB, n, 0); + sdb_noret_addr_unset(NDB, n); RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(analysis, n, -1); if (!fcn) { // eprintf ("can't find function at 0x%"PFMT64x"\n", n); @@ -619,13 +619,13 @@ RZ_API bool rz_analysis_noreturn_drop(RzAnalysis *analysis, const char *expr) { } else { fcnname = expr; } - sdb_noret_func_unset(NDB, fcnname, 0); + sdb_noret_func_unset(NDB, fcnname); return false; } static bool rz_analysis_is_noreturn(RzAnalysis *analysis, const char *name) { return rz_type_func_is_noreturn(analysis->typedb, name) || - sdb_noret_func_get(analysis->sdb_noret, name, NULL); + sdb_noret_func_get(analysis->sdb_noret, name); } static bool rz_analysis_noreturn_at_name(RzAnalysis *analysis, const char *name) { @@ -647,7 +647,7 @@ static bool rz_analysis_noreturn_at_name(RzAnalysis *analysis, const char *name) } RZ_API bool rz_analysis_noreturn_at_addr(RzAnalysis *analysis, ut64 addr) { - return sdb_noret_addr_get(analysis->sdb_noret, addr, NULL); + return sdb_noret_addr_get(analysis->sdb_noret, addr); } static bool noreturn_recurse(RzAnalysis *analysis, ut64 addr) { diff --git a/librz/arch/asm.c b/librz/arch/asm.c index 7b24d92b189..1a7c12e592f 100644 --- a/librz/arch/asm.c +++ b/librz/arch/asm.c @@ -1209,7 +1209,7 @@ RZ_API int rz_asm_get_offset(RzAsm *a, int type, int idx) { // link to rbin } RZ_API char *rz_asm_describe(RzAsm *a, const char *str) { - return (a && a->pair) ? sdb_get(a->pair, str, 0) : NULL; + return (a && a->pair) ? sdb_get(a->pair, str) : NULL; } RZ_API RzList /**/ *rz_asm_get_plugins(RzAsm *a) { diff --git a/librz/arch/cc.c b/librz/arch/cc.c index 1a75f30dee3..198b5ad80ed 100644 --- a/librz/arch/cc.c +++ b/librz/arch/cc.c @@ -11,19 +11,19 @@ do { \ char key[512]; \ rz_strf(key, __VA_ARGS__); \ - sdb_unset(x, key, 0); \ + sdb_unset(x, key); \ } while (0) #define cc_sdb_setf(x, y, ...) \ do { \ char key[512]; \ rz_strf(key, __VA_ARGS__); \ - sdb_set(x, key, y, 0); \ + sdb_set(x, key, y); \ } while (0) RZ_API void rz_analysis_cc_del(RzAnalysis *analysis, const char *name) { rz_return_if_fail(analysis && name); - sdb_unset(DB, name, 0); + sdb_unset(DB, name); cc_sdb_unsetf(DB, "cc.%s.ret", name); cc_sdb_unsetf(DB, "cc.%s.maxargs", name); cc_sdb_unsetf(DB, "cc.%s.argn", name); @@ -63,7 +63,7 @@ RZ_API bool rz_analysis_cc_set(RzAnalysis *analysis, const char *expr) { free(e); return false; } - sdb_set(DB, ccname, "cc", 0); + sdb_set(DB, ccname, "cc"); cc_sdb_setf(DB, e, "cc.%s.ret", ccname); RzList *ccArgs = rz_str_split_list(args, ",", 0); @@ -93,12 +93,12 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) { rz_return_val_if_fail(analysis && name, NULL); char *tmp_cc = NULL; // get cc by name and print the expr - if (rz_str_cmp(sdb_const_get(DB, name, 0), "cc", -1)) { + if (rz_str_cmp(sdb_const_get(DB, name), "cc", -1)) { RZ_LOG_ERROR("analysis: '%s' is not a valid calling convention name\n", name); return NULL; } tmp_cc = rz_str_newf("cc.%s.ret", name); - const char *ret = tmp_cc ? sdb_const_get(DB, tmp_cc, 0) : NULL; + const char *ret = tmp_cc ? sdb_const_get(DB, tmp_cc) : NULL; free(tmp_cc); if (!ret) { RZ_LOG_ERROR("analysis: Cannot find return key in calling convention named '%s'\n", name); @@ -110,7 +110,7 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) { bool isFirst = true; for (int i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) { char *k = rz_str_newf("cc.%s.arg%d", name, i); - const char *arg = k ? sdb_const_get(DB, k, 0) : NULL; + const char *arg = k ? sdb_const_get(DB, k) : NULL; free(k); if (!arg) { break; @@ -119,7 +119,7 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) { isFirst = false; } tmp_cc = rz_str_newf("cc.%s.argn", name); - const char *argn = tmp_cc ? sdb_const_get(DB, tmp_cc, 0) : NULL; + const char *argn = tmp_cc ? sdb_const_get(DB, tmp_cc) : NULL; free(tmp_cc); if (argn) { rz_strbuf_appendf(sb, "%s%s", isFirst ? "" : ", ", argn); @@ -137,7 +137,7 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) { RZ_API bool rz_analysis_cc_exist(RzAnalysis *analysis, const char *convention) { rz_return_val_if_fail(analysis && convention, false); - const char *x = sdb_const_get(DB, convention, 0); + const char *x = sdb_const_get(DB, convention); return x && *x && !strcmp(x, "cc"); } @@ -149,11 +149,11 @@ RZ_API const char *rz_analysis_cc_arg(RzAnalysis *analysis, const char *conventi } char *query = rz_str_newf("cc.%s.arg%d", convention, n); - const char *ret = query ? sdb_const_get(DB, query, 0) : NULL; + const char *ret = query ? sdb_const_get(DB, query) : NULL; free(query); if (!ret) { query = rz_str_newf("cc.%s.argn", convention); - ret = query ? sdb_const_get(DB, query, 0) : NULL; + ret = query ? sdb_const_get(DB, query) : NULL; free(query); } return ret ? rz_str_constpool_get(&analysis->constpool, ret) : NULL; @@ -162,7 +162,7 @@ RZ_API const char *rz_analysis_cc_arg(RzAnalysis *analysis, const char *conventi RZ_API const char *rz_analysis_cc_self(RzAnalysis *analysis, const char *convention) { rz_return_val_if_fail(analysis && convention, NULL); char *query = rz_str_newf("cc.%s.self", convention); - const char *self = query ? sdb_const_get(DB, query, 0) : NULL; + const char *self = query ? sdb_const_get(DB, query) : NULL; free(query); return self ? rz_str_constpool_get(&analysis->constpool, self) : NULL; } @@ -177,14 +177,14 @@ RZ_API void rz_analysis_cc_set_self(RzAnalysis *analysis, const char *convention RZ_LOG_ERROR("analysis: Cannot allocate key for sdb_set\n"); return; } - sdb_set(analysis->sdb_cc, query, self, 0); + sdb_set(analysis->sdb_cc, query, self); free(query); } RZ_API const char *rz_analysis_cc_error(RzAnalysis *analysis, const char *convention) { rz_return_val_if_fail(analysis && convention, NULL); char *query = rz_str_newf("cc.%s.error", convention); - const char *error = query ? sdb_const_get(DB, query, 0) : NULL; + const char *error = query ? sdb_const_get(DB, query) : NULL; free(query); return error ? rz_str_constpool_get(&analysis->constpool, error) : NULL; } @@ -198,7 +198,7 @@ RZ_API void rz_analysis_cc_set_error(RzAnalysis *analysis, const char *conventio RZ_LOG_ERROR("analysis: Cannot allocate key for sdb_set\n"); return; } - sdb_set(analysis->sdb_cc, key, error, 0); + sdb_set(analysis->sdb_cc, key, error); free(key); } @@ -208,7 +208,7 @@ RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc) { if (!query) { return 0; } - const char *res = sdb_const_get(DB, query, 0); + const char *res = sdb_const_get(DB, query); free(query); int maxargs = res ? atoi(res) : 0; if (maxargs < 0 || maxargs > RZ_ANALYSIS_CC_MAXARG) { @@ -220,7 +220,7 @@ RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc) { RZ_API const char *rz_analysis_cc_ret(RzAnalysis *analysis, const char *convention) { rz_return_val_if_fail(analysis && convention, NULL); char *query = rz_str_newf("cc.%s.ret", convention); - const char *res = query ? sdb_const_get(DB, query, 0) : NULL; + const char *res = query ? sdb_const_get(DB, query) : NULL; free(query); return res; } @@ -241,22 +241,22 @@ RZ_API RzStackAddr rz_analysis_cc_shadow_store(RzAnalysis *analysis, const char RZ_API const char *rz_analysis_cc_default(RzAnalysis *analysis) { rz_return_val_if_fail(analysis, NULL); - return sdb_const_get(DB, "default.cc", 0); + return sdb_const_get(DB, "default.cc"); } RZ_API void rz_analysis_set_cc_default(RzAnalysis *analysis, const char *cc) { rz_return_if_fail(analysis && cc); - sdb_set(DB, "default.cc", cc, 0); + sdb_set(DB, "default.cc", cc); } RZ_API const char *rz_analysis_syscc_default(RzAnalysis *analysis) { rz_return_val_if_fail(analysis, NULL); - return sdb_const_get(DB, "default.syscc", 0); + return sdb_const_get(DB, "default.syscc"); } RZ_API void rz_analysis_set_syscc_default(RzAnalysis *analysis, const char *cc) { rz_return_if_fail(analysis && cc); - sdb_set(DB, "default.syscc", cc, 0); + sdb_set(DB, "default.syscc", cc); } RZ_API const char *rz_analysis_cc_func(RzAnalysis *analysis, const char *func_name) { diff --git a/librz/arch/class.c b/librz/arch/class.c index 387a856341e..135229cc4b4 100644 --- a/librz/arch/class.c +++ b/librz/arch/class.c @@ -90,7 +90,7 @@ RZ_API RzAnalysisClassErr rz_analysis_class_create(RzAnalysis *analysis, const c RzAnalysisClassErr err = RZ_ANALYSIS_CLASS_ERR_SUCCESS; const char *key = key_class(name_sanitized); if (!sdb_exists(analysis->sdb_classes, key)) { - sdb_set(analysis->sdb_classes, key, "c", 0); + sdb_set(analysis->sdb_classes, key, "c"); RzEventClass event = { .name = name_sanitized }; if (analysis->ev) { rz_event_send(analysis->ev, RZ_EVENT_CLASS_NEW, &event); @@ -113,7 +113,7 @@ RZ_API void rz_analysis_class_delete(RzAnalysis *analysis, const char *name) { rz_analysis_class_method_delete_class(analysis, class_name_sanitized); rz_analysis_class_vtable_delete_class(analysis, class_name_sanitized); - if (!sdb_remove(analysis->sdb_classes, key_class(class_name_sanitized), 0)) { + if (!sdb_remove(analysis->sdb_classes, key_class(class_name_sanitized))) { free(class_name_sanitized); return; } @@ -123,7 +123,7 @@ RZ_API void rz_analysis_class_delete(RzAnalysis *analysis, const char *name) { free(class_name_sanitized); return; } - char *attr_type_array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *attr_type_array = sdb_get(analysis->sdb_classes_attrs, key); free(key); char *attr_type; @@ -132,20 +132,20 @@ RZ_API void rz_analysis_class_delete(RzAnalysis *analysis, const char *name) { if (!key) { continue; } - char *attr_id_array = sdb_get(analysis->sdb_classes_attrs, key, 0); - sdb_remove(analysis->sdb_classes_attrs, key, 0); + char *attr_id_array = sdb_get(analysis->sdb_classes_attrs, key); + sdb_remove(analysis->sdb_classes_attrs, key); free(key); if (attr_id_array) { char *attr_id; sdb_aforeach(attr_id, attr_id_array) { key = key_attr_content(class_name_sanitized, attr_type, attr_id); if (key) { - sdb_remove(analysis->sdb_classes_attrs, key, 0); + sdb_remove(analysis->sdb_classes_attrs, key); free(key); } key = key_attr_content_specific(class_name_sanitized, attr_type, attr_id); if (key) { - sdb_remove(analysis->sdb_classes_attrs, key, 0); + sdb_remove(analysis->sdb_classes_attrs, key); free(key); } sdb_aforeach_next(attr_id); @@ -158,7 +158,7 @@ RZ_API void rz_analysis_class_delete(RzAnalysis *analysis, const char *name) { key = key_attr_types(class_name_sanitized); if (key) { - sdb_remove(analysis->sdb_classes_attrs, key, 0); + sdb_remove(analysis->sdb_classes_attrs, key); free(key); } @@ -193,12 +193,12 @@ RZ_API void rz_analysis_class_foreach(RzAnalysis *analysis, SdbForeachCallback c } static bool rename_key(Sdb *sdb, const char *key_old, const char *key_new) { - char *content = sdb_get(sdb, key_old, 0); + char *content = sdb_get(sdb, key_old); if (!content) { return false; } - sdb_remove(sdb, key_old, 0); - sdb_set(sdb, key_new, content, 0); + sdb_remove(sdb, key_old); + sdb_set(sdb, key_new, content); free(content); return true; } @@ -231,7 +231,7 @@ RZ_API RzAnalysisClassErr rz_analysis_class_rename(RzAnalysis *analysis, const c char *key = key_attr_types(old_name_sanitized); if (key) { - char *attr_types = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *attr_types = sdb_get(analysis->sdb_classes_attrs, key); free(key); char *attr_type_cur; sdb_aforeach(attr_type_cur, attr_types) { @@ -239,7 +239,7 @@ RZ_API RzAnalysisClassErr rz_analysis_class_rename(RzAnalysis *analysis, const c if (!key) { continue; } - char *attr_ids = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *attr_ids = sdb_get(analysis->sdb_classes_attrs, key); free(key); char *attr_id_cur; sdb_aforeach(attr_id_cur, attr_ids) { @@ -294,7 +294,7 @@ static char *rz_analysis_class_get_attr_raw(RzAnalysis *analysis, const char *cl if (!key) { return NULL; } - char *ret = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *ret = sdb_get(analysis->sdb_classes_attrs, key); free(key); return ret; } @@ -329,17 +329,17 @@ static RzAnalysisClassErr rz_analysis_class_set_attr_raw(RzAnalysis *analysis, c char *key = key_attr_types(class_name); if (key) { - sdb_array_add(analysis->sdb_classes_attrs, key, attr_type_str, 0); + sdb_array_add(analysis->sdb_classes_attrs, key, attr_type_str); free(key); } key = key_attr_type_attrs(class_name, attr_type_str); if (key) { - sdb_array_add(analysis->sdb_classes_attrs, key, attr_id, 0); + sdb_array_add(analysis->sdb_classes_attrs, key, attr_id); free(key); } key = key_attr_content(class_name, attr_type_str, attr_id); if (key) { - sdb_set(analysis->sdb_classes_attrs, key, content, 0); + sdb_set(analysis->sdb_classes_attrs, key, content); free(key); } @@ -383,20 +383,20 @@ static RzAnalysisClassErr rz_analysis_class_delete_attr_raw(RzAnalysis *analysis char *key = key_attr_content(class_name, attr_type_str, attr_id); if (key) { - sdb_remove(analysis->sdb_classes_attrs, key, 0); + sdb_remove(analysis->sdb_classes_attrs, key); free(key); } key = key_attr_content_specific(class_name, attr_type_str, attr_id); if (key) { - sdb_remove(analysis->sdb_classes_attrs, key, 0); + sdb_remove(analysis->sdb_classes_attrs, key); free(key); } key = key_attr_type_attrs(class_name, attr_type_str); if (key) { - sdb_array_remove(analysis->sdb_classes_attrs, key, attr_id, 0); + sdb_array_remove(analysis->sdb_classes_attrs, key, attr_id); if (!sdb_exists(analysis->sdb_classes_attrs, key)) { - sdb_array_remove(analysis->sdb_classes_attrs, key_attr_types(class_name), attr_type_str, 0); + sdb_array_remove(analysis->sdb_classes_attrs, key_attr_types(class_name), attr_type_str); } free(key); } @@ -439,26 +439,26 @@ static RzAnalysisClassErr rz_analysis_class_rename_attr_raw(RzAnalysis *analysis return RZ_ANALYSIS_CLASS_ERR_OTHER; } - if (sdb_array_contains(analysis->sdb_classes_attrs, key, attr_id_new, 0)) { + if (sdb_array_contains(analysis->sdb_classes_attrs, key, attr_id_new)) { free(key); return RZ_ANALYSIS_CLASS_ERR_CLASH; } - if (!sdb_array_remove(analysis->sdb_classes_attrs, key, attr_id_old, 0)) { + if (!sdb_array_remove(analysis->sdb_classes_attrs, key, attr_id_old)) { free(key); return RZ_ANALYSIS_CLASS_ERR_NONEXISTENT_ATTR; } - sdb_array_add(analysis->sdb_classes_attrs, key, attr_id_new, 0); + sdb_array_add(analysis->sdb_classes_attrs, key, attr_id_new); free(key); key = key_attr_content(class_name, attr_type_str, attr_id_old); if (key) { - char *content = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *content = sdb_get(analysis->sdb_classes_attrs, key); if (content) { - sdb_remove(analysis->sdb_classes_attrs, key, 0); + sdb_remove(analysis->sdb_classes_attrs, key); key = key_attr_content(class_name, attr_type_str, attr_id_new); - sdb_set(analysis->sdb_classes_attrs, key, content, 0); + sdb_set(analysis->sdb_classes_attrs, key, content); free(content); } free(key); @@ -466,11 +466,11 @@ static RzAnalysisClassErr rz_analysis_class_rename_attr_raw(RzAnalysis *analysis key = key_attr_content_specific(class_name, attr_type_str, attr_id_old); if (key) { - char *content = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *content = sdb_get(analysis->sdb_classes_attrs, key); if (content) { - sdb_remove(analysis->sdb_classes_attrs, key, 0); + sdb_remove(analysis->sdb_classes_attrs, key); key = key_attr_content_specific(class_name, attr_type_str, attr_id_new); - sdb_set(analysis->sdb_classes_attrs, key, content, 0); + sdb_set(analysis->sdb_classes_attrs, key, content); free(content); } free(key); @@ -522,7 +522,7 @@ static void rz_analysis_class_unique_attr_id_raw(RzAnalysis *analysis, const cha do { snprintf(out, out_size, "%" PFMT64u, id); id++; - } while (sdb_array_contains(analysis->sdb_classes_attrs, key, out, 0)); + } while (sdb_array_contains(analysis->sdb_classes_attrs, key, out)); free(key); } @@ -764,7 +764,7 @@ RZ_API RzVector /**/ *rz_analysis_class_method_get_all(RzAnaly free(class_name_sanitized); return NULL; } - char *array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *array = sdb_get(analysis->sdb_classes_attrs, key); free(key); free(class_name_sanitized); @@ -827,7 +827,7 @@ static void rz_analysis_class_method_rename_class(RzAnalysis *analysis, const ch if (!key) { return; } - char *array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *array = sdb_get(analysis->sdb_classes_attrs, key); free(key); if (!array) { return; @@ -851,7 +851,7 @@ static void rz_analysis_class_method_delete_class(RzAnalysis *analysis, const ch if (!key) { return; } - char *array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *array = sdb_get(analysis->sdb_classes_attrs, key); if (!array) { return; } @@ -957,7 +957,7 @@ RZ_API RzVector /**/ *rz_analysis_class_base_get_all(RzAnal free(class_name_sanitized); return NULL; } - char *array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *array = sdb_get(analysis->sdb_classes_attrs, key); free(key); free(class_name_sanitized); @@ -1145,7 +1145,7 @@ RZ_API RzVector /**/ *rz_analysis_class_vtable_get_all(RzAnaly free(class_name_sanitized); return NULL; } - char *array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *array = sdb_get(analysis->sdb_classes_attrs, key); free(key); free(class_name_sanitized); @@ -1208,7 +1208,7 @@ static void rz_analysis_class_vtable_rename_class(RzAnalysis *analysis, const ch if (!key) { return; } - char *array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *array = sdb_get(analysis->sdb_classes_attrs, key); free(key); if (!array) { return; @@ -1232,7 +1232,7 @@ static void rz_analysis_class_vtable_delete_class(RzAnalysis *analysis, const ch if (!key) { return; } - char *array = sdb_get(analysis->sdb_classes_attrs, key, 0); + char *array = sdb_get(analysis->sdb_classes_attrs, key); free(key); if (!array) { return; diff --git a/librz/arch/esil/esil_stats.c b/librz/arch/esil/esil_stats.c index 5fc6af9a25d..d1ba22057bf 100644 --- a/librz/arch/esil/esil_stats.c +++ b/librz/arch/esil/esil_stats.c @@ -4,33 +4,33 @@ #include static int hook_flag_read(RzAnalysisEsil *esil, const char *flag, ut64 *num) { - sdb_array_add(esil->stats, "flg.read", flag, 0); + sdb_array_add(esil->stats, "flg.read", flag); return 0; } static int hook_command(RzAnalysisEsil *esil, const char *op) { - sdb_array_add(esil->stats, "ops.list", op, 0); + sdb_array_add(esil->stats, "ops.list", op); return 0; } static int hook_mem_read(RzAnalysisEsil *esil, ut64 addr, ut8 *buf, int len) { - sdb_array_add_num(esil->stats, "mem.read", addr, 0); + sdb_array_add_num(esil->stats, "mem.read", addr); return 0; } static int hook_mem_write(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len) { - sdb_array_add_num(esil->stats, "mem.write", addr, 0); + sdb_array_add_num(esil->stats, "mem.write", addr); return 0; } static int hook_reg_read(RzAnalysisEsil *esil, const char *name, ut64 *res, int *size) { const char *key = (*name >= '0' && *name <= '9') ? "num.load" : "reg.read"; - sdb_array_add(esil->stats, key, name, 0); + sdb_array_add(esil->stats, key, name); return 0; } static int hook_reg_write(RzAnalysisEsil *esil, const char *name, ut64 *val) { - sdb_array_add(esil->stats, "reg.write", name, 0); + sdb_array_add(esil->stats, "reg.write", name); return 0; } diff --git a/librz/arch/platform_profile.c b/librz/arch/platform_profile.c index 0687aa37a9f..fd4759cd4b5 100644 --- a/librz/arch/platform_profile.c +++ b/librz/arch/platform_profile.c @@ -130,14 +130,14 @@ static bool sdb_load_arch_profile(RzPlatformTarget *t, Sdb *sdb) { if (!strcmp(sdbkv_value(kv), "io")) { const char *io_name = sdbkv_key(kv); char *argument_key = rz_str_newf("%s.address", io_name); - ut64 io_address = sdb_num_get(sdb, argument_key, NULL); + ut64 io_address = sdb_num_get(sdb, argument_key); free(argument_key); ht_up_insert(c->registers_mmio, io_address, (char *)io_name); } if (!strcmp(sdbkv_value(kv), "ext_io")) { const char *ext_io_name = sdbkv_key(kv); char *argument_key = rz_str_newf("%s.address", ext_io_name); - ut64 ext_io_address = sdb_num_get(sdb, argument_key, NULL); + ut64 ext_io_address = sdb_num_get(sdb, argument_key); free(argument_key); ht_up_insert(c->registers_extended, ext_io_address, (char *)ext_io_name); } diff --git a/librz/arch/platform_target_index.c b/librz/arch/platform_target_index.c index 1537da5919d..1c022ffb7ef 100644 --- a/librz/arch/platform_target_index.c +++ b/librz/arch/platform_target_index.c @@ -74,14 +74,14 @@ static bool sdb_load_platform_profile(RZ_NONNULL RzPlatformTargetIndex *t, RZ_NO rz_platform_item_free(item); return false; } - ut64 address = sdb_num_get(sdb, argument_key, NULL); + ut64 address = sdb_num_get(sdb, argument_key); if (!address) { rz_platform_item_free(item); return false; } argument_key = rz_str_newf("%s.comment", item->name); - char *comment = sdb_get(sdb, argument_key, NULL); + char *comment = sdb_get(sdb, argument_key); if (comment) { item->comment = comment; } diff --git a/librz/arch/serialize_analysis.c b/librz/arch/serialize_analysis.c index 637dafb64cc..65dbd6d0a29 100644 --- a/librz/arch/serialize_analysis.c +++ b/librz/arch/serialize_analysis.c @@ -200,7 +200,7 @@ static void block_store(RZ_NONNULL Sdb *db, const char *key, RzAnalysisBlock *bl } pj_end(j); - sdb_set(db, key, pj_string(j), 0); + sdb_set(db, key, pj_string(j)); pj_free(j); } @@ -919,7 +919,7 @@ RZ_API void rz_serialize_analysis_global_var_save(RZ_NONNULL Sdb *db, RZ_NONNULL } pj_end(j); - sdb_set(db, addr, pj_string(j), 0); + sdb_set(db, addr, pj_string(j)); pj_reset(j); } pj_free(j); @@ -1148,7 +1148,7 @@ static void function_store(RZ_NONNULL Sdb *db, const char *key, RzAnalysisFuncti } pj_end(j); - sdb_set(db, key, pj_string(j), 0); + sdb_set(db, key, pj_string(j)); pj_free(j); } @@ -1434,7 +1434,7 @@ static bool store_xrefs_list_cb(void *db, const ut64 k, const void *v) { HtUP *ht = (HtUP *)v; ht_up_foreach(ht, store_xref_cb, j); pj_end(j); - sdb_set(db, key, pj_string(j), 0); + sdb_set(db, key, pj_string(j)); pj_free(j); return true; } @@ -1533,7 +1533,7 @@ RZ_API void rz_serialize_analysis_meta_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzAna #define FLUSH \ pj_end(j); \ if (snprintf(key, sizeof(key), "0x%" PFMT64x, addr) >= 0) { \ - sdb_set(db, key, pj_string(j), 0); \ + sdb_set(db, key, pj_string(j)); \ } rz_interval_tree_foreach (&analysis->meta, it, meta) { @@ -1880,7 +1880,7 @@ static bool hints_acc_store_cb(void *user, const ut64 addr, const void *v) { } } pj_end(j); - sdb_set(db, key, pj_string(j), 0); + sdb_set(db, key, pj_string(j)); pj_free(j); return true; } @@ -2126,7 +2126,7 @@ RZ_API void rz_serialize_analysis_imports_save(RZ_NONNULL Sdb *db, RZ_NONNULL Rz RzListIter *it; const char *imp; rz_list_foreach (analysis->imports, it, imp) { - sdb_set(db, imp, "i", 0); + sdb_set(db, imp, "i"); } } diff --git a/librz/bin/dwarf/dwarf.c b/librz/bin/dwarf/dwarf.c index 60811dfd2a1..1e131b1de8b 100644 --- a/librz/bin/dwarf/dwarf.c +++ b/librz/bin/dwarf/dwarf.c @@ -170,7 +170,7 @@ static const char *mach0_uuid(RZ_BORROW RZ_NONNULL RzBinFile *bf) { RZ_LOG_WARN("mach0 file contains multiple uuids\n"); } snprintf(key, sizeof(key) - 1, "uuid.%d", mo->uuidn - 1); - return sdb_const_get(mo->kv, key, 0); + return sdb_const_get(mo->kv, key); } typedef struct { diff --git a/librz/bin/format/elf/elf.c b/librz/bin/format/elf/elf.c index 2bfe8438aa7..853f2eee9c4 100644 --- a/librz/bin/format/elf/elf.c +++ b/librz/bin/format/elf/elf.c @@ -111,11 +111,11 @@ static bool in_physical_phdr(RzBinElfSegment *segment, ut64 addr) { } static bool init_phdr_sdb(ELFOBJ *bin) { - return sdb_num_set(bin->kv, "elf_phdr.offset", bin->ehdr.e_phoff, 0) && - sdb_num_set(bin->kv, "elf_phdr.size", sizeof(Elf_(Phdr)), 0) && - sdb_set(bin->kv, "elf_p_flags.cparse", sdb_elf_p_flags_cparse, 0) && - sdb_set(bin->kv, "elf_p_type.cparse", sdb_elf_p_type_cparse, 0) && - sdb_set(bin->kv, "elf_phdr.format", sdb_elf_phdr_format, 0); + return sdb_num_set(bin->kv, "elf_phdr.offset", bin->ehdr.e_phoff) && + sdb_num_set(bin->kv, "elf_phdr.size", sizeof(Elf_(Phdr))) && + sdb_set(bin->kv, "elf_p_flags.cparse", sdb_elf_p_flags_cparse) && + sdb_set(bin->kv, "elf_p_type.cparse", sdb_elf_p_type_cparse) && + sdb_set(bin->kv, "elf_phdr.format", sdb_elf_phdr_format); } static bool init_phdr_aux(ELFOBJ *bin, RzVector /**/ *sections, RzBinObjectLoadOptions *options) { @@ -139,16 +139,16 @@ static void init_phdr(ELFOBJ *bin, RzVector /**/ *sections, RzBinObj } static bool init_ehdr_sdb(ELFOBJ *bin) { - return sdb_num_set(bin->kv, "elf_header.offset", 0, 0) && - sdb_num_set(bin->kv, "elf_header.size", sizeof(Elf_(Ehdr)), 0) && - sdb_set(bin->kv, "elf_class.cparse", sdb_elf_class_cparse, 0) && - sdb_set(bin->kv, "elf_data.cparse", sdb_elf_data_cparse, 0) && - sdb_set(bin->kv, "elf_hdr_version.cparse", sdb_elf_hdr_version_cparse, 0) && - sdb_set(bin->kv, "elf_header.format", sdb_elf_header_format, 0) && - sdb_set(bin->kv, "elf_ident.format", sdb_elf_ident_format, 0) && - sdb_set(bin->kv, "elf_machine.cparse", sdb_elf_machine_cparse, 0) && - sdb_set(bin->kv, "elf_obj_version.cparse", sdb_elf_obj_version_cparse, 0) && - sdb_set(bin->kv, "elf_type.cparse", sdb_elf_type_cparse, 0); + return sdb_num_set(bin->kv, "elf_header.offset", 0) && + sdb_num_set(bin->kv, "elf_header.size", sizeof(Elf_(Ehdr))) && + sdb_set(bin->kv, "elf_class.cparse", sdb_elf_class_cparse) && + sdb_set(bin->kv, "elf_data.cparse", sdb_elf_data_cparse) && + sdb_set(bin->kv, "elf_hdr_version.cparse", sdb_elf_hdr_version_cparse) && + sdb_set(bin->kv, "elf_header.format", sdb_elf_header_format) && + sdb_set(bin->kv, "elf_ident.format", sdb_elf_ident_format) && + sdb_set(bin->kv, "elf_machine.cparse", sdb_elf_machine_cparse) && + sdb_set(bin->kv, "elf_obj_version.cparse", sdb_elf_obj_version_cparse) && + sdb_set(bin->kv, "elf_type.cparse", sdb_elf_type_cparse); } static bool init_ehdr(ELFOBJ *bin) { @@ -160,15 +160,15 @@ static bool init_ehdr(ELFOBJ *bin) { } static bool init_shdr_sdb(ELFOBJ *bin) { - return sdb_num_set(bin->kv, "elf_shdr.offset", bin->ehdr.e_shoff, 0) && - sdb_num_set(bin->kv, "elf_shdr.size", sizeof(Elf_(Shdr)), 0) && + return sdb_num_set(bin->kv, "elf_shdr.offset", bin->ehdr.e_shoff) && + sdb_num_set(bin->kv, "elf_shdr.size", sizeof(Elf_(Shdr))) && #if RZ_BIN_ELF64 - sdb_set(bin->kv, "elf_s_flags_64.cparse", sdb_elf_s_flags_64_cparse, 0) && + sdb_set(bin->kv, "elf_s_flags_64.cparse", sdb_elf_s_flags_64_cparse) && #else - sdb_set(bin->kv, "elf_s_flags_32.cparse", sdb_elf_s_flags_32_cparse, 0) && + sdb_set(bin->kv, "elf_s_flags_32.cparse", sdb_elf_s_flags_32_cparse) && #endif - sdb_set(bin->kv, "elf_s_type.cparse", sdb_elf_s_type_cparse, 0) && - sdb_set(bin->kv, "elf_shdr.format", sdb_elf_shdr_format, 0); + sdb_set(bin->kv, "elf_s_type.cparse", sdb_elf_s_type_cparse) && + sdb_set(bin->kv, "elf_shdr.format", sdb_elf_shdr_format); } static bool init_shdr_aux(ELFOBJ *bin, RzBinObjectLoadOptions *options, RzVector /**/ *sections) { @@ -187,8 +187,8 @@ static void init_shdr(ELFOBJ *bin, RzBinObjectLoadOptions *options, RzVector /*< } static bool init_shstrtab_sdb(ELFOBJ *bin, ut64 offset, ut64 size) { - return sdb_num_set(bin->kv, "elf_shstrtab.offset", offset, 0) && - sdb_num_set(bin->kv, "elf_shstrtab.size", size, 0); + return sdb_num_set(bin->kv, "elf_shstrtab.offset", offset) && + sdb_num_set(bin->kv, "elf_shstrtab.size", size); } static bool init_shstrtab_aux(ELFOBJ *bin, RzVector /**/ *sections) { @@ -219,11 +219,11 @@ static void init_shstrtab(ELFOBJ *bin, RzVector /**/ *sections) { static bool init_dt_dynamic_sdb(ELFOBJ *bin) { switch (Elf_(rz_bin_elf_has_relro)(bin)) { case RZ_BIN_ELF_FULL_RELRO: - return sdb_set(bin->kv, "elf.relro", "full", 0); + return sdb_set(bin->kv, "elf.relro", "full"); case RZ_BIN_ELF_PART_RELRO: - return sdb_set(bin->kv, "elf.relro", "partial", 0); + return sdb_set(bin->kv, "elf.relro", "partial"); default: - return sdb_set(bin->kv, "elf.relro", "no", 0); + return sdb_set(bin->kv, "elf.relro", "no"); } return false; @@ -245,8 +245,8 @@ static void init_dt_dynamic(ELFOBJ *bin) { } static bool init_dynstr_sdb(ELFOBJ *bin, ut64 strtab_addr, Elf_(Xword) strtab_size) { - return sdb_num_set(bin->kv, "elf_dynstr.offset", strtab_addr, 0) && - sdb_num_set(bin->kv, "elf_dynstr.size", strtab_size, 0); + return sdb_num_set(bin->kv, "elf_dynstr.offset", strtab_addr) && + sdb_num_set(bin->kv, "elf_dynstr.size", strtab_size); } static bool init_dynstr_aux(ELFOBJ *bin) { diff --git a/librz/bin/format/elf/elf_info.c b/librz/bin/format/elf/elf_info.c index 906e2132771..56bdff70aa5 100644 --- a/librz/bin/format/elf/elf_info.c +++ b/librz/bin/format/elf/elf_info.c @@ -673,8 +673,8 @@ static char *get_elf_intrp(ELFOBJ *bin, RzBinElfSegment *segment) { ut64 addr = segment->data.p_offset; size_t size = segment->data.p_filesz; - if (!sdb_num_set(bin->kv, "elf_header.intrp_addr", addr, 0) || - !sdb_num_set(bin->kv, "elf_header.intrp_size", size, 0)) { + if (!sdb_num_set(bin->kv, "elf_header.intrp_addr", addr) || + !sdb_num_set(bin->kv, "elf_header.intrp_size", size)) { return NULL; } @@ -687,7 +687,7 @@ static char *get_elf_intrp(ELFOBJ *bin, RzBinElfSegment *segment) { return NULL; } - if (!sdb_set(bin->kv, "elf_header.intrp", str, 0)) { + if (!sdb_set(bin->kv, "elf_header.intrp", str)) { free(str); return NULL; } @@ -1050,7 +1050,7 @@ static bool get_versym_entry_sdb_from_verneed(ELFOBJ *bin, Sdb *sdb, const char return false; } - if (!sdb_set_owned(sdb, key, value, 0)) { + if (!sdb_set_owned(sdb, key, value)) { return false; } @@ -1111,7 +1111,7 @@ static bool get_versym_entry_sdb_from_verdef(ELFOBJ *bin, Sdb *sdb, const char * return false; } - if (!sdb_set_owned(sdb, key, value, 0)) { + if (!sdb_set_owned(sdb, key, value)) { return false; } @@ -1144,9 +1144,9 @@ static Sdb *get_gnu_versym(ELFOBJ *bin) { return NULL; } - if (!sdb_num_set(sdb, "num_entries", number_of_symbols, 0) || - !sdb_num_set(sdb, "addr", versym_addr, 0) || - !sdb_num_set(sdb, "offset", versym_offset, 0)) { + if (!sdb_num_set(sdb, "num_entries", number_of_symbols) || + !sdb_num_set(sdb, "addr", versym_addr) || + !sdb_num_set(sdb, "offset", versym_offset)) { sdb_free(sdb); return NULL; } @@ -1168,13 +1168,13 @@ static Sdb *get_gnu_versym(ELFOBJ *bin) { switch (versym_entry) { case VER_NDX_LOCAL: - if (!sdb_set(sdb, key, "0 (*local*)", 0)) { + if (!sdb_set(sdb, key, "0 (*local*)")) { sdb_free(sdb); return NULL; } break; case VER_NDX_GLOBAL: - if (!sdb_set(sdb, key, "1 (*global*)", 0)) { + if (!sdb_set(sdb, key, "1 (*global*)")) { sdb_free(sdb); return NULL; } @@ -1206,14 +1206,14 @@ static Sdb *get_vernaux_entry_sdb(ELFOBJ *bin, Elf_(Vernaux) vernaux_entry, size } char *flags = get_ver_flags(vernaux_entry.vna_flags); - if (!sdb_set_owned(sdb_vernaux, "flags", flags, 0)) { + if (!sdb_set_owned(sdb_vernaux, "flags", flags)) { sdb_free(sdb_vernaux); return NULL; } - if (!sdb_num_set(sdb_vernaux, "idx", index, 0) || - !sdb_num_set(sdb_vernaux, "version", vernaux_entry.vna_other, 0) || - !sdb_set(sdb_vernaux, "name", tmp, 0)) { + if (!sdb_num_set(sdb_vernaux, "idx", index) || + !sdb_num_set(sdb_vernaux, "version", vernaux_entry.vna_other) || + !sdb_set(sdb_vernaux, "name", tmp)) { sdb_free(sdb_vernaux); return NULL; } @@ -1232,10 +1232,10 @@ static Sdb *get_verneed_entry_sdb_aux(ELFOBJ *bin, Elf_(Verneed) verneed_entry, return NULL; } - if (!sdb_num_set(sdb_version, "cnt", verneed_entry.vn_cnt, 0) || - !sdb_num_set(sdb_version, "idx", index, 0) || - !sdb_num_set(sdb_version, "vn_version", verneed_entry.vn_version, 0) || - !sdb_set(sdb_version, "file_name", tmp, 0)) { + if (!sdb_num_set(sdb_version, "cnt", verneed_entry.vn_cnt) || + !sdb_num_set(sdb_version, "idx", index) || + !sdb_num_set(sdb_version, "vn_version", verneed_entry.vn_version) || + !sdb_set(sdb_version, "file_name", tmp)) { sdb_free(sdb_version); return NULL; } @@ -1302,9 +1302,9 @@ static Sdb *get_gnu_verneed(ELFOBJ *bin) { return NULL; } - if (!sdb_num_set(sdb, "num_entries", verneed_num, 0) || - !sdb_num_set(sdb, "addr", verneed_addr, 0) || - !sdb_num_set(sdb, "offset", verneed_offset, 0)) { + if (!sdb_num_set(sdb, "num_entries", verneed_num) || + !sdb_num_set(sdb, "addr", verneed_addr) || + !sdb_num_set(sdb, "offset", verneed_offset)) { sdb_free(sdb); return NULL; } diff --git a/librz/bin/format/java/class_bin.c b/librz/bin/format/java/class_bin.c index ac9a745469f..afc476619e7 100644 --- a/librz/bin/format/java/class_bin.c +++ b/librz/bin/format/java/class_bin.c @@ -257,19 +257,19 @@ static void java_set_sdb(Sdb *kv, RzBinJavaClass *bin, ut64 offset, ut64 size) { char *tmp_val; char tmp_key[256]; - sdb_num_set(kv, "java_class.offset", offset, 0); - sdb_num_set(kv, "java_class.size", size, 0); - sdb_num_set(kv, "java_class.magic", size, 0); - sdb_num_set(kv, "java_class.minor_version", size, 0); - sdb_num_set(kv, "java_class.major_version", size, 0); + sdb_num_set(kv, "java_class.offset", offset); + sdb_num_set(kv, "java_class.size", size); + sdb_num_set(kv, "java_class.magic", size); + sdb_num_set(kv, "java_class.minor_version", size); + sdb_num_set(kv, "java_class.major_version", size); tmp_val = rz_bin_java_class_version(bin); if (tmp_val) { - sdb_set(kv, "java_class.version", tmp_val, 0); + sdb_set(kv, "java_class.version", tmp_val); free(tmp_val); } - sdb_num_set(kv, "java_class.constant_pool_count", bin->constant_pool_count, 0); + sdb_num_set(kv, "java_class.constant_pool_count", bin->constant_pool_count); for (ut32 i = 0; i < bin->constant_pool_count; ++i) { ConstPool *cpool = bin->constant_pool[i]; if (!cpool) { @@ -278,14 +278,14 @@ static void java_set_sdb(Sdb *kv, RzBinJavaClass *bin, ut64 offset, ut64 size) { tmp_val = java_constant_pool_stringify(cpool); if (tmp_val) { snprintf(tmp_key, sizeof(tmp_key), "java_class.constant_pool_%d", i); - sdb_set(kv, tmp_key, tmp_val, 0); + sdb_set(kv, tmp_key, tmp_val); free(tmp_val); } } - sdb_num_set(kv, "java_class.fields_count", bin->fields_count, 0); - sdb_num_set(kv, "java_class.methods_count", bin->methods_count, 0); - sdb_num_set(kv, "java_class.attributes_count", bin->attributes_count, 0); + sdb_num_set(kv, "java_class.fields_count", bin->fields_count); + sdb_num_set(kv, "java_class.methods_count", bin->methods_count); + sdb_num_set(kv, "java_class.attributes_count", bin->attributes_count); } /** diff --git a/librz/bin/format/mach0/mach0.c b/librz/bin/format/mach0/mach0.c index cd26ffb7963..2a9fbb94328 100644 --- a/librz/bin/format/mach0/mach0.c +++ b/librz/bin/format/mach0/mach0.c @@ -96,140 +96,106 @@ static void init_sdb_formats(struct MACH0_(obj_t) * bin) { */ sdb_set(bin->kv, "mach0_build_platform.cparse", "enum mach0_build_platform" - "{MACOS=1, IOS=2, TVOS=3, WATCHOS=4, BRIDGEOS=5, IOSMAC=6, IOSSIMULATOR=7, TVOSSIMULATOR=8, WATCHOSSIMULATOR=9};", - 0); + "{MACOS=1, IOS=2, TVOS=3, WATCHOS=4, BRIDGEOS=5, IOSMAC=6, IOSSIMULATOR=7, TVOSSIMULATOR=8, WATCHOSSIMULATOR=9};"); sdb_set(bin->kv, "mach0_build_tool.cparse", "enum mach0_build_tool" - "{CLANG=1, SWIFT=2, LD=3};", - 0); + "{CLANG=1, SWIFT=2, LD=3};"); sdb_set(bin->kv, "mach0_load_command_type.cparse", "enum mach0_load_command_type" - "{ LC_SEGMENT=0x00000001ULL, LC_SYMTAB=0x00000002ULL, LC_SYMSEG=0x00000003ULL, LC_THREAD=0x00000004ULL, LC_UNIXTHREAD=0x00000005ULL, LC_LOADFVMLIB=0x00000006ULL, LC_IDFVMLIB=0x00000007ULL, LC_IDENT=0x00000008ULL, LC_FVMFILE=0x00000009ULL, LC_PREPAGE=0x0000000aULL, LC_DYSYMTAB=0x0000000bULL, LC_LOAD_DYLIB=0x0000000cULL, LC_ID_DYLIB=0x0000000dULL, LC_LOAD_DYLINKER=0x0000000eULL, LC_ID_DYLINKER=0x0000000fULL, LC_PREBOUND_DYLIB=0x00000010ULL, LC_ROUTINES=0x00000011ULL, LC_SUB_FRAMEWORK=0x00000012ULL, LC_SUB_UMBRELLA=0x00000013ULL, LC_SUB_CLIENT=0x00000014ULL, LC_SUB_LIBRARY=0x00000015ULL, LC_TWOLEVEL_HINTS=0x00000016ULL, LC_PREBIND_CKSUM=0x00000017ULL, LC_LOAD_WEAK_DYLIB=0x80000018ULL, LC_SEGMENT_64=0x00000019ULL, LC_ROUTINES_64=0x0000001aULL, LC_UUID=0x0000001bULL, LC_RPATH=0x8000001cULL, LC_CODE_SIGNATURE=0x0000001dULL, LC_SEGMENT_SPLIT_INFO=0x0000001eULL, LC_REEXPORT_DYLIB=0x8000001fULL, LC_LAZY_LOAD_DYLIB=0x00000020ULL, LC_ENCRYPTION_INFO=0x00000021ULL, LC_DYLD_INFO=0x00000022ULL, LC_DYLD_INFO_ONLY=0x80000022ULL, LC_LOAD_UPWARD_DYLIB=0x80000023ULL, LC_VERSION_MIN_MACOSX=0x00000024ULL, LC_VERSION_MIN_IPHONEOS=0x00000025ULL, LC_FUNCTION_STARTS=0x00000026ULL, LC_DYLD_ENVIRONMENT=0x00000027ULL, LC_MAIN=0x80000028ULL, LC_DATA_IN_CODE=0x00000029ULL, LC_SOURCE_VERSION=0x0000002aULL, LC_DYLIB_CODE_SIGN_DRS=0x0000002bULL, LC_ENCRYPTION_INFO_64=0x0000002cULL, LC_LINKER_OPTION=0x0000002dULL, LC_LINKER_OPTIMIZATION_HINT=0x0000002eULL, LC_VERSION_MIN_TVOS=0x0000002fULL, LC_VERSION_MIN_WATCHOS=0x00000030ULL, LC_NOTE=0x00000031ULL, LC_BUILD_VERSION=0x00000032ULL };", - 0); + "{ LC_SEGMENT=0x00000001ULL, LC_SYMTAB=0x00000002ULL, LC_SYMSEG=0x00000003ULL, LC_THREAD=0x00000004ULL, LC_UNIXTHREAD=0x00000005ULL, LC_LOADFVMLIB=0x00000006ULL, LC_IDFVMLIB=0x00000007ULL, LC_IDENT=0x00000008ULL, LC_FVMFILE=0x00000009ULL, LC_PREPAGE=0x0000000aULL, LC_DYSYMTAB=0x0000000bULL, LC_LOAD_DYLIB=0x0000000cULL, LC_ID_DYLIB=0x0000000dULL, LC_LOAD_DYLINKER=0x0000000eULL, LC_ID_DYLINKER=0x0000000fULL, LC_PREBOUND_DYLIB=0x00000010ULL, LC_ROUTINES=0x00000011ULL, LC_SUB_FRAMEWORK=0x00000012ULL, LC_SUB_UMBRELLA=0x00000013ULL, LC_SUB_CLIENT=0x00000014ULL, LC_SUB_LIBRARY=0x00000015ULL, LC_TWOLEVEL_HINTS=0x00000016ULL, LC_PREBIND_CKSUM=0x00000017ULL, LC_LOAD_WEAK_DYLIB=0x80000018ULL, LC_SEGMENT_64=0x00000019ULL, LC_ROUTINES_64=0x0000001aULL, LC_UUID=0x0000001bULL, LC_RPATH=0x8000001cULL, LC_CODE_SIGNATURE=0x0000001dULL, LC_SEGMENT_SPLIT_INFO=0x0000001eULL, LC_REEXPORT_DYLIB=0x8000001fULL, LC_LAZY_LOAD_DYLIB=0x00000020ULL, LC_ENCRYPTION_INFO=0x00000021ULL, LC_DYLD_INFO=0x00000022ULL, LC_DYLD_INFO_ONLY=0x80000022ULL, LC_LOAD_UPWARD_DYLIB=0x80000023ULL, LC_VERSION_MIN_MACOSX=0x00000024ULL, LC_VERSION_MIN_IPHONEOS=0x00000025ULL, LC_FUNCTION_STARTS=0x00000026ULL, LC_DYLD_ENVIRONMENT=0x00000027ULL, LC_MAIN=0x80000028ULL, LC_DATA_IN_CODE=0x00000029ULL, LC_SOURCE_VERSION=0x0000002aULL, LC_DYLIB_CODE_SIGN_DRS=0x0000002bULL, LC_ENCRYPTION_INFO_64=0x0000002cULL, LC_LINKER_OPTION=0x0000002dULL, LC_LINKER_OPTIMIZATION_HINT=0x0000002eULL, LC_VERSION_MIN_TVOS=0x0000002fULL, LC_VERSION_MIN_WATCHOS=0x00000030ULL, LC_NOTE=0x00000031ULL, LC_BUILD_VERSION=0x00000032ULL };"); sdb_set(bin->kv, "mach0_header_filetype.cparse", "enum mach0_header_filetype" - "{MH_OBJECT=1, MH_EXECUTE=2, MH_FVMLIB=3, MH_CORE=4, MH_PRELOAD=5, MH_DYLIB=6, MH_DYLINKER=7, MH_BUNDLE=8, MH_DYLIB_STUB=9, MH_DSYM=10, MH_KEXT_BUNDLE=11};", - 0); + "{MH_OBJECT=1, MH_EXECUTE=2, MH_FVMLIB=3, MH_CORE=4, MH_PRELOAD=5, MH_DYLIB=6, MH_DYLINKER=7, MH_BUNDLE=8, MH_DYLIB_STUB=9, MH_DSYM=10, MH_KEXT_BUNDLE=11};"); sdb_set(bin->kv, "mach0_header_flags.cparse", "enum mach0_header_flags" - "{MH_NOUNDEFS=1, MH_INCRLINK=2,MH_DYLDLINK=4,MH_BINDATLOAD=8,MH_PREBOUND=0x10, MH_SPLIT_SEGS=0x20,MH_LAZY_INIT=0x40,MH_TWOLEVEL=0x80, MH_FORCE_FLAT=0x100,MH_NOMULTIDEFS=0x200,MH_NOFIXPREBINDING=0x400, MH_PREBINDABLE=0x800, MH_ALLMODSBOUND=0x1000, MH_SUBSECTIONS_VIA_SYMBOLS=0x2000, MH_CANONICAL=0x4000,MH_WEAK_DEFINES=0x8000, MH_BINDS_TO_WEAK=0x10000,MH_ALLOW_STACK_EXECUTION=0x20000, MH_ROOT_SAFE=0x40000,MH_SETUID_SAFE=0x80000, MH_NO_REEXPORTED_DYLIBS=0x100000,MH_PIE=0x200000, MH_DEAD_STRIPPABLE_DYLIB=0x400000, MH_HAS_TLV_DESCRIPTORS=0x800000, MH_NO_HEAP_EXECUTION=0x1000000};", - 0); + "{MH_NOUNDEFS=1, MH_INCRLINK=2,MH_DYLDLINK=4,MH_BINDATLOAD=8,MH_PREBOUND=0x10, MH_SPLIT_SEGS=0x20,MH_LAZY_INIT=0x40,MH_TWOLEVEL=0x80, MH_FORCE_FLAT=0x100,MH_NOMULTIDEFS=0x200,MH_NOFIXPREBINDING=0x400, MH_PREBINDABLE=0x800, MH_ALLMODSBOUND=0x1000, MH_SUBSECTIONS_VIA_SYMBOLS=0x2000, MH_CANONICAL=0x4000,MH_WEAK_DEFINES=0x8000, MH_BINDS_TO_WEAK=0x10000,MH_ALLOW_STACK_EXECUTION=0x20000, MH_ROOT_SAFE=0x40000,MH_SETUID_SAFE=0x80000, MH_NO_REEXPORTED_DYLIBS=0x100000,MH_PIE=0x200000, MH_DEAD_STRIPPABLE_DYLIB=0x400000, MH_HAS_TLV_DESCRIPTORS=0x800000, MH_NO_HEAP_EXECUTION=0x1000000};"); sdb_set(bin->kv, "mach0_section_types.cparse", "enum mach0_section_types" - "{S_REGULAR=0, S_ZEROFILL=1, S_CSTRING_LITERALS=2, S_4BYTE_LITERALS=3, S_8BYTE_LITERALS=4, S_LITERAL_POINTERS=5, S_NON_LAZY_SYMBOL_POINTERS=6, S_LAZY_SYMBOL_POINTERS=7, S_SYMBOL_STUBS=8, S_MOD_INIT_FUNC_POINTERS=9, S_MOD_TERM_FUNC_POINTERS=0xa, S_COALESCED=0xb, S_GB_ZEROFILL=0xc, S_INTERPOSING=0xd, S_16BYTE_LITERALS=0xe, S_DTRACE_DOF=0xf, S_LAZY_DYLIB_SYMBOL_POINTERS=0x10, S_THREAD_LOCAL_REGULAR=0x11, S_THREAD_LOCAL_ZEROFILL=0x12, S_THREAD_LOCAL_VARIABLES=0x13, S_THREAD_LOCAL_VARIABLE_POINTERS=0x14, S_THREAD_LOCAL_INIT_FUNCTION_POINTERS=0x15, S_INIT_FUNC_OFFSETS=0x16};", - 0); + "{S_REGULAR=0, S_ZEROFILL=1, S_CSTRING_LITERALS=2, S_4BYTE_LITERALS=3, S_8BYTE_LITERALS=4, S_LITERAL_POINTERS=5, S_NON_LAZY_SYMBOL_POINTERS=6, S_LAZY_SYMBOL_POINTERS=7, S_SYMBOL_STUBS=8, S_MOD_INIT_FUNC_POINTERS=9, S_MOD_TERM_FUNC_POINTERS=0xa, S_COALESCED=0xb, S_GB_ZEROFILL=0xc, S_INTERPOSING=0xd, S_16BYTE_LITERALS=0xe, S_DTRACE_DOF=0xf, S_LAZY_DYLIB_SYMBOL_POINTERS=0x10, S_THREAD_LOCAL_REGULAR=0x11, S_THREAD_LOCAL_ZEROFILL=0x12, S_THREAD_LOCAL_VARIABLES=0x13, S_THREAD_LOCAL_VARIABLE_POINTERS=0x14, S_THREAD_LOCAL_INIT_FUNCTION_POINTERS=0x15, S_INIT_FUNC_OFFSETS=0x16};"); sdb_set(bin->kv, "mach0_section_attrs.cparse", "enum mach0_section_attrs" - "{S_ATTR_PURE_INSTRUCTIONS=0x800000ULL, S_ATTR_NO_TOC=0x400000ULL, S_ATTR_STRIP_STATIC_SYMS=0x200000ULL, S_ATTR_NO_DEAD_STRIP=0x100000ULL, S_ATTR_LIVE_SUPPORT=0x080000ULL, S_ATTR_SELF_MODIFYING_CODE=0x040000ULL, S_ATTR_DEBUG=0x020000ULL, S_ATTR_SOME_INSTRUCTIONS=0x000004ULL, S_ATTR_EXT_RELOC=0x000002ULL, S_ATTR_LOC_RELOC=0x000001ULL};", - 0); + "{S_ATTR_PURE_INSTRUCTIONS=0x800000ULL, S_ATTR_NO_TOC=0x400000ULL, S_ATTR_STRIP_STATIC_SYMS=0x200000ULL, S_ATTR_NO_DEAD_STRIP=0x100000ULL, S_ATTR_LIVE_SUPPORT=0x080000ULL, S_ATTR_SELF_MODIFYING_CODE=0x040000ULL, S_ATTR_DEBUG=0x020000ULL, S_ATTR_SOME_INSTRUCTIONS=0x000004ULL, S_ATTR_EXT_RELOC=0x000002ULL, S_ATTR_LOC_RELOC=0x000001ULL};"); sdb_set(bin->kv, "mach0_header.format", "xxx[4]Edd[4]B " - "magic cputype cpusubtype (mach0_header_filetype)filetype ncmds sizeofcmds (mach0_header_flags)flags", - 0); + "magic cputype cpusubtype (mach0_header_filetype)filetype ncmds sizeofcmds (mach0_header_flags)flags"); sdb_set(bin->kv, "mach0_segment.format", "[4]Ed[16]zxxxxoodx " - "(mach0_load_command_type)cmd cmdsize segname vmaddr vmsize fileoff filesize maxprot initprot nsects flags", - 0); + "(mach0_load_command_type)cmd cmdsize segname vmaddr vmsize fileoff filesize maxprot initprot nsects flags"); sdb_set(bin->kv, "mach0_segment64.format", "[4]Ed[16]zqqqqoodx " - "(mach0_load_command_type)cmd cmdsize segname vmaddr vmsize fileoff filesize maxprot initprot nsects flags", - 0); + "(mach0_load_command_type)cmd cmdsize segname vmaddr vmsize fileoff filesize maxprot initprot nsects flags"); sdb_set(bin->kv, "mach0_symtab_command.format", "[4]Edxdxd " - "(mach0_load_command_type)cmd cmdsize symoff nsyms stroff strsize", - 0); + "(mach0_load_command_type)cmd cmdsize symoff nsyms stroff strsize"); sdb_set(bin->kv, "mach0_dysymtab_command.format", "[4]Edddddddddddxdxdxxxd " - "(mach0_load_command_type)cmd cmdsize ilocalsym nlocalsym iextdefsym nextdefsym iundefsym nundefsym tocoff ntoc moddtaboff nmodtab extrefsymoff nextrefsyms inddirectsymoff nindirectsyms extreloff nextrel locreloff nlocrel", - 0); + "(mach0_load_command_type)cmd cmdsize ilocalsym nlocalsym iextdefsym nextdefsym iundefsym nundefsym tocoff ntoc moddtaboff nmodtab extrefsymoff nextrefsyms inddirectsymoff nindirectsyms extreloff nextrel locreloff nlocrel"); sdb_set(bin->kv, "mach0_section.format", "[16]z[16]zxxxxxx[1]E[3]Bxx " - "sectname segname addr size offset align reloff nreloc (mach0_section_types)flags_type (mach0_section_attrs)flags_attr reserved1 reserved2", - 0); + "sectname segname addr size offset align reloff nreloc (mach0_section_types)flags_type (mach0_section_attrs)flags_attr reserved1 reserved2"); sdb_set(bin->kv, "mach0_section64.format", "[16]z[16]zqqxxxx[1]E[3]Bxxx " - "sectname segname addr size offset align reloff nreloc (mach0_section_types)flags_type (mach0_section_attrs)flags_attr reserved1 reserved2 reserved3", - 0); + "sectname segname addr size offset align reloff nreloc (mach0_section_types)flags_type (mach0_section_attrs)flags_attr reserved1 reserved2 reserved3"); sdb_set(bin->kv, "mach0_dylib.format", "xxxxz " - "name_offset timestamp current_version compatibility_version name", - 0); + "name_offset timestamp current_version compatibility_version name"); sdb_set(bin->kv, "mach0_dylib_command.format", "[4]Ed? " - "(mach0_load_command_type)cmd cmdsize (mach0_dylib)dylib", - 0); + "(mach0_load_command_type)cmd cmdsize (mach0_dylib)dylib"); sdb_set(bin->kv, "mach0_id_dylib_command.format", "[4]Ed? " - "(mach0_load_command_type)cmd cmdsize (mach0_dylib)dylib", - 0); + "(mach0_load_command_type)cmd cmdsize (mach0_dylib)dylib"); sdb_set(bin->kv, "mach0_uuid_command.format", "[4]Ed[16]b " - "(mach0_load_command_type)cmd cmdsize uuid", - 0); + "(mach0_load_command_type)cmd cmdsize uuid"); sdb_set(bin->kv, "mach0_rpath_command.format", "[4]Edxz " - "(mach0_load_command_type)cmd cmdsize path_offset path", - 0); + "(mach0_load_command_type)cmd cmdsize path_offset path"); sdb_set(bin->kv, "mach0_entry_point_command.format", "[4]Edqq " - "(mach0_load_command_type)cmd cmdsize entryoff stacksize", - 0); + "(mach0_load_command_type)cmd cmdsize entryoff stacksize"); sdb_set(bin->kv, "mach0_encryption_info64_command.format", "[4]Edxddx " - "(mach0_load_command_type)cmd cmdsize offset size id padding", - 0); + "(mach0_load_command_type)cmd cmdsize offset size id padding"); sdb_set(bin->kv, "mach0_encryption_info_command.format", "[4]Edxdd " - "(mach0_load_command_type)cmd cmdsize offset size id", - 0); + "(mach0_load_command_type)cmd cmdsize offset size id"); sdb_set(bin->kv, "mach0_code_signature_command.format", "[4]Edxd " - "(mach0_load_command_type)cmd cmdsize offset size", - 0); + "(mach0_load_command_type)cmd cmdsize offset size"); sdb_set(bin->kv, "mach0_dyld_info_only_command.format", "[4]Edxdxdxdxdxd " - "(mach0_load_command_type)cmd cmdsize rebase_off rebase_size bind_off bind_size weak_bind_off weak_bind_size lazy_bind_off lazy_bind_size export_off export_size", - 0); + "(mach0_load_command_type)cmd cmdsize rebase_off rebase_size bind_off bind_size weak_bind_off weak_bind_size lazy_bind_off lazy_bind_size export_off export_size"); sdb_set(bin->kv, "mach0_load_dylinker_command.format", "[4]Edxz " - "(mach0_load_command_type)cmd cmdsize name_offset name", - 0); + "(mach0_load_command_type)cmd cmdsize name_offset name"); sdb_set(bin->kv, "mach0_id_dylinker_command.format", "[4]Edxzi " - "(mach0_load_command_type)cmd cmdsize name_offset name", - 0); + "(mach0_load_command_type)cmd cmdsize name_offset name"); sdb_set(bin->kv, "mach0_build_version_command.format", "[4]Ed[4]Exxd " - "(mach0_load_command_type)cmd cmdsize (mach0_build_platform)platform minos sdk ntools", - 0); + "(mach0_load_command_type)cmd cmdsize (mach0_build_platform)platform minos sdk ntools"); sdb_set(bin->kv, "mach0_build_version_tool.format", "[4]Ex " - "(mach0_build_tool)tool version", - 0); + "(mach0_build_tool)tool version"); sdb_set(bin->kv, "mach0_source_version_command.format", "[4]Edq " - "(mach0_load_command_type)cmd cmdsize version", - 0); + "(mach0_load_command_type)cmd cmdsize version"); sdb_set(bin->kv, "mach0_function_starts_command.format", "[4]Edxd " - "(mach0_load_command_type)cmd cmdsize offset size", - 0); + "(mach0_load_command_type)cmd cmdsize offset size"); sdb_set(bin->kv, "mach0_data_in_code_command.format", "[4]Edxd " - "(mach0_load_command_type)cmd cmdsize offset size", - 0); + "(mach0_load_command_type)cmd cmdsize offset size"); sdb_set(bin->kv, "mach0_version_min_command.format", "[4]Edxx " - "(mach0_load_command_type)cmd cmdsize version reserved", - 0); + "(mach0_load_command_type)cmd cmdsize version reserved"); sdb_set(bin->kv, "mach0_segment_split_info_command.format", "[4]Edxd " - "(mach0_load_command_type)cmd cmdsize offset size", - 0); + "(mach0_load_command_type)cmd cmdsize offset size"); sdb_set(bin->kv, "mach0_unixthread_command.format", "[4]Eddd " - "(mach0_load_command_type)cmd cmdsize flavor count", - 0); + "(mach0_load_command_type)cmd cmdsize flavor count"); } static bool init_hdr(struct MACH0_(obj_t) * bin) { @@ -271,7 +237,7 @@ static bool init_hdr(struct MACH0_(obj_t) * bin) { bin->hdr.reserved = rz_read_ble(&machohdrbytes[28], bin->big_endian, 32); #endif init_sdb_formats(bin); - sdb_num_set(bin->kv, "mach0_header.offset", 0, 0); // wat about fatmach0? + sdb_num_set(bin->kv, "mach0_header.offset", 0); // wat about fatmach0? return true; } @@ -336,12 +302,12 @@ static bool parse_segments(struct MACH0_(obj_t) * bin, ut64 off) { bin->segs[j].flags = rz_read_ble32(&segcom[i], bin->big_endian); #if RZ_BIN_MACH064 - sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_segment64_%zu.offset", j), off, 0); + sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_segment64_%zu.offset", j), off); #else - sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_segment_%zu.offset", j), off, 0); + sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_segment_%zu.offset", j), off); #endif - sdb_num_set(bin->kv, "mach0_segments.count", 0, 0); + sdb_num_set(bin->kv, "mach0_segments.count", 0); if (bin->segs[j].nsects > 0) { sect = bin->nsects; @@ -398,11 +364,11 @@ static bool parse_segments(struct MACH0_(obj_t) * bin, ut64 off) { memcpy(&bin->sects[k].segname, &sec[i], 16); i += 16; - sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_section_%.16s_%.16s.offset", bin->sects[k].segname, bin->sects[k].sectname), offset, 0); + sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_section_%.16s_%.16s.offset", bin->sects[k].segname, bin->sects[k].sectname), offset); #if RZ_BIN_MACH064 - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_section_%.16s_%.16s.format", bin->sects[k].segname, bin->sects[k].sectname), "mach0_section64", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_section_%.16s_%.16s.format", bin->sects[k].segname, bin->sects[k].sectname), "mach0_section64"); #else - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_section_%.16s_%.16s.format", bin->sects[k].segname, bin->sects[k].sectname), "mach0_section", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_section_%.16s_%.16s.format", bin->sects[k].segname, bin->sects[k].sectname), "mach0_section"); #endif #if RZ_BIN_MACH064 @@ -944,7 +910,7 @@ static bool parse_signature(struct MACH0_(obj_t) * bin, ut64 off) { ut32 ident_size = rz_read_ble32(p + 8, 1); char *ident = rz_str_ndup((const char *)p + 28, ident_size); if (ident) { - sdb_set(bin->kv, "mach0.ident", ident, 0); + sdb_set(bin->kv, "mach0.ident", ident); free(ident); } } else { @@ -1125,7 +1091,7 @@ static int parse_thread(struct MACH0_(obj_t) * bin, struct load_command *lc, ut6 bin->entry = pc; } if (pc_offset != UT64_MAX) { - sdb_num_set(bin->kv, "mach0.entry.offset", pc_offset, 0); + sdb_num_set(bin->kv, "mach0.entry.offset", pc_offset); } } @@ -1470,24 +1436,24 @@ static int init_items(struct MACH0_(obj_t) * bin) { break; } - sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".offset", i), off, 0); + sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".offset", i), off); const char *format_name = cmd_to_pf_definition(lc.cmd); if (format_name) { - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), format_name, 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), format_name); } else { - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), "[4]Ed (mach_load_command_type)cmd size", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), "[4]Ed (mach_load_command_type)cmd size"); } switch (lc.cmd) { case LC_DATA_IN_CODE: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "data_in_code", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "data_in_code"); break; case LC_RPATH: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "rpath", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "rpath"); break; case LC_SEGMENT_64: case LC_SEGMENT: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "segment", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "segment"); bin->nsegs++; if (!parse_segments(bin, off)) { RZ_LOG_ERROR("mach0: error parsing segment\n"); @@ -1496,42 +1462,42 @@ static int init_items(struct MACH0_(obj_t) * bin) { } break; case LC_SYMTAB: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "symtab", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "symtab"); if (!parse_symtab(bin, off)) { RZ_LOG_ERROR("mach0: error parsing symtab\n"); return false; } break; case LC_DYSYMTAB: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dysymtab", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dysymtab"); if (!parse_dysymtab(bin, off)) { RZ_LOG_ERROR("mach0: error parsing dysymtab\n"); return false; } break; case LC_DYLIB_CODE_SIGN_DRS: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dylib_code_sign_drs", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dylib_code_sign_drs"); break; case LC_VERSION_MIN_MACOSX: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_macosx", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_macosx"); if (bin->platform == UT32_MAX) { bin->platform = MACH0_PLATFORM_MACOS; } break; case LC_VERSION_MIN_IPHONEOS: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_iphoneos", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_iphoneos"); if (bin->platform == UT32_MAX) { bin->platform = MACH0_PLATFORM_IOS; } break; case LC_VERSION_MIN_TVOS: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_tvos", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_tvos"); if (bin->platform == UT32_MAX) { bin->platform = MACH0_PLATFORM_TVOS; } break; case LC_VERSION_MIN_WATCHOS: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_watchos", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version_min_watchos"); if (bin->platform == UT32_MAX) { bin->platform = MACH0_PLATFORM_WATCHOS; } @@ -1545,7 +1511,7 @@ static int init_items(struct MACH0_(obj_t) * bin) { break; } case LC_UUID: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "uuid", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "uuid"); { struct uuid_command uc = { 0 }; if (off + sizeof(struct uuid_command) > bin->size) { @@ -1557,7 +1523,7 @@ static int init_items(struct MACH0_(obj_t) * bin) { char val[128]; snprintf(key, sizeof(key) - 1, "uuid.%d", bin->uuidn++); rz_hex_bin2str((ut8 *)&uc.uuid, 16, val); - sdb_set(bin->kv, key, val, 0); + sdb_set(bin->kv, key, val); // for (i=0;i<16; i++) bprintf ("%02x%c", uc.uuid[i], (i==15)?'\n':'-'); } } @@ -1565,7 +1531,7 @@ static int init_items(struct MACH0_(obj_t) * bin) { case LC_ENCRYPTION_INFO_64: /* TODO: the struct is probably different here */ case LC_ENCRYPTION_INFO: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "encryption_info", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "encryption_info"); { struct MACH0_(encryption_info_command) eic = { 0 }; ut8 seic[sizeof(struct MACH0_(encryption_info_command))] = { 0 }; @@ -1581,16 +1547,16 @@ static int init_items(struct MACH0_(obj_t) * bin) { eic.cryptid = rz_read_ble32(&seic[16], bin->big_endian); bin->has_crypto = eic.cryptid; - sdb_set(bin->kv, "crypto", "true", 0); - sdb_num_set(bin->kv, "cryptid", eic.cryptid, 0); - sdb_num_set(bin->kv, "cryptoff", eic.cryptoff, 0); - sdb_num_set(bin->kv, "cryptsize", eic.cryptsize, 0); - sdb_num_set(bin->kv, "cryptheader", off, 0); + sdb_set(bin->kv, "crypto", "true"); + sdb_num_set(bin->kv, "cryptid", eic.cryptid); + sdb_num_set(bin->kv, "cryptoff", eic.cryptoff); + sdb_num_set(bin->kv, "cryptsize", eic.cryptsize); + sdb_num_set(bin->kv, "cryptheader", off); } } break; case LC_LOAD_DYLINKER: { - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dylinker", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dylinker"); RZ_FREE(bin->intrp); // bprintf ("[mach0] load dynamic linker\n"); struct dylinker_command dy = { 0 }; @@ -1623,7 +1589,7 @@ static int init_items(struct MACH0_(obj_t) * bin) { ut64 ss; } ep = { 0 }; ut8 sep[2 * sizeof(ut64)] = { 0 }; - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "main", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "main"); if (!is_first_thread) { RZ_LOG_ERROR("mach0: LC_MAIN with other threads\n"); @@ -1640,20 +1606,20 @@ static int init_items(struct MACH0_(obj_t) * bin) { bin->entry = ep.eo; bin->main_cmd = lc; - sdb_num_set(bin->kv, "mach0.entry.offset", off + 8, 0); - sdb_num_set(bin->kv, "stacksize", ep.ss, 0); + sdb_num_set(bin->kv, "mach0.entry.offset", off + 8); + sdb_num_set(bin->kv, "stacksize", ep.ss); is_first_thread = false; } break; case LC_UNIXTHREAD: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "unixthread", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "unixthread"); if (!is_first_thread) { RZ_LOG_ERROR("mach0: LC_UNIXTHREAD with other threads\n"); return false; } // fallthrough case LC_THREAD: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "thread", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "thread"); if (!parse_thread(bin, &lc, off, is_first_thread)) { RZ_LOG_ERROR("mach0: Cannot parse thread\n"); return false; @@ -1662,7 +1628,7 @@ static int init_items(struct MACH0_(obj_t) * bin) { break; case LC_LOAD_DYLIB: case LC_LOAD_WEAK_DYLIB: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "load_dylib", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "load_dylib"); bin->nlibs++; if (!parse_dylib(bin, off)) { RZ_LOG_ERROR("mach0: Cannot parse dylib\n"); @@ -1673,7 +1639,7 @@ static int init_items(struct MACH0_(obj_t) * bin) { case LC_DYLD_INFO: case LC_DYLD_INFO_ONLY: { ut8 dyldi[sizeof(struct dyld_info_command)] = { 0 }; - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dyld_info", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dyld_info"); bin->dyld_info = calloc(1, sizeof(struct dyld_info_command)); if (bin->dyld_info) { if (off + sizeof(struct dyld_info_command) > bin->size) { @@ -1702,27 +1668,27 @@ static int init_items(struct MACH0_(obj_t) * bin) { } break; case LC_CODE_SIGNATURE: parse_signature(bin, off); - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "signature", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "signature"); /* ut32 dataoff // ut32 datasize */ break; case LC_SOURCE_VERSION: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "version"); /* uint64_t version; */ /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */ break; case LC_SEGMENT_SPLIT_INFO: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "split_info", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "split_info"); /* TODO */ break; case LC_FUNCTION_STARTS: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "function_starts", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "function_starts"); if (!parse_function_starts(bin, off)) { RZ_LOG_ERROR("mach0: Cannot parse LC_FUNCTION_STARTS\n"); } break; case LC_REEXPORT_DYLIB: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dylib", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "dylib"); /* TODO */ break; default: @@ -1745,17 +1711,17 @@ static int init_items(struct MACH0_(obj_t) * bin) { break; } - sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".offset", i), off, 0); + sdb_num_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".offset", i), off); const char *format_name = cmd_to_pf_definition(lc.cmd); if (format_name) { - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), format_name, 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), format_name); } else { - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), "[4]Ed (mach_load_command_type)cmd size", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".format", i), "[4]Ed (mach_load_command_type)cmd size"); } switch (lc.cmd) { case LC_DATA_IN_CODE: - sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "data_in_code", 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "mach0_cmd_%" PFMT64u ".cmd", i), "data_in_code"); if (bin->options.verbose) { ut8 buf[8]; rz_buf_read_at(bin->b, off + 8, buf, sizeof(buf)); @@ -2771,9 +2737,9 @@ struct addr_t *MACH0_(get_entrypoint)(struct MACH0_(obj_t) * bin) { } entry->addr = ea; entry->offset = MACH0_(vaddr_to_paddr)(bin, entry->addr); - entry->haddr = sdb_num_get(bin->kv, "mach0.entry.offset", 0); - sdb_num_set(bin->kv, "mach0.entry.vaddr", entry->addr, 0); - sdb_num_set(bin->kv, "mach0.entry.paddr", bin->entry, 0); + entry->haddr = sdb_num_get(bin->kv, "mach0.entry.offset"); + sdb_num_set(bin->kv, "mach0.entry.vaddr", entry->addr); + sdb_num_set(bin->kv, "mach0.entry.paddr", bin->entry); if (entry->offset == 0 && !bin->sects) { int i; @@ -2781,7 +2747,7 @@ struct addr_t *MACH0_(get_entrypoint)(struct MACH0_(obj_t) * bin) { // XXX: section name shoudnt matter .. just check for exec flags if (!strncmp(bin->sects[i].sectname, "__text", 6)) { entry->offset = (ut64)bin->sects[i].offset; - sdb_num_set(bin->kv, "mach0.entry", entry->offset, 0); + sdb_num_set(bin->kv, "mach0.entry", entry->offset); entry->addr = (ut64)bin->sects[i].addr; if (!entry->addr) { // workaround for object files eprintf("entrypoint is 0...\n"); @@ -2801,7 +2767,7 @@ void MACH0_(kv_loadlibs)(struct MACH0_(obj_t) * bin) { int i; char tmpbuf[32]; for (i = 0; i < bin->nlibs; i++) { - sdb_set(bin->kv, rz_strf(tmpbuf, "libs.%d.name", i), bin->libs[i], 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "libs.%d.name", i), bin->libs[i]); } } @@ -2817,7 +2783,7 @@ struct lib_t *MACH0_(get_libs)(struct MACH0_(obj_t) * bin) { } char tmpbuf[32]; for (i = 0; i < bin->nlibs; i++) { - sdb_set(bin->kv, rz_strf(tmpbuf, "libs.%d.name", i), bin->libs[i], 0); + sdb_set(bin->kv, rz_strf(tmpbuf, "libs.%d.name", i), bin->libs[i]); strncpy(libs[i].name, bin->libs[i], RZ_BIN_MACH0_STRING_LENGTH - 1); libs[i].name[RZ_BIN_MACH0_STRING_LENGTH - 1] = '\0'; libs[i].last = 0; diff --git a/librz/bin/format/mdmp/mdmp.c b/librz/bin/format/mdmp/mdmp.c index c3a75644339..31f6e22a77e 100644 --- a/librz/bin/format/mdmp/mdmp.c +++ b/librz/bin/format/mdmp/mdmp.c @@ -137,13 +137,11 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { /* FIXME: Why are we getting struct missing errors when it finds them */ sdb_set(obj->kv, "mdmp_mem_state.cparse", "enum mdmp_mem_state { MEM_COMMIT=0x1000, " - "MEM_FREE=0x10000, MEM_RESERVE=0x02000 };", - 0); + "MEM_FREE=0x10000, MEM_RESERVE=0x02000 };"); sdb_set(obj->kv, "mdmp_mem_type.cparse", "enum mdmp_mem_type { MEM_IMAGE=0x1000000, " - "MEM_MAPPED=0x40000, MEM_PRIVATE=0x20000 };", - 0); + "MEM_MAPPED=0x40000, MEM_PRIVATE=0x20000 };"); sdb_set(obj->kv, "mdmp_page_protect.cparse", "enum mdmp_page_protect { PAGE_NOACCESS=1, " @@ -151,14 +149,12 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "PAGE_EXECUTE=0x10, PAGE_EXECUTE_READ=0x20, " "PAGE_EXECUTE_READWRITE=0x40, PAGE_EXECUTE_WRITECOPY=0x80, " "PAGE_GUARD=0x100, PAGE_NOCACHE=0x200, " - "PAGE_WRITECOMBINE=0x400, PAGE_TARGETS_INVALID=0x40000000 };", - 0); + "PAGE_WRITECOMBINE=0x400, PAGE_TARGETS_INVALID=0x40000000 };"); sdb_set(obj->kv, "mdmp_misc1_flags.cparse", "enum mdmp_misc1_flags { MINIDUMP_MISC1_PROCESS_ID=1, " "MINIDUMP_MISC1_PROCESS_TIMES=2, " - "MINIDUMP_MISC1_PROCESSOR_POWER_INFO=4 };", - 0); + "MINIDUMP_MISC1_PROCESSOR_POWER_INFO=4 };"); sdb_set(obj->kv, "mdmp_processor_architecture.cparse", "enum mdmp_processor_architecture { " @@ -166,21 +162,18 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "PROCESSOR_ARCHITECTURE_ARM=5, " "PROCESSOR_ARCHITECTURE_IA64=6, " "PROCESSOR_ARCHITECTURE_AMD64=9, " - "PROCESSOR_ARCHITECTURE_UNKNOWN=0xffff };", - 0); + "PROCESSOR_ARCHITECTURE_UNKNOWN=0xffff };"); sdb_set(obj->kv, "mdmp_product_type.cparse", "enum mdmp_product_type { " "VER_NT_WORKSTATION=1, VER_NT_DOMAIN_CONTROLLER=2, " - "VER_NT_SERVER=3 };", - 0); + "VER_NT_SERVER=3 };"); sdb_set(obj->kv, "mdmp_platform_id.cparse", "enum mdmp_platform_id { " "VER_PLATFORM_WIN32s=0, " "VER_PLATFORM_WIN32_WINDOWS=1, " - "VER_PLATFORM_WIN32_NT=2 };", - 0); + "VER_PLATFORM_WIN32_NT=2 };"); sdb_set(obj->kv, "mdmp_suite_mask.cparse", "enum mdmp_suite_mask { " @@ -190,8 +183,7 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "VER_SUITE_EMBEDDEDNT=0x40, VER_SUITE_DATACENTER=0x80, " "VER_SUITE_SINGLEUSERTS=0x100, VER_SUITE_PERSONAL=0x200, " "VER_SUITE_BLADE=0x400, VER_SUITE_STORAGE_SERVER=0x2000, " - "VER_SUITE_COMPUTE_SERVER=0x4000 };", - 0); + "VER_SUITE_COMPUTE_SERVER=0x4000 };"); sdb_set(obj->kv, "mdmp_callback_type.cparse", "enum mdmp_callback_type { ModuleCallback=0," @@ -204,8 +196,7 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "IncludeVmRegionCallback=10, " "IoStartCallback=11, IoWriteAllCallback=12, " "IoFinishCallback=13, ReadMemoryFailureCallback=14, " - "SecondaryFlagsCallback=15 };", - 0); + "SecondaryFlagsCallback=15 };"); sdb_set(obj->kv, "mdmp_exception_code.cparse", "enum mdmp_exception_code { " @@ -232,27 +223,23 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "EXCEPTION_INTEGER_OVERFLOW=0xc0000095, " "EXCEPTION_PRIVILEGED_INSTRUCTION=0xc0000096, " "EXCEPTION_STACK_OVERFLOW=0xc00000fd, " - "EXCEPTION_POSSIBLE_DEADLOCK=0xc0000194 };", - 0); + "EXCEPTION_POSSIBLE_DEADLOCK=0xc0000194 };"); sdb_set(obj->kv, "mdmp_exception_flags.cparse", "enum mdmp_exception_flags { " "EXCEPTION_CONTINUABLE=0, " - "EXCEPTION_NONCONTINUABLE=1 };", - 0); + "EXCEPTION_NONCONTINUABLE=1 };"); sdb_set(obj->kv, "mdmp_handle_object_information_type.cparse", "enum mdmp_handle_object_information_type { " "MiniHandleObjectInformationNone=0, " "MiniThreadInformation1=1, MiniMutantInformation1=2, " "MiniMutantInformation2=3, MiniMutantProcessInformation1=4, " - "MiniProcessInformation2=5 };", - 0); + "MiniProcessInformation2=5 };"); sdb_set(obj->kv, "mdmp_secondary_flags.cparse", "enum mdmp_secondary_flags { " - "MiniSecondaryWithoutPowerInfo=0 };", - 0); + "MiniSecondaryWithoutPowerInfo=0 };"); sdb_set(obj->kv, "mdmp_stream_type.cparse", "enum mdmp_stream_type { UnusedStream=0, " @@ -266,8 +253,7 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "MiscInfoStream=15, MemoryInfoListStream=16, " "ThreadInfoListStream=17, " "HandleOperationListStream=18, " - "LastReservedStream=0xffff };", - 0); + "LastReservedStream=0xffff };"); sdb_set(obj->kv, "mdmp_type.cparse", "enum mdmp_type { " "MiniDumpNormal=0x0, " @@ -292,16 +278,14 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "MiniDumpWithTokenInformation=0x40000, " "MiniDumpWithModuleHeaders=0x80000, " "MiniDumpFilterTriage=0x100000, " - "MiniDumpValidTypeFlags=0x1fffff };", - 0); + "MiniDumpValidTypeFlags=0x1fffff };"); sdb_set(obj->kv, "mdmp_module_write_flags.cparse", "enum mdmp_module_write_flags { " "ModuleWriteModule=0, ModuleWriteDataSeg=2, " "ModuleWriteMiscRecord=4, ModuleWriteCvRecord=8, " "ModuleReferencedByMemory=0x10, ModuleWriteTlsData=0x20, " - "ModuleWriteCodeSegs=0x40 };", - 0); + "ModuleWriteCodeSegs=0x40 };"); sdb_set(obj->kv, "mdmp_thread_write_flags.cparse", "enum mdmp_thread_write_flags { " @@ -309,33 +293,29 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "ThreadWriteContext=4, ThreadWriteBackingStore=8, " "ThreadWriteInstructionWindow=0x10, " "ThreadWriteThreadData=0x20, " - "ThreadWriteThreadInfo=0x40 };", - 0); + "ThreadWriteThreadInfo=0x40 };"); sdb_set(obj->kv, "mdmp_context_flags.cparse", "enum mdmp_context_flags { CONTEXT_i386=0x10000, " "CONTEXT_CONTROL=0x10001, CONTEXT_INTEGER=0x10002, " "CONTEXT_SEGMENTS=0x10004, CONTEXT_FLOATING_POINT=0x10008, " "CONTEXT_DEBUG_REGISTERS=0x10010, " - "CONTEXT_EXTENDED_REGISTERS=0x10020 };", - 0); + "CONTEXT_EXTENDED_REGISTERS=0x10020 };"); sdb_set(obj->kv, "mdmp_location_descriptor.format", - "dd DataSize RVA", 0); + "dd DataSize RVA"); sdb_set(obj->kv, "mdmp_location_descriptor64.format", - "qq DataSize RVA", 0); + "qq DataSize RVA"); sdb_set(obj->kv, "mdmp_memory_descriptor.format", "q? " "StartOfMemoryRange " - "(mdmp_location_descriptor)Memory", - 0); + "(mdmp_location_descriptor)Memory"); sdb_set(obj->kv, "mdmp_memory_descriptor64.format", "qq " - "StartOfMemoryRange DataSize", - 0); + "StartOfMemoryRange DataSize"); #if 0 /* TODO: Flag dependent thus not fully implemented */ sdb_set (obj->kv, "mdmp_context.format", "[4]B " - "(mdmp_context_flags)ContextFlags", 0); + "(mdmp_context_flags)ContextFlags"); #endif sdb_set(obj->kv, "mdmp_vs_fixedfileinfo.format", "ddddddddddddd " @@ -343,10 +323,9 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { "dwFileVersionLs dwProductVersionMs " "dwProductVersionLs dwFileFlagsMask dwFileFlags " "dwFileOs dwFileType dwFileSubtype dwFileDateMs " - "dwFileDateLs", - 0); + "dwFileDateLs"); - sdb_set(obj->kv, "mdmp_string.format", "dZ Length Buffer", 0); + sdb_set(obj->kv, "mdmp_string.format", "dZ Length Buffer"); } static bool mdmp_read_header(RzBuffer *b, MiniDmpHeader *hdr) { @@ -381,13 +360,12 @@ static bool rz_bin_mdmp_init_hdr(MiniDmpObj *obj) { return false; } - sdb_num_set(obj->kv, "mdmp.hdr.time_date_stamp", obj->hdr->time_date_stamp, 0); - sdb_num_set(obj->kv, "mdmp.hdr.flags", obj->hdr->flags, 0); - sdb_num_set(obj->kv, "mdmp_header.offset", 0, 0); + sdb_num_set(obj->kv, "mdmp.hdr.time_date_stamp", obj->hdr->time_date_stamp); + sdb_num_set(obj->kv, "mdmp.hdr.flags", obj->hdr->flags); + sdb_num_set(obj->kv, "mdmp_header.offset", 0); sdb_set(obj->kv, "mdmp_header.format", "[4]zddddt[8]B Signature " "Version NumberOfStreams StreamDirectoryRVA CheckSum " - "TimeDateStamp (mdmp_type)Flags", - 0); + "TimeDateStamp (mdmp_type)Flags"); return true; } @@ -658,15 +636,13 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { sdb_set(obj->kv, "mdmp_thread.format", "ddddq?? " "ThreadId SuspendCount PriorityClass Priority " "Teb (mdmp_memory_descriptor)Stack " - "(mdmp_location_descriptor)ThreadContext", - 0); + "(mdmp_location_descriptor)ThreadContext"); sdb_num_set(obj->kv, "mdmp_thread_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_thread_list.format", rz_strf(tmpbuf, "d[%d]? " "NumberOfThreads (mdmp_thread)Threads", - thread_list.number_of_threads), - 0); + thread_list.number_of_threads)); /* TODO: Not yet fully parsed or utilised */ break; @@ -681,15 +657,13 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { "(mdmp_vs_fixedfileinfo)VersionInfo " "(mdmp_location_descriptor)CvRecord " "(mdmp_location_descriptor)MiscRecord " - "Reserved0 Reserved1", - 0); + "Reserved0 Reserved1"); sdb_num_set(obj->kv, "mdmp_module_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_module_list.format", rz_strf(tmpbuf, "d[%d]? " "NumberOfModule (mdmp_module)Modules", - module_list.number_of_modules), - 0); + module_list.number_of_modules)); offset = entry->location.rva + sizeof(module_list); for (i = 0; i < module_list.number_of_modules; i++) { @@ -710,13 +684,12 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_num_set(obj->kv, "mdmp_memory_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_memory_list.format", rz_strf(tmpbuf, "d[%d]? " "NumberOfMemoryRanges " "(mdmp_memory_descriptor)MemoryRanges ", - memory_list.number_of_memory_ranges), - 0); + memory_list.number_of_memory_ranges)); offset = entry->location.rva + sizeof(MiniDmpModuleList); for (i = 0; i < memory_list.number_of_memory_ranges; i++) { @@ -744,15 +717,13 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { "(mdmp_exception_flags)ExceptionFlags " "ExceptionRecord ExceptionAddress " "NumberParameters __UnusedAlignment " - "ExceptionInformation", - 0); + "ExceptionInformation"); sdb_num_set(obj->kv, "mdmp_exception_stream.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_exception_stream.format", "dd?? " "ThreadId __Alignment " "(mdmp_exception)ExceptionRecord " - "(mdmp_location_descriptor)ThreadContext", - 0); + "(mdmp_location_descriptor)ThreadContext"); break; case SYSTEM_INFO_STREAM: @@ -763,15 +734,14 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { break; } sdb_num_set(obj->kv, "mdmp_system_info.offset", - entry->location.rva, 0); + entry->location.rva); /* TODO: We need E as a byte! */ sdb_set(obj->kv, "mdmp_system_info.format", "[2]EwwbBddd[4]Ed[2]Ew[2]q " "(mdmp_processor_architecture)ProcessorArchitecture " "ProcessorLevel ProcessorRevision NumberOfProcessors " "(mdmp_product_type)ProductType " "MajorVersion MinorVersion BuildNumber (mdmp_platform_id)PlatformId " - "CsdVersionRva (mdmp_suite_mask)SuiteMask Reserved2 ProcessorFeatures", - 0); + "CsdVersionRva (mdmp_suite_mask)SuiteMask Reserved2 ProcessorFeatures"); break; case THREAD_EX_LIST_STREAM: @@ -784,15 +754,13 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { "ThreadId SuspendCount PriorityClass Priority " "Teb (mdmp_memory_descriptor)Stack " "(mdmp_location_descriptor)ThreadContext " - "(mdmp_memory_descriptor)BackingStore", - 0); + "(mdmp_memory_descriptor)BackingStore"); sdb_num_set(obj->kv, "mdmp_thread_ex_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_thread_ex_list.format", rz_strf(tmpbuf, "d[%d]? NumberOfThreads " "(mdmp_thread_ex)Threads", - thread_ex_list.number_of_threads), - 0); + thread_ex_list.number_of_threads)); offset = entry->location.rva + sizeof(MiniDmpThreadExList); for (i = 0; i < thread_ex_list.number_of_threads; i++) { @@ -811,13 +779,12 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_num_set(obj->kv, "mdmp_memory64_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_memory64_list.format", rz_strf(tmpbuf, "qq[%" PFMT64d "]? NumberOfMemoryRanges " "BaseRva " "(mdmp_memory_descriptor64)MemoryRanges", - memory64_list.number_of_memory_ranges), - 0); + memory64_list.number_of_memory_ranges)); obj->streams.memories64.base_rva = memory64_list.base_rva; offset = entry->location.rva + sizeof(MiniDmpMemList64); @@ -843,9 +810,9 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_num_set(obj->kv, "mdmp_comment_stream_a.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_comment_stream_a.format", - "s CommentA", 0); + "s CommentA"); break; case COMMENT_STREAM_W: @@ -860,9 +827,9 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_num_set(obj->kv, "mdmp_comment_stream_w.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_comment_stream_w.format", - "s CommentW", 0); + "s CommentW"); break; case HANDLE_DATA_STREAM: @@ -875,11 +842,10 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_num_set(obj->kv, "mdmp_handle_data_stream.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_handle_data_stream.format", "dddd " "SizeOfHeader SizeOfDescriptor " - "NumberOfDescriptors Reserved", - 0); + "NumberOfDescriptors Reserved"); break; case FUNCTION_TABLE_STREAM: /* TODO: Not yet fully parsed or utilised */ @@ -891,11 +857,10 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_num_set(obj->kv, "mdmp_function_table_stream.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_function_table_stream.format", "dddddd " "SizeOfHeader SizeOfDescriptor SizeOfNativeDescriptor " - "SizeOfFunctionEntry NumberOfDescriptors SizeOfAlignPad", - 0); + "SizeOfFunctionEntry NumberOfDescriptors SizeOfAlignPad"); break; case UNLOADED_MODULE_LIST_STREAM: /* TODO: Not yet fully parsed or utilised */ @@ -906,13 +871,11 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { sdb_set(obj->kv, "mdmp_unloaded_module.format", "qddtd " "BaseOfImage SizeOfImage CheckSum TimeDateStamp " - "ModuleNameRva", - 0); + "ModuleNameRva"); sdb_num_set(obj->kv, "mdmp_unloaded_module_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_unloaded_module_list.format", "ddd " - "SizeOfHeader SizeOfEntry NumberOfEntries", - 0); + "SizeOfHeader SizeOfEntry NumberOfEntries"); for (i = 0; i < unloaded_module_list.number_of_entries; i++) { MiniDmpUnloadedModule *module = RZ_NEW(MiniDmpUnloadedModule); @@ -935,14 +898,13 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { /* TODO: Handle different sizes */ sdb_num_set(obj->kv, "mdmp_misc_info.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_misc_info.format", "d[4]Bdtttddddd " "SizeOfInfo (mdmp_misc1_flags)Flags1 ProcessId " "ProcessCreateTime ProcessUserTime ProcessKernelTime " "ProcessorMaxMhz ProcessorCurrentMhz " "ProcessorMhzLimit ProcessorMaxIdleState " - "ProcessorCurrentIdleState", - 0); + "ProcessorCurrentIdleState"); break; case MEMORY_INFO_LIST_STREAM: @@ -955,15 +917,13 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { "qq[4]Edq[4]E[4]E[4]Ed BaseAddress AllocationBase " "(mdmp_page_protect)AllocationProtect __Alignment1 RegionSize " "(mdmp_mem_state)State (mdmp_page_protect)Protect " - "(mdmp_mem_type)Type __Alignment2", - 0); + "(mdmp_mem_type)Type __Alignment2"); sdb_num_set(obj->kv, "mdmp_memory_info_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_memory_info_list.format", rz_strf(tmpbuf, "ddq[%" PFMT64d "]? SizeOfHeader SizeOfEntry " "NumberOfEntries (mdmp_memory_info)MemoryInfo", - memory_info_list.number_of_entries), - 0); + memory_info_list.number_of_entries)); for (i = 0; i < memory_info_list.number_of_entries; i++) { MiniDmpMemInfo *info = RZ_NEW(MiniDmpMemInfo); @@ -984,13 +944,11 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { sdb_set(obj->kv, "mdmp_thread_info.format", "ddddttttqq " "ThreadId DumpFlags DumpError ExitStatus CreateTime " - "ExitTime KernelTime UserTime StartAddress Affinity", - 0); + "ExitTime KernelTime UserTime StartAddress Affinity"); sdb_num_set(obj->kv, "mdmp_thread_info_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_thread_info_list.format", "ddd " - "SizeOfHeader SizeOfEntry NumberOfEntries", - 0); + "SizeOfHeader SizeOfEntry NumberOfEntries"); for (i = 0; i < thread_info_list.number_of_entries; i++) { MiniDmpThreadInfo *info = RZ_NEW(MiniDmpThreadInfo); @@ -1010,10 +968,9 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_num_set(obj->kv, "mdmp_handle_operation_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_handle_operation_list.format", "dddd " - "SizeOfHeader SizeOfEntry NumberOfEntries Reserved", - 0); + "SizeOfHeader SizeOfEntry NumberOfEntries Reserved"); for (i = 0; i < handle_operation_list.number_of_entries; i++) { AVRFHandleOp *op = RZ_NEW(AVRFHandleOp); @@ -1034,14 +991,12 @@ static bool mdmp_init_directory_entry(MiniDmpObj *obj, MiniDmpDir *entry) { } sdb_set(obj->kv, "mdmp_token_info.format", "ddq " - "TokenSize TokenId TokenHandle", - 0); + "TokenSize TokenId TokenHandle"); sdb_num_set(obj->kv, "mdmp_token_info_list.offset", - entry->location.rva, 0); + entry->location.rva); sdb_set(obj->kv, "mdmp_token_info_list.format", "dddd " - "TokenListSize TokenListEntries ListHeaderSize ElementHeaderSize", - 0); + "TokenListSize TokenListEntries ListHeaderSize ElementHeaderSize"); for (i = 0; i < token_info_list.number_of_entries; i++) { MiniDmpTokenInfo *info = RZ_NEW(MiniDmpTokenInfo); @@ -1078,11 +1033,10 @@ static bool mdmp_read_directory(MiniDmpObj *obj, ut64 addr, MiniDmpDir *entry) { static bool rz_bin_mdmp_init_directory(MiniDmpObj *obj) { sdb_num_set(obj->kv, "mdmp_directory.offset", - obj->hdr->stream_directory_rva, 0); + obj->hdr->stream_directory_rva); sdb_set(obj->kv, "mdmp_directory.format", "[4]E? " "(mdmp_stream_type)StreamType " - "(mdmp_location_descriptor)Location", - 0); + "(mdmp_location_descriptor)Location"); ut64 rvadir = obj->hdr->stream_directory_rva; ut64 bytes_left = rvadir < obj->size ? obj->size - rvadir : 0; diff --git a/librz/bin/format/mdmp/mdmp_pe.c b/librz/bin/format/mdmp/mdmp_pe.c index 8fcb7bee276..313c654abb5 100644 --- a/librz/bin/format/mdmp/mdmp_pe.c +++ b/librz/bin/format/mdmp/mdmp_pe.c @@ -16,19 +16,19 @@ static void PE_(add_tls_callbacks)(struct PE_(rz_bin_pe_obj_t) * bin, RzPVector do { key = rz_strf(tmpbuf, "pe.tls_callback%d_paddr", count); - paddr = sdb_num_get(bin->kv, key, 0); + paddr = sdb_num_get(bin->kv, key); if (!paddr) { break; } key = rz_strf(tmpbuf, "pe.tls_callback%d_vaddr", count); - vaddr = sdb_num_get(bin->kv, key, 0); + vaddr = sdb_num_get(bin->kv, key); if (!vaddr) { break; } key = rz_strf(tmpbuf, "pe.tls_callback%d_haddr", count); - haddr = sdb_num_get(bin->kv, key, 0); + haddr = sdb_num_get(bin->kv, key); if (!haddr) { break; } diff --git a/librz/bin/format/mz/mz.c b/librz/bin/format/mz/mz.c index e24e1c64019..7c0468f46d8 100644 --- a/librz/bin/format/mz/mz.c +++ b/librz/bin/format/mz/mz.c @@ -262,17 +262,16 @@ static int rz_bin_mz_init_hdr(struct rz_bin_mz_obj_t *bin) { return false; } - sdb_num_set(bin->kv, "mz.initial.cs", mz->cs, 0); - sdb_num_set(bin->kv, "mz.initial.ip", mz->ip, 0); - sdb_num_set(bin->kv, "mz.initial.ss", mz->ss, 0); - sdb_num_set(bin->kv, "mz.initial.sp", mz->sp, 0); - sdb_num_set(bin->kv, "mz.overlay_number", mz->overlay_number, 0); - sdb_num_set(bin->kv, "mz.dos_header.offset", 0, 0); + sdb_num_set(bin->kv, "mz.initial.cs", mz->cs); + sdb_num_set(bin->kv, "mz.initial.ip", mz->ip); + sdb_num_set(bin->kv, "mz.initial.ss", mz->ss); + sdb_num_set(bin->kv, "mz.initial.sp", mz->sp); + sdb_num_set(bin->kv, "mz.overlay_number", mz->overlay_number); + sdb_num_set(bin->kv, "mz.dos_header.offset", 0); sdb_set(bin->kv, "mz.dos_header.format", "[2]zwwwwwwwwwwwww" " signature bytes_in_last_block blocks_in_file num_relocs " " header_paragraphs min_extra_paragraphs max_extra_paragraphs " - " ss sp checksum ip cs reloc_table_offset overlay_number ", - 0); + " ss sp checksum ip cs reloc_table_offset overlay_number "); bin->dos_extended_header_size = mz->reloc_table_offset - sizeof(MZ_image_dos_header); diff --git a/librz/bin/format/ne/ne.c b/librz/bin/format/ne/ne.c index 5501174cb78..e86146db29a 100644 --- a/librz/bin/format/ne/ne.c +++ b/librz/bin/format/ne/ne.c @@ -60,7 +60,7 @@ static char *__func_name_from_ord(char *module, ut16 ordinal) { char *name; if (rz_file_exists(path)) { Sdb *sdb = sdb_new(NULL, path, 0); - name = sdb_get(sdb, ord, NULL); + name = sdb_get(sdb, ord); if (!name) { name = ord; } else { diff --git a/librz/bin/format/objc/mach0_classes.c b/librz/bin/format/objc/mach0_classes.c index e912b3b12e3..53c096c36eb 100644 --- a/librz/bin/format/objc/mach0_classes.c +++ b/librz/bin/format/objc/mach0_classes.c @@ -1076,12 +1076,12 @@ static void get_class_ro_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, ut32 *is_me free(name); } } - sdb_num_set(bin->kv, rz_strf(tmpbuf, "objc_class_%s.offset", klass->name), s, 0); + sdb_num_set(bin->kv, rz_strf(tmpbuf, "objc_class_%s.offset", klass->name), s); } #ifdef RZ_BIN_MACH064 - sdb_set(bin->kv, "objc_class.format", "lllll isa super cache vtable data", 0); + sdb_set(bin->kv, "objc_class.format", "lllll isa super cache vtable data"); #else - sdb_set(bin->kv, "objc_class.format", "xxxxx isa super cache vtable data", 0); + sdb_set(bin->kv, "objc_class.format", "xxxxx isa super cache vtable data"); #endif if (cro.baseMethods > 0) { diff --git a/librz/bin/format/pe/pe_hdr.c b/librz/bin/format/pe/pe_hdr.c index a8541ffb002..adb75250391 100644 --- a/librz/bin/format/pe/pe_hdr.c +++ b/librz/bin/format/pe/pe_hdr.c @@ -131,12 +131,11 @@ int PE_(bin_pe_init_hdr)(RzBinPEObj *bin) { RZ_LOG_INFO("read (dos header)\n"); return false; } - sdb_num_set(bin->kv, "pe_dos_header.offset", 0, 0); + sdb_num_set(bin->kv, "pe_dos_header.offset", 0); sdb_set(bin->kv, "pe_dos_header.format", "[2]zwwwwwwwwwwwww[4]www[10]wx" " e_magic e_cblp e_cp e_crlc e_cparhdr e_minalloc e_maxalloc" " e_ss e_sp e_csum e_ip e_cs e_lfarlc e_ovno e_res e_oemid" - " e_oeminfo e_res2 e_lfanew", - 0); + " e_oeminfo e_res2 e_lfanew"); if (bin->dos_header->e_lfanew > (unsigned int)bin->size) { RZ_LOG_INFO("Invalid e_lfanew field\n"); return false; @@ -150,22 +149,20 @@ int PE_(bin_pe_init_hdr)(RzBinPEObj *bin) { RZ_LOG_INFO("read (nt header)\n"); return false; } - sdb_set(bin->kv, "pe_magic.cparse", "enum pe_magic { IMAGE_NT_OPTIONAL_HDR32_MAGIC=0x10b, IMAGE_NT_OPTIONAL_HDR64_MAGIC=0x20b, IMAGE_ROM_OPTIONAL_HDR_MAGIC=0x107 };", 0); + sdb_set(bin->kv, "pe_magic.cparse", "enum pe_magic { IMAGE_NT_OPTIONAL_HDR32_MAGIC=0x10b, IMAGE_NT_OPTIONAL_HDR64_MAGIC=0x20b, IMAGE_ROM_OPTIONAL_HDR_MAGIC=0x107 };"); sdb_set(bin->kv, "pe_subsystem.cparse", "enum pe_subsystem { IMAGE_SUBSYSTEM_UNKNOWN=0, IMAGE_SUBSYSTEM_NATIVE=1, IMAGE_SUBSYSTEM_WINDOWS_GUI=2, " " IMAGE_SUBSYSTEM_WINDOWS_CUI=3, IMAGE_SUBSYSTEM_OS2_CUI=5, IMAGE_SUBSYSTEM_POSIX_CUI=7, IMAGE_SUBSYSTEM_WINDOWS_CE_GUI=9, " " IMAGE_SUBSYSTEM_EFI_APPLICATION=10, IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER=11, IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER=12, " - " IMAGE_SUBSYSTEM_EFI_ROM=13, IMAGE_SUBSYSTEM_XBOX=14, IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION=16 };", - 0); + " IMAGE_SUBSYSTEM_EFI_ROM=13, IMAGE_SUBSYSTEM_XBOX=14, IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION=16 };"); sdb_set(bin->kv, "pe_dllcharacteristics.cparse", "enum pe_dllcharacteristics { IMAGE_LIBRARY_PROCESS_INIT=0x0001, IMAGE_LIBRARY_PROCESS_TERM=0x0002, " " IMAGE_LIBRARY_THREAD_INIT=0x0004, IMAGE_LIBRARY_THREAD_TERM=0x0008, IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA=0x0020, " " IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE=0x0040, IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY=0x0080, " " IMAGE_DLLCHARACTERISTICS_NX_COMPAT=0x0100, IMAGE_DLLCHARACTERISTICS_NO_ISOLATION=0x0200,IMAGE_DLLCHARACTERISTICS_NO_SEH=0x0400, " " IMAGE_DLLCHARACTERISTICS_NO_BIND=0x0800, IMAGE_DLLCHARACTERISTICS_APPCONTAINER=0x1000, IMAGE_DLLCHARACTERISTICS_WDM_DRIVER=0x2000, " - " IMAGE_DLLCHARACTERISTICS_GUARD_CF=0x4000, IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE=0x8000};", - 0); + " IMAGE_DLLCHARACTERISTICS_GUARD_CF=0x4000, IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE=0x8000};"); #if RZ_BIN_PE64 - sdb_num_set(bin->kv, "pe_nt_image_headers64.offset", bin->dos_header->e_lfanew, 0); - sdb_set(bin->kv, "pe_nt_image_headers64.format", "[4]z?? signature (pe_image_file_header)fileHeader (pe_image_optional_header64)optionalHeader", 0); + sdb_num_set(bin->kv, "pe_nt_image_headers64.offset", bin->dos_header->e_lfanew); + sdb_set(bin->kv, "pe_nt_image_headers64.format", "[4]z?? signature (pe_image_file_header)fileHeader (pe_image_optional_header64)optionalHeader"); sdb_set(bin->kv, "pe_image_optional_header64.format", "[2]Ebbxxxxxqxxwwwwwwxxxx[2]E[2]Bqqqqxx[16]?" " (pe_magic)magic majorLinkerVersion minorLinkerVersion sizeOfCode sizeOfInitializedData" " sizeOfUninitializedData addressOfEntryPoint baseOfCode imageBase" @@ -173,11 +170,10 @@ int PE_(bin_pe_init_hdr)(RzBinPEObj *bin) { " majorImageVersion minorImageVersion majorSubsystemVersion minorSubsystemVersion" " win32VersionValue sizeOfImage sizeOfHeaders checkSum (pe_subsystem)subsystem (pe_dllcharacteristics)dllCharacteristics" " sizeOfStackReserve sizeOfStackCommit sizeOfHeapReserve sizeOfHeapCommit loaderFlags" - " numberOfRvaAndSizes (pe_image_data_directory)dataDirectory", - 0); + " numberOfRvaAndSizes (pe_image_data_directory)dataDirectory"); #else - sdb_num_set(bin->kv, "pe_nt_image_headers32.offset", bin->dos_header->e_lfanew, 0); - sdb_set(bin->kv, "pe_nt_image_headers32.format", "[4]z?? signature (pe_image_file_header)fileHeader (pe_image_optional_header32)optionalHeader", 0); + sdb_num_set(bin->kv, "pe_nt_image_headers32.offset", bin->dos_header->e_lfanew); + sdb_set(bin->kv, "pe_nt_image_headers32.format", "[4]z?? signature (pe_image_file_header)fileHeader (pe_image_optional_header32)optionalHeader"); sdb_set(bin->kv, "pe_image_optional_header32.format", "[2]Ebbxxxxxxxxxwwwwwwxxxx[2]E[2]Bxxxxxx[16]?" " (pe_magic)magic majorLinkerVersion minorLinkerVersion sizeOfCode sizeOfInitializedData" " sizeOfUninitializedData addressOfEntryPoint baseOfCode baseOfData imageBase" @@ -185,28 +181,25 @@ int PE_(bin_pe_init_hdr)(RzBinPEObj *bin) { " majorImageVersion minorImageVersion majorSubsystemVersion minorSubsystemVersion" " win32VersionValue sizeOfImage sizeOfHeaders checkSum (pe_subsystem)subsystem (pe_dllcharacteristics)dllCharacteristics" " sizeOfStackReserve sizeOfStackCommit sizeOfHeapReserve sizeOfHeapCommit loaderFlags numberOfRvaAndSizes" - " (pe_image_data_directory)dataDirectory", - 0); + " (pe_image_data_directory)dataDirectory"); #endif - sdb_set(bin->kv, "pe_machine.cparse", "enum pe_machine { IMAGE_FILE_MACHINE_I386=0x014c, IMAGE_FILE_MACHINE_IA64=0x0200, IMAGE_FILE_MACHINE_AMD64=0x8664 };", 0); + sdb_set(bin->kv, "pe_machine.cparse", "enum pe_machine { IMAGE_FILE_MACHINE_I386=0x014c, IMAGE_FILE_MACHINE_IA64=0x0200, IMAGE_FILE_MACHINE_AMD64=0x8664 };"); sdb_set(bin->kv, "pe_characteristics.cparse", "enum pe_characteristics { " " IMAGE_FILE_RELOCS_STRIPPED=0x0001, IMAGE_FILE_EXECUTABLE_IMAGE=0x0002, IMAGE_FILE_LINE_NUMS_STRIPPED=0x0004, " " IMAGE_FILE_LOCAL_SYMS_STRIPPED=0x0008, IMAGE_FILE_AGGRESIVE_WS_TRIM=0x0010, IMAGE_FILE_LARGE_ADDRESS_AWARE=0x0020, " " IMAGE_FILE_BYTES_REVERSED_LO=0x0080, IMAGE_FILE_32BIT_MACHINE=0x0100, IMAGE_FILE_DEBUG_STRIPPED=0x0200, " " IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP=0x0400, IMAGE_FILE_NET_RUN_FROM_SWAP=0x0800, IMAGE_FILE_SYSTEM=0x1000, " - " IMAGE_FILE_DLL=0x2000, IMAGE_FILE_UP_SYSTEM_ONLY=0x4000, IMAGE_FILE_BYTES_REVERSED_HI=0x8000 };", - 0); + " IMAGE_FILE_DLL=0x2000, IMAGE_FILE_UP_SYSTEM_ONLY=0x4000, IMAGE_FILE_BYTES_REVERSED_HI=0x8000 };"); sdb_set(bin->kv, "pe_image_file_header.format", "[2]Ewtxxw[2]B" " (pe_machine)machine numberOfSections timeDateStamp pointerToSymbolTable" - " numberOfSymbols sizeOfOptionalHeader (pe_characteristics)characteristics", - 0); - sdb_set(bin->kv, "pe_image_data_directory.format", "xx virtualAddress size", 0); + " numberOfSymbols sizeOfOptionalHeader (pe_characteristics)characteristics"); + sdb_set(bin->kv, "pe_image_data_directory.format", "xx virtualAddress size"); // adding compile time to the SDB { - sdb_num_set(bin->kv, "image_file_header.TimeDateStamp", bin->nt_headers->file_header.TimeDateStamp, 0); + sdb_num_set(bin->kv, "image_file_header.TimeDateStamp", bin->nt_headers->file_header.TimeDateStamp); char *timestr = rz_time_stamp_to_str(bin->nt_headers->file_header.TimeDateStamp); - sdb_set_owned(bin->kv, "image_file_header.TimeDateStamp_string", timestr, 0); + sdb_set_owned(bin->kv, "image_file_header.TimeDateStamp_string", timestr); } bin->optional_header = &bin->nt_headers->optional_header; bin->data_directory = (PE_(image_data_directory *)) & bin->optional_header->DataDirectory; diff --git a/librz/bin/format/pe/pe_imports.c b/librz/bin/format/pe/pe_imports.c index 5983f8a02d8..c422d03ab3d 100644 --- a/librz/bin/format/pe/pe_imports.c +++ b/librz/bin/format/pe/pe_imports.c @@ -43,7 +43,7 @@ int PE_(read_image_delay_import_directory)(RzBuffer *b, ut64 addr, PE_(image_del static char *resolveModuleOrdinal(Sdb *sdb, const char *module, int ordinal) { Sdb *db = sdb; char tmpbuf[32]; - char *foo = sdb_get(db, rz_strf(tmpbuf, "%d", ordinal), 0); + char *foo = sdb_get(db, rz_strf(tmpbuf, "%d", ordinal)); if (foo && *foo) { return foo; } else { diff --git a/librz/bin/format/pe/pe_overlay.c b/librz/bin/format/pe/pe_overlay.c index 5f397e6d3ed..f4bfd84e9fb 100644 --- a/librz/bin/format/pe/pe_overlay.c +++ b/librz/bin/format/pe/pe_overlay.c @@ -68,8 +68,8 @@ int PE_(bin_pe_init_overlay)(RzBinPEObj *bin) { ut64 pe_overlay_size; ut64 pe_overlay_offset = PE_(bin_pe_get_overlay)(bin, &pe_overlay_size); if (pe_overlay_offset) { - sdb_num_set(bin->kv, "pe_overlay.offset", pe_overlay_offset, 0); - sdb_num_set(bin->kv, "pe_overlay.size", pe_overlay_size, 0); + sdb_num_set(bin->kv, "pe_overlay.offset", pe_overlay_offset); + sdb_num_set(bin->kv, "pe_overlay.size", pe_overlay_size); } return 0; } \ No newline at end of file diff --git a/librz/bin/format/pe/pe_rsrc.c b/librz/bin/format/pe/pe_rsrc.c index fb6d9a1c9e3..f15d1e1038d 100644 --- a/librz/bin/format/pe/pe_rsrc.c +++ b/librz/bin/format/pe/pe_rsrc.c @@ -704,7 +704,7 @@ static Sdb *Pe_r_bin_store_var(Var *var) { if (sdb) { for (; i < var->numOfValues; i++) { snprintf(key, 20, "%d", i); - sdb_num_set(sdb, key, var->Value[i], 0); + sdb_num_set(sdb, key, var->Value[i]); } } } @@ -749,8 +749,8 @@ static Sdb *Pe_r_bin_store_string(String *string) { sdb_free(sdb); return NULL; } - sdb_set(sdb, "key", encodedKey, 0); - sdb_set(sdb, "value", encodedVal, 0); + sdb_set(sdb, "key", encodedKey); + sdb_set(sdb, "value", encodedVal); free(encodedKey); free(encodedVal); return sdb; @@ -773,7 +773,7 @@ static Sdb *Pe_r_bin_store_string_table(StringTable *stringTable) { sdb_free(sdb); return NULL; } - sdb_set(sdb, "key", encodedKey, 0); + sdb_set(sdb, "key", encodedKey); free(encodedKey); for (; i < stringTable->numOfChildren; i++) { snprintf(key, 20, "string%d", i); @@ -809,19 +809,19 @@ static Sdb *Pe_r_bin_store_fixed_file_info(PE_VS_FIXEDFILEINFO *vs_fixedFileInfo if (!sdb) { return NULL; } - sdb_num_set(sdb, "Signature", vs_fixedFileInfo->dwSignature, 0); - sdb_num_set(sdb, "StrucVersion", vs_fixedFileInfo->dwStrucVersion, 0); - sdb_num_set(sdb, "FileVersionMS", vs_fixedFileInfo->dwFileVersionMS, 0); - sdb_num_set(sdb, "FileVersionLS", vs_fixedFileInfo->dwFileVersionLS, 0); - sdb_num_set(sdb, "ProductVersionMS", vs_fixedFileInfo->dwProductVersionMS, 0); - sdb_num_set(sdb, "ProductVersionLS", vs_fixedFileInfo->dwProductVersionLS, 0); - sdb_num_set(sdb, "FileFlagsMask", vs_fixedFileInfo->dwFileFlagsMask, 0); - sdb_num_set(sdb, "FileFlags", vs_fixedFileInfo->dwFileFlags, 0); - sdb_num_set(sdb, "FileOS", vs_fixedFileInfo->dwFileOS, 0); - sdb_num_set(sdb, "FileType", vs_fixedFileInfo->dwFileType, 0); - sdb_num_set(sdb, "FileSubtype", vs_fixedFileInfo->dwFileSubtype, 0); - sdb_num_set(sdb, "FileDateMS", vs_fixedFileInfo->dwFileDateMS, 0); - sdb_num_set(sdb, "FileDateLS", vs_fixedFileInfo->dwFileDateLS, 0); + sdb_num_set(sdb, "Signature", vs_fixedFileInfo->dwSignature); + sdb_num_set(sdb, "StrucVersion", vs_fixedFileInfo->dwStrucVersion); + sdb_num_set(sdb, "FileVersionMS", vs_fixedFileInfo->dwFileVersionMS); + sdb_num_set(sdb, "FileVersionLS", vs_fixedFileInfo->dwFileVersionLS); + sdb_num_set(sdb, "ProductVersionMS", vs_fixedFileInfo->dwProductVersionMS); + sdb_num_set(sdb, "ProductVersionLS", vs_fixedFileInfo->dwProductVersionLS); + sdb_num_set(sdb, "FileFlagsMask", vs_fixedFileInfo->dwFileFlagsMask); + sdb_num_set(sdb, "FileFlags", vs_fixedFileInfo->dwFileFlags); + sdb_num_set(sdb, "FileOS", vs_fixedFileInfo->dwFileOS); + sdb_num_set(sdb, "FileType", vs_fixedFileInfo->dwFileType); + sdb_num_set(sdb, "FileSubtype", vs_fixedFileInfo->dwFileSubtype); + sdb_num_set(sdb, "FileDateMS", vs_fixedFileInfo->dwFileDateMS); + sdb_num_set(sdb, "FileDateLS", vs_fixedFileInfo->dwFileDateLS); return sdb; } @@ -1474,7 +1474,7 @@ static void _parse_resource_directory(RzBinPEObj *bin, Pe_image_resource_directo break; } /* Compare compileTimeStamp to resource timestamp to figure out if DOS date or POSIX date */ - if (rz_time_stamp_is_dos_format((ut32)sdb_num_get(bin->kv, "image_file_header.TimeDateStamp", 0), dir->TimeDateStamp)) { + if (rz_time_stamp_is_dos_format((ut32)sdb_num_get(bin->kv, "image_file_header.TimeDateStamp"), dir->TimeDateStamp)) { rs->timestr = rz_time_stamp_to_str(rz_time_dos_time_stamp_to_posix(dir->TimeDateStamp)); } else { rs->timestr = rz_time_stamp_to_str(dir->TimeDateStamp); @@ -1504,18 +1504,18 @@ static void _store_resource_sdb(RzBinPEObj *bin) { char tmpbuf[64]; rz_list_foreach (bin->resources, iter, rs) { key = rz_strf(tmpbuf, "resource.%d.timestr", index); - sdb_set(sdb, key, rs->timestr, 0); + sdb_set(sdb, key, rs->timestr); key = rz_strf(tmpbuf, "resource.%d.vaddr", index); vaddr = PE_(bin_pe_rva_to_va)(bin, rs->data->OffsetToData); - sdb_num_set(sdb, key, vaddr, 0); + sdb_num_set(sdb, key, vaddr); key = rz_strf(tmpbuf, "resource.%d.name", index); - sdb_set(sdb, key, rs->name, 0); + sdb_set(sdb, key, rs->name); key = rz_strf(tmpbuf, "resource.%d.size", index); - sdb_num_set(sdb, key, rs->data->Size, 0); + sdb_num_set(sdb, key, rs->data->Size); key = rz_strf(tmpbuf, "resource.%d.type", index); - sdb_set(sdb, key, rs->type, 0); + sdb_set(sdb, key, rs->type); key = rz_strf(tmpbuf, "resource.%d.language", index); - sdb_set(sdb, key, rs->language, 0); + sdb_set(sdb, key, rs->language); index++; } sdb_ns_set(bin->kv, "pe_resource", sdb); diff --git a/librz/bin/format/pe/pe_tls.c b/librz/bin/format/pe/pe_tls.c index c03e0546fa2..19e371131fb 100644 --- a/librz/bin/format/pe/pe_tls.c +++ b/librz/bin/format/pe/pe_tls.c @@ -27,13 +27,13 @@ static void bin_pe_store_tls_callbacks(RzBinPEObj *bin, PE_DWord callbacks) { } } key = rz_strf(tmpbuf, "pe.tls_callback%d_vaddr", count); - sdb_num_set(bin->kv, key, addressOfTLSCallback, 0); + sdb_num_set(bin->kv, key, addressOfTLSCallback); key = rz_strf(tmpbuf, "pe.tls_callback%d_paddr", count); paddr = PE_(bin_pe_rva_to_paddr)(bin, PE_(bin_pe_va_to_rva)(bin, (PE_DWord)addressOfTLSCallback)); - sdb_num_set(bin->kv, key, paddr, 0); + sdb_num_set(bin->kv, key, paddr); key = rz_strf(tmpbuf, "pe.tls_callback%d_haddr", count); haddr = callbacks; - sdb_num_set(bin->kv, key, haddr, 0); + sdb_num_set(bin->kv, key, haddr); count++; callbacks += sizeof(addressOfTLSCallback); } diff --git a/librz/bin/format/te/te.c b/librz/bin/format/te/te.c index 6643edf3786..f03a83fff99 100644 --- a/librz/bin/format/te/te.c +++ b/librz/bin/format/te/te.c @@ -65,26 +65,21 @@ static int rz_bin_te_init_hdr(struct rz_bin_te_obj_t *bin) { "TE_IMAGE_FILE_MACHINE_R3000=0x0162, TE_IMAGE_FILE_MACHINE_R4000=0x0166, TE_IMAGE_FILE_MACHINE_SH3=0x01a2, " "TE_IMAGE_FILE_MACHINE_SH3DSP=0x01a3, TE_IMAGE_FILE_MACHINE_SH3E=0x01a4, TE_IMAGE_FILE_MACHINE_SH4=0x01a6, " "TE_IMAGE_FILE_MACHINE_SH5=0x01a8, TE_IMAGE_FILE_MACHINE_THUMB=0x01c2, TE_IMAGE_FILE_MACHINE_TRICORE=0x0520, " - "TE_IMAGE_FILE_MACHINE_WCEMIPSV2=0x0169};", - 0); + "TE_IMAGE_FILE_MACHINE_WCEMIPSV2=0x0169};"); sdb_set(bin->kv, "te_subsystem.cparse", "enum te_subsystem { TE_IMAGE_SUBSYSTEM_UNKNOWN=0, TE_IMAGE_SUBSYSTEM_NATIVE=1, " "TE_IMAGE_SUBSYSTEM_WINDOWS_GUI=2, TE_IMAGE_SUBSYSTEM_WINDOWS_CUI=3, " "TE_IMAGE_SUBSYSTEM_POSIX_CUI=7, TE_IMAGE_SUBSYSTEM_WINDOWS_CE_GU=9, " "TE_IMAGE_SUBSYSTEM_EFI_APPLICATION=10, TE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER=11, TE_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER=12, " - "TE_IMAGE_SUBSYSTEM_EFI_ROM=13, TE_IMAGE_SUBSYSTEM_XBOX=14};", - 0); - sdb_num_set(bin->kv, "te_header.offset", 0, 0); + "TE_IMAGE_SUBSYSTEM_EFI_ROM=13, TE_IMAGE_SUBSYSTEM_XBOX=14};"); + sdb_num_set(bin->kv, "te_header.offset", 0); sdb_set(bin->kv, "te_header.format", "[2]z[2]Eb[1]Ewxxq" - " Signature (te_machine)Machine NumberOfSections (te_subsystem)Subsystem StrippedSize AddressOfEntryPoint BaseOfCode ImageBase", - 0); - sdb_num_set(bin->kv, "te_directory1_header.offset", 24, 0); + " Signature (te_machine)Machine NumberOfSections (te_subsystem)Subsystem StrippedSize AddressOfEntryPoint BaseOfCode ImageBase"); + sdb_num_set(bin->kv, "te_directory1_header.offset", 24); sdb_set(bin->kv, "te_directory1_header.format", "xx" - " VirtualAddress Size", - 0); - sdb_num_set(bin->kv, "te_directory2_header.offset", 32, 0); + " VirtualAddress Size"); + sdb_num_set(bin->kv, "te_directory2_header.offset", 32); sdb_set(bin->kv, "te_directory2_header.format", "xx" - " VirtualAddress Size", - 0); + " VirtualAddress Size"); if (strncmp((char *)&bin->header->Signature, "VZ", 2)) { return false; diff --git a/librz/bin/p/bin_art.c b/librz/bin/p/bin_art.c index dca7a238daa..2e3d704e47b 100644 --- a/librz/bin/p/bin_art.c +++ b/librz/bin/p/bin_art.c @@ -44,17 +44,17 @@ static int art_header_load(ArtObj *ao, Sdb *db) { char tmpbuf[32]; ARTHeader *art = &ao->art; (void)rz_buf_fread_at(ao->buf, 0, (ut8 *)art, "IIiiiiiiiiiiii", 1); - sdb_set(db, "img.base", rz_strf(tmpbuf, "0x%x", art->image_base), 0); - sdb_set(db, "img.size", rz_strf(tmpbuf, "0x%x", art->image_size), 0); - sdb_set(db, "art.checksum", rz_strf(tmpbuf, "0x%x", art->checksum), 0); - sdb_set(db, "art.version", rz_strf(tmpbuf, "%c%c%c", art->version[0], art->version[1], art->version[2]), 0); - sdb_set(db, "oat.begin", rz_strf(tmpbuf, "0x%x", art->oat_file_begin), 0); - sdb_set(db, "oat.end", rz_strf(tmpbuf, "0x%x", art->oat_file_end), 0); - sdb_set(db, "oat_data.begin", rz_strf(tmpbuf, "0x%x", art->oat_data_begin), 0); - sdb_set(db, "oat_data.end", rz_strf(tmpbuf, "0x%x", art->oat_data_end), 0); - sdb_set(db, "patch_delta", rz_strf(tmpbuf, "0x%x", art->patch_delta), 0); - sdb_set(db, "image_roots", rz_strf(tmpbuf, "0x%x", art->image_roots), 0); - sdb_set(db, "compile_pic", rz_strf(tmpbuf, "0x%x", art->compile_pic), 0); + sdb_set(db, "img.base", rz_strf(tmpbuf, "0x%x", art->image_base)); + sdb_set(db, "img.size", rz_strf(tmpbuf, "0x%x", art->image_size)); + sdb_set(db, "art.checksum", rz_strf(tmpbuf, "0x%x", art->checksum)); + sdb_set(db, "art.version", rz_strf(tmpbuf, "%c%c%c", art->version[0], art->version[1], art->version[2])); + sdb_set(db, "oat.begin", rz_strf(tmpbuf, "0x%x", art->oat_file_begin)); + sdb_set(db, "oat.end", rz_strf(tmpbuf, "0x%x", art->oat_file_end)); + sdb_set(db, "oat_data.begin", rz_strf(tmpbuf, "0x%x", art->oat_data_begin)); + sdb_set(db, "oat_data.end", rz_strf(tmpbuf, "0x%x", art->oat_data_end)); + sdb_set(db, "patch_delta", rz_strf(tmpbuf, "0x%x", art->patch_delta)); + sdb_set(db, "image_roots", rz_strf(tmpbuf, "0x%x", art->image_roots)); + sdb_set(db, "compile_pic", rz_strf(tmpbuf, "0x%x", art->compile_pic)); return true; } diff --git a/librz/bin/p/bin_bootimg.c b/librz/bin/p/bin_bootimg.c index 46fb1594f27..bcf90a661d5 100644 --- a/librz/bin/p/bin_bootimg.c +++ b/librz/bin/p/bin_bootimg.c @@ -58,18 +58,18 @@ static int bootimg_header_load(BootImageObj *obj, Sdb *db) { BootImage *bi = &obj->bi; (void)rz_buf_read_at(obj->buf, 0, (ut8 *)bi, sizeof(BootImage)); if ((n = rz_str_ndup((char *)bi->name, BOOT_NAME_SIZE))) { - sdb_set(db, "name", n, 0); + sdb_set(db, "name", n); free(n); } if ((n = rz_str_ndup((char *)bi->cmdline, BOOT_ARGS_SIZE))) { - sdb_set(db, "cmdline", n, 0); + sdb_set(db, "cmdline", n); free(n); } for (i = 0; i < 8; i++) { - sdb_num_set(db, "id", (ut64)bi->id[i], 0); + sdb_num_set(db, "id", (ut64)bi->id[i]); } if ((n = rz_str_ndup((char *)bi->extra_cmdline, BOOT_EXTRA_ARGS_SIZE))) { - sdb_set(db, "extra_cmdline", n, 0); + sdb_set(db, "extra_cmdline", n); free(n); } return true; diff --git a/librz/bin/p/bin_mdmp.c b/librz/bin/p/bin_mdmp.c index ae34fe284b7..334dc7bc509 100644 --- a/librz/bin/p/bin_mdmp.c +++ b/librz/bin/p/bin_mdmp.c @@ -66,8 +66,8 @@ static RzBinInfo *mdmp_info(RzBinFile *bf) { ret->rpath = strdup("NONE"); ret->type = strdup("MDMP (MiniDump crash report data)"); - sdb_set(bf->sdb, "mdmp.flags", rz_strf(tmpbuf, "0x%08" PFMT64x, obj->hdr->flags), 0); - sdb_num_set(bf->sdb, "mdmp.streams", obj->hdr->number_of_streams, 0); + sdb_set(bf->sdb, "mdmp.flags", rz_strf(tmpbuf, "0x%08" PFMT64x, obj->hdr->flags)); + sdb_num_set(bf->sdb, "mdmp.streams", obj->hdr->number_of_streams); if (obj->streams.system_info) { switch (obj->streams.system_info->processor_architecture) { diff --git a/librz/bin/p/bin_nro.c b/librz/bin/p/bin_nro.c index 4d50ae7c43f..8a3f209c5d2 100644 --- a/librz/bin/p/bin_nro.c +++ b/librz/bin/p/bin_nro.c @@ -89,12 +89,12 @@ static RzPVector /**/ *entries(RzBinFile *bf) { static Sdb *get_sdb(RzBinFile *bf) { Sdb *kv = sdb_new0(); - sdb_num_set(kv, "nro_start.offset", 0, 0); - sdb_num_set(kv, "nro_start.size", 16, 0); - sdb_set(kv, "nro_start.format", "xxq unused mod_memoffset padding", 0); - sdb_num_set(kv, "nro_header.offset", 16, 0); - sdb_num_set(kv, "nro_header.size", 0x70, 0); - sdb_set(kv, "nro_header.format", "xxxxxxxxxxxx magic unk size unk2 text_offset text_size ro_offset ro_size data_offset data_size bss_size unk3", 0); + sdb_num_set(kv, "nro_start.offset", 0); + sdb_num_set(kv, "nro_start.size", 16); + sdb_set(kv, "nro_start.format", "xxq unused mod_memoffset padding"); + sdb_num_set(kv, "nro_header.offset", 16); + sdb_num_set(kv, "nro_header.size", 0x70); + sdb_set(kv, "nro_header.format", "xxxxxxxxxxxx magic unk size unk2 text_offset text_size ro_offset ro_size data_offset data_size bss_size unk3"); sdb_ns_set(bf->sdb, "info", kv); return kv; } diff --git a/librz/bin/p/bin_nso.c b/librz/bin/p/bin_nso.c index ec5f1a7f0a5..784df278ec3 100644 --- a/librz/bin/p/bin_nso.c +++ b/librz/bin/p/bin_nso.c @@ -229,12 +229,12 @@ static RzPVector /**/ *entries(RzBinFile *bf) { static Sdb *get_sdb(RzBinFile *bf) { Sdb *kv = sdb_new0(); - sdb_num_set(kv, "nso_start.offset", 0, 0); - sdb_num_set(kv, "nso_start.size", 16, 0); - sdb_set(kv, "nso_start.format", "xxq unused mod_memoffset padding", 0); - sdb_num_set(kv, "nso_header.offset", 0, 0); - sdb_num_set(kv, "nso_header.size", 0x40, 0); - sdb_set(kv, "nso_header.format", "xxxxxxxxxxxx magic unk size unk2 text_offset text_size ro_offset ro_size data_offset data_size bss_size unk3", 0); + sdb_num_set(kv, "nso_start.offset", 0); + sdb_num_set(kv, "nso_start.size", 16); + sdb_set(kv, "nso_start.format", "xxq unused mod_memoffset padding"); + sdb_num_set(kv, "nso_header.offset", 0); + sdb_num_set(kv, "nso_header.size", 0x40); + sdb_set(kv, "nso_header.format", "xxxxxxxxxxxx magic unk size unk2 text_offset text_size ro_offset ro_size data_offset data_size bss_size unk3"); sdb_ns_set(bf->sdb, "info", kv); return kv; } diff --git a/librz/bin/p/bin_pe.inc b/librz/bin/p/bin_pe.inc index 67e49f675e9..d6ff371cb45 100644 --- a/librz/bin/p/bin_pe.inc +++ b/librz/bin/p/bin_pe.inc @@ -70,19 +70,19 @@ static void add_tls_callbacks(RzBinFile *bf, RzPVector /**/ *vec) { do { key = rz_strf(tmpbuf, "pe.tls_callback%d_paddr", count); - paddr = sdb_num_get(bin->kv, key, 0); + paddr = sdb_num_get(bin->kv, key); if (!paddr) { break; } key = rz_strf(tmpbuf, "pe.tls_callback%d_vaddr", count); - vaddr = sdb_num_get(bin->kv, key, 0); + vaddr = sdb_num_get(bin->kv, key); if (!vaddr) { break; } key = rz_strf(tmpbuf, "pe.tls_callback%d_haddr", count); - haddr = sdb_num_get(bin->kv, key, 0); + haddr = sdb_num_get(bin->kv, key); if (!haddr) { break; } @@ -242,8 +242,8 @@ static void find_pe_overlay(RzBinFile *bf) { ut64 pe_overlay_size; ut64 pe_overlay_offset = PE_(bin_pe_get_overlay)(bf->o->bin_obj, &pe_overlay_size); if (pe_overlay_offset) { - sdb_num_set(bf->sdb, "pe_overlay.offset", pe_overlay_offset, 0); - sdb_num_set(bf->sdb, "pe_overlay.size", pe_overlay_size, 0); + sdb_num_set(bf->sdb, "pe_overlay.offset", pe_overlay_offset); + sdb_num_set(bf->sdb, "pe_overlay.size", pe_overlay_size); } } @@ -627,7 +627,7 @@ static RzBinInfo *info(RzBinFile *bf) { } claimed_checksum = PE_(bin_pe_get_claimed_checksum)(bf->o->bin_obj); actual_checksum = PE_(bin_pe_get_actual_checksum)(bf->o->bin_obj); - pe_overlay = sdb_num_get(bf->sdb, "pe_overlay.size", 0); + pe_overlay = sdb_num_get(bf->sdb, "pe_overlay.size"); ret->bits = PE_(rz_bin_pe_get_bits)(bf->o->bin_obj); ret->big_endian = PE_(rz_bin_pe_is_big_endian)(bf->o->bin_obj); ret->dbg_info = 0; @@ -639,22 +639,22 @@ static RzBinInfo *info(RzBinFile *bf) { ret->pe_overlay = pe_overlay > 0; ret->signature = bin ? bin->is_signed : false; Sdb *db = sdb_ns(bf->sdb, "pe", true); - sdb_bool_set(db, "canary", has_canary(bf), 0); - sdb_bool_set(db, "highva", haschr(bin, IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA), 0); - sdb_bool_set(db, "aslr", haschr(bin, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE), 0); - sdb_bool_set(db, "forceintegrity", haschr(bin, IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY), 0); - sdb_bool_set(db, "nx", haschr(bin, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT), 0); - sdb_bool_set(db, "isolation", !haschr(bin, IMAGE_DLLCHARACTERISTICS_NO_ISOLATION), 0); - sdb_bool_set(db, "seh", !haschr(bin, IMAGE_DLLCHARACTERISTICS_NO_SEH), 0); - sdb_bool_set(db, "bind", !haschr(bin, IMAGE_DLLCHARACTERISTICS_NO_BIND), 0); - sdb_bool_set(db, "appcontainer", haschr(bin, IMAGE_DLLCHARACTERISTICS_APPCONTAINER), 0); - sdb_bool_set(db, "wdmdriver", haschr(bin, IMAGE_DLLCHARACTERISTICS_WDM_DRIVER), 0); - sdb_bool_set(db, "guardcf", haschr(bin, IMAGE_DLLCHARACTERISTICS_GUARD_CF), 0); - sdb_bool_set(db, "terminalserveraware", haschr(bin, IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE), 0); - sdb_num_set(db, "bits", ret->bits, 0); - sdb_set(db, "claimed_checksum", ret->claimed_checksum, 0); - sdb_set(db, "actual_checksum", ret->actual_checksum, 0); - sdb_bool_set(db, "is_authhash_valid", PE_(bin_pe_is_authhash_valid)(bf->o->bin_obj), 0); + sdb_bool_set(db, "canary", has_canary(bf)); + sdb_bool_set(db, "highva", haschr(bin, IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA)); + sdb_bool_set(db, "aslr", haschr(bin, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE)); + sdb_bool_set(db, "forceintegrity", haschr(bin, IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY)); + sdb_bool_set(db, "nx", haschr(bin, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)); + sdb_bool_set(db, "isolation", !haschr(bin, IMAGE_DLLCHARACTERISTICS_NO_ISOLATION)); + sdb_bool_set(db, "seh", !haschr(bin, IMAGE_DLLCHARACTERISTICS_NO_SEH)); + sdb_bool_set(db, "bind", !haschr(bin, IMAGE_DLLCHARACTERISTICS_NO_BIND)); + sdb_bool_set(db, "appcontainer", haschr(bin, IMAGE_DLLCHARACTERISTICS_APPCONTAINER)); + sdb_bool_set(db, "wdmdriver", haschr(bin, IMAGE_DLLCHARACTERISTICS_WDM_DRIVER)); + sdb_bool_set(db, "guardcf", haschr(bin, IMAGE_DLLCHARACTERISTICS_GUARD_CF)); + sdb_bool_set(db, "terminalserveraware", haschr(bin, IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE)); + sdb_num_set(db, "bits", ret->bits); + sdb_set(db, "claimed_checksum", ret->claimed_checksum); + sdb_set(db, "actual_checksum", ret->actual_checksum); + sdb_bool_set(db, "is_authhash_valid", PE_(bin_pe_is_authhash_valid)(bf->o->bin_obj)); ret->has_va = true; diff --git a/librz/bin/p/bin_qnx.c b/librz/bin/p/bin_qnx.c index 3c7346ef5ef..8802ac57b98 100644 --- a/librz/bin/p/bin_qnx.c +++ b/librz/bin/p/bin_qnx.c @@ -34,18 +34,18 @@ static bool lmf_header_load(lmf_header *lmfh, RzBuffer *buf, Sdb *db) { return false; } char tmpbuf[32]; - sdb_set(db, "qnx.version", rz_strf(tmpbuf, "0x%xH", lmfh->version), 0); - sdb_set(db, "qnx.cflags", rz_strf(tmpbuf, "0x%xH", lmfh->cflags), 0); - sdb_set(db, "qnx.cpu", rz_strf(tmpbuf, "0x%xH", lmfh->cpu), 0); - sdb_set(db, "qnx.fpu", rz_strf(tmpbuf, "0x%xH", lmfh->fpu), 0); - sdb_set(db, "qnx.code_index", rz_strf(tmpbuf, "0x%x", lmfh->code_index), 0); - sdb_set(db, "qnx.stack_index", rz_strf(tmpbuf, "0x%x", lmfh->stack_index), 0); - sdb_set(db, "qnx.heap_index", rz_strf(tmpbuf, "0x%x", lmfh->heap_index), 0); - sdb_set(db, "qnx.argv_index", rz_strf(tmpbuf, "0x%x", lmfh->argv_index), 0); - sdb_set(db, "qnx.code_offset", rz_strf(tmpbuf, "0x%x", lmfh->code_offset), 0); - sdb_set(db, "qnx.stack_nbytes", rz_strf(tmpbuf, "0x%x", lmfh->stack_nbytes), 0); - sdb_set(db, "qnx.heap_nbytes", rz_strf(tmpbuf, "0x%x", lmfh->heap_nbytes), 0); - sdb_set(db, "qnx.image_base", rz_strf(tmpbuf, "0x%x", lmfh->image_base), 0); + sdb_set(db, "qnx.version", rz_strf(tmpbuf, "0x%xH", lmfh->version)); + sdb_set(db, "qnx.cflags", rz_strf(tmpbuf, "0x%xH", lmfh->cflags)); + sdb_set(db, "qnx.cpu", rz_strf(tmpbuf, "0x%xH", lmfh->cpu)); + sdb_set(db, "qnx.fpu", rz_strf(tmpbuf, "0x%xH", lmfh->fpu)); + sdb_set(db, "qnx.code_index", rz_strf(tmpbuf, "0x%x", lmfh->code_index)); + sdb_set(db, "qnx.stack_index", rz_strf(tmpbuf, "0x%x", lmfh->stack_index)); + sdb_set(db, "qnx.heap_index", rz_strf(tmpbuf, "0x%x", lmfh->heap_index)); + sdb_set(db, "qnx.argv_index", rz_strf(tmpbuf, "0x%x", lmfh->argv_index)); + sdb_set(db, "qnx.code_offset", rz_strf(tmpbuf, "0x%x", lmfh->code_offset)); + sdb_set(db, "qnx.stack_nbytes", rz_strf(tmpbuf, "0x%x", lmfh->stack_nbytes)); + sdb_set(db, "qnx.heap_nbytes", rz_strf(tmpbuf, "0x%x", lmfh->heap_nbytes)); + sdb_set(db, "qnx.image_base", rz_strf(tmpbuf, "0x%x", lmfh->image_base)); return true; } diff --git a/librz/bin/p/bin_te.c b/librz/bin/p/bin_te.c index c7c0f36f4ed..fd4a13d77ba 100644 --- a/librz/bin/p/bin_te.c +++ b/librz/bin/p/bin_te.c @@ -135,7 +135,7 @@ static RzBinInfo *info(RzBinFile *bf) { ret->dbg_info = 0; ret->has_va = true; - sdb_num_set(bf->sdb, "te.bits", ret->bits, 0); + sdb_num_set(bf->sdb, "te.bits", ret->bits); return ret; } diff --git a/librz/bin/p/bin_vsf.c b/librz/bin/p/bin_vsf.c index ac978de5705..9821ede9b17 100644 --- a/librz/bin/p/bin_vsf.c +++ b/librz/bin/p/bin_vsf.c @@ -317,13 +317,13 @@ static RzBinInfo *info(RzBinFile *bf) { return ret; } - sdb_num_set(vsf_obj->kv, "vsf.reg_a", vsf_obj->maincpu->ac, 0); - sdb_num_set(vsf_obj->kv, "vsf.reg_x", vsf_obj->maincpu->xr, 0); - sdb_num_set(vsf_obj->kv, "vsf.reg_y", vsf_obj->maincpu->yr, 0); - sdb_num_set(vsf_obj->kv, "vsf.reg_sp", vsf_obj->maincpu->sp, 0); - sdb_num_set(vsf_obj->kv, "vsf.reg_pc", vsf_obj->maincpu->pc, 0); - sdb_num_set(vsf_obj->kv, "vsf.reg_st", vsf_obj->maincpu->st, 0); - sdb_num_set(vsf_obj->kv, "vsf.clock", vsf_obj->maincpu->clk, 0); + sdb_num_set(vsf_obj->kv, "vsf.reg_a", vsf_obj->maincpu->ac); + sdb_num_set(vsf_obj->kv, "vsf.reg_x", vsf_obj->maincpu->xr); + sdb_num_set(vsf_obj->kv, "vsf.reg_y", vsf_obj->maincpu->yr); + sdb_num_set(vsf_obj->kv, "vsf.reg_sp", vsf_obj->maincpu->sp); + sdb_num_set(vsf_obj->kv, "vsf.reg_pc", vsf_obj->maincpu->pc); + sdb_num_set(vsf_obj->kv, "vsf.reg_st", vsf_obj->maincpu->st); + sdb_num_set(vsf_obj->kv, "vsf.clock", vsf_obj->maincpu->clk); return ret; } diff --git a/librz/bp/serialize_bp.c b/librz/bp/serialize_bp.c index 8bf0cff8fc4..9b23128f128 100644 --- a/librz/bp/serialize_bp.c +++ b/librz/bp/serialize_bp.c @@ -57,7 +57,7 @@ RZ_API void rz_serialize_bp_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzBreakpoint *bp pj_end(j); char key[19]; - sdb_set(db, rz_strf(key, "0x%" PFMT64x, bp_item->addr), pj_string(j), 0); + sdb_set(db, rz_strf(key, "0x%" PFMT64x, bp_item->addr), pj_string(j)); pj_free(j); } } diff --git a/librz/config/config.c b/librz/config/config.c index 5c19b059ed0..9464a739c05 100644 --- a/librz/config/config.c +++ b/librz/config/config.c @@ -548,7 +548,7 @@ RZ_API void rz_config_serialize(RZ_NONNULL RzConfig *config, RZ_NONNULL Sdb *db) RzListIter *iter; RzConfigNode *node; rz_list_foreach (config->nodes, iter, node) { - sdb_set(db, node->name, node->value, 0); + sdb_set(db, node->name, node->value); } } diff --git a/librz/config/serialize_config.c b/librz/config/serialize_config.c index 0048796102e..fe5c5361662 100644 --- a/librz/config/serialize_config.c +++ b/librz/config/serialize_config.c @@ -20,7 +20,7 @@ RZ_API void rz_serialize_config_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzConfig *co RzListIter *iter; RzConfigNode *node; rz_list_foreach (config->nodes, iter, node) { - sdb_set(db, node->name, node->value, 0); + sdb_set(db, node->name, node->value); } } diff --git a/librz/core/agraph.c b/librz/core/agraph.c index 8774c8d24cf..5a5f60111ba 100644 --- a/librz/core/agraph.c +++ b/librz/core/agraph.c @@ -246,7 +246,7 @@ static void update_node_dimension(const RzGraph /**/ *g, int is_mini, static void append_shortcut(const RzAGraph *g, char *title, char *nodetitle, int left) { char buf[127] = { 0 }; rz_strf(buf, "agraph.nodes.%s.shortcut", nodetitle); - const char *shortcut = sdb_const_get(g->db, buf, 0); + const char *shortcut = sdb_const_get(g->db, buf); if (shortcut) { if (g->can->color) { // XXX: do not hardcode color here @@ -2256,7 +2256,7 @@ static void get_bbupdate(RzAGraph *g, RzCore *core, RzAnalysisFunction *fcn) { if (shortcut) { char buf[384] = { 0 }; rz_strf(buf, "agraph.nodes.%s.shortcut", title); - sdb_set(g->db, buf, shortcut, 0); + sdb_set(g->db, buf, shortcut); free(shortcut); } } @@ -2696,14 +2696,14 @@ static void update_graph_sizes(RzAGraph *g) { g->w = g->h = 0; } - sdb_num_set(g->db, "agraph.w", g->w, 0); - sdb_num_set(g->db, "agraph.h", g->h, 0); + sdb_num_set(g->db, "agraph.w", g->w); + sdb_num_set(g->db, "agraph.h", g->h); /* delta_x, delta_y are needed to make every other x,y coordinates * unsigned, so that we can use sdb_num_ API */ delta_x = g->x < 0 ? -g->x : 0; delta_y = g->y < 0 ? -g->y : 0; - sdb_num_set(g->db, "agraph.delta_x", delta_x, 0); - sdb_num_set(g->db, "agraph.delta_y", delta_y, 0); + sdb_num_set(g->db, "agraph.delta_x", delta_x); + sdb_num_set(g->db, "agraph.delta_y", delta_y); } RZ_API void rz_agraph_set_curnode(RzAGraph *g, RzANode *a) { @@ -2712,7 +2712,7 @@ RZ_API void rz_agraph_set_curnode(RzAGraph *g, RzANode *a) { } g->curnode = a->gnode; if (a->title) { - sdb_set(g->db, "agraph.curnode", a->title, 0); + sdb_set(g->db, "agraph.curnode", a->title); if (g->on_curnode_change) { g->on_curnode_change(a, g->on_curnode_change_data); } @@ -2740,13 +2740,13 @@ static void agraph_set_layout(RzAGraph *g) { } char buf[384] = { 0 }; rz_strf(buf, "agraph.nodes.%s.x", a->title); - sdb_num_set(g->db, buf, rebase(g, a->x), 0); + sdb_num_set(g->db, buf, rebase(g, a->x)); rz_strf(buf, "agraph.nodes.%s.y", a->title); - sdb_num_set(g->db, buf, rebase(g, a->y), 0); + sdb_num_set(g->db, buf, rebase(g, a->y)); rz_strf(buf, "agraph.nodes.%s.w", a->title); - sdb_num_set(g->db, buf, a->w, 0); + sdb_num_set(g->db, buf, a->w); rz_strf(buf, "agraph.nodes.%s.h", a->title); - sdb_num_set(g->db, buf, a->h, 0); + sdb_num_set(g->db, buf, a->h); } } @@ -3622,20 +3622,20 @@ static void graphNodeMove(RzAGraph *g, int dir, int speed) { } } -static void sdb_set_enc(Sdb *db, const char *key, const char *v, ut32 cas) { +static void sdb_set_enc(Sdb *db, const char *key, const char *v) { char *estr = sdb_encode((const void *)v, -1); - sdb_set(db, key, estr, cas); + sdb_set(db, key, estr); free(estr); } static void agraph_sdb_init(const RzAGraph *g) { - sdb_bool_set(g->db, "agraph.is_callgraph", g->is_callgraph, 0); + sdb_bool_set(g->db, "agraph.is_callgraph", g->is_callgraph); RzCons *cons = rz_cons_singleton(); - sdb_set_enc(g->db, "agraph.color_box", cons->context->pal.graph_box, 0); - sdb_set_enc(g->db, "agraph.color_box2", cons->context->pal.graph_box2, 0); - sdb_set_enc(g->db, "agraph.color_box3", cons->context->pal.graph_box3, 0); - sdb_set_enc(g->db, "agraph.color_true", cons->context->pal.graph_true, 0); - sdb_set_enc(g->db, "agraph.color_false", cons->context->pal.graph_false, 0); + sdb_set_enc(g->db, "agraph.color_box", cons->context->pal.graph_box); + sdb_set_enc(g->db, "agraph.color_box2", cons->context->pal.graph_box2); + sdb_set_enc(g->db, "agraph.color_box3", cons->context->pal.graph_box3); + sdb_set_enc(g->db, "agraph.color_true", cons->context->pal.graph_true); + sdb_set_enc(g->db, "agraph.color_false", cons->context->pal.graph_false); } RZ_API Sdb *rz_agraph_get_sdb(RzAGraph *g) { @@ -3682,7 +3682,7 @@ RZ_API void rz_agraph_print_json(RzAGraph *g, PJ *pj) { RZ_API void rz_agraph_set_title(RzAGraph *g, const char *title) { free(g->title); g->title = title ? strdup(title) : NULL; - sdb_set(g->db, "agraph.title", g->title, 0); + sdb_set(g->db, "agraph.title", g->title); } /** @@ -3760,7 +3760,7 @@ RZ_API RzANode *rz_agraph_add_node(const RzAGraph *g, const char *title, const c ht_sp_update(g->nodes, res->title, res); char *s, *estr, *b; size_t len; - sdb_array_add(g->db, "agraph.nodes", res->title, 0); + sdb_array_add(g->db, "agraph.nodes", res->title); b = strdup(res->body); len = strlen(b); if (len > 0 && b[len - 1] == '\n') { @@ -3772,7 +3772,7 @@ RZ_API RzANode *rz_agraph_add_node(const RzAGraph *g, const char *title, const c free(b); char buf[384] = { 0 }; rz_strf(buf, "agraph.nodes.%s.body", res->title); - sdb_set_owned(g->db, buf, s, 0); + sdb_set_owned(g->db, buf, s); } return res; } @@ -3788,21 +3788,21 @@ RZ_API bool rz_agraph_del_node(const RzAGraph *g, const char *title) { return false; } char buf[384] = { 0 }; - sdb_array_remove(g->db, "agraph.nodes", res->title, 0); + sdb_array_remove(g->db, "agraph.nodes", res->title); rz_strf(buf, "agraph.nodes.%s", res->title); - sdb_set(g->db, buf, NULL, 0); + sdb_set(g->db, buf, NULL); rz_strf(buf, "agraph.nodes.%s.body", res->title); - sdb_set(g->db, buf, 0, 0); + sdb_set(g->db, buf, 0); rz_strf(buf, "agraph.nodes.%s.x", res->title); - sdb_set(g->db, buf, NULL, 0); + sdb_set(g->db, buf, NULL); rz_strf(buf, "agraph.nodes.%s.y", res->title); - sdb_set(g->db, buf, NULL, 0); + sdb_set(g->db, buf, NULL); rz_strf(buf, "agraph.nodes.%s.w", res->title); - sdb_set(g->db, buf, NULL, 0); + sdb_set(g->db, buf, NULL); rz_strf(buf, "agraph.nodes.%s.h", res->title); - sdb_set(g->db, buf, NULL, 0); + sdb_set(g->db, buf, NULL); rz_strf(buf, "agraph.nodes.%s.neighbours", res->title); - sdb_set(g->db, buf, NULL, 0); + sdb_set(g->db, buf, NULL); const RzList *innodes = rz_graph_innodes(g->graph, res->gnode); rz_list_foreach (innodes, it, gn) { @@ -3811,7 +3811,7 @@ RZ_API bool rz_agraph_del_node(const RzAGraph *g, const char *title) { } rz_strf(buf, "agraph.nodes.%s.neighbours", res->title); const char *key = buf; - sdb_array_remove(g->db, key, res->title, 0); + sdb_array_remove(g->db, key, res->title); } rz_graph_del_node(g->graph, res->gnode); @@ -3891,7 +3891,7 @@ RZ_API void rz_agraph_add_edge(const RzAGraph *g, RzANode *a, RzANode *b) { char buf[384] = { 0 }; rz_strf(buf, "agraph.nodes.%s.neighbours", a->title); char *k = buf; - sdb_array_add(g->db, k, b->title, 0); + sdb_array_add(g->db, k, b->title); } } @@ -3901,7 +3901,7 @@ RZ_API void rz_agraph_add_edge_at(const RzAGraph *g, RzANode *a, RzANode *b, int char buf[384] = { 0 }; rz_strf(buf, "agraph.nodes.%s.neighbours", a->title); char *k = buf; - sdb_array_insert(g->db, k, nth, b->title, 0); + sdb_array_insert(g->db, k, nth, b->title); } rz_graph_add_edge_at(g->graph, a->gnode, b->gnode, nth); } @@ -3912,7 +3912,7 @@ RZ_API void rz_agraph_del_edge(const RzAGraph *g, RzANode *a, RzANode *b) { char buf[384] = { 0 }; rz_strf(buf, "agraph.nodes.%s.neighbours", a->title); char *k = buf; - sdb_array_remove(g->db, k, b->title, 0); + sdb_array_remove(g->db, k, b->title); } rz_graph_del_edge(g->graph, a->gnode, b->gnode); } diff --git a/librz/core/analysis_tp.c b/librz/core/analysis_tp.c index 6ed5591112e..a5ddeaca8ac 100644 --- a/librz/core/analysis_tp.c +++ b/librz/core/analysis_tp.c @@ -240,7 +240,7 @@ static RzList /**/ *parse_format(RzCore *core, char *fmt) { } *tmp = '\0'; const char *query = rz_strf(tmpbuf, "spec.%s.%s", spec, arr); - char *type = (char *)sdb_const_get(s, query, 0); + char *type = (char *)sdb_const_get(s, query); if (type) { rz_list_append(ret, type); } diff --git a/librz/core/cagraph.c b/librz/core/cagraph.c index ea9999b7d22..5d37c88608f 100644 --- a/librz/core/cagraph.c +++ b/librz/core/cagraph.c @@ -244,7 +244,7 @@ RZ_IPI bool rz_core_agraph_add_shortcut(RzCore *core, RzAGraph *g, RzANode *an, return false; } char *key = rz_str_newf("agraph.nodes.%s.shortcut", title); - sdb_set(g->db, key, shortcut, 0); + sdb_set(g->db, key, shortcut); free(key); // title + "[o{shortcut}]", so w + 3 ? an->shortcut_w = strlen(shortcut) + 3; diff --git a/librz/core/cbin.c b/librz/core/cbin.c index 84d12c9a1d8..baea0038dcf 100644 --- a/librz/core/cbin.c +++ b/librz/core/cbin.c @@ -166,7 +166,7 @@ RZ_API void rz_core_bin_export_info(RzCore *core, int mode) { flagname = dup; int fmtsize = rz_type_format_struct_size(core->analysis->typedb, v, 0, 0); char *offset_key = rz_str_newf("%s.offset", flagname); - const char *off = sdb_const_get(db, offset_key, 0); + const char *off = sdb_const_get(db, offset_key); free(offset_key); if (off) { if (IS_MODE_RZCMD(mode)) { @@ -298,7 +298,7 @@ RZ_API bool rz_core_bin_apply_all_info(RzCore *r, RzBinFile *binfile) { ut16 bits = info->bits; ut64 baseaddr = rz_bin_get_baddr(r->bin); rz_config_set_i(r->config, "bin.baddr", baseaddr); - sdb_num_add(r->sdb, "orig_baddr", baseaddr, 0); + sdb_num_add(r->sdb, "orig_baddr", baseaddr); r->dbg->bp->baddr = baseaddr; rz_config_set(r->config, "asm.arch", arch); rz_config_set_i(r->config, "asm.bits", bits); @@ -1114,7 +1114,7 @@ static ut8 bin_reloc_size(RzBinReloc *reloc) { static char *resolveModuleOrdinal(Sdb *sdb, const char *module, int ordinal) { Sdb *db = sdb; char tmpbuf[16]; - char *foo = sdb_get(db, rz_strf(tmpbuf, "%d", ordinal), 0); + char *foo = sdb_get(db, rz_strf(tmpbuf, "%d", ordinal)); return (foo && *foo) ? foo : NULL; } @@ -1659,12 +1659,12 @@ RZ_API bool rz_core_bin_apply_resources(RzCore *core, RzBinFile *binfile) { rz_flag_space_push(core->flags, RZ_FLAGS_FS_RESOURCES); while (true) { char key[64]; - char *timestr = sdb_get(sdb, rz_strf(key, "resource.%d.timestr", index), 0); + char *timestr = sdb_get(sdb, rz_strf(key, "resource.%d.timestr", index)); if (!timestr) { break; } - ut64 vaddr = sdb_num_get(sdb, rz_strf(key, "resource.%d.vaddr", index), 0); - int size = (int)sdb_num_get(sdb, rz_strf(key, "resource.%d.size", index), 0); + ut64 vaddr = sdb_num_get(sdb, rz_strf(key, "resource.%d.vaddr", index)); + int size = (int)sdb_num_get(sdb, rz_strf(key, "resource.%d.size", index)); rz_flag_set(core->flags, rz_strf(key, "resource.%d", index), vaddr, size); index++; } @@ -1755,7 +1755,7 @@ RZ_API RZ_BORROW const char *rz_core_bin_get_compile_time(RZ_NONNULL RzBinFile * Sdb *binFileSdb = bf->sdb; Sdb *info_ns = sdb_ns(binFileSdb, "info", false); const char *timeDateStamp_string = sdb_const_get(info_ns, - "image_file_header.TimeDateStamp_string", 0); + "image_file_header.TimeDateStamp_string"); return timeDateStamp_string; } @@ -3139,7 +3139,7 @@ RZ_API bool rz_core_bin_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile } pj_ks(pj, "endian", endian); if (info->rclass && !strcmp(info->rclass, "mdmp")) { - tmp_buf = sdb_get(bf->sdb, "mdmp.flags", 0); + tmp_buf = sdb_get(bf->sdb, "mdmp.flags"); if (tmp_buf) { pj_ks(pj, "flags", tmp_buf); free(tmp_buf); @@ -3184,7 +3184,7 @@ RZ_API bool rz_core_bin_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile pj_ki(pj, "pcalign", uv); } - tmp_buf = sdb_get(obj->kv, "elf.relro", 0); + tmp_buf = sdb_get(obj->kv, "elf.relro"); if (tmp_buf) { pj_ks(pj, "relro", tmp_buf); free(tmp_buf); @@ -3198,7 +3198,7 @@ RZ_API bool rz_core_bin_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile } if (info->rclass && !strcmp(info->rclass, "mdmp")) { - v = sdb_num_get(bf->sdb, "mdmp.streams", 0); + v = sdb_num_get(bf->sdb, "mdmp.streams"); if (v != -1) { pj_ki(pj, "streams", v); } @@ -3264,7 +3264,7 @@ RZ_API bool rz_core_bin_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile rz_table_add_rowf(t, "ss", "dbg_file", str2na(info->debug_file_name)); rz_table_add_rowf(t, "ss", "endian", str2na(endian)); if (info->rclass && !strcmp(info->rclass, "mdmp")) { - tmp_buf = sdb_get(bf->sdb, "mdmp.flags", 0); + tmp_buf = sdb_get(bf->sdb, "mdmp.flags"); if (tmp_buf) { rz_table_add_rowf(t, "ss", "flags", tmp_buf); free(tmp_buf); @@ -3295,7 +3295,7 @@ RZ_API bool rz_core_bin_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile rz_table_add_rowf(t, "sd", "pcalign", uv); } - tmp_buf = sdb_get(obj->kv, "elf.relro", 0); + tmp_buf = sdb_get(obj->kv, "elf.relro"); if (tmp_buf) { rz_table_add_rowf(t, "ss", "relro", tmp_buf); free(tmp_buf); @@ -3307,7 +3307,7 @@ RZ_API bool rz_core_bin_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile } if (info->rclass && !strcmp(info->rclass, "mdmp")) { - v = sdb_num_get(bf->sdb, "mdmp.streams", 0); + v = sdb_num_get(bf->sdb, "mdmp.streams"); if (v != -1) { rz_table_add_rowf(t, "sd", "streams", v); } @@ -4216,35 +4216,35 @@ static void bin_pe_versioninfo(RzCore *r, PJ *pj, int mode) { break; } free(path_fixedfileinfo); - ut32 file_version_ms = sdb_num_get(sdb, "FileVersionMS", 0); - ut32 file_version_ls = sdb_num_get(sdb, "FileVersionLS", 0); + ut32 file_version_ms = sdb_num_get(sdb, "FileVersionMS"); + ut32 file_version_ls = sdb_num_get(sdb, "FileVersionLS"); char *file_version = rz_str_newf("%u.%u.%u.%u", file_version_ms >> 16, file_version_ms & 0xFFFF, file_version_ls >> 16, file_version_ls & 0xFFFF); - ut32 product_version_ms = sdb_num_get(sdb, "ProductVersionMS", 0); - ut32 product_version_ls = sdb_num_get(sdb, "ProductVersionLS", 0); + ut32 product_version_ms = sdb_num_get(sdb, "ProductVersionMS"); + ut32 product_version_ls = sdb_num_get(sdb, "ProductVersionLS"); char *product_version = rz_str_newf("%u.%u.%u.%u", product_version_ms >> 16, product_version_ms & 0xFFFF, product_version_ls >> 16, product_version_ls & 0xFFFF); if (IS_MODE_JSON(mode)) { - pj_kn(pj, "Signature", sdb_num_get(sdb, "Signature", 0)); - pj_kn(pj, "StrucVersion", sdb_num_get(sdb, "StrucVersion", 0)); + pj_kn(pj, "Signature", sdb_num_get(sdb, "Signature")); + pj_kn(pj, "StrucVersion", sdb_num_get(sdb, "StrucVersion")); pj_ks(pj, "FileVersion", file_version); pj_ks(pj, "ProductVersion", product_version); - pj_kn(pj, "FileFlagsMask", sdb_num_get(sdb, "FileFlagsMask", 0)); - pj_kn(pj, "FileFlags", sdb_num_get(sdb, "FileFlags", 0)); - pj_kn(pj, "FileOS", sdb_num_get(sdb, "FileOS", 0)); - pj_kn(pj, "FileType", sdb_num_get(sdb, "FileType", 0)); - pj_kn(pj, "FileSubType", sdb_num_get(sdb, "FileSubType", 0)); + pj_kn(pj, "FileFlagsMask", sdb_num_get(sdb, "FileFlagsMask")); + pj_kn(pj, "FileFlags", sdb_num_get(sdb, "FileFlags")); + pj_kn(pj, "FileOS", sdb_num_get(sdb, "FileOS")); + pj_kn(pj, "FileType", sdb_num_get(sdb, "FileType")); + pj_kn(pj, "FileSubType", sdb_num_get(sdb, "FileSubType")); pj_end(pj); } else { - rz_cons_printf(" Signature: 0x%" PFMT64x "\n", sdb_num_get(sdb, "Signature", 0)); - rz_cons_printf(" StrucVersion: 0x%" PFMT64x "\n", sdb_num_get(sdb, "StrucVersion", 0)); + rz_cons_printf(" Signature: 0x%" PFMT64x "\n", sdb_num_get(sdb, "Signature")); + rz_cons_printf(" StrucVersion: 0x%" PFMT64x "\n", sdb_num_get(sdb, "StrucVersion")); rz_cons_printf(" FileVersion: %s\n", file_version); rz_cons_printf(" ProductVersion: %s\n", product_version); - rz_cons_printf(" FileFlagsMask: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileFlagsMask", 0)); - rz_cons_printf(" FileFlags: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileFlags", 0)); - rz_cons_printf(" FileOS: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileOS", 0)); - rz_cons_printf(" FileType: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileType", 0)); - rz_cons_printf(" FileSubType: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileSubType", 0)); + rz_cons_printf(" FileFlagsMask: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileFlagsMask")); + rz_cons_printf(" FileFlags: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileFlags")); + rz_cons_printf(" FileOS: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileOS")); + rz_cons_printf(" FileType: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileType")); + rz_cons_printf(" FileSubType: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileSubType")); rz_cons_newline(); } free(file_version); @@ -4270,8 +4270,8 @@ static void bin_pe_versioninfo(RzCore *r, PJ *pj, int mode) { if (sdb) { int lenkey = 0; int lenval = 0; - ut8 *key_utf16 = sdb_decode(sdb_const_get(sdb, "key", 0), &lenkey); - ut8 *val_utf16 = sdb_decode(sdb_const_get(sdb, "value", 0), &lenval); + ut8 *key_utf16 = sdb_decode(sdb_const_get(sdb, "key"), &lenkey); + ut8 *val_utf16 = sdb_decode(sdb_const_get(sdb, "value"), &lenval); ut8 *key_utf8 = calloc(lenkey * 2, 1); ut8 *val_utf8 = calloc(lenval * 2, 1); if (!key_utf8 || !val_utf8 || @@ -4312,9 +4312,9 @@ static void bin_elf_versioninfo_versym(RzCore *r, PJ *pj, int mode) { pj_ka(pj, "versym"); // "versym": [ } - const ut64 addr = sdb_num_get(sdb, "addr", 0); - const ut64 offset = sdb_num_get(sdb, "offset", 0); - const ut64 num_entries = sdb_num_get(sdb, "num_entries", 0); + const ut64 addr = sdb_num_get(sdb, "addr"); + const ut64 offset = sdb_num_get(sdb, "offset"); + const ut64 num_entries = sdb_num_get(sdb, "num_entries"); if (IS_MODE_JSON(mode)) { pj_o(pj); // { @@ -4330,7 +4330,7 @@ static void bin_elf_versioninfo_versym(RzCore *r, PJ *pj, int mode) { char tmpbuf[32]; for (size_t i = 0; i < num_entries; i++) { const char *const key = rz_strf(tmpbuf, "entry%zu", i); - const char *const value = sdb_const_get(sdb, key, 0); + const char *const value = sdb_const_get(sdb, key); if (!value) { continue; @@ -4368,8 +4368,8 @@ static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode) { pj_ka(pj, "verneed"); // "verneed": 1[ } - const ut64 address = sdb_num_get(sdb, "addr", 0); - const ut64 offset = sdb_num_get(sdb, "offset", 0); + const ut64 address = sdb_num_get(sdb, "addr"); + const ut64 offset = sdb_num_get(sdb, "offset"); if (IS_MODE_JSON(mode)) { pj_o(pj); // 1{ @@ -4378,7 +4378,7 @@ static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode) { pj_ka(pj, "entries"); // "entries": 2[ } else { rz_cons_printf("Version need has %d entries:\n", - (int)sdb_num_get(sdb, "num_entries", 0)); + (int)sdb_num_get(sdb, "num_entries")); rz_cons_printf(" Addr: 0x%08" PFMT64x, address); @@ -4398,14 +4398,14 @@ static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode) { if (IS_MODE_JSON(mode)) { pj_o(pj); // 2{ - pj_kn(pj, "idx", sdb_num_get(sdb, "idx", 0)); - pj_ki(pj, "vn_version", (int)sdb_num_get(sdb, "vn_version", 0)); + pj_kn(pj, "idx", sdb_num_get(sdb, "idx")); + pj_ki(pj, "vn_version", (int)sdb_num_get(sdb, "vn_version")); } else { rz_cons_printf(" 0x%08" PFMT64x ": Version: %d", - sdb_num_get(sdb, "idx", 0), (int)sdb_num_get(sdb, "vn_version", 0)); + sdb_num_get(sdb, "idx"), (int)sdb_num_get(sdb, "vn_version")); } - if ((filename = sdb_const_get(sdb, "file_name", 0))) { + if ((filename = sdb_const_get(sdb, "file_name"))) { if (IS_MODE_JSON(mode)) { pj_ks(pj, "file_name", filename); } else { @@ -4413,7 +4413,7 @@ static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode) { } } - const int cnt = (int)sdb_num_get(sdb, "cnt", 0); + const int cnt = (int)sdb_num_get(sdb, "cnt"); if (IS_MODE_JSON(mode)) { pj_ki(pj, "cnt", cnt); @@ -4435,10 +4435,10 @@ static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode) { } free(path_vernaux); - const ut64 idx = sdb_num_get(sdb, "idx", 0); - const char *const name = sdb_const_get(sdb, "name", 0); - const char *const flags = sdb_const_get(sdb, "flags", 0); - const int version = (int)sdb_num_get(sdb, "version", 0); + const ut64 idx = sdb_num_get(sdb, "idx"); + const char *const name = sdb_const_get(sdb, "name"); + const char *const flags = sdb_const_get(sdb, "flags"); + const int version = (int)sdb_num_get(sdb, "version"); if (IS_MODE_JSON(mode)) { pj_o(pj); diff --git a/librz/core/cdebug.c b/librz/core/cdebug.c index b17ff4b67e4..7a1d8a922e7 100644 --- a/librz/core/cdebug.c +++ b/librz/core/cdebug.c @@ -1206,7 +1206,7 @@ static bool siglistcb(void *p, const SdbKv *kv) { int opt; if (atoi(sdbkv_key(kv)) > 0) { strncpy(key + 4, sdbkv_key(kv), 20); - opt = sdb_num_get(ds->dbg->sgnls, key, 0); + opt = sdb_num_get(ds->dbg->sgnls, key); if (opt && ds->state->mode == RZ_OUTPUT_MODE_STANDARD) { rz_cons_printf("%s %s", sdbkv_key(kv), sdbkv_value(kv)); const char *optstr = signal_option(opt); @@ -1227,7 +1227,7 @@ static bool siglistjsoncb(void *p, const SdbKv *kv) { int opt; if (atoi(sdbkv_key(kv)) > 0) { strncpy(key + 4, sdbkv_key(kv), 20); - opt = (int)sdb_num_get(ds->dbg->sgnls, key, 0); + opt = (int)sdb_num_get(ds->dbg->sgnls, key); pj_o(ds->state->d.pj); pj_ks(ds->state->d.pj, "signum", sdbkv_key(kv)); pj_ks(ds->state->d.pj, "name", sdbkv_value(kv)); @@ -1248,7 +1248,7 @@ static bool siglisttblcb(void *p, const SdbKv *kv) { int opt; if (atoi(sdbkv_key(kv)) > 0) { strncpy(key + 4, sdbkv_key(kv), 20); - opt = (int)sdb_num_get(ds->dbg->sgnls, key, 0); + opt = (int)sdb_num_get(ds->dbg->sgnls, key); const char *optstr = signal_option(opt); rz_table_add_rowf(ds->state->d.t, "sss", sdbkv_key(kv), sdbkv_value(kv), rz_str_get(optstr)); } diff --git a/librz/core/cil.c b/librz/core/cil.c index 2341ae11765..f09a70a55a8 100644 --- a/librz/core/cil.c +++ b/librz/core/cil.c @@ -157,7 +157,7 @@ RZ_API void rz_core_analysis_esil_init_mem(RZ_NONNULL RzCore *core, RZ_NULLABLE } RzIOMap *stack_map; if (!name && addr == UT64_MAX && size == UT32_MAX) { - const char *fi = sdb_const_get(core->sdb, "aeim.fd", 0); + const char *fi = sdb_const_get(core->sdb, "aeim.fd"); if (fi) { // Close the fd associated with the aeim stack ut64 fd = sdb_atoi(fi); @@ -181,7 +181,7 @@ RZ_API void rz_core_analysis_esil_init_mem(RZ_NONNULL RzCore *core, RZ_NULLABLE free(stack_name); char val[128], *v; v = sdb_itoa(esil->stack_fd, val, 10); - sdb_set(core->sdb, "aeim.fd", v, 0); + sdb_set(core->sdb, "aeim.fd", v); rz_config_set_b(core->config, "io.va", true); if (pattern && *pattern) { @@ -252,7 +252,7 @@ RZ_API void rz_core_analysis_esil_init_mem_del(RZ_NONNULL RzCore *core, RZ_NULLA } rz_flag_unset_name(core->flags, stack_name); rz_flag_unset_name(core->flags, "aeim.stack"); - sdb_unset(core->sdb, "aeim.fd", 0); + sdb_unset(core->sdb, "aeim.fd"); free(stack_name); } diff --git a/librz/core/cmd/cmd_debug.c b/librz/core/cmd/cmd_debug.c index f43b92f3404..c282a991c05 100644 --- a/librz/core/cmd/cmd_debug.c +++ b/librz/core/cmd/cmd_debug.c @@ -110,10 +110,10 @@ static RzGraphNode *get_graphtrace_node(RzGraph /**/ *g, Sd char tn_key[TN_KEY_LEN]; snprintf(tn_key, TN_KEY_LEN, TN_KEY_FMT, tn->addr); - gn = (RzGraphNode *)(size_t)sdb_num_get(nodes, tn_key, NULL); + gn = (RzGraphNode *)(size_t)sdb_num_get(nodes, tn_key); if (!gn) { gn = rz_graph_add_node(g, tn); - sdb_num_set(nodes, tn_key, (ut64)(size_t)gn, 0); + sdb_num_set(nodes, tn_key, (ut64)(size_t)gn); } return gn; } diff --git a/librz/core/cmd/cmd_search.c b/librz/core/cmd/cmd_search.c index d995c1e324a..919d338fd46 100644 --- a/librz/core/cmd/cmd_search.c +++ b/librz/core/cmd/cmd_search.c @@ -1533,7 +1533,7 @@ static int rz_core_search_rop(RzCore *core, RzInterval search_itv, int opt, cons result = false; goto bad; } - sdb_concat(gadgetSdb, headAddr, addr, 0); + sdb_concat(gadgetSdb, headAddr, addr); free(addr); } free(headAddr); diff --git a/librz/core/cmd/cmd_search_rop.c b/librz/core/cmd/cmd_search_rop.c index 0d07d3a355d..89d64e135e4 100644 --- a/librz/core/cmd/cmd_search_rop.c +++ b/librz/core/cmd/cmd_search_rop.c @@ -696,30 +696,30 @@ static void rop_classify(RzCore *core, Sdb *db, RzList /**/ *ropList, co if (nop == 1) { char *str_nop = rz_str_newf("%s NOP", str); - sdb_set(db_nop, key, str_nop, 0); + sdb_set(db_nop, key, str_nop); free(str_nop); } else { if (mov) { char *str_mov = rz_str_newf("%s MOV { %s }", str, mov); - sdb_set(db_mov, key, str_mov, 0); + sdb_set(db_mov, key, str_mov); free(str_mov); free(mov); } if (ct) { char *str_ct = rz_str_newf("%s LOAD_CONST { %s }", str, ct); - sdb_set(db_ct, key, str_ct, 0); + sdb_set(db_ct, key, str_ct); free(str_ct); free(ct); } if (arithm) { char *str_arithm = rz_str_newf("%s ARITHMETIC { %s }", str, arithm); - sdb_set(db_aritm, key, str_arithm, 0); + sdb_set(db_aritm, key, str_arithm); free(str_arithm); free(arithm); } if (arithm_ct) { char *str_arithm_ct = rz_str_newf("%s ARITHMETIC_CONST { %s }", str, arithm_ct); - sdb_set(db_aritm_ct, key, str_arithm_ct, 0); + sdb_set(db_aritm_ct, key, str_arithm_ct); free(str_arithm_ct); free(arithm_ct); } diff --git a/librz/core/disasm.c b/librz/core/disasm.c index f22d742ff01..80d6ba6e645 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -4219,13 +4219,13 @@ static char *ssa_get(RzAnalysisEsil *esil, const char *reg) { if (!ds->ssa) { ds->ssa = sdb_new0(); } - int n = sdb_num_get(ds->ssa, reg, NULL); + int n = sdb_num_get(ds->ssa, reg); return rz_str_newf("%s_%d", reg, n); } static void ssa_set(RzAnalysisEsil *esil, const char *reg) { RzDisasmState *ds = esil->user; - (void)sdb_num_inc(ds->ssa, reg, 1, 0); + (void)sdb_num_inc(ds->ssa, reg, 1); } #define RZ_DISASM_MAX_STR 512 diff --git a/librz/core/project.c b/librz/core/project.c index 2efefe73020..11e3e7d804f 100644 --- a/librz/core/project.c +++ b/librz/core/project.c @@ -34,8 +34,8 @@ RZ_API RZ_NONNULL const char *rz_project_err_message(RzProjectErr err) { RZ_API RzProjectErr rz_project_save(RzCore *core, RzProject *prj, const char *file) { char projver[32]; - sdb_set(prj, RZ_PROJECT_KEY_TYPE, RZ_PROJECT_TYPE, 0); - sdb_set(prj, RZ_PROJECT_KEY_VERSION, rz_strf(projver, "%u", RZ_PROJECT_VERSION), 0); + sdb_set(prj, RZ_PROJECT_KEY_TYPE, RZ_PROJECT_TYPE); + sdb_set(prj, RZ_PROJECT_KEY_VERSION, rz_strf(projver, "%u", RZ_PROJECT_VERSION)); rz_serialize_core_save(sdb_ns(prj, "core", true), core, file); return RZ_PROJECT_ERR_SUCCESS; } @@ -133,11 +133,11 @@ RZ_API void rz_project_free(RzProject *prj) { RZ_API RzProjectErr rz_project_load(RzCore *core, RzProject *prj, bool load_bin_io, RZ_NULLABLE const char *file, RzSerializeResultInfo *res) { rz_return_val_if_fail(core && prj, RZ_PROJECT_ERR_UNKNOWN); - const char *type = sdb_const_get(prj, RZ_PROJECT_KEY_TYPE, 0); + const char *type = sdb_const_get(prj, RZ_PROJECT_KEY_TYPE); if (!type || strcmp(type, RZ_PROJECT_TYPE) != 0) { return RZ_PROJECT_ERR_INVALID_TYPE; } - const char *version_str = sdb_const_get(prj, RZ_PROJECT_KEY_VERSION, 0); + const char *version_str = sdb_const_get(prj, RZ_PROJECT_KEY_VERSION); if (!version_str) { return RZ_PROJECT_ERR_INVALID_VERSION; } diff --git a/librz/core/project_migrate.c b/librz/core/project_migrate.c index ebe468f1086..4517ceb4c81 100644 --- a/librz/core/project_migrate.c +++ b/librz/core/project_migrate.c @@ -48,7 +48,7 @@ bool v1_v2_types_foreach_cb(void *user, const SdbKv *kv) { return true; } V1V2TypesCtx *ctx = user; - sdb_set(ctx->noreturn_db, k, v, 0); + sdb_set(ctx->noreturn_db, k, v); rz_list_push(ctx->moved_keys, strdup(k)); return true; } @@ -71,7 +71,7 @@ RZ_API bool rz_project_migrate_v1_v2(RzProject *prj, RzSerializeResultInfo *res) RzListIter *it; char *s; rz_list_foreach (ctx.moved_keys, it, s) { - sdb_unset(types_db, s, 0); + sdb_unset(types_db, s); } rz_list_free(ctx.moved_keys); return true; @@ -99,13 +99,13 @@ bool v2_v3_types_foreach_cb(void *user, const SdbKv *kv) { const char *k = sdbkv_key(kv); const char *v = sdbkv_value(kv); if (rz_str_startswith(k, "func.") || !strcmp(v, "func")) { - sdb_set(ctx->callables_db, k, v, 0); + sdb_set(ctx->callables_db, k, v); rz_list_push(ctx->moved_keys, strdup(k)); } else if (rz_str_startswith(k, "link.")) { // Old addresses were stored as hexadecimal numbers without `0x` part // New addresses have them char *tl_key = rz_str_newf("0x%s", k + strlen("link.")); - sdb_set(ctx->typelinks_db, tl_key, v, 0); + sdb_set(ctx->typelinks_db, tl_key, v); free(tl_key); rz_list_push(ctx->moved_keys, strdup(k)); } @@ -131,7 +131,7 @@ RZ_API bool rz_project_migrate_v2_v3(RzProject *prj, RzSerializeResultInfo *res) RzListIter *it; char *s; rz_list_foreach (ctx.moved_keys, it, s) { - sdb_unset(types_db, s, 0); + sdb_unset(types_db, s); } rz_list_free(ctx.moved_keys); return true; @@ -165,7 +165,7 @@ RZ_API bool rz_project_migrate_v3_v4(RzProject *prj, RzSerializeResultInfo *res) RzListIter *it; char *s; rz_list_foreach (ctx.moved_keys, it, s) { - sdb_unset(typelinks_db, s, 0); + sdb_unset(typelinks_db, s); } rz_list_free(ctx.moved_keys); #endif @@ -191,29 +191,29 @@ RZ_API bool rz_project_migrate_v4_v5(RzProject *prj, RzSerializeResultInfo *res) // Common keys: // unknown_t=type // type.unknown_t.typeclass=Integral - sdb_set(types_db, "unknown_t", "type", 0); - sdb_set(types_db, "type.unknown_t.typeclass", "Integral", 0); + sdb_set(types_db, "unknown_t", "type"); + sdb_set(types_db, "type.unknown_t.typeclass", "Integral"); // Now we read the bits value from "asm.bits=XX" in "/core/config" - int bits = sdb_num_get(config_db, "asm.bits", 0); + int bits = sdb_num_get(config_db, "asm.bits"); switch (bits) { case 16: // type.unknown_t=w // type.unknown_t.size=16 - sdb_set(types_db, "type.unknown_t", "w", 0); - sdb_set(types_db, "type.unknown_t.size", "16", 0); + sdb_set(types_db, "type.unknown_t", "w"); + sdb_set(types_db, "type.unknown_t.size", "16"); break; case 64: // type.unknown_t=q // type.unknown_t.size=64 - sdb_set(types_db, "type.unknown_t", "q", 0); - sdb_set(types_db, "type.unknown_t.size", "64", 0); + sdb_set(types_db, "type.unknown_t", "q"); + sdb_set(types_db, "type.unknown_t.size", "64"); break; case 32: default: // type.unknown_t=d // type.unknown_t.size=32 - sdb_set(types_db, "type.unknown_t", "d", 0); - sdb_set(types_db, "type.unknown_t.size", "32", 0); + sdb_set(types_db, "type.unknown_t", "d"); + sdb_set(types_db, "type.unknown_t.size", "32"); break; } return true; @@ -266,20 +266,20 @@ RZ_API bool rz_project_migrate_v7_v8(RzProject *prj, RzSerializeResultInfo *res) sdb_ns_unset(analysis_db, "zigns", NULL); Sdb *config_db; RZ_SERIALIZE_SUB(core_db, config_db, res, "config", return false;); - sdb_unset(config_db, "zign.autoload", 0); - sdb_unset(config_db, "zign.diff.bthresh", 0); - sdb_unset(config_db, "zign.diff.gthresh", 0); - sdb_unset(config_db, "zign.match.bytes", 0); - sdb_unset(config_db, "zign.match.graph", 0); - sdb_unset(config_db, "zign.match.hash", 0); - sdb_unset(config_db, "zign.match.offset", 0); - sdb_unset(config_db, "zign.match.refs", 0); - sdb_unset(config_db, "zign.match.types", 0); - sdb_unset(config_db, "zign.maxsz", 0); - sdb_unset(config_db, "zign.mincc", 0); - sdb_unset(config_db, "zign.minsz", 0); - sdb_unset(config_db, "zign.prefix", 0); - sdb_unset(config_db, "zign.threshold", 0); + sdb_unset(config_db, "zign.autoload"); + sdb_unset(config_db, "zign.diff.bthresh"); + sdb_unset(config_db, "zign.diff.gthresh"); + sdb_unset(config_db, "zign.match.bytes"); + sdb_unset(config_db, "zign.match.graph"); + sdb_unset(config_db, "zign.match.hash"); + sdb_unset(config_db, "zign.match.offset"); + sdb_unset(config_db, "zign.match.refs"); + sdb_unset(config_db, "zign.match.types"); + sdb_unset(config_db, "zign.maxsz"); + sdb_unset(config_db, "zign.mincc"); + sdb_unset(config_db, "zign.minsz"); + sdb_unset(config_db, "zign.prefix"); + sdb_unset(config_db, "zign.threshold"); return true; } @@ -418,7 +418,7 @@ bool v10_v11_functions_foreach_cb(void *user, const SdbKv *kv) { if (!res) { goto end; } - sdb_set_owned(ctx->db_new, k, res, 0); + sdb_set_owned(ctx->db_new, k, res); ret = true; end: rz_json_free(j); @@ -431,7 +431,7 @@ RZ_API bool rz_project_migrate_v10_v11(RzProject *prj, RzSerializeResultInfo *re RZ_SERIALIZE_SUB(prj, core_db, res, "core", return false;); Sdb *config_db; RZ_SERIALIZE_SUB(core_db, config_db, res, "config", return false;); - sdb_unset(config_db, "analysis.vars.stackname", 0); + sdb_unset(config_db, "analysis.vars.stackname"); Sdb *analysis_db; RZ_SERIALIZE_SUB(core_db, analysis_db, res, "analysis", return false;); @@ -460,12 +460,12 @@ RZ_API bool rz_project_migrate_v10_v11(RzProject *prj, RzSerializeResultInfo *re // static inline bool sdb_rename(Sdb *db, const char *old_key, const char *new_key) { - char *val = sdb_get(db, old_key, 0); + char *val = sdb_get(db, old_key); if (!val) { return false; } - sdb_unset(db, old_key, 0); - sdb_set_owned(db, new_key, val, 0); + sdb_unset(db, old_key); + sdb_set_owned(db, new_key, val); return true; } @@ -506,7 +506,7 @@ bool v12_v13_types_foreach_cb(void *user, const SdbKv *kv) { pj_ks(j, "addr", k); // We don't have constraints for typelink here. pj_end(j); - sdb_set(ctx->global_vars_db, k, pj_string(j), 0); + sdb_set(ctx->global_vars_db, k, pj_string(j)); pj_free(j); rz_list_push(ctx->moved_keys, strdup(k)); } @@ -532,7 +532,7 @@ RZ_API bool rz_project_migrate_v12_v13(RzProject *prj, RzSerializeResultInfo *re RzListIter *it; char *s; rz_list_foreach (ctx.moved_keys, it, s) { - sdb_unset(typelinks_db, s, 0); + sdb_unset(typelinks_db, s); } rz_list_free(ctx.moved_keys); return true; @@ -585,7 +585,7 @@ bool v13_v14_foreach_cb(void *user, const SdbKv *kv) { } pj_end(j); - sdb_set(fn_db, k, pj_string(j), 0); + sdb_set(fn_db, k, pj_string(j)); pj_free(j); rz_json_free(fn_j); } @@ -636,7 +636,7 @@ RZ_API bool rz_project_migrate_v15_v16(RzProject *prj, RzSerializeResultInfo *re sdb_rename(config_db, "bin.minstr", "str.search.min_length"); sdb_rename(config_db, "bin.str.enc", "str.search.encoding"); sdb_rename(config_db, "bin.maxstrbuf", "str.search.buffer_size"); - sdb_unset(config_db, "bin.maxstr", 0); + sdb_unset(config_db, "bin.maxstr"); return true; } @@ -652,7 +652,7 @@ RZ_API bool rz_project_migrate_v16_v17(RzProject *prj, RzSerializeResultInfo *re RZ_SERIALIZE_SUB(prj, core_db, res, "core", return false;); Sdb *flags_db; RZ_SERIALIZE_SUB(core_db, flags_db, res, "flags", return false;); - sdb_unset(flags_db, "base", 0); + sdb_unset(flags_db, "base"); return true; } diff --git a/librz/core/serialize_core.c b/librz/core/serialize_core.c index c758932d23b..2a044efcea1 100644 --- a/librz/core/serialize_core.c +++ b/librz/core/serialize_core.c @@ -33,12 +33,12 @@ RZ_API void rz_serialize_core_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *core, if (snprintf(buf, sizeof(buf), "0x%" PFMT64x, core->offset) < 0) { return; } - sdb_set(db, "offset", buf, 0); + sdb_set(db, "offset", buf); if (snprintf(buf, sizeof(buf), "0x%" PFMT32x, core->blocksize) < 0) { return; } - sdb_set(db, "blocksize", buf, 0); + sdb_set(db, "blocksize", buf); } static const char *const config_exclude[] = { @@ -83,14 +83,14 @@ RZ_API bool rz_serialize_core_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *core, SUB("debug", rz_serialize_debug_load(subdb, core->dbg, res)); SUB("seek", rz_serialize_core_seek_load(subdb, core, res)); - const char *str = sdb_const_get(db, "offset", 0); + const char *str = sdb_const_get(db, "offset"); if (!str || !*str) { RZ_SERIALIZE_ERR(res, "missing offset in core"); return false; } core->offset = strtoull(str, NULL, 0); - str = sdb_const_get(db, "blocksize", 0); + str = sdb_const_get(db, "blocksize"); if (!str || !*str) { RZ_SERIALIZE_ERR(res, "missing blocksize in core"); return false; @@ -173,12 +173,12 @@ static void file_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *core, RZ_NULLABLE c if (!filename) { return; } - sdb_set(db, "raw", filename, 0); + sdb_set(db, "raw", filename); char *abs = rz_file_abspath(filename); if (!abs) { return; } - sdb_set(db, "absolute", abs, 0); + sdb_set(db, "absolute", abs); if (prj_file) { char *prj_dir = prj_dir_abs(prj_file); if (!prj_dir) { @@ -186,7 +186,7 @@ static void file_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *core, RZ_NULLABLE c } char *rel = prj_relative_make(prj_dir, abs); if (rel) { - sdb_set(db, "relative", rel, 0); + sdb_set(db, "relative", rel); free(rel); } free(prj_dir); @@ -224,7 +224,7 @@ static bool file_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *core, RZ_NULLABLE c rz_bin_file_delete_all(core->bin); FileRet r = FILE_DOES_NOT_EXIST; - const char *rel = sdb_const_get(db, "relative", 0); + const char *rel = sdb_const_get(db, "relative"); if (rel && prj_file) { char *prj_dir = prj_dir_abs(prj_file); if (prj_dir) { @@ -240,7 +240,7 @@ static bool file_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *core, RZ_NULLABLE c return r == FILE_SUCCESS; } - const char *file = sdb_const_get(db, "absolute", 0); + const char *file = sdb_const_get(db, "absolute"); if (file) { r = try_load_file(core, file, res); } @@ -248,7 +248,7 @@ static bool file_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *core, RZ_NULLABLE c return r == FILE_SUCCESS; } - file = sdb_const_get(db, "raw", 0); + file = sdb_const_get(db, "raw"); if (file) { r = try_load_file(core, file, res); } @@ -288,7 +288,7 @@ RZ_API void rz_serialize_core_seek_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzCore *c pj_end(j); char key[12]; - sdb_set(db, rz_strf(key, "%" PFMT32d, undo->idx), pj_string(j), 0); + sdb_set(db, rz_strf(key, "%" PFMT32d, undo->idx), pj_string(j)); pj_free(j); } diff --git a/librz/debug/dsession.c b/librz/debug/dsession.c index e0035d1ef30..bf7427b9876 100644 --- a/librz/debug/dsession.c +++ b/librz/debug/dsession.c @@ -262,7 +262,7 @@ static bool serialize_register_cb(void *db, const ut64 k, const void *v) { } pj_end(j); - sdb_set(db, rz_strf(tmpbuf, "0x%" PFMT64x, k), pj_string(j), 0); + sdb_set(db, rz_strf(tmpbuf, "0x%" PFMT64x, k), pj_string(j)); pj_free(j); return true; } @@ -290,7 +290,7 @@ static bool serialize_memory_cb(void *db, const ut64 k, const void *v) { } pj_end(j); - sdb_set(db, rz_strf(tmpbuf, "0x%" PFMT64x, k), pj_string(j), 0); + sdb_set(db, rz_strf(tmpbuf, "0x%" PFMT64x, k), pj_string(j)); pj_free(j); return true; } @@ -359,7 +359,7 @@ static void serialize_checkpoints(Sdb *db, RzVector /**/ *che pj_end(j); pj_end(j); - sdb_set(db, rz_strf(tmpbuf, "0x%x", chkpt->cnum), pj_string(j), 0); + sdb_set(db, rz_strf(tmpbuf, "0x%x", chkpt->cnum), pj_string(j)); pj_free(j); } } @@ -399,7 +399,7 @@ static void serialize_checkpoints(Sdb *db, RzVector /**/ *che * - This mostly follows rz-db-style serialization */ RZ_API void rz_debug_session_serialize(RzDebugSession *session, Sdb *db) { - sdb_num_set(db, "maxcnum", session->maxcnum, 0); + sdb_num_set(db, "maxcnum", session->maxcnum); serialize_registers(sdb_ns(db, "registers", true), session->registers); serialize_memory(sdb_ns(db, "memory", true), session->memory); serialize_checkpoints(sdb_ns(db, "checkpoints", true), session->checkpoints); @@ -704,7 +704,7 @@ static Sdb *session_sdb_load(const char *path) { RZ_API void rz_debug_session_deserialize(RzDebugSession *session, Sdb *db) { Sdb *subdb; - session->maxcnum = sdb_num_get(db, "maxcnum", 0); + session->maxcnum = sdb_num_get(db, "maxcnum"); #define DESERIALIZE(ns, func) \ do { \ diff --git a/librz/debug/dsignal.c b/librz/debug/dsignal.c index bd0deb83839..f4ac726fa04 100644 --- a/librz/debug/dsignal.c +++ b/librz/debug/dsignal.c @@ -56,8 +56,8 @@ RZ_API void rz_debug_signal_init(RzDebug *dbg) { // XXX DB = sdb_new(NULL, "signals", 0); for (i = 0; signals[i].k; i++) { - sdb_set(DB, signals[i].k, signals[i].v, 0); - sdb_set(DB, signals[i].v, signals[i].k, 0); + sdb_set(DB, signals[i].k, signals[i].v); + sdb_set(DB, signals[i].v, signals[i].k); } } @@ -72,7 +72,7 @@ RZ_API void rz_debug_signal_setup(RzDebug *dbg, int num, int opt) { RZ_API int rz_debug_signal_what(RzDebug *dbg, int num) { char k[32]; snprintf(k, sizeof(k), "cfg.%d", num); - return sdb_num_get(DB, k, 0); + return sdb_num_get(DB, k); } RZ_API int rz_debug_signal_set(RzDebug *dbg, int num, ut64 addr) { diff --git a/librz/debug/p/native/windows/windows_message.c b/librz/debug/p/native/windows/windows_message.c index 79b1f52c8db..21dbce9739f 100644 --- a/librz/debug/p/native/windows/windows_message.c +++ b/librz/debug/p/native/windows/windows_message.c @@ -423,8 +423,8 @@ static DWORD get_msg_type(char *name) { init_msg_types(&msg_types); } ut32 found; - const char *type_str = sdb_const_get(msg_types, name, &found); - if (found) { + const char *type_str = sdb_const_get(msg_types, name); + if (type_str) { int type = rz_num_get(NULL, type_str); return type; } diff --git a/librz/egg/egg.c b/librz/egg/egg.c index 7ae6f6e23c3..86651fadacc 100644 --- a/librz/egg/egg.c +++ b/librz/egg/egg.c @@ -524,11 +524,11 @@ RZ_API void rz_egg_fill(RzEgg *egg, int pos, int type, int argc, int length) { } RZ_API void rz_egg_option_set(RzEgg *egg, const char *key, const char *val) { - sdb_set(egg->db, key, val, 0); + sdb_set(egg->db, key, val); } RZ_API char *rz_egg_option_get(RzEgg *egg, const char *key) { - return sdb_get(egg->db, key, NULL); + return sdb_get(egg->db, key); } RZ_API int rz_egg_shellcode(RzEgg *egg, const char *name) { diff --git a/librz/flag/serialize_flag.c b/librz/flag/serialize_flag.c index fb4621a5c53..3dfc3542a25 100644 --- a/librz/flag/serialize_flag.c +++ b/librz/flag/serialize_flag.c @@ -31,7 +31,7 @@ RZ_API void rz_serialize_flag_zones_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzList / pj_kn(j, "from", item->from); pj_kn(j, "to", item->to); pj_end(j); - sdb_set(db, item->name, pj_string(j), 0); + sdb_set(db, item->name, pj_string(j)); pj_free(j); } } @@ -113,14 +113,14 @@ static bool flag_save_cb(RzFlagItem *flag, void *user) { pj_ks(j, "alias", flag->alias); } pj_end(j); - sdb_set(db, flag->name, pj_string(j), 0); + sdb_set(db, flag->name, pj_string(j)); pj_free(j); return true; } RZ_API void rz_serialize_flag_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzFlag *flag) { rz_serialize_spaces_save(sdb_ns(db, "spaces", true), &flag->spaces); - sdb_set(db, "realnames", flag->realnames ? "1" : "0", 0); + sdb_set(db, "realnames", flag->realnames ? "1" : "0"); sdb_copy(flag->tags, sdb_ns(db, "tags", true)); rz_serialize_flag_zones_save(sdb_ns(db, "zones", true), flag->zones); rz_flag_foreach(flag, flag_save_cb, sdb_ns(db, "flags", true)); @@ -263,7 +263,7 @@ static bool load_flags(RZ_NONNULL Sdb *flags_db, RZ_NONNULL RzFlag *flag) { RZ_API bool rz_serialize_flag_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzFlag *flag, RZ_NULLABLE RzSerializeResultInfo *res) { rz_flag_unset_all(flag); - const char *str = sdb_const_get(db, "realnames", 0); + const char *str = sdb_const_get(db, "realnames"); if (!str) { RZ_SERIALIZE_ERR(res, "flag realnames key is missing"); return false; diff --git a/librz/flag/tags.c b/librz/flag/tags.c index a2f2d0e67c2..377458fa4b3 100644 --- a/librz/flag/tags.c +++ b/librz/flag/tags.c @@ -6,7 +6,7 @@ RZ_API void rz_flag_tags_set(RzFlag *f, const char *name, const char *words) { rz_return_if_fail(f && name && words); char tmpbuf[256]; - sdb_set(f->tags, rz_strf(tmpbuf, "tag.%s", name), words, -1); + sdb_set(f->tags, rz_strf(tmpbuf, "tag.%s", name), words); } RZ_API RZ_OWN RzList /**/ *rz_flag_tags_list(RzFlag *f) { @@ -54,7 +54,7 @@ RZ_API RzList /**/ *rz_flag_tags_get(RzFlag *f, const char *name) rz_return_val_if_fail(f && name, NULL); char tmpbuf[256]; RzList *res = rz_list_newf(NULL); - char *words = sdb_get(f->tags, rz_strf(tmpbuf, "tag.%s", name), NULL); + char *words = sdb_get(f->tags, rz_strf(tmpbuf, "tag.%s", name)); if (words) { RzList *list = rz_str_split_list(words, " ", 0); struct iter_glob_flag_t u = { .res = res, .words = list }; diff --git a/librz/io/serialize_io.c b/librz/io/serialize_io.c index 41794c4c4be..36f8a0f8588 100644 --- a/librz/io/serialize_io.c +++ b/librz/io/serialize_io.c @@ -71,7 +71,7 @@ static bool file_save_cb(void *user, void *data, ut32 id) { // TODO: plugin pj_end(j); - sdb_set(db, key, pj_string(j), 0); + sdb_set(db, key, pj_string(j)); pj_free(j); if (desc->cache->count) { diff --git a/librz/syscall/syscall.c b/librz/syscall/syscall.c index ff408c385c2..7a872d7c20c 100644 --- a/librz/syscall/syscall.c +++ b/librz/syscall/syscall.c @@ -156,7 +156,7 @@ static bool sdb_load_sysregs(RzSysregsDB *sysregdb, Sdb *sdb) { rz_sysreg_item_free(sysregitem); return false; } - ut64 address = sdb_num_get(sdb, argument_key, NULL); + ut64 address = sdb_num_get(sdb, argument_key); free(argument_key); if (!address) { rz_sysreg_item_free(sysregitem); @@ -164,7 +164,7 @@ static bool sdb_load_sysregs(RzSysregsDB *sysregdb, Sdb *sdb) { } argument_key = rz_str_newf("%s.comment", name); - char *comment = sdb_get(sdb, argument_key, NULL); + char *comment = sdb_get(sdb, argument_key); free(argument_key); sysregitem->type = sdbkv_dup_value(kv); sysregitem->comment = comment; @@ -334,7 +334,7 @@ static int getswi(RzSyscall *s, int swi) { } RZ_API int rz_syscall_get_swi(RzSyscall *s) { - return (int)sdb_num_get(s->db, "_", NULL); + return (int)sdb_num_get(s->db, "_"); } RZ_API RzSyscallItem *rz_syscall_get(RzSyscall *s, int num, int swi) { @@ -350,19 +350,19 @@ RZ_API RzSyscallItem *rz_syscall_get(RzSyscall *s, int num, int swi) { } else { key = rz_strf(tmpbuf, "0x%02x.%d", swi, num); } - ret = sdb_const_get(s->db, key, 0); + ret = sdb_const_get(s->db, key); if (!ret) { key = rz_strf(tmpbuf, "0x%02x.0x%02x", swi, num); // Workaround until Syscall SDB is fixed - ret = sdb_const_get(s->db, key, 0); + ret = sdb_const_get(s->db, key); if (!ret) { key = rz_strf(tmpbuf, "0x%02x.%d", num, swi); // Workaround until Syscall SDB is fixed - ret = sdb_const_get(s->db, key, 0); + ret = sdb_const_get(s->db, key); if (!ret) { return NULL; } } } - ret2 = sdb_const_get(s->db, ret, 0); + ret2 = sdb_const_get(s->db, ret); if (!ret2) { return NULL; } @@ -374,9 +374,9 @@ RZ_API int rz_syscall_get_num(RzSyscall *s, const char *str) { if (!s->db) { return -1; } - int sn = (int)sdb_array_get_num(s->db, str, 1, NULL); + int sn = (int)sdb_array_get_num(s->db, str, 1); if (sn == 0) { - return (int)sdb_array_get_num(s->db, str, 0, NULL); + return (int)sdb_array_get_num(s->db, str, 0); } return sn; } @@ -389,7 +389,7 @@ RZ_API const char *rz_syscall_get_i(RzSyscall *s, int num, int swi) { char foo[32]; swi = getswi(s, swi); snprintf(foo, sizeof(foo), "0x%x.%d", swi, num); - return sdb_const_get(s->db, foo, 0); + return sdb_const_get(s->db, foo); } static bool callback_list(void *u, const SdbKv *kv) { diff --git a/librz/type/serialize_functions.c b/librz/type/serialize_functions.c index 6b24fbd2a23..5cfde054cf3 100644 --- a/librz/type/serialize_functions.c +++ b/librz/type/serialize_functions.c @@ -55,14 +55,14 @@ static RzCallable *get_callable_type(RzTypeDB *typedb, Sdb *sdb, const char *nam } RzStrBuf key; - size_t arguments = sdb_num_get(sdb, rz_strbuf_initf(&key, "func.%s.args", name), 0); + size_t arguments = sdb_num_get(sdb, rz_strbuf_initf(&key, "func.%s.args", name)); if (arguments > 0 && !rz_pvector_reserve(callable->args, arguments)) { goto error; } int i; for (i = 0; i < arguments; i++) { - char *values = sdb_get(sdb, rz_strbuf_setf(&key, "func.%s.arg.%d", name, i), NULL); + char *values = sdb_get(sdb, rz_strbuf_setf(&key, "func.%s.arg.%d", name, i)); if (!values) { goto error; @@ -96,7 +96,7 @@ static RzCallable *get_callable_type(RzTypeDB *typedb, Sdb *sdb, const char *nam } } - const char *rettype = sdb_const_get(sdb, rz_strbuf_setf(&key, "func.%s.ret", name), 0); + const char *rettype = sdb_const_get(sdb, rz_strbuf_setf(&key, "func.%s.ret", name)); if (!rettype) { // best we can do for a broken database rettype = "void"; @@ -112,7 +112,7 @@ static RzCallable *get_callable_type(RzTypeDB *typedb, Sdb *sdb, const char *nam callable->ret = ttype; // Optional "noreturn" attribute - callable->noret = sdb_bool_get(sdb, rz_strbuf_setf(&key, "func.%s.noreturn", name), 0); + callable->noret = sdb_bool_get(sdb, rz_strbuf_setf(&key, "func.%s.noreturn", name)); rz_strbuf_fini(&key); rz_list_free(cache_newly_added); @@ -193,11 +193,11 @@ static void save_callable(const RzTypeDB *typedb, Sdb *sdb, const RzCallable *ca */ const char *cname = callable->name; // name=func - sdb_set(sdb, cname, "func", 0); + sdb_set(sdb, cname, "func"); // func.name.args=N char *key = rz_str_newf("func.%s.args", cname); - sdb_num_set(sdb, key, rz_pvector_len(callable->args), 0); + sdb_num_set(sdb, key, rz_pvector_len(callable->args)); free(key); RzStrBuf param_key; @@ -214,7 +214,7 @@ static void save_callable(const RzTypeDB *typedb, Sdb *sdb, const RzCallable *ca char *arg_type = rz_type_as_string(typedb, arg->type); sdb_set(sdb, rz_strbuf_setf(¶m_key, "func.%s.arg.%zu", cname, i), - rz_strbuf_setf(¶m_val, "%s,%s", arg_type, arg_name), 0ULL); + rz_strbuf_setf(¶m_val, "%s,%s", arg_type, arg_name)); free(arg_name); free(arg_type); } @@ -225,14 +225,14 @@ static void save_callable(const RzTypeDB *typedb, Sdb *sdb, const RzCallable *ca if (callable->ret) { key = rz_str_newf("func.%s.ret", cname); char *ret_type = rz_type_as_string(typedb, callable->ret); - sdb_set_owned(sdb, key, ret_type, 0); + sdb_set_owned(sdb, key, ret_type); free(key); } // Optional "noreturn" attribute if (callable->noret) { char *noreturn_key = rz_str_newf("func.%s.noreturn", cname); - sdb_bool_set(sdb, noreturn_key, true, 0); + sdb_bool_set(sdb, noreturn_key, true); free(noreturn_key); } } diff --git a/librz/type/serialize_types.c b/librz/type/serialize_types.c index e285cf3fc72..0d511fbc809 100644 --- a/librz/type/serialize_types.c +++ b/librz/type/serialize_types.c @@ -28,7 +28,7 @@ static char *get_type_data(Sdb *sdb, const char *type, const char *sname) { if (!key) { return NULL; } - char *members = sdb_get(sdb, key, NULL); + char *members = sdb_get(sdb, key); free(key); return members; } @@ -58,7 +58,7 @@ static TypeFormatPair *get_enum_type(Sdb *sdb, const char *sname) { if (!val_key) { goto error; } - const char *value = sdb_const_get(sdb, val_key, NULL); + const char *value = sdb_const_get(sdb, val_key); free(val_key); if (!value) { // if nothing is found, ret NULL @@ -77,7 +77,7 @@ static TypeFormatPair *get_enum_type(Sdb *sdb, const char *sname) { free(members); RzStrBuf key; - char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname), 0); + char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname)); rz_strbuf_fini(&key); TypeFormatPair *tpair = RZ_NEW0(TypeFormatPair); @@ -114,7 +114,7 @@ static TypeFormatPair *get_struct_type(RzTypeDB *typedb, Sdb *sdb, const char *s if (!type_key) { goto error; } - char *values = sdb_get(sdb, type_key, NULL); + char *values = sdb_get(sdb, type_key); free(type_key); if (!values) { @@ -154,7 +154,7 @@ static TypeFormatPair *get_struct_type(RzTypeDB *typedb, Sdb *sdb, const char *s } RzStrBuf key; - const char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname), 0); + const char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname)); rz_strbuf_fini(&key); TypeFormatPair *tpair = RZ_NEW0(TypeFormatPair); @@ -192,7 +192,7 @@ static TypeFormatPair *get_union_type(RzTypeDB *typedb, Sdb *sdb, const char *sn if (!type_key) { goto error; } - char *values = sdb_get(sdb, type_key, NULL); + char *values = sdb_get(sdb, type_key); free(type_key); if (!values) { @@ -223,7 +223,7 @@ static TypeFormatPair *get_union_type(RzTypeDB *typedb, Sdb *sdb, const char *sn } RzStrBuf key; - const char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname), 0); + const char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname)); rz_strbuf_fini(&key); TypeFormatPair *tpair = RZ_NEW0(TypeFormatPair); @@ -261,7 +261,7 @@ static TypeFormatPair *get_typedef_type(RzTypeDB *typedb, Sdb *sdb, const char * } RzStrBuf key; - char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname), 0); + char *format = sdb_get(sdb, rz_strbuf_initf(&key, "type.%s", sname)); rz_strbuf_fini(&key); TypeFormatPair *tpair = RZ_NEW0(TypeFormatPair); @@ -296,14 +296,14 @@ static TypeFormatPair *get_atomic_type(RzTypeDB *typedb, Sdb *sdb, const char *s base_type->name = strdup(sname); RzStrBuf key; - base_type->size = sdb_num_get(sdb, rz_strbuf_initf(&key, "type.%s.size", sname), 0); + base_type->size = sdb_num_get(sdb, rz_strbuf_initf(&key, "type.%s.size", sname)); RzTypeTypeclass typeclass = RZ_TYPE_TYPECLASS_NONE; - const char *tclass = sdb_const_get(sdb, rz_strbuf_setf(&key, "type.%s.typeclass", sname), 0); + const char *tclass = sdb_const_get(sdb, rz_strbuf_setf(&key, "type.%s.typeclass", sname)); if (tclass) { typeclass = rz_type_typeclass_from_string(tclass); } set_base_type_typeclass(base_type, typeclass); - const char *format = sdb_const_get(sdb, rz_strbuf_setf(&key, "type.%s", sname), 0); + const char *format = sdb_const_get(sdb, rz_strbuf_setf(&key, "type.%s", sname)); rz_strbuf_fini(&key); TypeFormatPair *tpair = RZ_NEW0(TypeFormatPair); @@ -370,7 +370,7 @@ static void save_struct(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type */ char *sname = type->name; // name=struct - sdb_set(sdb, sname, kind, 0); + sdb_set(sdb, sname, kind); RzStrBuf arglist; RzStrBuf param_key; @@ -387,7 +387,7 @@ static void save_struct(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type char *member_type = rz_type_as_string(typedb, member->type); sdb_set(sdb, rz_strbuf_setf(¶m_key, "%s.%s.%s", kind, sname, member_sname), - rz_strbuf_setf(¶m_val, "%s,%zu,%u", member_type, member->offset, 0), 0ULL); + rz_strbuf_setf(¶m_val, "%s,%zu,%u", member_type, member->offset, 0)); free(member_type); free(member_sname); @@ -395,7 +395,7 @@ static void save_struct(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type } // struct.name=param1,param2,paramN char *key = rz_str_newf("%s.%s", kind, sname); - sdb_set(sdb, key, rz_strbuf_get(&arglist), 0); + sdb_set(sdb, key, rz_strbuf_get(&arglist)); free(key); rz_strbuf_fini(&arglist); @@ -418,7 +418,7 @@ static void save_union(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type) */ char *sname = type->name; // name=union - sdb_set(sdb, sname, kind, 0); + sdb_set(sdb, sname, kind); RzStrBuf arglist; RzStrBuf param_key; @@ -435,7 +435,7 @@ static void save_union(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type) char *member_type = rz_type_as_string(typedb, member->type); sdb_set(sdb, rz_strbuf_setf(¶m_key, "%s.%s.%s", kind, sname, member_sname), - rz_strbuf_setf(¶m_val, "%s,%zu,%u", member_type, member->offset, 0), 0ULL); + rz_strbuf_setf(¶m_val, "%s,%zu,%u", member_type, member->offset, 0)); free(member_type); free(member_sname); @@ -443,7 +443,7 @@ static void save_union(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type) } // union.name=arg1,arg2,argN char *key = rz_str_newf("%s.%s", kind, sname); - sdb_set(sdb, key, rz_strbuf_get(&arglist), 0); + sdb_set(sdb, key, rz_strbuf_get(&arglist)); free(key); rz_strbuf_fini(&arglist); @@ -467,7 +467,7 @@ static void save_enum(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type) enum.MyEnum.argN=0x3 */ char *sname = type->name; - sdb_set(sdb, sname, "enum", 0); + sdb_set(sdb, sname, "enum"); RzStrBuf arglist; RzStrBuf param_key; @@ -483,18 +483,18 @@ static void save_enum(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *type) char *case_sname = rz_str_sanitize_sdb_key(cas->name); sdb_set(sdb, rz_strbuf_setf(¶m_key, "enum.%s.%s", sname, case_sname), - rz_strbuf_setf(¶m_val, "0x%" PFMT64x "", cas->val), 0); + rz_strbuf_setf(¶m_val, "0x%" PFMT64x "", cas->val)); sdb_set(sdb, rz_strbuf_setf(¶m_key, "enum.%s.0x%" PFMT64x "", sname, cas->val), - case_sname, 0); + case_sname); free(case_sname); rz_strbuf_appendf(&arglist, (i++ == 0) ? "%s" : ",%s", cas->name); } // enum.name=arg1,arg2,argN char *key = rz_str_newf("enum.%s", sname); - sdb_set(sdb, key, rz_strbuf_get(&arglist), 0); + sdb_set(sdb, key, rz_strbuf_get(&arglist)); free(key); rz_strbuf_fini(&arglist); @@ -513,7 +513,7 @@ static void save_atomic_type(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType type.char.typeclass=Signed Integral */ char *sname = type->name; - sdb_set(sdb, sname, "type", 0); + sdb_set(sdb, sname, "type"); RzStrBuf key; RzStrBuf val; @@ -522,15 +522,15 @@ static void save_atomic_type(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType sdb_set(sdb, rz_strbuf_setf(&key, "type.%s.size", sname), - rz_strbuf_setf(&val, "%" PFMT64u "", type->size), 0); + rz_strbuf_setf(&val, "%" PFMT64u "", type->size)); sdb_set(sdb, rz_strbuf_setf(&key, "type.%s.typeclass", sname), - rz_type_typeclass_as_string(get_base_type_typeclass(type)), 0); + rz_type_typeclass_as_string(get_base_type_typeclass(type))); const char *typefmt = rz_type_db_format_get(typedb, sname); sdb_set(sdb, rz_strbuf_setf(&key, "type.%s", sname), - typefmt, 0); + typefmt); rz_strbuf_fini(&key); rz_strbuf_fini(&val); @@ -546,7 +546,7 @@ static void save_typedef(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *typ typedef.byte=char */ char *sname = type->name; - sdb_set(sdb, sname, "typedef", 0); + sdb_set(sdb, sname, "typedef"); RzStrBuf key; RzStrBuf val; @@ -556,7 +556,7 @@ static void save_typedef(const RzTypeDB *typedb, Sdb *sdb, const RzBaseType *typ char *ttype = rz_type_as_string(typedb, type->type); sdb_set(sdb, rz_strbuf_setf(&key, "typedef.%s", sname), - rz_strbuf_setf(&val, "%s", ttype), 0); + rz_strbuf_setf(&val, "%s", ttype)); free(ttype); diff --git a/librz/util/sdb/src/array.c b/librz/util/sdb/src/array.c index 7d0dc3066b1..a2c096384d6 100644 --- a/librz/util/sdb/src/array.c +++ b/librz/util/sdb/src/array.c @@ -60,9 +60,9 @@ static inline int int_cmp(const void *a, const void *b) { return 0; } -RZ_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx, ut32 *cas) { +RZ_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx) { int i; - const char *n, *str = sdb_const_get(s, key, cas); + const char *n, *str = sdb_const_get(s, key); if (!str || !*str) { return 0LL; } @@ -78,8 +78,8 @@ RZ_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx, ut32 *cas) { return sdb_atoi(str); } -RZ_API char *sdb_array_get(Sdb *s, const char *key, int idx, ut32 *cas) { - const char *str = sdb_const_get(s, key, cas); +RZ_API char *sdb_array_get(Sdb *s, const char *key, int idx) { + const char *str = sdb_const_get(s, key); const char *p = str; char *o, *n; int i, len; @@ -128,22 +128,20 @@ RZ_API char *sdb_array_get(Sdb *s, const char *key, int idx, ut32 *cas) { return NULL; } -RZ_API int sdb_array_insert_num(Sdb *s, const char *key, int idx, ut64 val, - ut32 cas) { +RZ_API int sdb_array_insert_num(Sdb *s, const char *key, int idx, ut64 val) { char valstr[64]; return sdb_array_insert(s, key, idx, - sdb_itoa(val, valstr, SDB_NUM_BASE), cas); + sdb_itoa(val, valstr, SDB_NUM_BASE)); } // TODO: done, but there's room for improvement -RZ_API int sdb_array_insert(Sdb *s, const char *key, int idx, const char *val, - ut32 cas) { +RZ_API bool sdb_array_insert(Sdb *s, const char *key, int idx, const char *val) { int lnstr, lstr; size_t lval; char *x, *ptr; - const char *str = sdb_const_get_len(s, key, &lstr, 0); + const char *str = sdb_const_get_len(s, key, &lstr); if (!str || !*str) { - return sdb_set(s, key, val, cas); + return sdb_set(s, key, val); } lval = strlen(val); lstr--; @@ -195,42 +193,40 @@ RZ_API int sdb_array_insert(Sdb *s, const char *key, int idx, const char *val, free(nstr); free(x); // fallback for empty buckets - return sdb_array_set(s, key, idx, val, cas); + return sdb_array_set(s, key, idx, val); } } - return sdb_set_owned(s, key, x, cas); + return sdb_set_owned(s, key, x); } -RZ_API int sdb_array_set_num(Sdb *s, const char *key, int idx, ut64 val, - ut32 cas) { +RZ_API bool sdb_array_set_num(Sdb *s, const char *key, int idx, ut64 val) { char valstr[SDB_NUM_BUFSZ]; - return sdb_array_set(s, key, idx, sdb_itoa(val, valstr, SDB_NUM_BASE), - cas); + return sdb_array_set(s, key, idx, sdb_itoa(val, valstr, SDB_NUM_BASE)); } -RZ_API int sdb_array_add_num(Sdb *s, const char *key, ut64 val, ut32 cas) { +RZ_API bool sdb_array_add_num(Sdb *s, const char *key, ut64 val) { char buf[SDB_NUM_BUFSZ]; char *v = sdb_itoa(val, buf, SDB_NUM_BASE); - if (!sdb_array_contains(s, key, v, NULL)) { + if (!sdb_array_contains(s, key, v)) { if (val < 256) { char *v = sdb_itoa(val, buf, 10); - return sdb_array_add(s, key, v, cas); + return sdb_array_add(s, key, v); } } - return sdb_array_add(s, key, v, cas); + return sdb_array_add(s, key, v); } // XXX: index should be supressed here? if its a set we shouldnt change the index -RZ_API int sdb_array_add(Sdb *s, const char *key, const char *val, ut32 cas) { - if (sdb_array_contains(s, key, val, NULL)) { - return 0; +RZ_API bool sdb_array_add(Sdb *s, const char *key, const char *val) { + if (sdb_array_contains(s, key, val)) { + return false; } - return sdb_array_insert(s, key, -1, val, cas); + return sdb_array_insert(s, key, -1, val); } -RZ_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val, ut32 cas) { +RZ_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val) { int lstr, lval, i, j; - const char *str_e, *str_lp, *str_p, *str = sdb_const_get_len(s, key, &lstr, 0); + const char *str_e, *str_lp, *str_p, *str = sdb_const_get_len(s, key, &lstr); char *nstr, *nstr_p, **vals; const char null = '\0'; if (!str || !*str) { @@ -282,19 +278,18 @@ RZ_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val, ut32 c } else { *(--nstr_p) = '\0'; } - sdb_set_owned(s, key, nstr, cas); + sdb_set_owned(s, key, nstr); free(vals); return 0; } -RZ_API int sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val, - ut32 cas) { +RZ_API bool sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val) { int i; char valstr[SDB_NUM_BUFSZ]; - const char *str = sdb_const_get(s, key, 0); + const char *str = sdb_const_get(s, key); const char *n = str; if (!str || !*str) { - return sdb_set(s, key, sdb_itoa(val, valstr, SDB_NUM_BASE), cas); + return sdb_set(s, key, sdb_itoa(val, valstr, SDB_NUM_BASE)); } for (i = 0; n; i++) { if (val <= sdb_atoi(n)) { @@ -302,22 +297,19 @@ RZ_API int sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val, } n = sdb_const_anext(n); } - return sdb_array_insert_num(s, key, n ? i : -1, val, cas); + return sdb_array_insert_num(s, key, n ? i : -1, val); } -RZ_API int sdb_array_unset(Sdb *s, const char *key, int idx, ut32 cas) { - return sdb_array_set(s, key, idx, "", cas); +RZ_API int sdb_array_unset(Sdb *s, const char *key, int idx) { + return sdb_array_set(s, key, idx, ""); } -RZ_API bool sdb_array_append(Sdb *s, const char *key, const char *val, - ut32 cas) { +RZ_API bool sdb_array_append(Sdb *s, const char *key, const char *val) { int str_len = 0; - ut32 kas = cas; - const char *str = sdb_const_get_len(s, key, &str_len, &kas); - if (!val || (cas && cas != kas)) { + const char *str = sdb_const_get_len(s, key, &str_len); + if (!val) { return false; } - cas = kas; if (str && *str && str_len > 0) { int val_len = strlen(val); char *newval = malloc(str_len + val_len + 2); @@ -328,31 +320,30 @@ RZ_API bool sdb_array_append(Sdb *s, const char *key, const char *val, newval[str_len] = SDB_RS; memcpy(newval + str_len + 1, val, val_len); newval[str_len + val_len + 1] = 0; - sdb_set_owned(s, key, newval, cas); + sdb_set_owned(s, key, newval); } else { - sdb_set(s, key, val, cas); + sdb_set(s, key, val); } return true; } -RZ_API bool sdb_array_append_num(Sdb *s, const char *key, ut64 val, ut32 cas) { - return sdb_array_set_num(s, key, -1, val, cas); +RZ_API bool sdb_array_append_num(Sdb *s, const char *key, ut64 val) { + return sdb_array_set_num(s, key, -1, val); } -RZ_API int sdb_array_set(Sdb *s, const char *key, int idx, const char *val, - ut32 cas) { +RZ_API bool sdb_array_set(Sdb *s, const char *key, int idx, const char *val) { int lstr, lval, len; - const char *usr, *str = sdb_const_get_len(s, key, &lstr, 0); + const char *usr, *str = sdb_const_get_len(s, key, &lstr); char *ptr; if (!str || !*str) { - return sdb_set(s, key, val, cas); + return sdb_set(s, key, val); } // XXX: should we cache sdb_alen value inside kv? len = sdb_alen(str); lstr--; if (idx < 0 || idx == len) { // append - return sdb_array_insert(s, key, -1, val, cas); + return sdb_array_insert(s, key, -1, val); } lval = strlen(val); if (idx > len) { @@ -365,7 +356,7 @@ RZ_API int sdb_array_set(Sdb *s, const char *key, int idx, const char *val, newkey[i] = SDB_RS; } memcpy(newkey + i, val, lval + 1); - ret = sdb_array_insert(s, key, -1, newkey, cas); + ret = sdb_array_insert(s, key, -1, newkey); free(newkey); return ret; } @@ -386,20 +377,20 @@ RZ_API int sdb_array_set(Sdb *s, const char *key, int idx, const char *val, ptr[lval] = SDB_RS; strcpy(ptr + lval + 1, usr); } - return sdb_set_owned(s, key, nstr, 0); + return sdb_set_owned(s, key, nstr); } - return 0; + return false; } -RZ_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val, ut32 cas) { - const char *n, *p, *str = sdb_const_get(s, key, 0); +RZ_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val) { + const char *n, *p, *str = sdb_const_get(s, key); int idx = 0; ut64 num; if (str) { for (p = str;; idx++) { num = sdb_atoi(p); if (num == val) { - return sdb_array_delete(s, key, idx, cas); + return sdb_array_delete(s, key, idx); } n = strchr(p, SDB_RS); if (!n) { @@ -412,9 +403,8 @@ RZ_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val, ut32 cas) { } /* get array index of given value */ -RZ_API int sdb_array_indexof(Sdb *s, const char *key, const char *val, - ut32 cas) { - const char *str = sdb_const_get(s, key, 0); +RZ_API int sdb_array_indexof(Sdb *s, const char *key, const char *val) { + const char *str = sdb_const_get(s, key); const char *n, *p = str; int i; for (i = 0;; i++) { @@ -433,15 +423,14 @@ RZ_API int sdb_array_indexof(Sdb *s, const char *key, const char *val, } // previously named del_str... pair with _add -RZ_API int sdb_array_remove(Sdb *s, const char *key, const char *val, - ut32 cas) { - const char *str = sdb_const_get(s, key, 0); +RZ_API int sdb_array_remove(Sdb *s, const char *key, const char *val) { + const char *str = sdb_const_get(s, key); const char *n, *p = str; int idx; if (p) { for (idx = 0;; idx++) { if (!astrcmp(p, val)) { - return sdb_array_delete(s, key, idx, cas); + return sdb_array_delete(s, key, idx); } n = strchr(p, SDB_RS); if (!n) { @@ -453,9 +442,9 @@ RZ_API int sdb_array_remove(Sdb *s, const char *key, const char *val, return 0; } -RZ_API int sdb_array_delete(Sdb *s, const char *key, int idx, ut32 cas) { +RZ_API int sdb_array_delete(Sdb *s, const char *key, int idx) { int i; - char *p, *n, *str = sdb_get(s, key, 0); + char *p, *n, *str = sdb_get(s, key); p = str; if (!str || !*str) { free(str); @@ -483,22 +472,22 @@ RZ_API int sdb_array_delete(Sdb *s, const char *key, int idx, ut32 cas) { *p = 0; p[1] = 0; } - sdb_set_owned(s, key, str, cas); + sdb_set_owned(s, key, str); return 1; } // XXX Doesnt work if numbers are stored in different base -RZ_API bool sdb_array_contains_num(Sdb *s, const char *key, ut64 num, ut32 *cas) { +RZ_API bool sdb_array_contains_num(Sdb *s, const char *key, ut64 num) { char val[SDB_NUM_BUFSZ]; char *nval = sdb_itoa(num, val, SDB_NUM_BASE); - return sdb_array_contains(s, key, nval, cas); + return sdb_array_contains(s, key, nval); } -RZ_API bool sdb_array_contains(Sdb *s, const char *key, const char *val, ut32 *cas) { +RZ_API bool sdb_array_contains(Sdb *s, const char *key, const char *val) { if (!s || !key || !val) { return false; } - const char *next, *ptr = sdb_const_get(s, key, cas); + const char *next, *ptr = sdb_const_get(s, key); if (ptr && *ptr) { size_t vlen = strlen(val); while (1) { @@ -517,40 +506,38 @@ RZ_API bool sdb_array_contains(Sdb *s, const char *key, const char *val, ut32 *c } RZ_API int sdb_array_size(Sdb *s, const char *key) { - return sdb_alen(sdb_const_get(s, key, 0)); + return sdb_alen(sdb_const_get(s, key)); } // NOTE: ignore empty buckets RZ_API int sdb_array_length(Sdb *s, const char *key) { - return sdb_alen_ignore_empty(sdb_const_get(s, key, 0)); + return sdb_alen_ignore_empty(sdb_const_get(s, key)); } -RZ_API int sdb_array_push_num(Sdb *s, const char *key, ut64 num, ut32 cas) { +RZ_API int sdb_array_push_num(Sdb *s, const char *key, ut64 num) { char buf[SDB_NUM_BUFSZ], *n = sdb_itoa(num, buf, SDB_NUM_BASE); - return sdb_array_push(s, key, n, cas); + return sdb_array_push(s, key, n); } -RZ_API bool sdb_array_push(Sdb *s, const char *key, const char *val, ut32 cas) { - return sdb_array_prepend(s, key, val, cas); +RZ_API bool sdb_array_push(Sdb *s, const char *key, const char *val) { + return sdb_array_prepend(s, key, val); } -RZ_API bool sdb_array_prepend_num(Sdb *s, const char *key, ut64 num, ut32 cas) { +RZ_API bool sdb_array_prepend_num(Sdb *s, const char *key, ut64 num) { char buf[SDB_NUM_BUFSZ]; char *n = sdb_itoa(num, buf, SDB_NUM_BASE); - return sdb_array_push(s, key, n, cas); + return sdb_array_push(s, key, n); } -RZ_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val, ut32 cas) { +RZ_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val) { if (!s || !key || !val) { return false; } int str_len = 0; - ut32 kas = cas; - const char *str = sdb_const_get_len(s, key, &str_len, &kas); - if (!val || (cas && cas != kas)) { + const char *str = sdb_const_get_len(s, key, &str_len); + if (!val) { return false; } - cas = kas; if (str && *str) { int val_len = strlen(val); char *newval = malloc(str_len + val_len + 2); @@ -562,80 +549,66 @@ RZ_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val, ut32 cas memcpy(newval + val_len + 1, str, str_len); newval[str_len + val_len + 1] = 0; // TODO: optimize this because we already have allocated and strlened everything - sdb_set_owned(s, key, newval, cas); + sdb_set_owned(s, key, newval); } else { - sdb_set(s, key, val, cas); + sdb_set(s, key, val); } return true; } -RZ_API ut64 sdb_array_pop_num(Sdb *s, const char *key, ut32 *cas) { +RZ_API ut64 sdb_array_pop_num(Sdb *s, const char *key) { ut64 ret; - char *a = sdb_array_pop(s, key, cas); + char *a = sdb_array_pop(s, key); if (!a) { - if (cas) { - *cas = UT32_MAX; // invalid - } return UT64_MAX; } - if (cas) { - *cas = 0; - } ret = sdb_atoi(a); free(a); return ret; } -RZ_API char *sdb_array_pop(Sdb *s, const char *key, ut32 *cas) { - return sdb_array_pop_head(s, key, cas); +RZ_API char *sdb_array_pop(Sdb *s, const char *key) { + return sdb_array_pop_head(s, key); } -RZ_API char *sdb_array_pop_head(Sdb *s, const char *key, ut32 *cas) { +RZ_API char *sdb_array_pop_head(Sdb *s, const char *key) { // remove last element in - ut32 kas; - char *end, *str = sdb_get(s, key, &kas); + char *end, *str = sdb_get(s, key); if (!str || !*str) { free(str); return NULL; } - if (cas && *cas != kas) { - *cas = kas; - } end = strchr(str, SDB_RS); if (end) { *end = 0; - sdb_set(s, key, end + 1, 0); + sdb_set(s, key, end + 1); } else { - sdb_unset(s, key, 0); + sdb_unset(s, key); } return str; } -RZ_API char *sdb_array_pop_tail(Sdb *s, const char *key, ut32 *cas) { - ut32 kas; - char *end, *str = sdb_get(s, key, &kas); +RZ_API char *sdb_array_pop_tail(Sdb *s, const char *key) { + char *end, *str = sdb_get(s, key); if (!str || !*str) { free(str); return NULL; } - if (cas && *cas != kas) { - *cas = kas; - } for (end = str + strlen(str) - 1; end > str && *end != SDB_RS; end--) { // nothing to see here } if (*end == SDB_RS) { *end++ = 0; } - sdb_set_owned(s, key, str, 0); + sdb_set_owned(s, key, str); // XXX: probably wrong return strdup(end); } -RZ_API void sdb_array_sort(Sdb *s, const char *key, ut32 cas) { +RZ_API void sdb_array_sort(Sdb *s, const char *key) { char *nstr, *str, **strs; int lstr, j, i; - str = sdb_get_len(s, key, &lstr, 0); + str = sdb_get_len(s, key, &lstr); if (!str) { return; } @@ -660,14 +633,14 @@ RZ_API void sdb_array_sort(Sdb *s, const char *key, ut32 cas) { } else { *nstr = '\0'; } - sdb_set_owned(s, key, str, cas); + sdb_set_owned(s, key, str); free(strs); } -RZ_API void sdb_array_sort_num(Sdb *s, const char *key, ut32 cas) { +RZ_API void sdb_array_sort_num(Sdb *s, const char *key) { char *ret, *nstr; - char *str = sdb_get(s, key, 0); + char *str = sdb_get(s, key); if (!str) { return; } @@ -692,7 +665,7 @@ RZ_API void sdb_array_sort_num(Sdb *s, const char *key, ut32 cas) { nstr[*nums] = '\0'; ret = sdb_fmt_tostr(nums + 1, nstr); - sdb_set_owned(s, key, ret, cas); + sdb_set_owned(s, key, ret); free(nstr); free(nums); diff --git a/librz/util/sdb/src/diff.c b/librz/util/sdb/src/diff.c index 5ef8969e1a3..3a21c6aea71 100644 --- a/librz/util/sdb/src/diff.c +++ b/librz/util/sdb/src/diff.c @@ -103,7 +103,7 @@ static bool sdb_diff_kv_cb(void *user, const SdbKv *kv) { const char *k = sdbkv_key(kv); const char *v = sdbkv_value(kv); Sdb *other = ctx->add ? ctx->ctx->a : ctx->ctx->b; - const char *other_val = sdb_const_get(other, k, NULL); + const char *other_val = sdb_const_get(other, k); if (!other_val || !*other_val) { DIFF(ctx->ctx, sdb_diff_report_kv(ctx->ctx, k, v, ctx->add); diff --git a/librz/util/sdb/src/num.c b/librz/util/sdb/src/num.c index 677ac95eb80..a36d0d5aae6 100644 --- a/librz/util/sdb/src/num.c +++ b/librz/util/sdb/src/num.c @@ -6,84 +6,79 @@ // check if key exists and if it's a number.. rename? RZ_API bool sdb_num_exists(Sdb *s, const char *key) { - const char *o = sdb_const_get(s, key, NULL); + const char *o = sdb_const_get(s, key); return o ? (*o >= '0' && *o <= '9') : false; } -RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas) { - const char *v = sdb_const_get(s, key, cas); +RZ_API ut64 sdb_num_get(Sdb *s, const char *key) { + const char *v = sdb_const_get(s, key); return (!v || *v == '-') ? 0LL : sdb_atoi(v); } -RZ_API int sdb_num_add(Sdb *s, const char *key, ut64 v, ut32 cas) { +RZ_API bool sdb_num_add(Sdb *s, const char *key, ut64 v) { char *val, b[SDB_NUM_BUFSZ]; - int numbase = sdb_num_base(sdb_const_get(s, key, NULL)); + int numbase = sdb_num_base(sdb_const_get(s, key)); val = sdb_itoa(v, b, numbase); - return sdb_add(s, key, val, cas); + return sdb_add(s, key, val); } -RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas) { +RZ_API bool sdb_num_set(Sdb *s, const char *key, ut64 v) { char *val, b[SDB_NUM_BUFSZ]; - int numbase = sdb_num_base(sdb_const_get(s, key, NULL)); + int numbase = sdb_num_base(sdb_const_get(s, key)); val = sdb_itoa(v, b, numbase); - return sdb_set(s, key, val, cas); + return sdb_set(s, key, val); } -RZ_API ut64 sdb_num_inc(Sdb *s, const char *key, ut64 n2, ut32 cas) { - ut32 c; - ut64 n = sdb_num_get(s, key, &c); +RZ_API ut64 sdb_num_inc(Sdb *s, const char *key, ut64 n2) { + ut64 n = sdb_num_get(s, key); ut64 res = n + n2; - if ((cas && c != cas) || res < n) { + if (res < n) { return 0LL; } - sdb_num_set(s, key, res, cas); + sdb_num_set(s, key, res); return res; } -RZ_API ut64 sdb_num_dec(Sdb *s, const char *key, ut64 n2, ut32 cas) { - ut32 c; - ut64 n = sdb_num_get(s, key, &c); - if (cas && c != cas) { - return 0LL; - } +RZ_API ut64 sdb_num_dec(Sdb *s, const char *key, ut64 n2) { + ut64 n = sdb_num_get(s, key); if (n2 > n) { - sdb_set(s, key, "0", cas); + sdb_set(s, key, "0"); return 0LL; // XXX must be -1LL? } n -= n2; - sdb_num_set(s, key, n, cas); + sdb_num_set(s, key, n); return n; } -RZ_API int sdb_num_min(Sdb *db, const char *k, ut64 n, ut32 cas) { - const char *a = sdb_const_get(db, k, NULL); +RZ_API int sdb_num_min(Sdb *db, const char *k, ut64 n) { + const char *a = sdb_const_get(db, k); return (!a || n < sdb_atoi(a)) - ? sdb_num_set(db, k, n, cas) + ? sdb_num_set(db, k, n) : 0; } -RZ_API int sdb_num_max(Sdb *db, const char *k, ut64 n, ut32 cas) { - const char *a = sdb_const_get(db, k, NULL); +RZ_API int sdb_num_max(Sdb *db, const char *k, ut64 n) { + const char *a = sdb_const_get(db, k); return (!a || n > sdb_atoi(a)) - ? sdb_num_set(db, k, n, cas) + ? sdb_num_set(db, k, n) : 0; } -RZ_API int sdb_bool_set(Sdb *db, const char *str, bool v, ut32 cas) { - return sdb_set(db, str, v ? "true" : "false", cas); +RZ_API bool sdb_bool_set(Sdb *db, const char *str, bool v) { + return sdb_set(db, str, v ? "true" : "false"); } -RZ_API bool sdb_bool_get(Sdb *db, const char *str, ut32 *cas) { - const char *b = sdb_const_get(db, str, cas); +RZ_API bool sdb_bool_get(Sdb *db, const char *str) { + const char *b = sdb_const_get(db, str); return b && (!strcmp(b, "1") || !strcmp(b, "true")); } /* pointers */ -RZ_API int sdb_ptr_set(Sdb *db, const char *key, void *p, ut32 cas) { - return sdb_num_set(db, key, (ut64)(size_t)p, cas); +RZ_API int sdb_ptr_set(Sdb *db, const char *key, void *p) { + return sdb_num_set(db, key, (ut64)(size_t)p); } -RZ_API void *sdb_ptr_get(Sdb *db, const char *key, ut32 *cas) { - return (void *)(size_t)sdb_num_get(db, key, cas); +RZ_API void *sdb_ptr_get(Sdb *db, const char *key) { + return (void *)(size_t)sdb_num_get(db, key); } diff --git a/librz/util/sdb/src/query.c b/librz/util/sdb/src/query.c index 35d121cd3f4..7bbf571b490 100644 --- a/librz/util/sdb/src/query.c +++ b/librz/util/sdb/src/query.c @@ -234,7 +234,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { next = strchr(eq + 1, ';'); if (next) *next = 0; - val = sdb_const_get(s, eq + 1, 0); + val = sdb_const_get(s, eq + 1); if (!val) { eprintf("No value for '%s'\n", eq + 1); goto fail; @@ -291,7 +291,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { slash = strchr(cmd, '/'); } if (*cmd == '?') { - const char *val = sdb_const_get(s, cmd + 1, 0); + const char *val = sdb_const_get(s, cmd + 1); const char *type = sdb_type(val); out_concat(type); } else if (*cmd == '*') { @@ -343,7 +343,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { } if (*cmd == '$') { free(newcmd); - char *nc = sdb_get(s, cmd + 1, 0); + char *nc = sdb_get(s, cmd + 1); cmd = newcmd = (nc) ? nc : strdup(""); } // cmd = val @@ -392,8 +392,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { int idx = sdb_atoi(cmd + 2); /* +[idx]key=n */ /* -[idx]key=n */ - ut64 curnum = sdb_array_get_num(s, - eb + 1, idx, 0); + ut64 curnum = sdb_array_get_num(s, eb + 1, idx); if (eq) { /* +[idx]key=n --> key[idx] += n */ /* -[idx]key=n --> key[idx] -= n */ @@ -405,7 +404,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { } else { // never happens } - sdb_array_set_num(s, eb + 1, idx, curnum, 0); + sdb_array_set_num(s, eb + 1, idx, curnum); } else { /* +[idx]key --> key[idx] + 1 */ /* -[idx]key --> key[idx] - 1 */ @@ -434,23 +433,23 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { d = sdb_atoi(val); } if (op == '+') { - sdb_num_inc(s, cmd + 1, d, 0); + sdb_num_inc(s, cmd + 1, d); } else { - sdb_num_dec(s, cmd + 1, d, 0); + sdb_num_dec(s, cmd + 1, d); } } else { if (*cmd == '+') { - sdb_concat(s, cmd + 1, val, 0); + sdb_concat(s, cmd + 1, val); } else { - sdb_uncat(s, cmd + 1, val, 0); + sdb_uncat(s, cmd + 1, val); } } } else { - int base = sdb_num_base(sdb_const_get(s, cmd + 1, 0)); + int base = sdb_num_base(sdb_const_get(s, cmd + 1)); if (*cmd == '+') { - n = sdb_num_inc(s, cmd + 1, d, 0); + n = sdb_num_inc(s, cmd + 1, d); } else { - n = sdb_num_dec(s, cmd + 1, d, 0); + n = sdb_num_dec(s, cmd + 1, d); } // keep base if (base == 16) { @@ -507,18 +506,18 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { } else if (cmd[1] == '!') { if (cmd[2] == '+') { // [!+]key=aa # add_sorted - sdb_array_add_sorted(s, p, val, 0); + sdb_array_add_sorted(s, p, val); } else { // [!]key # sort - sdb_array_sort(s, p, 0); + sdb_array_sort(s, p); } } else if (cmd[1] == '#') { // [#+]key=num # add_sorted_num if (cmd[2] == '+') { // [#]key # sort_num - sdb_array_add_sorted_num(s, p, sdb_atoi(val), 0); + sdb_array_add_sorted_num(s, p, sdb_atoi(val)); } else { - sdb_array_sort_num(s, p, 0); + sdb_array_sort_num(s, p); } } else if (cmd[1] == '+' || cmd[1] == '-') { if (cmd[1] == cmd[2]) { @@ -529,9 +528,9 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { /* invalid syntax */ } else { if (eq) { - sdb_array_push(s, p, val, 0); + sdb_array_push(s, p, val); } else { - char *ret = sdb_array_pop(s, p, 0); + char *ret = sdb_array_pop(s, p); out_concat(ret); free(ret); } @@ -546,10 +545,10 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { if (eq) { if (cmd[1] == '+') { // [+]K=1 - sdb_array_add(s, p, val, 0); + sdb_array_add(s, p, val); } else { // [-]K= = remove first element - sdb_array_remove(s, p, val, 0); + sdb_array_remove(s, p, val); } // return NULL; } else { @@ -557,20 +556,20 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { if (cmd[1] == '+') { // [+]K = remove first element // XXX: this is a little strange syntax to remove an item - ret = sdb_array_get(s, p, 0, 0); + ret = sdb_array_get(s, p, 0); if (ret && *ret) { out_concat(ret); } // (+)foo :: remove first element - sdb_array_delete(s, p, 0, 0); + sdb_array_delete(s, p, 0); } else { // [-]K = remove last element - ret = sdb_array_get(s, p, -1, 0); + ret = sdb_array_get(s, p, -1); if (ret && *ret) { out_concat(ret); } // (-)foo :: remove last element - sdb_array_delete(s, p, -1, 0); + sdb_array_delete(s, p, -1); } free(ret); } @@ -580,7 +579,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { if (eq) { /* [+3]foo=bla */ if (i < 0) { - char *tmp = sdb_array_get(s, p, -i, NULL); + char *tmp = sdb_array_get(s, p, -i); if (tmp) { if (encode) { char *newtmp = (void *)sdb_decode(tmp, NULL); @@ -592,7 +591,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { } ok = 0; out_concat(tmp); - sdb_array_delete(s, p, -i, 0); + sdb_array_delete(s, p, -i); free(tmp); } else goto fail; @@ -600,7 +599,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { if (encode) { val = sdb_encode((const ut8 *)val, -1); } - ok = cmd[1] ? ((cmd[1] == '+') ? sdb_array_insert(s, p, i, val, 0) : sdb_array_set(s, p, i, val, 0)) : sdb_array_delete(s, p, i, 0); + ok = cmd[1] ? ((cmd[1] == '+') ? sdb_array_insert(s, p, i, val) : sdb_array_set(s, p, i, val)) : sdb_array_delete(s, p, i); if (encode) { free((void *)val); val = NULL; @@ -614,22 +613,22 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { if (i == 0) { /* [-b]foo */ if (cmd[1] == '-') { - sdb_array_remove(s, p, cmd + 2, 0); + sdb_array_remove(s, p, cmd + 2); } else { eprintf("TODO: [b]foo -> get index of b key inside foo array\n"); // sdb_array_dels (s, p, cmd+1, 0); } } else if (i < 0) { /* [-3]foo */ - char *tmp = sdb_array_get(s, p, -i, NULL); + char *tmp = sdb_array_get(s, p, -i); if (tmp && *tmp) { out_concat(tmp); - sdb_array_delete(s, p, -i, 0); + sdb_array_delete(s, p, -i); } free(tmp); } else { /* [+3]foo */ - char *tmp = sdb_array_get(s, p, i, NULL); + char *tmp = sdb_array_get(s, p, i); if (tmp && *tmp) { out_concat(tmp); } @@ -646,15 +645,15 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { } if (cmd[1]) { int idx = atoi(cmd + 1); - ok = sdb_array_set(s, p, idx, sval, 0); + ok = sdb_array_set(s, p, idx, sval); // TODO: handle when idx > sdb_alen if (encode) free(sval); } else { if (encode) { - ok = sdb_set_owned(s, p, sval, 0); + ok = sdb_set_owned(s, p, sval); } else { - ok = sdb_set(s, p, sval, 0); + ok = sdb_set(s, p, sval); } } if (ok && buf) { @@ -662,11 +661,11 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { } } else { /* [3]foo */ - const char *sval = sdb_const_get(s, p, 0); + const char *sval = sdb_const_get(s, p); size_t wl; if (cmd[1]) { i = atoi(cmd + 1); - buf = sdb_array_get(s, p, i, NULL); + buf = sdb_array_get(s, p, i); if (buf) { bufset = 1; len = strlen(buf) + 1; @@ -733,7 +732,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { cmd[i] = '\0'; i--; } - ok = sdb_set(s, cmd, val, 0); + ok = sdb_set(s, cmd, val); if (encode) { free((void *)val); val = NULL; @@ -744,7 +743,7 @@ RZ_API char *sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd) { } else { // 0 0 kvpath // sdbget - if ((q = sdb_const_get(s, cmd, 0))) { + if ((q = sdb_const_get(s, cmd))) { if (encode) { q = (void *)sdb_decode(q, NULL); } diff --git a/librz/util/sdb/src/sdb.c b/librz/util/sdb/src/sdb.c index 8531e4f348e..b689603b83b 100644 --- a/librz/util/sdb/src/sdb.c +++ b/librz/util/sdb/src/sdb.c @@ -25,14 +25,6 @@ static inline SdbKv *next_kv(HtSS *ht, SdbKv *kv) { (j) < (bt)->count; \ (j) = (count) == (ht)->count ? j + 1 : j, (kv) = (count) == (ht)->count ? next_kv(ht, kv) : kv, (count) = (ht)->count) -static inline int nextcas(void) { - static ut32 cas = 1; - if (!cas) { - cas++; - } - return cas++; -} - // TODO: use mmap instead of read.. much faster! RZ_API Sdb *sdb_new0(void) { return sdb_new(NULL, NULL, 0); @@ -78,12 +70,10 @@ RZ_API Sdb *sdb_new(const char *path, const char *name, int lock) { break; } if (sdb_open(s, s->dir) == -1) { - s->last = s->timestamped ? sdb_now() : 0LL; // TODO: must fail if we cant open for write in sync } s->name = strdup(name); } else { - s->last = s->timestamped ? sdb_now() : 0LL; s->fd = -1; } s->fdump = -1; @@ -127,7 +117,7 @@ RZ_API void sdb_file(Sdb *s, const char *dir) { } static bool sdb_merge_cb(void *user, const SdbKv *kv) { - sdb_set(user, sdbkv_key(kv), sdbkv_value(kv), 0); + sdb_set(user, sdbkv_key(kv), sdbkv_value(kv)); return true; } @@ -207,14 +197,10 @@ RZ_API bool sdb_free(Sdb *s) { return false; } -RZ_API const char *sdb_const_get_len(Sdb *s, const char *key, int *vlen, ut32 *cas) { +RZ_API const char *sdb_const_get_len(Sdb *s, const char *key, int *vlen) { ut32 pos, len; - ut64 now = 0LL; bool found; - if (cas) { - *cas = 0; - } if (vlen) { *vlen = 0; } @@ -230,18 +216,6 @@ RZ_API const char *sdb_const_get_len(Sdb *s, const char *key, int *vlen, ut32 *c if (!sdbkv_value(kv) || !*sdbkv_value(kv)) { return NULL; } - if (s->timestamped && kv->expire) { - if (!now) { - now = sdb_now(); - } - if (now > kv->expire) { - sdb_unset(s, key, 0); - return NULL; - } - } - if (cas) { - *cas = kv->cas; - } if (vlen) { *vlen = sdbkv_value_len(kv); } @@ -266,36 +240,35 @@ RZ_API const char *sdb_const_get_len(Sdb *s, const char *key, int *vlen, ut32 *c return s->db.map + pos; } -RZ_API const char *sdb_const_get(Sdb *s, const char *key, ut32 *cas) { - return sdb_const_get_len(s, key, NULL, cas); +RZ_API const char *sdb_const_get(Sdb *s, const char *key) { + return sdb_const_get_len(s, key, NULL); } // TODO: add sdb_getf? -RZ_API char *sdb_get_len(Sdb *s, const char *key, int *vlen, ut32 *cas) { - const char *value = sdb_const_get_len(s, key, vlen, cas); +RZ_API char *sdb_get_len(Sdb *s, const char *key, int *vlen) { + const char *value = sdb_const_get_len(s, key, vlen); return value ? strdup(value) : NULL; } -RZ_API char *sdb_get(Sdb *s, const char *key, ut32 *cas) { - return sdb_get_len(s, key, NULL, cas); +RZ_API char *sdb_get(Sdb *s, const char *key) { + return sdb_get_len(s, key, NULL); } -RZ_API int sdb_unset(Sdb *s, const char *key, ut32 cas) { - return key ? sdb_set(s, key, "", cas) : 0; +RZ_API int sdb_unset(Sdb *s, const char *key) { + return key ? sdb_set(s, key, "") : 0; } /* remove from memory */ -RZ_API bool sdb_remove(Sdb *s, const char *key, ut32 cas) { +RZ_API bool sdb_remove(Sdb *s, const char *key) { return sdb_ht_delete(s->ht, key); } // alias for '-key=str'.. '+key=str' concats -RZ_API int sdb_uncat(Sdb *s, const char *key, const char *value, ut32 cas) { +RZ_API bool sdb_uncat(Sdb *s, const char *key, const char *value) { // remove 'value' from current key value. - // TODO: cas is ignored here int vlen = 0, valen; - char *p, *v = sdb_get_len(s, key, &vlen, NULL); + char *p, *v = sdb_get_len(s, key, &vlen); int mod = 0; if (!v || !key || !value) { free(v); @@ -309,40 +282,40 @@ RZ_API int sdb_uncat(Sdb *s, const char *key, const char *value, ut32 cas) { } } if (mod) { - sdb_set_owned(s, key, v, 0); + sdb_set_owned(s, key, v); } else { free(v); } return 0; } -RZ_API int sdb_concat(Sdb *s, const char *key, const char *value, ut32 cas) { +RZ_API bool sdb_concat(Sdb *s, const char *key, const char *value) { int kl, vl; const char *p; char *o; if (!s || !key || !*key || !value || !*value) { return 0; } - p = sdb_const_get_len(s, key, &kl, 0); + p = sdb_const_get_len(s, key, &kl); if (!p) { - return sdb_set(s, key, value, cas); + return sdb_set(s, key, value); } vl = strlen(value); o = malloc(kl + vl + 1); if (o) { memcpy(o, p, kl); memcpy(o + kl, value, vl + 1); - return sdb_set_owned(s, key, o, cas); + return sdb_set_owned(s, key, o); } - return 0; + return false; } // set if not defined -RZ_API int sdb_add(Sdb *s, const char *key, const char *val, ut32 cas) { +RZ_API bool sdb_add(Sdb *s, const char *key, const char *val) { if (sdb_exists(s, key)) { - return 0; + return false; } - return sdb_set(s, key, val, cas); + return sdb_set(s, key, val); } RZ_API bool sdb_exists(Sdb *s, const char *key) { @@ -387,7 +360,6 @@ RZ_API int sdb_open(Sdb *s, const char *file) { s->path = NULL; // TODO: path is important } } - s->last = 0LL; if (s->fd != -1 && fstat(s->fd, &st) != -1) { if ((S_IFREG & st.st_mode) != S_IFREG) { eprintf("Database must be a file\n"); @@ -395,7 +367,6 @@ RZ_API int sdb_open(Sdb *s, const char *file) { s->fd = -1; return -1; } - s->last = st.st_mtime; } if (s->fd != -1) { cdb_init(&s->db, s->fd); @@ -506,8 +477,6 @@ RZ_API SdbKv *sdbkv_new2(const char *k, int kl, const char *v, int vl) { kv->base.value = NULL; kv->base.value_len = 0; } - kv->cas = nextcas(); - kv->expire = 0LL; return kv; } @@ -535,12 +504,12 @@ RZ_API RZ_OWN char *sdbkv_dup_value(RZ_NONNULL const SdbKv *kv) { return rz_mem_dup(sdbkv_value(kv), sdbkv_value_len(kv) + 1); } -static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32 cas) { +static bool sdb_set_internal(Sdb *s, const char *key, char *val, int owned) { ut32 vlen, klen; SdbKv *kv; bool found; if (!s || !key) { - return 0; + return false; } if (!val) { if (owned) { @@ -556,16 +525,9 @@ static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32 kv = sdb_ht_find_kvp(s->ht, key, &found); if (found && sdbkv_value(kv)) { if (cdb_findnext(&s->db, sdb_hash(key), key, klen)) { - if (cas && kv->cas != cas) { - if (owned) { - free(val); - } - return 0; - } if (vlen == sdbkv_value_len(kv) && !strcmp(sdbkv_value(kv), val)) { - return kv->cas; + return true; } - kv->cas = cas = nextcas(); if (owned) { kv->base.value_len = vlen; free(kv->base.value); @@ -581,7 +543,7 @@ static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32 } else { sdb_ht_delete(s->ht, key); } - return cas; + return true; } // empty values are also stored // TODO store only the ones that are in the CDB @@ -595,20 +557,19 @@ static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32 kv = sdbkv_new2(key, klen, val, vlen); } if (kv) { - ut32 cas = kv->cas = nextcas(); sdb_ht_insert_kvp(s->ht, kv, true /*update*/); free(kv); - return cas; + return true; } - return 0; + return false; } -RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas) { - return sdb_set_internal(s, key, val, 1, cas); +RZ_API bool sdb_set_owned(Sdb *s, const char *key, char *val) { + return sdb_set_internal(s, key, val, 1); } -RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas) { - return sdb_set_internal(s, key, (char *)val, 0, cas); +RZ_API bool sdb_set(Sdb *s, const char *key, const char *val) { + return sdb_set_internal(s, key, (char *)val, 0); } static bool get_items_cb(void *user, const SdbKv *kv) { @@ -821,9 +782,9 @@ RZ_API bool sdb_sync(Sdb *s) { ut32 j, count; BUCKET_FOREACH_SAFE(s->ht, bt, j, count, kv) { - if (sdbkv_key(kv) && sdbkv_value(kv) && *sdbkv_value(kv) && !kv->expire) { + if (sdbkv_key(kv) && sdbkv_value(kv) && *sdbkv_value(kv)) { if (sdb_disk_insert(s, sdbkv_key(kv), sdbkv_value(kv))) { - sdb_remove(s, sdbkv_key(kv), 0); + sdb_remove(s, sdbkv_key(kv)); } } } @@ -911,67 +872,6 @@ RZ_API bool sdb_dump_next(RZ_NONNULL Sdb *s, RZ_OUT RZ_NONNULL SdbKv *kv) { return true; } -static inline ut64 parse_expire(ut64 e) { - const ut64 month = 30 * 24 * 60 * 60; - if (e > 0 && e < month) { - e += sdb_now(); - } - return e; -} - -RZ_API bool sdb_expire_set(Sdb *s, const char *key, ut64 expire, ut32 cas) { - char *buf; - ut32 pos, len; - SdbKv *kv; - bool found; - s->timestamped = true; - if (!key) { - s->expire = parse_expire(expire); - return true; - } - kv = (SdbKv *)sdb_ht_find_kvp(s->ht, key, &found); - if (found && kv) { - if (*sdbkv_value(kv)) { - if (!cas || cas == kv->cas) { - kv->expire = parse_expire(expire); - return true; - } - } - return false; - } - if (s->fd == -1) { - return false; - } - (void)cdb_findstart(&s->db); - if (!cdb_findnext(&s->db, sdb_hash(key), key, strlen(key) + 1)) { - return false; - } - pos = cdb_datapos(&s->db); - len = cdb_datalen(&s->db); - if (len < 1 || len >= INT32_MAX) { - return false; - } - if (!(buf = calloc(1, len + 1))) { - return false; - } - cdb_read(&s->db, buf, len, pos); - buf[len] = 0; - sdb_set_owned(s, key, buf, cas); - return sdb_expire_set(s, key, expire, cas); // recursive -} - -RZ_API ut64 sdb_expire_get(Sdb *s, const char *key, ut32 *cas) { - bool found = false; - SdbKv *kv = (SdbKv *)sdb_ht_find_kvp(s->ht, key, &found); - if (found && kv && *sdbkv_value(kv)) { - if (cas) { - *cas = kv->cas; - } - return kv->expire; - } - return 0LL; -} - RZ_API void sdb_config(Sdb *s, int options) { s->options = options; if (options & SDB_OPTION_SYNC) { @@ -979,7 +879,6 @@ RZ_API void sdb_config(Sdb *s, int options) { } if (options & SDB_OPTION_NOSTAMP) { // sync on every query - s->last = 0LL; } if (options & SDB_OPTION_FS) { // have access to fs (handle '.' or not in query) @@ -1002,7 +901,7 @@ RZ_API void sdb_drain(Sdb *s, Sdb *f) { static bool copy_foreach_cb(void *user, const SdbKv *kv) { Sdb *dst = user; - sdb_set(dst, sdbkv_key(kv), sdbkv_value(kv), 0); + sdb_set(dst, sdbkv_key(kv), sdbkv_value(kv)); return true; } @@ -1023,7 +922,7 @@ typedef struct { static bool unset_cb(void *user, const SdbKv *kv) { UnsetCallbackData *ucd = user; if (sdb_match(sdbkv_key(kv), ucd->key)) { - sdb_unset(ucd->sdb, sdbkv_key(kv), 0); + sdb_unset(ucd->sdb, sdbkv_key(kv)); } return true; } diff --git a/librz/util/sdb/src/sdb.h b/librz/util/sdb/src/sdb.h index eeced3254be..3f3a549c7bb 100644 --- a/librz/util/sdb/src/sdb.h +++ b/librz/util/sdb/src/sdb.h @@ -77,13 +77,10 @@ typedef struct sdb_t { ut32 dump_end_pos; ///< Used in sdb_dump_next() int fdump; char *ndump; - ut64 expire; - ut64 last; // timestamp of last change int options; int ns_lock; // TODO: merge into options? SdbList *ns; ut32 depth; - bool timestamped; } Sdb; typedef struct sdb_ns_t { @@ -125,8 +122,8 @@ RZ_API char *sdb_querys(Sdb *s, char *buf, size_t len, const char *cmd); RZ_API char *sdb_querysf(Sdb *s, char *buf, size_t buflen, const char *fmt, ...); RZ_API int sdb_query_file(Sdb *s, const char *file); RZ_API bool sdb_exists(Sdb *, const char *key); -RZ_API bool sdb_remove(Sdb *, const char *key, ut32 cas); -RZ_API int sdb_unset(Sdb *, const char *key, ut32 cas); +RZ_API bool sdb_remove(Sdb *, const char *key); +RZ_API int sdb_unset(Sdb *, const char *key); RZ_API int sdb_unset_like(Sdb *s, const char *k); // diffing @@ -149,40 +146,40 @@ RZ_API bool sdb_diff(Sdb *a, Sdb *b, SdbDiffCallback cb, void *cb_user); RZ_API bool sdb_diff_eq(Sdb *a, Sdb *b, VALUE_EQ_F eq, SdbDiffCallback cb, void *cb_user); // Gets a pointer to the value associated with `key`. -RZ_API char *sdb_get(Sdb *, const char *key, ut32 *cas); +RZ_API char *sdb_get(Sdb *, const char *key); // Gets a pointer to the value associated with `key` and returns in `vlen` the // length of the value string. -RZ_API char *sdb_get_len(Sdb *, const char *key, int *vlen, ut32 *cas); +RZ_API char *sdb_get_len(Sdb *, const char *key, int *vlen); // Gets a const pointer to the value associated with `key` -RZ_API const char *sdb_const_get(Sdb *, const char *key, ut32 *cas); +RZ_API const char *sdb_const_get(Sdb *, const char *key); // Gets a const pointer to the value associated with `key` and returns in // `vlen` the length of the value string. -RZ_API const char *sdb_const_get_len(Sdb *s, const char *key, int *vlen, ut32 *cas); -RZ_API int sdb_set(Sdb *, const char *key, const char *data, ut32 cas); -RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas); -RZ_API int sdb_concat(Sdb *s, const char *key, const char *value, ut32 cas); -RZ_API int sdb_uncat(Sdb *s, const char *key, const char *value, ut32 cas); -RZ_API int sdb_add(Sdb *s, const char *key, const char *val, ut32 cas); +RZ_API const char *sdb_const_get_len(Sdb *s, const char *key, int *vlen); +RZ_API bool sdb_set(Sdb *, const char *key, const char *data); +RZ_API bool sdb_set_owned(Sdb *s, const char *key, char *val); +RZ_API bool sdb_concat(Sdb *s, const char *key, const char *value); +RZ_API bool sdb_uncat(Sdb *s, const char *key, const char *value); +RZ_API bool sdb_add(Sdb *s, const char *key, const char *val); RZ_API bool sdb_sync(Sdb *); RZ_API void sdbkv_free(RZ_NULLABLE SdbKv *kv); /* num.c */ RZ_API bool sdb_num_exists(Sdb *, const char *key); RZ_API int sdb_num_base(const char *s); -RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas); -RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas); -RZ_API int sdb_num_add(Sdb *s, const char *key, ut64 v, ut32 cas); -RZ_API ut64 sdb_num_inc(Sdb *s, const char *key, ut64 n, ut32 cas); -RZ_API ut64 sdb_num_dec(Sdb *s, const char *key, ut64 n, ut32 cas); -RZ_API int sdb_num_min(Sdb *s, const char *key, ut64 v, ut32 cas); -RZ_API int sdb_num_max(Sdb *s, const char *key, ut64 v, ut32 cas); +RZ_API ut64 sdb_num_get(Sdb *s, const char *key); +RZ_API bool sdb_num_set(Sdb *s, const char *key, ut64 v); +RZ_API bool sdb_num_add(Sdb *s, const char *key, ut64 v); +RZ_API ut64 sdb_num_inc(Sdb *s, const char *key, ut64 n); +RZ_API ut64 sdb_num_dec(Sdb *s, const char *key, ut64 n); +RZ_API int sdb_num_min(Sdb *s, const char *key, ut64 v); +RZ_API int sdb_num_max(Sdb *s, const char *key, ut64 v); /* ptr */ -RZ_API int sdb_ptr_set(Sdb *db, const char *key, void *p, ut32 cas); -RZ_API void *sdb_ptr_get(Sdb *db, const char *key, ut32 *cas); +RZ_API int sdb_ptr_set(Sdb *db, const char *key, void *p); +RZ_API void *sdb_ptr_get(Sdb *db, const char *key); /* create db */ RZ_API bool sdb_disk_create(Sdb *s); @@ -213,8 +210,6 @@ RZ_API bool sdb_unlink(Sdb *s); RZ_API int sdb_lock_wait(RZ_UNUSED const char *s); /* expiration */ -RZ_API bool sdb_expire_set(Sdb *s, const char *key, ut64 expire, ut32 cas); -RZ_API ut64 sdb_expire_get(Sdb *s, const char *key, ut32 *cas); RZ_API ut64 sdb_now(void); RZ_API ut64 sdb_unow(void); RZ_API ut32 sdb_hash(const char *key); @@ -232,43 +227,43 @@ RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r); RZ_API bool sdb_ns_unset(Sdb *s, const char *name, Sdb *r); // array -RZ_API bool sdb_array_contains(Sdb *s, const char *key, const char *val, ut32 *cas); -RZ_API bool sdb_array_contains_num(Sdb *s, const char *key, ut64 val, ut32 *cas); -RZ_API int sdb_array_indexof(Sdb *s, const char *key, const char *val, ut32 cas); -RZ_API int sdb_array_set(Sdb *s, const char *key, int idx, const char *val, ut32 cas); -RZ_API int sdb_array_set_num(Sdb *s, const char *key, int idx, ut64 val, ut32 cas); -RZ_API bool sdb_array_append(Sdb *s, const char *key, const char *val, ut32 cas); -RZ_API bool sdb_array_append_num(Sdb *s, const char *key, ut64 val, ut32 cas); -RZ_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val, ut32 cas); -RZ_API bool sdb_array_prepend_num(Sdb *s, const char *key, ut64 val, ut32 cas); -RZ_API char *sdb_array_get(Sdb *s, const char *key, int idx, ut32 *cas); -RZ_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx, ut32 *cas); -RZ_API int sdb_array_get_idx(Sdb *s, const char *key, const char *val, ut32 cas); // agetv -RZ_API int sdb_array_insert(Sdb *s, const char *key, int idx, const char *val, ut32 cas); -RZ_API int sdb_array_insert_num(Sdb *s, const char *key, int idx, ut64 val, ut32 cas); -RZ_API int sdb_array_unset(Sdb *s, const char *key, int n, ut32 cas); // leaves empty bucket -RZ_API int sdb_array_delete(Sdb *s, const char *key, int n, ut32 cas); -RZ_API void sdb_array_sort(Sdb *s, const char *key, ut32 cas); -RZ_API void sdb_array_sort_num(Sdb *s, const char *key, ut32 cas); +RZ_API bool sdb_array_contains(Sdb *s, const char *key, const char *val); +RZ_API bool sdb_array_contains_num(Sdb *s, const char *key, ut64 val); +RZ_API int sdb_array_indexof(Sdb *s, const char *key, const char *val); +RZ_API bool sdb_array_set(Sdb *s, const char *key, int idx, const char *val); +RZ_API bool sdb_array_set_num(Sdb *s, const char *key, int idx, ut64 val); +RZ_API bool sdb_array_append(Sdb *s, const char *key, const char *val); +RZ_API bool sdb_array_append_num(Sdb *s, const char *key, ut64 val); +RZ_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val); +RZ_API bool sdb_array_prepend_num(Sdb *s, const char *key, ut64 val); +RZ_API char *sdb_array_get(Sdb *s, const char *key, int idx); +RZ_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx); +RZ_API int sdb_array_get_idx(Sdb *s, const char *key, const char *val); // agetv +RZ_API bool sdb_array_insert(Sdb *s, const char *key, int idx, const char *val); +RZ_API int sdb_array_insert_num(Sdb *s, const char *key, int idx, ut64 val); +RZ_API int sdb_array_unset(Sdb *s, const char *key, int n); // leaves empty bucket +RZ_API int sdb_array_delete(Sdb *s, const char *key, int n); +RZ_API void sdb_array_sort(Sdb *s, const char *key); +RZ_API void sdb_array_sort_num(Sdb *s, const char *key); // set // Adds string `val` at the end of array `key`. -RZ_API int sdb_array_add(Sdb *s, const char *key, const char *val, ut32 cas); +RZ_API bool sdb_array_add(Sdb *s, const char *key, const char *val); // Adds number `val` at the end of array `key`. -RZ_API int sdb_array_add_num(Sdb *s, const char *key, ut64 val, ut32 cas); +RZ_API bool sdb_array_add_num(Sdb *s, const char *key, ut64 val); // Adds string `val` in the sorted array `key`. -RZ_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val, ut32 cas); +RZ_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val); // Adds number `val` in the sorted array `key`. -RZ_API int sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val, ut32 cas); +RZ_API bool sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val); // Removes the string `val` from the array `key`. -RZ_API int sdb_array_remove(Sdb *s, const char *key, const char *val, ut32 cas); +RZ_API int sdb_array_remove(Sdb *s, const char *key, const char *val); // Removes the number `val` from the array `key`. -RZ_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val, ut32 cas); +RZ_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val); // helpers RZ_API char *sdb_anext(char *str, char **next); @@ -281,20 +276,20 @@ RZ_API int sdb_array_length(Sdb *s, const char *key); int sdb_array_list(Sdb *s, const char *key); // Adds the string `val` to the start of array `key`. -RZ_API bool sdb_array_push(Sdb *s, const char *key, const char *val, ut32 cas); +RZ_API bool sdb_array_push(Sdb *s, const char *key, const char *val); // Returns the string at the start of array `key` or // NULL if there are no elements. -RZ_API char *sdb_array_pop(Sdb *s, const char *key, ut32 *cas); +RZ_API char *sdb_array_pop(Sdb *s, const char *key); // Adds the number `val` to the start of array `key`. -RZ_API int sdb_array_push_num(Sdb *s, const char *key, ut64 num, ut32 cas); +RZ_API int sdb_array_push_num(Sdb *s, const char *key, ut64 num); // Returns the number at the start of array `key`. -RZ_API ut64 sdb_array_pop_num(Sdb *s, const char *key, ut32 *cas); +RZ_API ut64 sdb_array_pop_num(Sdb *s, const char *key); -RZ_API char *sdb_array_pop_head(Sdb *s, const char *key, ut32 *cas); -RZ_API char *sdb_array_pop_tail(Sdb *s, const char *key, ut32 *cas); +RZ_API char *sdb_array_pop_head(Sdb *s, const char *key); +RZ_API char *sdb_array_pop_tail(Sdb *s, const char *key); /* Util.c */ RZ_API int sdb_isnum(const char *s); @@ -302,8 +297,8 @@ RZ_API bool sdb_isempty(Sdb *s); RZ_API const char *sdb_type(const char *k); RZ_API bool sdb_match(const char *str, const char *glob); -RZ_API int sdb_bool_set(Sdb *db, const char *str, bool v, ut32 cas); -RZ_API bool sdb_bool_get(Sdb *db, const char *str, ut32 *cas); +RZ_API bool sdb_bool_set(Sdb *db, const char *str, bool v); +RZ_API bool sdb_bool_get(Sdb *db, const char *str); // base64 RZ_API ut8 *sdb_decode(const char *in, int *len); diff --git a/librz/util/sdb/src/sdbht.c b/librz/util/sdb/src/sdbht.c index 3f32fa77dfe..6ed196100a1 100644 --- a/librz/util/sdb/src/sdbht.c +++ b/librz/util/sdb/src/sdbht.c @@ -26,7 +26,6 @@ static bool sdb_ht_internal_insert(HtSS *ht, const char *key, const char *value, } kvp.base.key_len = strlen(kvp.base.key); kvp.base.value_len = strlen(kvp.base.value); - kvp.expire = 0; return ht_ss_insert_kv(ht, (HtSSKv *)&kvp, update); err: diff --git a/librz/util/sdb/src/sdbht.h b/librz/util/sdb/src/sdbht.h index 937e5b8093d..b22f67967d2 100644 --- a/librz/util/sdb/src/sdbht.h +++ b/librz/util/sdb/src/sdbht.h @@ -14,8 +14,6 @@ extern "C" { typedef struct sdb_kv { // sub of HtSSKv so we can cast safely HtSSKv base; - ut32 cas; - ut64 expire; } SdbKv; static inline const char *sdbkv_key(const SdbKv *kv) { diff --git a/librz/util/sdb/src/text.c b/librz/util/sdb/src/text.c index dc10d564a43..add3e6e2c59 100644 --- a/librz/util/sdb/src/text.c +++ b/librz/util/sdb/src/text.c @@ -261,7 +261,7 @@ static void load_process_line(LoadCtx *ctx) { if (!*k || !*v) { break; } - sdb_set(ctx->cur_db, k, v, 0); + sdb_set(ctx->cur_db, k, v); break; } default: diff --git a/librz/util/serialize_spaces.c b/librz/util/serialize_spaces.c index 7bb1ffd410d..6df42eba713 100644 --- a/librz/util/serialize_spaces.c +++ b/librz/util/serialize_spaces.c @@ -20,7 +20,7 @@ #define KEY_SPACES "spaces" RZ_API void rz_serialize_spaces_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzSpaces *spaces) { - sdb_set(db, KEY_NAME, spaces->name, 0); + sdb_set(db, KEY_NAME, spaces->name); PJ *j = pj_new(); if (!j) { @@ -34,14 +34,14 @@ RZ_API void rz_serialize_spaces_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzSpaces *sp } pj_s(j, spaces->current ? spaces->current->name : "*"); // push current manually, will be popped on load pj_end(j); - sdb_set(db, KEY_SPACESTACK, pj_string(j), 0); + sdb_set(db, KEY_SPACESTACK, pj_string(j)); pj_free(j); Sdb *db_spaces = sdb_ns(db, KEY_SPACES, true); RBIter rbiter; RzSpace *space; rz_rbtree_foreach (spaces->spaces, rbiter, space, RzSpace, rb) { - sdb_set(db_spaces, space->name, "s", 0); + sdb_set(db_spaces, space->name, "s"); } } @@ -54,7 +54,7 @@ static bool foreach_space_cb(void *user, const SdbKv *kv) { RZ_API bool rz_serialize_spaces_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzSpaces *spaces, bool load_name, RZ_NULLABLE RzSerializeResultInfo *res) { if (load_name) { char *old_name = (char *)spaces->name; - spaces->name = sdb_get(db, KEY_NAME, NULL); + spaces->name = sdb_get(db, KEY_NAME); if (!spaces->name) { spaces->name = old_name; RZ_SERIALIZE_ERR(res, "failed to get spaces name from db"); @@ -72,7 +72,7 @@ RZ_API bool rz_serialize_spaces_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzSpaces *sp } sdb_foreach(db_spaces, foreach_space_cb, spaces); - char *stack_json_str = sdb_get(db, KEY_SPACESTACK, NULL); + char *stack_json_str = sdb_get(db, KEY_SPACESTACK); if (!stack_json_str) { RZ_SERIALIZE_ERR(res, "spacestack is missing"); return false; diff --git a/test/integration/test_project_migrate.c b/test/integration/test_project_migrate.c index d2ca7018e7d..81923664ee6 100644 --- a/test/integration/test_project_migrate.c +++ b/test/integration/test_project_migrate.c @@ -49,14 +49,14 @@ static bool test_migrate_v1_v2_noreturn() { Sdb *types_db = sdb_ns(analysis_db, "types", false); mu_assert_notnull(types_db, "types ns"); - mu_assert_null(sdb_get(types_db, "addr.1337.noreturn", 0), "old noreturn deleted"); - mu_assert_null(sdb_get(types_db, "addr.4242.noreturn", 0), "old noreturn deleted"); + mu_assert_null(sdb_get(types_db, "addr.1337.noreturn"), "old noreturn deleted"); + mu_assert_null(sdb_get(types_db, "addr.4242.noreturn"), "old noreturn deleted"); Sdb *noreturn_db = sdb_ns(analysis_db, "noreturn", false); mu_assert_notnull(noreturn_db, "noreturn ns"); - mu_assert_streq_free(sdb_get(noreturn_db, "addr.1337.noreturn", 0), "true", "new noreturn added"); - mu_assert_streq_free(sdb_get(noreturn_db, "addr.4242.noreturn", 0), "true", "new noreturn added"); + mu_assert_streq_free(sdb_get(noreturn_db, "addr.1337.noreturn"), "true", "new noreturn added"); + mu_assert_streq_free(sdb_get(noreturn_db, "addr.4242.noreturn"), "true", "new noreturn added"); rz_serialize_result_info_free(res); rz_project_free(prj); @@ -100,18 +100,18 @@ static bool test_migrate_v2_v3_typelink_callables() { Sdb *types_db = sdb_ns(analysis_db, "types", false); mu_assert_notnull(types_db, "types ns"); - mu_assert_null(sdb_get(types_db, "func._Exit.args", 0), "old function deleted"); - mu_assert_null(sdb_get(types_db, "_Exit", 0), "old function deleted"); - mu_assert_null(sdb_get(types_db, "link.080484b0", 0), "old typelink deleted"); + mu_assert_null(sdb_get(types_db, "func._Exit.args"), "old function deleted"); + mu_assert_null(sdb_get(types_db, "_Exit"), "old function deleted"); + mu_assert_null(sdb_get(types_db, "link.080484b0"), "old typelink deleted"); Sdb *callables_db = sdb_ns(analysis_db, "callables", false); mu_assert_notnull(callables_db, "callables ns"); - mu_assert_streq_free(sdb_get(callables_db, "func._Exit.args", 0), "1", "new callable added"); - mu_assert_streq_free(sdb_get(callables_db, "_Exit", 0), "func", "new callable added"); + mu_assert_streq_free(sdb_get(callables_db, "func._Exit.args"), "1", "new callable added"); + mu_assert_streq_free(sdb_get(callables_db, "_Exit"), "func", "new callable added"); Sdb *typelinks_db = sdb_ns(analysis_db, "typelinks", false); mu_assert_notnull(typelinks_db, "typelinks ns"); - mu_assert_streq_free(sdb_get(typelinks_db, "0x080484b0", 0), "char *", "new typelink added"); + mu_assert_streq_free(sdb_get(typelinks_db, "0x080484b0"), "char *", "new typelink added"); rz_serialize_result_info_free(res); rz_project_free(prj); @@ -164,7 +164,7 @@ static bool test_migrate_v3_v4_typelink() { // Typelinks still exist too Sdb *typelinks_db = sdb_ns(analysis_db, "typelinks", false); mu_assert_notnull(typelinks_db, "typelinks ns"); - mu_assert_streq_free(sdb_get(typelinks_db, "0x08048660", 0), "uint32_t", "new callable added"); + mu_assert_streq_free(sdb_get(typelinks_db, "0x08048660"), "uint32_t", "new callable added"); rz_serialize_result_info_free(res); rz_project_free(prj); @@ -185,9 +185,9 @@ static bool test_migrate_v4_v5_types() { Sdb *types_db = sdb_ns(analysis_db, "types", false); mu_assert_notnull(types_db, "types ns"); - mu_assert_streq_free(sdb_get(types_db, "unknown_t", 0), "type", "unknown_t added"); - mu_assert_streq_free(sdb_get(types_db, "type.unknown_t", 0), "d", "unknown_t added"); - mu_assert_streq_free(sdb_get(types_db, "type.unknown_t.size", 0), "32", "unknown_t added"); + mu_assert_streq_free(sdb_get(types_db, "unknown_t"), "type", "unknown_t added"); + mu_assert_streq_free(sdb_get(types_db, "type.unknown_t"), "d", "unknown_t added"); + mu_assert_streq_free(sdb_get(types_db, "type.unknown_t.size"), "32", "unknown_t added"); rz_serialize_result_info_free(res); rz_project_free(prj); @@ -249,21 +249,21 @@ static bool test_migrate_v7_v8_zignatures() { Sdb *config_db = sdb_ns(core_db, "config", false); mu_assert_notnull(config_db, "config ns"); - mu_assert_streq_free(sdb_get(config_db, "analysis.apply.signature", 0), "true", "config"); - mu_assert_null(sdb_get(config_db, "zign.autoload", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.diff.bthresh", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.diff.gthresh", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.match.bytes", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.match.graph", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.match.hash", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.match.offset", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.match.refs", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.match.types", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.maxsz", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.mincc", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.minsz", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.prefix", 0), "config"); - mu_assert_null(sdb_get(config_db, "zign.threshold", 0), "config"); + mu_assert_streq_free(sdb_get(config_db, "analysis.apply.signature"), "true", "config"); + mu_assert_null(sdb_get(config_db, "zign.autoload"), "config"); + mu_assert_null(sdb_get(config_db, "zign.diff.bthresh"), "config"); + mu_assert_null(sdb_get(config_db, "zign.diff.gthresh"), "config"); + mu_assert_null(sdb_get(config_db, "zign.match.bytes"), "config"); + mu_assert_null(sdb_get(config_db, "zign.match.graph"), "config"); + mu_assert_null(sdb_get(config_db, "zign.match.hash"), "config"); + mu_assert_null(sdb_get(config_db, "zign.match.offset"), "config"); + mu_assert_null(sdb_get(config_db, "zign.match.refs"), "config"); + mu_assert_null(sdb_get(config_db, "zign.match.types"), "config"); + mu_assert_null(sdb_get(config_db, "zign.maxsz"), "config"); + mu_assert_null(sdb_get(config_db, "zign.mincc"), "config"); + mu_assert_null(sdb_get(config_db, "zign.minsz"), "config"); + mu_assert_null(sdb_get(config_db, "zign.prefix"), "config"); + mu_assert_null(sdb_get(config_db, "zign.threshold"), "config"); rz_serialize_result_info_free(res); rz_project_free(prj); @@ -309,7 +309,7 @@ static bool test_migrate_v10_v11_stack_vars_bp() { mu_assert_notnull(functions_db, "functions ns"); // bp vars - const char *val = sdb_const_get(functions_db, "0x113c", 0); + const char *val = sdb_const_get(functions_db, "0x113c"); const char *varfunc_expect = "{\"name\":\"dbg.varfunc\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":-8,\"maxstack\":24,\"ninstr\":14," "\"bp_frame\":true,\"bp_off\":8,\"bbs\":[4412]," @@ -329,7 +329,7 @@ static bool test_migrate_v10_v11_stack_vars_bp() { mu_assert_streq(val, varfunc_expect, "varfunc"); // also some reg vars - val = sdb_const_get(functions_db, "0x1175", 0); + val = sdb_const_get(functions_db, "0x1175"); const char *main_expect = "{\"name\":\"dbg.main\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":-8,\"maxstack\":24,\"ninstr\":15," "\"bp_frame\":true,\"bp_off\":8,\"bbs\":[4469]," @@ -365,7 +365,7 @@ static bool test_migrate_v10_v11_stack_vars_sp() { mu_assert_notnull(functions_db, "functions ns"); // sp vars - const char *val = sdb_const_get(functions_db, "0x1137", 0); + const char *val = sdb_const_get(functions_db, "0x1137"); const char *varfunc_expect = "{\"name\":\"sym.varfunc\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":-8,\"maxstack\":16,\"ninstr\":12," "\"bp_frame\":true,\"bbs\":[4407]," @@ -385,7 +385,7 @@ static bool test_migrate_v10_v11_stack_vars_sp() { mu_assert_streq(val, varfunc_expect, "varfunc"); // also some reg vars - val = sdb_const_get(functions_db, "0x1174", 0); + val = sdb_const_get(functions_db, "0x1174"); const char *main_expect = "{\"name\":\"main\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":-8,\"maxstack\":24,\"ninstr\":13," "\"bp_frame\":true,\"bbs\":[4468],\"vars\":[" @@ -415,9 +415,9 @@ static bool test_migrate_v2_v12() { mu_assert_notnull(core_db, "core ns"); Sdb *config_db = sdb_ns(core_db, "config", false); mu_assert_notnull(config_db, "debug ns"); - mu_assert_notnull(sdb_const_get(config_db, "asm.debuginfo", 0), "asm.debuginfo"); - mu_assert_notnull(sdb_const_get(config_db, "asm.debuginfo.abspath", 0), "asm.debuginfo.abspath"); - mu_assert_notnull(sdb_const_get(config_db, "asm.debuginfo.file", 0), "asm.debuginfo.file"); + mu_assert_notnull(sdb_const_get(config_db, "asm.debuginfo"), "asm.debuginfo"); + mu_assert_notnull(sdb_const_get(config_db, "asm.debuginfo.abspath"), "asm.debuginfo.abspath"); + mu_assert_notnull(sdb_const_get(config_db, "asm.debuginfo.file"), "asm.debuginfo.file"); rz_serialize_result_info_free(res); rz_project_free(prj); @@ -441,7 +441,7 @@ static bool test_migrate_v9_v10_v11_stack_vars_bp() { mu_assert_notnull(functions_db, "functions ns"); // bp vars - const char *val = sdb_const_get(functions_db, "0x113c", 0); + const char *val = sdb_const_get(functions_db, "0x113c"); const char *varfunc_expect = "{\"name\":\"dbg.varfunc\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":8,\"maxstack\":24,\"ninstr\":14," "\"bp_frame\":true,\"bp_off\":8,\"bbs\":[4412]," @@ -461,7 +461,7 @@ static bool test_migrate_v9_v10_v11_stack_vars_bp() { mu_assert_streq(val, varfunc_expect, "varfunc"); // also some reg vars - val = sdb_const_get(functions_db, "0x1175", 0); + val = sdb_const_get(functions_db, "0x1175"); const char *main_expect = "{\"name\":\"dbg.main\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":8,\"maxstack\":24,\"ninstr\":15," "\"bp_frame\":true,\"bp_off\":8,\"bbs\":[4469]," @@ -497,7 +497,7 @@ static bool test_migrate_v9_v10_v11_stack_vars_sp() { mu_assert_notnull(functions_db, "functions ns"); // sp vars - const char *val = sdb_const_get(functions_db, "0x1137", 0); + const char *val = sdb_const_get(functions_db, "0x1137"); const char *varfunc_expect = "{\"name\":\"sym.varfunc\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":-8,\"maxstack\":16,\"ninstr\":12," "\"bp_frame\":true,\"bbs\":[4407]," @@ -517,7 +517,7 @@ static bool test_migrate_v9_v10_v11_stack_vars_sp() { mu_assert_streq(val, varfunc_expect, "varfunc"); // also some reg vars - val = sdb_const_get(functions_db, "0x1174", 0); + val = sdb_const_get(functions_db, "0x1174"); const char *main_expect = "{\"name\":\"main\",\"bits\":64,\"type\":4,\"cc\":\"amd64\",\"stack\":-8,\"maxstack\":24,\"ninstr\":13," "\"bp_frame\":true,\"bbs\":[4468],\"vars\":[" @@ -562,13 +562,13 @@ static bool test_migrate_v15_v16_str_config() { mu_assert_notnull(core_db, "core ns"); Sdb *config_db = sdb_ns(core_db, "config", false); mu_assert_notnull(config_db, "config ns"); - mu_assert_null(sdb_get(config_db, "bin.maxstr", 0), "config"); - mu_assert_null(sdb_get(config_db, "bin.minstr", 0), "config"); - mu_assert_null(sdb_get(config_db, "bin.str.enc", 0), "config"); - mu_assert_null(sdb_get(config_db, "bin.maxstrbuf", 0), "config"); - mu_assert_streq_free(sdb_get(config_db, "str.search.min_length", 0), "6", "config"); - mu_assert_streq_free(sdb_get(config_db, "str.search.encoding", 0), "utf8", "config"); - mu_assert_streq_free(sdb_get(config_db, "str.search.buffer_size", 0), "0x00b00123", "config"); + mu_assert_null(sdb_get(config_db, "bin.maxstr"), "config"); + mu_assert_null(sdb_get(config_db, "bin.minstr"), "config"); + mu_assert_null(sdb_get(config_db, "bin.str.enc"), "config"); + mu_assert_null(sdb_get(config_db, "bin.maxstrbuf"), "config"); + mu_assert_streq_free(sdb_get(config_db, "str.search.min_length"), "6", "config"); + mu_assert_streq_free(sdb_get(config_db, "str.search.encoding"), "utf8", "config"); + mu_assert_streq_free(sdb_get(config_db, "str.search.buffer_size"), "0x00b00123", "config"); rz_serialize_result_info_free(res); rz_project_free(prj); mu_end; @@ -584,7 +584,7 @@ static bool test_migrate_v16_v17_flags_base() { mu_assert_notnull(core_db, "core ns"); Sdb *config_db = sdb_ns(core_db, "flags", false); mu_assert_notnull(config_db, "config ns"); - mu_assert_null(sdb_get(config_db, "base", 0), "flags base"); + mu_assert_null(sdb_get(config_db, "base"), "flags base"); rz_serialize_result_info_free(res); rz_project_free(prj); mu_end; diff --git a/test/unit/test_analysis_cc.c b/test/unit/test_analysis_cc.c index 5f92edc47eb..131bbf83d4b 100644 --- a/test/unit/test_analysis_cc.c +++ b/test/unit/test_analysis_cc.c @@ -8,25 +8,25 @@ static Sdb *ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "cc.sectarian.ret", "rax", 0); - sdb_set(db, "cc.sectarian.arg1", "rcx", 0); - sdb_set(db, "cc.sectarian.arg0", "rdx", 0); - sdb_set(db, "cc.sectarian.argn", "stack", 0); - sdb_set(db, "cc.sectarian.maxargs", "2", 0); - sdb_set(db, "sectarian", "cc", 0); + sdb_set(db, "cc.sectarian.ret", "rax"); + sdb_set(db, "cc.sectarian.arg1", "rcx"); + sdb_set(db, "cc.sectarian.arg0", "rdx"); + sdb_set(db, "cc.sectarian.argn", "stack"); + sdb_set(db, "cc.sectarian.maxargs", "2"); + sdb_set(db, "sectarian", "cc"); return db; } static Sdb *ref_db_self_err() { Sdb *db = sdb_new0(); - sdb_set(db, "cc.sectarian.ret", "rax", 0); - sdb_set(db, "cc.sectarian.self", "rsi", 0); - sdb_set(db, "cc.sectarian.error", "rdi", 0); - sdb_set(db, "cc.sectarian.arg1", "rcx", 0); - sdb_set(db, "cc.sectarian.arg0", "rdx", 0); - sdb_set(db, "cc.sectarian.argn", "stack", 0); - sdb_set(db, "cc.sectarian.maxargs", "2", 0); - sdb_set(db, "sectarian", "cc", 0); + sdb_set(db, "cc.sectarian.ret", "rax"); + sdb_set(db, "cc.sectarian.self", "rsi"); + sdb_set(db, "cc.sectarian.error", "rdi"); + sdb_set(db, "cc.sectarian.arg1", "rcx"); + sdb_set(db, "cc.sectarian.arg0", "rdx"); + sdb_set(db, "cc.sectarian.argn", "stack"); + sdb_set(db, "cc.sectarian.maxargs", "2"); + sdb_set(db, "sectarian", "cc"); return db; } diff --git a/test/unit/test_analysis_function.c b/test/unit/test_analysis_function.c index e73ebd6c980..5f88fb573cc 100644 --- a/test/unit/test_analysis_function.c +++ b/test/unit/test_analysis_function.c @@ -18,24 +18,24 @@ static void setup_types_db(RzTypeDB *typedb) { } static void setup_sdb_for_function(Sdb *res) { - sdb_set(res, "ExitProcess", "func", 0); - sdb_num_set(res, "func.ExitProcess.args", 0, 0); - sdb_set(res, "func.ExitProcess.ret", "void", 0); - sdb_set(res, "ReadFile", "func", 0); - sdb_num_set(res, "func.ReadFile.args", 0, 0); - sdb_set(res, "func.ReadFile.ret", "void", 0); - sdb_set(res, "memcpy", "func", 0); - sdb_num_set(res, "func.memcpy.args", 0, 0); - sdb_set(res, "func.memcpy.ret", "void", 0); - sdb_set(res, "strchr", "func", 0); - sdb_num_set(res, "func.strchr.args", 0, 0); - sdb_set(res, "func.strchr.ret", "void", 0); - sdb_set(res, "__stack_chk_fail", "func", 0); - sdb_num_set(res, "func.__stack_chk_fail.args", 0, 0); - sdb_set(res, "func.__stack_chk_fail.ret", "void", 0); - sdb_set(res, "WSAStartup", "func", 0); - sdb_num_set(res, "func.WSAStartup.args", 0, 0); - sdb_set(res, "func.WSAStartup.ret", "void", 0); + sdb_set(res, "ExitProcess", "func"); + sdb_num_set(res, "func.ExitProcess.args", 0); + sdb_set(res, "func.ExitProcess.ret", "void"); + sdb_set(res, "ReadFile", "func"); + sdb_num_set(res, "func.ReadFile.args", 0); + sdb_set(res, "func.ReadFile.ret", "void"); + sdb_set(res, "memcpy", "func"); + sdb_num_set(res, "func.memcpy.args", 0); + sdb_set(res, "func.memcpy.ret", "void"); + sdb_set(res, "strchr", "func"); + sdb_num_set(res, "func.strchr.args", 0); + sdb_set(res, "func.strchr.ret", "void"); + sdb_set(res, "__stack_chk_fail", "func"); + sdb_num_set(res, "func.__stack_chk_fail.args", 0); + sdb_set(res, "func.__stack_chk_fail.ret", "void"); + sdb_set(res, "WSAStartup", "func"); + sdb_num_set(res, "func.WSAStartup.args", 0); + sdb_set(res, "func.WSAStartup.ret", "void"); } bool ht_up_count(void *user, const ut64 k, const void *v) { diff --git a/test/unit/test_debug_session.c b/test/unit/test_debug_session.c index b3a22030ca1..7323826ac04 100644 --- a/test/unit/test_debug_session.c +++ b/test/unit/test_debug_session.c @@ -9,14 +9,14 @@ Sdb *ref_db() { Sdb *db = sdb_new0(); - sdb_num_set(db, "maxcnum", 1, 0); + sdb_num_set(db, "maxcnum", 1); Sdb *registers_db = sdb_ns(db, "registers", true); - sdb_set(registers_db, "0x100", "[{\"cnum\":0,\"data\":1094861636},{\"cnum\":1,\"data\":3735928559}]", 0); + sdb_set(registers_db, "0x100", "[{\"cnum\":0,\"data\":1094861636},{\"cnum\":1,\"data\":3735928559}]"); Sdb *memory_sdb = sdb_ns(db, "memory", true); - sdb_set(memory_sdb, "0x7ffffffff000", "[{\"cnum\":0,\"data\":170},{\"cnum\":1,\"data\":187}]", 0); - sdb_set(memory_sdb, "0x7ffffffff001", "[{\"cnum\":0,\"data\":0},{\"cnum\":1,\"data\":1}]", 0); + sdb_set(memory_sdb, "0x7ffffffff000", "[{\"cnum\":0,\"data\":170},{\"cnum\":1,\"data\":187}]"); + sdb_set(memory_sdb, "0x7ffffffff001", "[{\"cnum\":0,\"data\":0},{\"cnum\":1,\"data\":1}]"); Sdb *checkpoints_sdb = sdb_ns(db, "checkpoints", true); sdb_set(checkpoints_sdb, "0x0", "{" @@ -38,8 +38,7 @@ Sdb *ref_db() { "\"snaps\":[" "{\"name\":\"[stack]\",\"addr\":8796092882944,\"addr_end\":8796092883200,\"size\":256,\"data\":\"8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8A==\",\"perm\":7,\"user\":0,\"shared\":true}" "]" - "}", - 0); + "}"); return db; } diff --git a/test/unit/test_sdb_array.c b/test/unit/test_sdb_array.c index 4b94e491226..cf8762fcc3b 100644 --- a/test/unit/test_sdb_array.c +++ b/test/unit/test_sdb_array.c @@ -8,25 +8,25 @@ bool test_sdb_array_push_pop(void) { Sdb *db = sdb_new(NULL, NULL, false); char *p; - sdb_array_push(db, "foo", "foo", 0); - sdb_array_push(db, "foo", "bar", 0); - sdb_array_push(db, "foo", "cow", 0); + sdb_array_push(db, "foo", "foo"); + sdb_array_push(db, "foo", "bar"); + sdb_array_push(db, "foo", "cow"); - mu_assert_streq(sdb_const_get(db, "foo", 0), "cow,bar,foo", "Not all items found"); + mu_assert_streq(sdb_const_get(db, "foo"), "cow,bar,foo", "Not all items found"); - p = sdb_array_pop(db, "foo", NULL); + p = sdb_array_pop(db, "foo"); mu_assert_streq(p, "cow", "cow was not at the top"); free(p); - p = sdb_array_pop(db, "foo", NULL); + p = sdb_array_pop(db, "foo"); mu_assert_streq(p, "bar", "bar was not at the top"); free(p); - p = sdb_array_pop(db, "foo", NULL); + p = sdb_array_pop(db, "foo"); mu_assert_streq(p, "foo", "foo was not at the top"); free(p); - p = sdb_array_pop(db, "foo", NULL); + p = sdb_array_pop(db, "foo"); mu_assert_eq((int)(size_t)p, (int)(size_t)NULL, "there shouldn't be any element in the array"); free(p); @@ -36,19 +36,19 @@ bool test_sdb_array_push_pop(void) { bool test_sdb_array_add_remove(void) { Sdb *db = sdb_new(NULL, NULL, false); - sdb_array_add(db, "foo", "foo", 0); - sdb_array_add(db, "foo", "bar", 0); - sdb_array_add(db, "foo", "cow", 0); + sdb_array_add(db, "foo", "foo"); + sdb_array_add(db, "foo", "bar"); + sdb_array_add(db, "foo", "cow"); - mu_assert_streq(sdb_const_get(db, "foo", 0), "foo,bar,cow", "Not all items found"); + mu_assert_streq(sdb_const_get(db, "foo"), "foo,bar,cow", "Not all items found"); - sdb_array_remove(db, "foo", "bar", 0); - mu_assert_streq(sdb_const_get(db, "foo", 0), "foo,cow", "bar was not deleted"); - sdb_array_remove(db, "foo", "nothing", 0); - mu_assert_streq(sdb_const_get(db, "foo", 0), "foo,cow", "nothing should be deleted"); - sdb_array_remove(db, "foo", "cow", 0); - sdb_array_remove(db, "foo", "foo", 0); - mu_assert_eq((int)(size_t)sdb_const_get(db, "foo", 0), (int)(size_t)NULL, "all elements should be deleted"); + sdb_array_remove(db, "foo", "bar"); + mu_assert_streq(sdb_const_get(db, "foo"), "foo,cow", "bar was not deleted"); + sdb_array_remove(db, "foo", "nothing"); + mu_assert_streq(sdb_const_get(db, "foo"), "foo,cow", "nothing should be deleted"); + sdb_array_remove(db, "foo", "cow"); + sdb_array_remove(db, "foo", "foo"); + mu_assert_eq((int)(size_t)sdb_const_get(db, "foo"), (int)(size_t)NULL, "all elements should be deleted"); sdb_free(db); mu_end; diff --git a/test/unit/test_sdb_diff.c b/test/unit/test_sdb_diff.c index eec326dc1c7..5b47a06360e 100644 --- a/test/unit/test_sdb_diff.c +++ b/test/unit/test_sdb_diff.c @@ -13,21 +13,21 @@ static Sdb *test_sdb_new(const char *file) { #else Sdb *r = sdb_new0(); #endif - sdb_set(r, "some", "stuff", 0); - sdb_set(r, "and", "even", 0); - sdb_set(r, "more", "stuff", 0); + sdb_set(r, "some", "stuff"); + sdb_set(r, "and", "even"); + sdb_set(r, "more", "stuff"); sdb_ns(r, "emptyns", true); Sdb *test_ns = sdb_ns(r, "test", true); - sdb_set(test_ns, "a", "123", 0); - sdb_set(test_ns, "b", "test", 0); - sdb_set(test_ns, "c", "hello", 0); + sdb_set(test_ns, "a", "123"); + sdb_set(test_ns, "b", "test"); + sdb_set(test_ns, "c", "hello"); Sdb *subspace_ns = sdb_ns(test_ns, "subspace", true); - sdb_set(subspace_ns, "some", "values", 0); - sdb_set(subspace_ns, "are", "saved", 0); - sdb_set(subspace_ns, "here", "lol", 0); + sdb_set(subspace_ns, "some", "values"); + sdb_set(subspace_ns, "are", "saved"); + sdb_set(subspace_ns, "here", "lol"); return r; } @@ -190,8 +190,8 @@ bool test_sdb_diff_ns_sub() { bool test_sdb_diff_kv() { Sdb *a = test_sdb_new("kv_a.sdb"); Sdb *b = test_sdb_new("kv_b.sdb"); - sdb_unset(b, "more", 0); - sdb_unset(sdb_ns(b, "test", false), "a", 0); + sdb_unset(b, "more"); + sdb_unset(sdb_ns(b, "test", false), "a"); mu_assert("kv removed (no diff)", !diff_str(a, b, NULL)); char *diff; @@ -218,8 +218,8 @@ bool test_sdb_diff_kv() { bool test_sdb_diff_kv_value() { Sdb *a = test_sdb_new("kv_value_a.sdb"); Sdb *b = test_sdb_new("kv_value_b.sdb"); - sdb_set(b, "more", "cowbell", 0); - sdb_set(sdb_ns(b, "test", false), "a", "reaper", 0); + sdb_set(b, "more", "cowbell"); + sdb_set(sdb_ns(b, "test", false), "a", "reaper"); mu_assert("kv value changed (no diff)", !diff_str(a, b, NULL)); char *diff; diff --git a/test/unit/test_sdb_sdb.c b/test/unit/test_sdb_sdb.c index e570dd0f828..1205849c198 100644 --- a/test/unit/test_sdb_sdb.c +++ b/test/unit/test_sdb_sdb.c @@ -9,11 +9,11 @@ bool test_sdb_kv_list(void) { Sdb *db = sdb_new(NULL, NULL, false); - sdb_set(db, "first__XX", " 2", 0); - sdb_set(db, "second_XXXX", " 4", 0); - sdb_set(db, "third__XXXXX", " 5", 0); - sdb_set(db, "fourth_XXX", " 3", 0); - sdb_set(db, "fifth__X", " 1", 0); + sdb_set(db, "first__XX", " 2"); + sdb_set(db, "second_XXXX", " 4"); + sdb_set(db, "third__XXXXX", " 5"); + sdb_set(db, "fourth_XXX", " 3"); + sdb_set(db, "fifth__X", " 1"); RzPVector *items = sdb_get_items(db, true); mu_assert_eq(rz_pvector_len(items), 5, "KV count"); @@ -35,20 +35,20 @@ bool test_sdb_kv_list(void) { static bool foreach_delete_cb(void *user, const SdbKv *kv) { if (strcmp(sdbkv_key(kv), "bar")) { - sdb_unset(user, sdbkv_key(kv), 0); + sdb_unset(user, sdbkv_key(kv)); } return true; } bool test_sdb_foreach_delete(void) { Sdb *db = sdb_new(NULL, NULL, false); - sdb_set(db, "foo", "bar", 0); - sdb_set(db, "bar", "cow", 0); - sdb_set(db, "low", "bar", 0); + sdb_set(db, "foo", "bar"); + sdb_set(db, "bar", "cow"); + sdb_set(db, "low", "bar"); sdb_foreach(db, foreach_delete_cb, db); - mu_assert("Item not deleted", !(int)(size_t)sdb_const_get(db, "foo", NULL)); - mu_assert("Item not deleted", (int)(size_t)sdb_const_get(db, "bar", NULL)); + mu_assert("Item not deleted", !(int)(size_t)sdb_const_get(db, "foo")); + mu_assert("Item not deleted", (int)(size_t)sdb_const_get(db, "bar")); sdb_free(db); mu_end; @@ -56,15 +56,15 @@ bool test_sdb_foreach_delete(void) { bool test_sdb_list_delete(void) { Sdb *db = sdb_new(NULL, NULL, false); - sdb_set(db, "foo", "bar", 0); - sdb_set(db, "bar", "cow", 0); - sdb_set(db, "low", "bar", 0); + sdb_set(db, "foo", "bar"); + sdb_set(db, "bar", "cow"); + sdb_set(db, "low", "bar"); RzPVector *items = sdb_get_items(db, true); void **iter; rz_pvector_foreach (items, iter) { SdbKv *kv = *iter; // printf ("--> %s\n", kv->key); - sdb_unset(db, sdbkv_key(kv), 0); + sdb_unset(db, sdbkv_key(kv)); } RzPVector *items2 = sdb_get_items(db, true); mu_assert("List is empty", !rz_pvector_len(items2)); @@ -77,7 +77,7 @@ bool test_sdb_list_delete(void) { bool test_sdb_list_big(void) { Sdb *db = sdb_new0(); for (int i = 0; i < 5000; i++) { - sdb_num_set(db, sdb_fmt("%d", i), i + 1, 0); + sdb_num_set(db, sdb_fmt("%d", i), i + 1); } RzPVector *items = sdb_get_items(db, true); mu_assert_eq(rz_pvector_len(items), 5000, "KV count"); @@ -89,13 +89,13 @@ bool test_sdb_list_big(void) { bool test_sdb_delete_none(void) { Sdb *db = sdb_new(NULL, NULL, false); - sdb_set(db, "foo", "bar", 0); - sdb_set(db, "bar", "cow", 0); - sdb_set(db, "low", "bar", 0); - sdb_unset(db, "fundas", 0); - sdb_unset(db, "barnas", 0); - sdb_unset(db, "bar", 0); - sdb_unset(db, "pinuts", 0); + sdb_set(db, "foo", "bar"); + sdb_set(db, "bar", "cow"); + sdb_set(db, "low", "bar"); + sdb_unset(db, "fundas"); + sdb_unset(db, "barnas"); + sdb_unset(db, "bar"); + sdb_unset(db, "pinuts"); RzPVector *items = sdb_get_items(db, false); mu_assert_eq(rz_pvector_len(items), 2, "Unmatched rows"); rz_pvector_free(items); @@ -109,10 +109,10 @@ bool test_sdb_delete_alot(void) { int i; for (i = 0; i < count; i++) { - sdb_set(db, sdb_fmt("key.%d", i), "bar", 0); + sdb_set(db, sdb_fmt("key.%d", i), "bar"); } for (i = 0; i < count; i++) { - sdb_unset(db, sdb_fmt("key.%d", i), 0); + sdb_unset(db, sdb_fmt("key.%d", i)); } RzPVector *items = sdb_get_items(db, false); mu_assert_eq(rz_pvector_len(items), 0, "Unmatched rows"); @@ -126,9 +126,9 @@ bool test_sdb_milset(void) { int i = 0; const int MAX = 1999; Sdb *s = sdb_new0(); - sdb_set(s, "foo", "bar", 0); + sdb_set(s, "foo", "bar"); for (i = 0; i < MAX; i++) { - if (!sdb_set(s, "foo", "bar", 0)) { + if (!sdb_set(s, "foo", "bar")) { mu_assert("milset: sdb_set failed", 0); break; } @@ -142,10 +142,10 @@ bool test_sdb_milset_random(void) { const int MAX = 1999; bool solved = true; Sdb *s = sdb_new0(); - sdb_set(s, "foo", "bar", 0); + sdb_set(s, "foo", "bar"); for (i = 0; i < MAX; i++) { char *v = sdb_fmt("bar%d", i); - if (!sdb_set(s, "foo", v, 0)) { + if (!sdb_set(s, "foo", v)) { solved = false; break; } @@ -165,8 +165,8 @@ bool test_sdb_namespace(void) { unlink(dbname); Sdb *n = sdb_ns(s, dbname, 1); if (n) { - sdb_set(n, "user.pancake", "pancake foo", 0); - sdb_set(n, "user.password", "jklsdf8r3o", 0); + sdb_set(n, "user.pancake", "pancake foo"); + sdb_set(n, "user.password", "jklsdf8r3o"); /* FIXED BUG1 ns_sync doesnt creates the database file */ sdb_ns_sync(s); // sdb_sync (n); @@ -188,7 +188,7 @@ bool test_sdb_namespace(void) { static bool foreach_filter_user_cb(void *user, const SdbKv *kv) { Sdb *db = (Sdb *)user; const char *key = sdbkv_key(kv); - const char *v = sdb_const_get(db, key, NULL); + const char *v = sdb_const_get(db, key); if (!v) { return false; } @@ -197,15 +197,15 @@ static bool foreach_filter_user_cb(void *user, const SdbKv *kv) { bool test_sdb_kv_list_filtered(void) { Sdb *db = sdb_new(NULL, NULL, false); - sdb_set(db, "crow", NULL, 0); - sdb_set(db, "foo", "bar", 0); - sdb_set(db, "bar", "cow", 0); - sdb_set(db, "bag", "horse", 0); - sdb_set(db, "boo", "cow", 0); - sdb_set(db, "bog", "horse", 0); - sdb_set(db, "low", "bar", 0); - sdb_set(db, "bip", "cow", 0); - sdb_set(db, "big", "horse", 0); + sdb_set(db, "crow", NULL); + sdb_set(db, "foo", "bar"); + sdb_set(db, "bar", "cow"); + sdb_set(db, "bag", "horse"); + sdb_set(db, "boo", "cow"); + sdb_set(db, "bog", "horse"); + sdb_set(db, "low", "bar"); + sdb_set(db, "bip", "cow"); + sdb_set(db, "big", "horse"); RzPVector *items = sdb_get_items_filter(db, foreach_filter_user_cb, db, true); mu_assert_eq(rz_pvector_len(items), 3, "list length"); SdbKv *kv = rz_pvector_at(items, 0); @@ -224,25 +224,25 @@ bool test_sdb_kv_list_filtered(void) { bool test_sdb_copy() { Sdb *src = sdb_new0(); - sdb_set(src, "i am", "thou", 0); - sdb_set(src, "thou art", "i", 0); + sdb_set(src, "i am", "thou"); + sdb_set(src, "thou art", "i"); Sdb *sub = sdb_ns(src, "subns", true); - sdb_set(sub, "rizin", "cool", 0); - sdb_set(sub, "cutter", "cooler", 0); + sdb_set(sub, "rizin", "cool"); + sdb_set(sub, "cutter", "cooler"); Sdb *dst = sdb_new0(); sdb_copy(src, dst); sdb_free(src); mu_assert_eq(sdb_count(dst), 2, "root count"); - mu_assert_streq(sdb_const_get(dst, "i am", 0), "thou", "root entries"); - mu_assert_streq(sdb_const_get(dst, "thou art", 0), "i", "root entries"); + mu_assert_streq(sdb_const_get(dst, "i am"), "thou", "root entries"); + mu_assert_streq(sdb_const_get(dst, "thou art"), "i", "root entries"); mu_assert_eq(ls_length(dst->ns), 1, "sub ns count"); Sdb *dst_sub = sdb_ns(dst, "subns", false); mu_assert_notnull(dst_sub, "subns"); mu_assert_eq(sdb_count(dst_sub), 2, "sub ns entries count"); - mu_assert_streq(sdb_const_get(dst_sub, "rizin", 0), "cool", "sub ns entries"); - mu_assert_streq(sdb_const_get(dst_sub, "cutter", 0), "cooler", "sub ns entries"); + mu_assert_streq(sdb_const_get(dst_sub, "rizin"), "cool", "sub ns entries"); + mu_assert_streq(sdb_const_get(dst_sub, "cutter"), "cooler", "sub ns entries"); sdb_free(dst); mu_end; @@ -318,58 +318,58 @@ static const char *text_ref_path_last_line = static Sdb *text_ref_simple_db() { Sdb *db = sdb_new0(); - sdb_set(db, "somekey", "somevalue", 0); - sdb_set(db, "aaa", "stuff", 0); - sdb_set(db, "bbb", "other stuff", 0); + sdb_set(db, "somekey", "somevalue"); + sdb_set(db, "aaa", "stuff"); + sdb_set(db, "bbb", "other stuff"); Sdb *sub = sdb_ns(db, "subnamespace", true); - sdb_set(sub, "key in sub", "value in sub", 0); - sdb_set(sub, "/more stuff", "in sub", 0); + sdb_set(sub, "key in sub", "value in sub"); + sdb_set(sub, "/more stuff", "in sub"); Sdb *subsub = sdb_ns(sub, "subsub", true); - sdb_set(subsub, "some stuff", "also down here", 0); + sdb_set(subsub, "some stuff", "also down here"); return db; } static Sdb *text_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, PERTURBATOR "key" PERTURBATOR, PERTURBATOR "value" PERTURBATOR, 0); - sdb_set(db, "aaa", "stuff", 0); - sdb_set(db, "bbb", "other stuff", 0); + sdb_set(db, PERTURBATOR "key" PERTURBATOR, PERTURBATOR "value" PERTURBATOR); + sdb_set(db, "aaa", "stuff"); + sdb_set(db, "bbb", "other stuff"); Sdb *sub = sdb_ns(db, "sub" PERTURBATOR "namespace", true); - sdb_set(sub, "key" PERTURBATOR "in sub", "value" PERTURBATOR "in sub", 0); - sdb_set(sub, "/more stuff\n", "\nin\nsub\n", 0); + sdb_set(sub, "key" PERTURBATOR "in sub", "value" PERTURBATOR "in sub"); + sdb_set(sub, "/more stuff\n", "\nin\nsub\n"); Sdb *subsub = sdb_ns(sub, "subsub", true); - sdb_set(subsub, "some stuff", "also down here", 0); + sdb_set(subsub, "some stuff", "also down here"); return db; } static Sdb *text_ref_bad_nl_db() { Sdb *db = sdb_new0(); - sdb_set(db, "non", "unix", 0); - sdb_set(db, "newlines", "should", 0); - sdb_set(db, "be", "banned", 0); + sdb_set(db, "non", "unix"); + sdb_set(db, "newlines", "should"); + sdb_set(db, "be", "banned"); return db; } static Sdb *text_ref_broken_db() { Sdb *db = sdb_new0(); - sdb_set(db, "///unnecessary", "/escapesuxa", 0); + sdb_set(db, "///unnecessary", "/escapesuxa"); Sdb *a = sdb_ns(db, "some", true); Sdb *b = sdb_ns(a, "subns", true); - sdb_set(b, "more", "equal=signs=than=one=", 0); + sdb_set(b, "more", "equal=signs=than=one="); Sdb *c = sdb_ns(b, "more", true); Sdb *d = sdb_ns(c, "further", true); - sdb_set(d, "escape", "newlines", 0); - sdb_set(d, "also escape", "nothingness", 0); + sdb_set(d, "escape", "newlines"); + sdb_set(d, "also escape", "nothingness"); return db; } static Sdb *text_ref_path_last_line_db() { Sdb *db = sdb_new0(); - sdb_set(db, "some", "stuff", 0); + sdb_set(db, "some", "stuff"); Sdb *a = sdb_ns(db, "a", true); Sdb *b = sdb_ns(a, "useless", true); sdb_ns(b, "namespace", true); @@ -553,9 +553,9 @@ bool test_sdb_text_load_file() { bool test_sdb_sync_disk() { Sdb *db = sdb_new(NULL, ".sync_disk_db", 0); - sdb_set(db, "mykey", "foobar", 0); - sdb_set(db, "zoo", "beef", 0); - sdb_set(db, "spam", "egg", 0); + sdb_set(db, "mykey", "foobar"); + sdb_set(db, "zoo", "beef"); + sdb_set(db, "spam", "egg"); sdb_sync(db); sdb_free(db); @@ -568,12 +568,12 @@ bool test_sdb_sync_disk() { mu_assert_eq(disk, 3, "Disk records"); mu_assert_eq(mem, 0, "Mem records"); - sdb_set(db, "mykey", "newfoobar", 0); + sdb_set(db, "mykey", "newfoobar"); sdb_stats(db, &disk, &mem); mu_assert_eq(disk, 3, "Disk records"); mu_assert_eq(mem, 1, "Mem records"); - char *val = sdb_get(db, "mykey", NULL); + char *val = sdb_get(db, "mykey"); mu_assert_streq(val, "newfoobar", "Overriden value"); free(val); @@ -594,7 +594,7 @@ bool test_sdb_sync_disk() { mu_assert_eq(disk, 3, "Disk records"); mu_assert_eq(mem, 0, "Mem records"); - val = sdb_get(db, "mykey", NULL); + val = sdb_get(db, "mykey"); mu_assert_streq(val, "newfoobar", "Overriden value"); free(val); diff --git a/test/unit/test_serialize_analysis.c b/test/unit/test_serialize_analysis.c index 7115aba8105..5d4baa125a5 100644 --- a/test/unit/test_serialize_analysis.c +++ b/test/unit/test_serialize_analysis.c @@ -68,8 +68,8 @@ bool test_analysis_switch_op_load() { Sdb *blocks_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "0x539", "{\"size\":42}", 0); - sdb_set(db, "0x4d2", "{\"size\":32,\"jump\":4883,\"fail\":16915,\"traced\":true,\"colorize\":16711680,\"switch_op\":{\"addr\":49232,\"min\":3,\"max\":5,\"def\":7,\"cases\":[]},\"ninstr\":3,\"op_pos\":[4,7],\"sp_delta\":[8,-8,16],\"sp\":256,\"cmpval\":262254561,\"cmpreg\":\"rax\"}", 0); + sdb_set(db, "0x539", "{\"size\":42}"); + sdb_set(db, "0x4d2", "{\"size\":32,\"jump\":4883,\"fail\":16915,\"traced\":true,\"colorize\":16711680,\"switch_op\":{\"addr\":49232,\"min\":3,\"max\":5,\"def\":7,\"cases\":[]},\"ninstr\":3,\"op_pos\":[4,7],\"sp_delta\":[8,-8,16],\"sp\":256,\"cmpval\":262254561,\"cmpreg\":\"rax\"}"); return db; } @@ -163,7 +163,7 @@ bool test_analysis_block_load() { rz_analysis_free(analysis); analysis = rz_analysis_new(); // This could lead to a buffer overflow if unchecked: - sdb_set(db, "0x539", "{\"size\":42,\"ninstr\":4,\"op_pos\":[4,7]}", 0); + sdb_set(db, "0x539", "{\"size\":42,\"ninstr\":4,\"op_pos\":[4,7]}"); succ = rz_serialize_analysis_blocks_load(db, analysis, NULL); mu_assert("reject invalid op_pos array length", !succ); @@ -179,14 +179,14 @@ bool test_analysis_block_load() { Sdb *functions_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "0x4d2", "{\"name\":\"effekt\",\"type\":1,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"pure\":true,\"bbs\":[1337]}", 0); - sdb_set(db, "0xbeef", "{\"name\":\"eskapist\",\"bits\":32,\"type\":16,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}", 0); - sdb_set(db, "0x539", "{\"name\":\"hirsch\",\"bits\":16,\"type\":0,\"cc\":\"fancycall\",\"stack\":42,\"maxstack\":123,\"ninstr\":13,\"bp_frame\":true,\"bp_off\":4,\"bbs\":[1337,1234],\"imports\":[\"earth\",\"rise\"],\"labels\":{\"beach\":1400,\"another\":1450,\"year\":1440}}", 0); - sdb_set(db, "0xdead", "{\"name\":\"agnosie\",\"bits\":32,\"type\":8,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}", 0); - sdb_set(db, "0xc0ffee", "{\"name\":\"lifnej\",\"bits\":32,\"type\":32,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}", 0); - sdb_set(db, "0x1092", "{\"name\":\"hiberno\",\"bits\":32,\"type\":2,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bbs\":[]}", 0); - sdb_set(db, "0x67932", "{\"name\":\"anamnesis\",\"bits\":32,\"type\":4,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"noreturn\":true,\"bbs\":[]}", 0); - sdb_set(db, "0x31337", "{\"name\":\"aldebaran\",\"bits\":32,\"type\":-1,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}", 0); + sdb_set(db, "0x4d2", "{\"name\":\"effekt\",\"type\":1,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"pure\":true,\"bbs\":[1337]}"); + sdb_set(db, "0xbeef", "{\"name\":\"eskapist\",\"bits\":32,\"type\":16,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}"); + sdb_set(db, "0x539", "{\"name\":\"hirsch\",\"bits\":16,\"type\":0,\"cc\":\"fancycall\",\"stack\":42,\"maxstack\":123,\"ninstr\":13,\"bp_frame\":true,\"bp_off\":4,\"bbs\":[1337,1234],\"imports\":[\"earth\",\"rise\"],\"labels\":{\"beach\":1400,\"another\":1450,\"year\":1440}}"); + sdb_set(db, "0xdead", "{\"name\":\"agnosie\",\"bits\":32,\"type\":8,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}"); + sdb_set(db, "0xc0ffee", "{\"name\":\"lifnej\",\"bits\":32,\"type\":32,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}"); + sdb_set(db, "0x1092", "{\"name\":\"hiberno\",\"bits\":32,\"type\":2,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bbs\":[]}"); + sdb_set(db, "0x67932", "{\"name\":\"anamnesis\",\"bits\":32,\"type\":4,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"noreturn\":true,\"bbs\":[]}"); + sdb_set(db, "0x31337", "{\"name\":\"aldebaran\",\"bits\":32,\"type\":-1,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[]}"); return db; } @@ -369,10 +369,10 @@ bool test_analysis_function_load() { static Sdb *noreturn_ref_db() { Sdb *db = sdb_new0(); - sdb_bool_set(db, "addr.8000500.noreturn", true, 0); - sdb_bool_set(db, "addr.8000555.noreturn", true, 0); - sdb_bool_set(db, "addr.8000610.noreturn", true, 0); - sdb_bool_set(db, "addr.8000632.noreturn", true, 0); + sdb_bool_set(db, "addr.8000500.noreturn", true); + sdb_bool_set(db, "addr.8000555.noreturn", true); + sdb_bool_set(db, "addr.8000610.noreturn", true); + sdb_bool_set(db, "addr.8000632.noreturn", true); return db; } @@ -380,10 +380,10 @@ bool test_analysis_function_noreturn_save() { RzAnalysis *analysis = rz_analysis_new(); rz_analysis_noreturn_add(analysis, NULL, 0x800800); - bool has = sdb_bool_get(analysis->sdb_noret, "addr.800800.noreturn", 0); + bool has = sdb_bool_get(analysis->sdb_noret, "addr.800800.noreturn"); mu_assert_true(has, "noreturn add error"); rz_analysis_noreturn_drop(analysis, "0x800800"); - bool hasnt = sdb_bool_get(analysis->sdb_noret, "addr.800800.noreturn", 0); + bool hasnt = sdb_bool_get(analysis->sdb_noret, "addr.800800.noreturn"); mu_assert_false(hasnt, "noreturn drop error"); rz_analysis_noreturn_add(analysis, NULL, 0x8000500); @@ -408,13 +408,13 @@ bool test_analysis_function_noreturn_load() { sdb_free(db); mu_assert("load success", succ); - bool has = sdb_bool_get(analysis->sdb_noret, "addr.8000500.noreturn", 0); - has &= sdb_bool_get(analysis->sdb_noret, "addr.8000555.noreturn", 0); - has &= sdb_bool_get(analysis->sdb_noret, "addr.8000610.noreturn", 0); - has &= sdb_bool_get(analysis->sdb_noret, "addr.8000632.noreturn", 0); + bool has = sdb_bool_get(analysis->sdb_noret, "addr.8000500.noreturn"); + has &= sdb_bool_get(analysis->sdb_noret, "addr.8000555.noreturn"); + has &= sdb_bool_get(analysis->sdb_noret, "addr.8000610.noreturn"); + has &= sdb_bool_get(analysis->sdb_noret, "addr.8000632.noreturn"); mu_assert_true(has, "noreturn load error"); - bool hasnt = sdb_bool_get(analysis->sdb_noret, "addr.800800.noreturn", 0); + bool hasnt = sdb_bool_get(analysis->sdb_noret, "addr.800800.noreturn"); mu_assert_false(hasnt, "noreturn should not exist"); rz_analysis_free(analysis); @@ -431,8 +431,7 @@ Sdb *vars_ref_db() { "{\"name\":\"var_10h\",\"type\":\"struct something\",\"storage\":{\"type\":\"stack\",\"stack\":-16}}," "{\"name\":\"arg_8h\",\"type\":\"uint64_t\",\"storage\":{\"type\":\"stack\",\"stack\":8},\"cmt\":\"I have no idea what this var does\"}," "{\"name\":\"arg_18h\",\"type\":\"struct something\",\"storage\":{\"type\":\"composite\",\"composite\":[{\"offset_in_bits\":0,\"size_in_bits\":32,\"storage\":{\"type\":\"reg\",\"reg\":\"rax\"}},{\"offset_in_bits\":32,\"size_in_bits\":32,\"storage\":{\"type\":\"reg\",\"reg\":\"rbx\"}}]}}" - "]}", - 0); + "]}"); return db; } @@ -633,10 +632,10 @@ bool test_analysis_var_load() { Sdb *xrefs_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "0x29a", "[{\"to\":333,\"type\":\"s\"}]", 0); - sdb_set(db, "0x1337", "[{\"to\":4242},{\"to\":4243,\"type\":\"c\"}]", 0); - sdb_set(db, "0x2a", "[{\"to\":4321,\"type\":\"d\"}]", 0); - sdb_set(db, "0x4d2", "[{\"to\":4243,\"type\":\"C\"}]", 0); + sdb_set(db, "0x29a", "[{\"to\":333,\"type\":\"s\"}]"); + sdb_set(db, "0x1337", "[{\"to\":4242},{\"to\":4243,\"type\":\"c\"}]"); + sdb_set(db, "0x2a", "[{\"to\":4321,\"type\":\"d\"}]"); + sdb_set(db, "0x4d2", "[{\"to\":4243,\"type\":\"C\"}]"); return db; } @@ -718,11 +717,11 @@ bool test_analysis_xrefs_load() { Sdb *meta_ref_db() { Sdb *db = sdb_new0(); Sdb *spaces_db = sdb_ns(db, "spaces", true); - sdb_set(spaces_db, "name", "CS", 0); - sdb_set(spaces_db, "spacestack", "[\"*\"]", 0); - sdb_set(sdb_ns(spaces_db, "spaces", true), "myspace", "s", 0); - sdb_set(db, "0x20a0", "[{\"size\":32,\"type\":\"s\",\"subtype\":78,\"str\":\"utf32be\"}]", 0); - sdb_set(db, "0x20c0", "[{\"size\":32,\"type\":\"s\",\"subtype\":103,\"str\":\"guess\"}]", 0); + sdb_set(spaces_db, "name", "CS"); + sdb_set(spaces_db, "spacestack", "[\"*\"]"); + sdb_set(sdb_ns(spaces_db, "spaces", true), "myspace", "s"); + sdb_set(db, "0x20a0", "[{\"size\":32,\"type\":\"s\",\"subtype\":78,\"str\":\"utf32be\"}]"); + sdb_set(db, "0x20c0", "[{\"size\":32,\"type\":\"s\",\"subtype\":103,\"str\":\"guess\"}]"); sdb_set(db, "0x1337", "[{\"size\":16,\"type\":\"d\"}," "{\"size\":17,\"type\":\"c\"}," @@ -733,13 +732,12 @@ Sdb *meta_ref_db() { "{\"type\":\"C\",\"str\":\"some comment here\"}," "{\"size\":23,\"type\":\"H\"}," "{\"size\":24,\"type\":\"t\"}," - "{\"type\":\"C\",\"str\":\"comment in space\",\"space\":\"myspace\"}]", - 0); - sdb_set(db, "0x2000", "[{\"size\":32,\"type\":\"s\",\"subtype\":98,\"str\":\"8bit\"}]", 0); - sdb_set(db, "0x2040", "[{\"size\":32,\"type\":\"s\",\"subtype\":117,\"str\":\"utf16le\"}]", 0); - sdb_set(db, "0x2080", "[{\"size\":32,\"type\":\"s\",\"subtype\":110,\"str\":\"utf16be\"}]", 0); - sdb_set(db, "0x2020", "[{\"size\":32,\"type\":\"s\",\"subtype\":56,\"str\":\"utf8\"}]", 0); - sdb_set(db, "0x2060", "[{\"size\":32,\"type\":\"s\",\"subtype\":85,\"str\":\"utf32le\"}]", 0); + "{\"type\":\"C\",\"str\":\"comment in space\",\"space\":\"myspace\"}]"); + sdb_set(db, "0x2000", "[{\"size\":32,\"type\":\"s\",\"subtype\":98,\"str\":\"8bit\"}]"); + sdb_set(db, "0x2040", "[{\"size\":32,\"type\":\"s\",\"subtype\":117,\"str\":\"utf16le\"}]"); + sdb_set(db, "0x2080", "[{\"size\":32,\"type\":\"s\",\"subtype\":110,\"str\":\"utf16be\"}]"); + sdb_set(db, "0x2020", "[{\"size\":32,\"type\":\"s\",\"subtype\":56,\"str\":\"utf8\"}]"); + sdb_set(db, "0x2060", "[{\"size\":32,\"type\":\"s\",\"subtype\":85,\"str\":\"utf32le\"}]"); return db; } @@ -894,93 +892,93 @@ bool test_analysis_meta_load() { Sdb *hints_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "0x1000", "{\"optype\":-2147483648}", 0); - sdb_set(db, "0x1001", "{\"optype\":1073741824}", 0); - sdb_set(db, "0x1002", "{\"optype\":536870912}", 0); - sdb_set(db, "0x1003", "{\"optype\":268435456}", 0); - sdb_set(db, "0x1004", "{\"optype\":134217728}", 0); - sdb_set(db, "0x1005", "{\"optype\":0}", 0); - sdb_set(db, "0x1006", "{\"optype\":1}", 0); - sdb_set(db, "0x1007", "{\"optype\":2}", 0); - sdb_set(db, "0x1008", "{\"optype\":268435458}", 0); - sdb_set(db, "0x1009", "{\"optype\":134217730}", 0); - sdb_set(db, "0x100a", "{\"optype\":402653186}", 0); - sdb_set(db, "0x100b", "{\"optype\":-2147483647}", 0); - sdb_set(db, "0x100c", "{\"optype\":-1879048191}", 0); - sdb_set(db, "0x100d", "{\"optype\":536870913}", 0); - sdb_set(db, "0x100e", "{\"optype\":-1610612735}", 0); - sdb_set(db, "0x100f", "{\"optype\":-2147483646}", 0); - sdb_set(db, "0x1010", "{\"optype\":3}", 0); - sdb_set(db, "0x1011", "{\"optype\":4}", 0); - sdb_set(db, "0x1012", "{\"optype\":268435460}", 0); - sdb_set(db, "0x1013", "{\"optype\":134217732}", 0); - sdb_set(db, "0x1014", "{\"optype\":402653188}", 0); - sdb_set(db, "0x1015", "{\"optype\":-2147483645}", 0); - sdb_set(db, "0x1016", "{\"optype\":-2147483644}", 0); - sdb_set(db, "0x1017", "{\"optype\":5}", 0); - sdb_set(db, "0x1018", "{\"optype\":-2147483643}", 0); - sdb_set(db, "0x1019", "{\"optype\":6}", 0); - sdb_set(db, "0x101a", "{\"optype\":7}", 0); - sdb_set(db, "0x101b", "{\"optype\":8}", 0); - sdb_set(db, "0x101c", "{\"optype\":9}", 0); - sdb_set(db, "0x101d", "{\"optype\":-2147483639}", 0); - sdb_set(db, "0x101e", "{\"optype\":10}", 0); - sdb_set(db, "0x101f", "{\"optype\":11}", 0); - sdb_set(db, "0x1020", "{\"optype\":-2147483637}", 0); - sdb_set(db, "0x1021", "{\"optype\":12}", 0); - sdb_set(db, "0x1022", "{\"optype\":268435468}", 0); - sdb_set(db, "0x1023", "{\"optype\":13}", 0); - sdb_set(db, "0x1024", "{\"optype\":14}", 0); - sdb_set(db, "0x1025", "{\"optype\":15}", 0); - sdb_set(db, "0x1026", "{\"optype\":16}", 0); - sdb_set(db, "0x1027", "{\"optype\":17}", 0); - sdb_set(db, "0x1028", "{\"optype\":18}", 0); - sdb_set(db, "0x1029", "{\"optype\":19}", 0); - sdb_set(db, "0x102a", "{\"optype\":20}", 0); - sdb_set(db, "0x102b", "{\"optype\":21}", 0); - sdb_set(db, "0x102c", "{\"optype\":22}", 0); - sdb_set(db, "0x102d", "{\"optype\":23}", 0); - sdb_set(db, "0x102e", "{\"optype\":24}", 0); - sdb_set(db, "0x102f", "{\"optype\":25}", 0); - sdb_set(db, "0x1030", "{\"optype\":26}", 0); - sdb_set(db, "0x1031", "{\"optype\":27}", 0); - sdb_set(db, "0x1032", "{\"optype\":28}", 0); - sdb_set(db, "0x1033", "{\"optype\":29}", 0); - sdb_set(db, "0x1034", "{\"optype\":30}", 0); - sdb_set(db, "0x1035", "{\"optype\":31}", 0); - sdb_set(db, "0x1036", "{\"optype\":32}", 0); - sdb_set(db, "0x1037", "{\"optype\":33}", 0); - sdb_set(db, "0x1038", "{\"optype\":34}", 0); - sdb_set(db, "0x1039", "{\"optype\":35}", 0); - sdb_set(db, "0x103a", "{\"optype\":36}", 0); - sdb_set(db, "0x103b", "{\"optype\":37}", 0); - sdb_set(db, "0x103c", "{\"optype\":38}", 0); - sdb_set(db, "0x103d", "{\"optype\":39}", 0); - sdb_set(db, "0x103e", "{\"optype\":40}", 0); - sdb_set(db, "0x103f", "{\"optype\":41}", 0); - sdb_set(db, "0x1040", "{\"optype\":42}", 0); - sdb_set(db, "0x1041", "{\"optype\":43}", 0); - sdb_set(db, "0x1042", "{\"optype\":44}", 0); - sdb_set(db, "0x1043", "{\"optype\":45}", 0); - sdb_set(db, "0x1044", "{\"optype\":46}", 0); - sdb_set(db, "0x1045", "{\"optype\":47}", 0); - sdb_set(db, "0x100", "{\"arch\":\"arm\",\"bits\":16}", 0); - sdb_set(db, "0x120", "{\"arch\":null}", 0); - sdb_set(db, "0x130", "{\"bits\":0}", 0); - sdb_set(db, "0x200", "{\"immbase\":10}", 0); - sdb_set(db, "0x210", "{\"jump\":1337,\"fail\":1234}", 0); - sdb_set(db, "0x220", "{\"syntax\":\"intel\"}", 0); - sdb_set(db, "0x230", "{\"frame\":48}", 0); - sdb_set(db, "0x240", "{\"ptr\":4321}", 0); - sdb_set(db, "0x250", "{\"nword\":3}", 0); - sdb_set(db, "0x260", "{\"ret\":666}", 0); - sdb_set(db, "0x270", "{\"newbits\":32}", 0); - sdb_set(db, "0x280", "{\"size\":7}", 0); - sdb_set(db, "0x290", "{\"opcode\":\"mov\"}", 0); - sdb_set(db, "0x2a0", "{\"toff\":\"sometype\"}", 0); - sdb_set(db, "0x2b0", "{\"esil\":\"13,29,+\"}", 0); - sdb_set(db, "0x2c0", "{\"high\":true}", 0); - sdb_set(db, "0x2d0", "{\"val\":54323}", 0); + sdb_set(db, "0x1000", "{\"optype\":-2147483648}"); + sdb_set(db, "0x1001", "{\"optype\":1073741824}"); + sdb_set(db, "0x1002", "{\"optype\":536870912}"); + sdb_set(db, "0x1003", "{\"optype\":268435456}"); + sdb_set(db, "0x1004", "{\"optype\":134217728}"); + sdb_set(db, "0x1005", "{\"optype\":0}"); + sdb_set(db, "0x1006", "{\"optype\":1}"); + sdb_set(db, "0x1007", "{\"optype\":2}"); + sdb_set(db, "0x1008", "{\"optype\":268435458}"); + sdb_set(db, "0x1009", "{\"optype\":134217730}"); + sdb_set(db, "0x100a", "{\"optype\":402653186}"); + sdb_set(db, "0x100b", "{\"optype\":-2147483647}"); + sdb_set(db, "0x100c", "{\"optype\":-1879048191}"); + sdb_set(db, "0x100d", "{\"optype\":536870913}"); + sdb_set(db, "0x100e", "{\"optype\":-1610612735}"); + sdb_set(db, "0x100f", "{\"optype\":-2147483646}"); + sdb_set(db, "0x1010", "{\"optype\":3}"); + sdb_set(db, "0x1011", "{\"optype\":4}"); + sdb_set(db, "0x1012", "{\"optype\":268435460}"); + sdb_set(db, "0x1013", "{\"optype\":134217732}"); + sdb_set(db, "0x1014", "{\"optype\":402653188}"); + sdb_set(db, "0x1015", "{\"optype\":-2147483645}"); + sdb_set(db, "0x1016", "{\"optype\":-2147483644}"); + sdb_set(db, "0x1017", "{\"optype\":5}"); + sdb_set(db, "0x1018", "{\"optype\":-2147483643}"); + sdb_set(db, "0x1019", "{\"optype\":6}"); + sdb_set(db, "0x101a", "{\"optype\":7}"); + sdb_set(db, "0x101b", "{\"optype\":8}"); + sdb_set(db, "0x101c", "{\"optype\":9}"); + sdb_set(db, "0x101d", "{\"optype\":-2147483639}"); + sdb_set(db, "0x101e", "{\"optype\":10}"); + sdb_set(db, "0x101f", "{\"optype\":11}"); + sdb_set(db, "0x1020", "{\"optype\":-2147483637}"); + sdb_set(db, "0x1021", "{\"optype\":12}"); + sdb_set(db, "0x1022", "{\"optype\":268435468}"); + sdb_set(db, "0x1023", "{\"optype\":13}"); + sdb_set(db, "0x1024", "{\"optype\":14}"); + sdb_set(db, "0x1025", "{\"optype\":15}"); + sdb_set(db, "0x1026", "{\"optype\":16}"); + sdb_set(db, "0x1027", "{\"optype\":17}"); + sdb_set(db, "0x1028", "{\"optype\":18}"); + sdb_set(db, "0x1029", "{\"optype\":19}"); + sdb_set(db, "0x102a", "{\"optype\":20}"); + sdb_set(db, "0x102b", "{\"optype\":21}"); + sdb_set(db, "0x102c", "{\"optype\":22}"); + sdb_set(db, "0x102d", "{\"optype\":23}"); + sdb_set(db, "0x102e", "{\"optype\":24}"); + sdb_set(db, "0x102f", "{\"optype\":25}"); + sdb_set(db, "0x1030", "{\"optype\":26}"); + sdb_set(db, "0x1031", "{\"optype\":27}"); + sdb_set(db, "0x1032", "{\"optype\":28}"); + sdb_set(db, "0x1033", "{\"optype\":29}"); + sdb_set(db, "0x1034", "{\"optype\":30}"); + sdb_set(db, "0x1035", "{\"optype\":31}"); + sdb_set(db, "0x1036", "{\"optype\":32}"); + sdb_set(db, "0x1037", "{\"optype\":33}"); + sdb_set(db, "0x1038", "{\"optype\":34}"); + sdb_set(db, "0x1039", "{\"optype\":35}"); + sdb_set(db, "0x103a", "{\"optype\":36}"); + sdb_set(db, "0x103b", "{\"optype\":37}"); + sdb_set(db, "0x103c", "{\"optype\":38}"); + sdb_set(db, "0x103d", "{\"optype\":39}"); + sdb_set(db, "0x103e", "{\"optype\":40}"); + sdb_set(db, "0x103f", "{\"optype\":41}"); + sdb_set(db, "0x1040", "{\"optype\":42}"); + sdb_set(db, "0x1041", "{\"optype\":43}"); + sdb_set(db, "0x1042", "{\"optype\":44}"); + sdb_set(db, "0x1043", "{\"optype\":45}"); + sdb_set(db, "0x1044", "{\"optype\":46}"); + sdb_set(db, "0x1045", "{\"optype\":47}"); + sdb_set(db, "0x100", "{\"arch\":\"arm\",\"bits\":16}"); + sdb_set(db, "0x120", "{\"arch\":null}"); + sdb_set(db, "0x130", "{\"bits\":0}"); + sdb_set(db, "0x200", "{\"immbase\":10}"); + sdb_set(db, "0x210", "{\"jump\":1337,\"fail\":1234}"); + sdb_set(db, "0x220", "{\"syntax\":\"intel\"}"); + sdb_set(db, "0x230", "{\"frame\":48}"); + sdb_set(db, "0x240", "{\"ptr\":4321}"); + sdb_set(db, "0x250", "{\"nword\":3}"); + sdb_set(db, "0x260", "{\"ret\":666}"); + sdb_set(db, "0x270", "{\"newbits\":32}"); + sdb_set(db, "0x280", "{\"size\":7}"); + sdb_set(db, "0x290", "{\"opcode\":\"mov\"}"); + sdb_set(db, "0x2a0", "{\"toff\":\"sometype\"}"); + sdb_set(db, "0x2b0", "{\"esil\":\"13,29,+\"}"); + sdb_set(db, "0x2c0", "{\"high\":true}"); + sdb_set(db, "0x2d0", "{\"val\":54323}"); return db; } @@ -1131,18 +1129,18 @@ bool test_analysis_hints_load() { Sdb *classes_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "Aeropause", "c", 0); - sdb_set(db, "Bright", "c", 0); + sdb_set(db, "Aeropause", "c"); + sdb_set(db, "Bright", "c"); Sdb *attrs_db = sdb_ns(db, "attrs", true); - sdb_set(attrs_db, "attrtypes.Bright", "base", 0); - sdb_set(attrs_db, "attr.Aeropause.vtable.0", "0x1000,4,80", 0); - sdb_set(attrs_db, "attrtypes.Aeropause", "method,vtable", 0); - sdb_set(attrs_db, "attr.Aeropause.method", "some_meth,some_other_meth", 0); - sdb_set(attrs_db, "attr.Bright.base", "0", 0); - sdb_set(attrs_db, "attr.Aeropause.vtable", "0", 0); - sdb_set(attrs_db, "attr.Bright.base.0", "Aeropause,8", 0); - sdb_set(attrs_db, "attr.Aeropause.method.some_meth", "4919,42,0,some_meth", 0); - sdb_set(attrs_db, "attr.Aeropause.method.some_other_meth", "4660,32,0,some_other_meth", 0); + sdb_set(attrs_db, "attrtypes.Bright", "base"); + sdb_set(attrs_db, "attr.Aeropause.vtable.0", "0x1000,4,80"); + sdb_set(attrs_db, "attrtypes.Aeropause", "method,vtable"); + sdb_set(attrs_db, "attr.Aeropause.method", "some_meth,some_other_meth"); + sdb_set(attrs_db, "attr.Bright.base", "0"); + sdb_set(attrs_db, "attr.Aeropause.vtable", "0"); + sdb_set(attrs_db, "attr.Bright.base.0", "Aeropause,8"); + sdb_set(attrs_db, "attr.Aeropause.method.some_meth", "4919,42,0,some_meth"); + sdb_set(attrs_db, "attr.Aeropause.method.some_other_meth", "4660,32,0,some_other_meth"); return db; } @@ -1259,14 +1257,14 @@ bool test_analysis_classes_load() { static Sdb *cc_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "cc.sectarian.ret", "rax", 0); - sdb_set(db, "cc.sectarian.self", "rsi", 0); - sdb_set(db, "cc.sectarian.error", "rdi", 0); - sdb_set(db, "cc.sectarian.arg1", "rcx", 0); - sdb_set(db, "cc.sectarian.arg0", "rdx", 0); - sdb_set(db, "cc.sectarian.argn", "stack", 0); - sdb_set(db, "cc.sectarian.maxargs", "2", 0); - sdb_set(db, "sectarian", "cc", 0); + sdb_set(db, "cc.sectarian.ret", "rax"); + sdb_set(db, "cc.sectarian.self", "rsi"); + sdb_set(db, "cc.sectarian.error", "rdi"); + sdb_set(db, "cc.sectarian.arg1", "rcx"); + sdb_set(db, "cc.sectarian.arg0", "rdx"); + sdb_set(db, "cc.sectarian.argn", "stack"); + sdb_set(db, "cc.sectarian.maxargs", "2"); + sdb_set(db, "sectarian", "cc"); return db; } @@ -1311,49 +1309,49 @@ Sdb *analysis_ref_db() { Sdb *db = sdb_new0(); Sdb *blocks = sdb_ns(db, "blocks", true); - sdb_set(blocks, "0x4d2", "{\"size\":32}", 0); - sdb_set(blocks, "0x539", "{\"size\":42}", 0); + sdb_set(blocks, "0x4d2", "{\"size\":32}"); + sdb_set(blocks, "0x539", "{\"size\":42}"); Sdb *functions = sdb_ns(db, "functions", true); - sdb_set(functions, "0x4d2", "{\"name\":\"effekt\",\"bits\":32,\"type\":1,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[1337]}", 0); - sdb_set(functions, "0x539", "{\"name\":\"hirsch\",\"bits\":32,\"type\":0,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[1337,1234]}", 0); + sdb_set(functions, "0x4d2", "{\"name\":\"effekt\",\"bits\":32,\"type\":1,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[1337]}"); + sdb_set(functions, "0x539", "{\"name\":\"hirsch\",\"bits\":32,\"type\":0,\"stack\":0,\"maxstack\":0,\"ninstr\":0,\"bp_frame\":true,\"bbs\":[1337,1234]}"); Sdb *noret = sdb_ns(db, "noreturn", true); - sdb_bool_set(noret, "addr.800800.noreturn", true, 0); + sdb_bool_set(noret, "addr.800800.noreturn", true); Sdb *xrefs = sdb_ns(db, "xrefs", true); - sdb_set(xrefs, "0x42", "[{\"to\":1337,\"type\":\"C\"}]", 0); - sdb_set(xrefs, "0x539", "[{\"to\":12648430,\"type\":\"d\"}]", 0); + sdb_set(xrefs, "0x42", "[{\"to\":1337,\"type\":\"C\"}]"); + sdb_set(xrefs, "0x539", "[{\"to\":12648430,\"type\":\"d\"}]"); Sdb *meta = sdb_ns(db, "meta", true); Sdb *meta_spaces = sdb_ns(meta, "spaces", true); sdb_ns(meta_spaces, "spaces", true); - sdb_set(meta_spaces, "spacestack", "[\"*\"]", 0); - sdb_set(meta_spaces, "name", "CS", 0); - sdb_set(meta, "0x1337", "[{\"type\":\"C\",\"subtype\":56,\"str\":\"some comment\"}]", 0); + sdb_set(meta_spaces, "spacestack", "[\"*\"]"); + sdb_set(meta_spaces, "name", "CS"); + sdb_set(meta, "0x1337", "[{\"type\":\"C\",\"subtype\":56,\"str\":\"some comment\"}]"); Sdb *hints = sdb_ns(db, "hints", true); - sdb_set(hints, "0x10e1", "{\"arch\":\"arm\"}", 0); + sdb_set(hints, "0x10e1", "{\"arch\":\"arm\"}"); Sdb *classes = sdb_ns(db, "classes", true); - sdb_set(classes, "Aeropause", "c", 0); + sdb_set(classes, "Aeropause", "c"); Sdb *class_attrs = sdb_ns(classes, "attrs", true); - sdb_set(class_attrs, "attrtypes.Aeropause", "method", 0); - sdb_set(class_attrs, "attr.Aeropause.method", "some_meth", 0); - sdb_set(class_attrs, "attr.Aeropause.method.some_meth", "4919,42,0,some_meth", 0); + sdb_set(class_attrs, "attrtypes.Aeropause", "method"); + sdb_set(class_attrs, "attr.Aeropause.method", "some_meth"); + sdb_set(class_attrs, "attr.Aeropause.method.some_meth", "4919,42,0,some_meth"); Sdb *imports = sdb_ns(db, "imports", true); - sdb_set(imports, "pigs", "i", 0); - sdb_set(imports, "dogs", "i", 0); - sdb_set(imports, "sheep", "i", 0); + sdb_set(imports, "pigs", "i"); + sdb_set(imports, "dogs", "i"); + sdb_set(imports, "sheep", "i"); Sdb *cc = sdb_ns(db, "cc", true); - sdb_set(cc, "cc.sectarian.ret", "rax", 0); - sdb_set(cc, "cc.sectarian.arg1", "rcx", 0); - sdb_set(cc, "cc.sectarian.arg0", "rdx", 0); - sdb_set(cc, "cc.sectarian.argn", "stack", 0); - sdb_set(cc, "cc.sectarian.maxargs", "2", 0); - sdb_set(cc, "sectarian", "cc", 0); + sdb_set(cc, "cc.sectarian.ret", "rax"); + sdb_set(cc, "cc.sectarian.arg1", "rcx"); + sdb_set(cc, "cc.sectarian.arg0", "rdx"); + sdb_set(cc, "cc.sectarian.argn", "stack"); + sdb_set(cc, "cc.sectarian.maxargs", "2"); + sdb_set(cc, "sectarian", "cc"); sdb_ns(db, "types", true); sdb_ns(db, "callables", true); diff --git a/test/unit/test_serialize_config.c b/test/unit/test_serialize_config.c index eb5a0389c8f..7ce1f77ca97 100644 --- a/test/unit/test_serialize_config.c +++ b/test/unit/test_serialize_config.c @@ -7,9 +7,9 @@ Sdb *ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "somestring", "somevalue", 0); - sdb_set(db, "someint", "42", 0); - sdb_set(db, "somebiggerint", "0x00001337", 0); + sdb_set(db, "somestring", "somevalue"); + sdb_set(db, "someint", "42"); + sdb_set(db, "somebiggerint", "0x00001337"); return db; } @@ -39,7 +39,7 @@ bool test_config_load() { rz_config_lock(config, true); Sdb *db = ref_db(); - sdb_set(db, "sneaky", "not part of config", 0); + sdb_set(db, "sneaky", "not part of config"); bool loaded = rz_serialize_config_load(db, config, NULL, NULL); sdb_free(db); mu_assert("load success", loaded); diff --git a/test/unit/test_serialize_debug.c b/test/unit/test_serialize_debug.c index e56bc2578a6..b6502c70fb7 100644 --- a/test/unit/test_serialize_debug.c +++ b/test/unit/test_serialize_debug.c @@ -13,8 +13,7 @@ Sdb *get_ref_sdb() { sdb_set(bp_sdb, "0x1337", "{\"cond\":\"bp_cond\",\"data\":\"bp_data\",\"delta\":2,\"enabled\":3," "\"expr\":\"bp_expr\",\"hits\":4,\"hw\":0,\"internal\":5,\"module_delta\":42," "\"module_name\":\"hax\",\"name\":\"spectre\",\"perm\":3,\"pids\":[0,1,2,3,4,5,6,7,8,9]," - "\"size\":1,\"swstep\":false,\"togglehits\":11,\"trace\":2}", - 0); + "\"size\":1,\"swstep\":false,\"togglehits\":11,\"trace\":2}"); return ref_sdb; } diff --git a/test/unit/test_serialize_flag.c b/test/unit/test_serialize_flag.c index 9f4598e6a83..b8505571bc5 100644 --- a/test/unit/test_serialize_flag.c +++ b/test/unit/test_serialize_flag.c @@ -8,27 +8,27 @@ Sdb *ref_0_db() { Sdb *db = sdb_new0(); - sdb_set(db, "realnames", "1", 0); + sdb_set(db, "realnames", "1"); Sdb *spaces_db = sdb_ns(db, "spaces", true); - sdb_set(spaces_db, "name", "fs", 0); - sdb_set(spaces_db, "spacestack", "[\"reveries\"]", 0); + sdb_set(spaces_db, "name", "fs"); + sdb_set(spaces_db, "spacestack", "[\"reveries\"]"); Sdb *spaces_spaces_db = sdb_ns(spaces_db, "spaces", true); - sdb_set(spaces_spaces_db, "ghost", "s", 0); - sdb_set(spaces_spaces_db, "reveries", "s", 0); + sdb_set(spaces_spaces_db, "ghost", "s"); + sdb_set(spaces_spaces_db, "reveries", "s"); Sdb *tags_db = sdb_ns(db, "tags", true); - sdb_set(tags_db, "tag." PERTURBATOR, PERTURBATOR, 0); - sdb_set(tags_db, "tag.lotus", "eater", 0); + sdb_set(tags_db, "tag." PERTURBATOR, PERTURBATOR); + sdb_set(tags_db, "tag.lotus", "eater"); Sdb *zones_db = sdb_ns(db, "zones", true); - sdb_set(zones_db, "blackwater park", "{\"from\":12345,\"to\":12648243}", 0); - sdb_set(zones_db, PERTURBATOR, "{\"from\":3735928559,\"to\":18446744073709551614}", 0); + sdb_set(zones_db, "blackwater park", "{\"from\":12345,\"to\":12648243}"); + sdb_set(zones_db, PERTURBATOR, "{\"from\":3735928559,\"to\":18446744073709551614}"); Sdb *flags_db = sdb_ns(db, "flags", true); - sdb_set(flags_db, "foobars", "{\"realname\":\"Foobars\",\"demangled\":true,\"offset\":4919,\"size\":16,\"space\":\"reveries\",\"color\":\"white\",\"comment\":\"windowpane\",\"alias\":\"f00b4r5\"}", 0); - sdb_set(flags_db, "f00b4r5", "{\"realname\":\"f00b4r5\",\"demangled\":false,\"offset\":4919,\"size\":1}", 0); - sdb_set(flags_db, "deliverance", "{\"realname\":\"deliverance\",\"demangled\":false,\"offset\":1403,\"size\":19}", 0); + sdb_set(flags_db, "foobars", "{\"realname\":\"Foobars\",\"demangled\":true,\"offset\":4919,\"size\":16,\"space\":\"reveries\",\"color\":\"white\",\"comment\":\"windowpane\",\"alias\":\"f00b4r5\"}"); + sdb_set(flags_db, "f00b4r5", "{\"realname\":\"f00b4r5\",\"demangled\":false,\"offset\":4919,\"size\":1}"); + sdb_set(flags_db, "deliverance", "{\"realname\":\"deliverance\",\"demangled\":false,\"offset\":1403,\"size\":19}"); return db; } @@ -65,11 +65,11 @@ RzFlag *ref_0_flag() { Sdb *ref_1_db() { Sdb *db = sdb_new0(); - sdb_set(db, "realnames", "0", 0); + sdb_set(db, "realnames", "0"); Sdb *spaces_db = sdb_ns(db, "spaces", true); - sdb_set(spaces_db, "name", "fs", 0); - sdb_set(spaces_db, "spacestack", "[\"*\"]", 0); + sdb_set(spaces_db, "name", "fs"); + sdb_set(spaces_db, "spacestack", "[\"*\"]"); sdb_ns(spaces_db, "spaces", true); sdb_ns(db, "tags", true); sdb_ns(db, "zones", true); diff --git a/test/unit/test_serialize_seek.c b/test/unit/test_serialize_seek.c index fb12c85408d..2c7830015a4 100644 --- a/test/unit/test_serialize_seek.c +++ b/test/unit/test_serialize_seek.c @@ -8,10 +8,10 @@ Sdb *get_ref_sdb() { Sdb *ref_sdb = sdb_new0(); - sdb_set(ref_sdb, "-1", "{\"offset\":16,\"cursor\":1,\"current\":false}", 0); - sdb_set(ref_sdb, "0", "{\"offset\":32,\"cursor\":2,\"current\":true}", 0); - sdb_set(ref_sdb, "1", "{\"offset\":48,\"cursor\":3,\"current\":false}", 0); - sdb_set(ref_sdb, "2", "{\"offset\":64,\"cursor\":4,\"current\":false}", 0); + sdb_set(ref_sdb, "-1", "{\"offset\":16,\"cursor\":1,\"current\":false}"); + sdb_set(ref_sdb, "0", "{\"offset\":32,\"cursor\":2,\"current\":true}"); + sdb_set(ref_sdb, "1", "{\"offset\":48,\"cursor\":3,\"current\":false}"); + sdb_set(ref_sdb, "2", "{\"offset\":64,\"cursor\":4,\"current\":false}"); return ref_sdb; } diff --git a/test/unit/test_serialize_spaces.c b/test/unit/test_serialize_spaces.c index 4ff4c335b62..4d02a964387 100644 --- a/test/unit/test_serialize_spaces.c +++ b/test/unit/test_serialize_spaces.c @@ -16,13 +16,13 @@ bool test_spaces_save(void) { rz_serialize_spaces_save(db, spaces); Sdb *expected = sdb_new0(); - sdb_set(expected, "name", "myspaces", 0); - sdb_set(expected, "spacestack", "[\"*\"]", 0); + sdb_set(expected, "name", "myspaces"); + sdb_set(expected, "spacestack", "[\"*\"]"); Sdb *expected_spaces = sdb_ns(expected, "spaces", true); - sdb_set(expected_spaces, "a", "s", 0); - sdb_set(expected_spaces, "b", "s", 0); - sdb_set(expected_spaces, "c", "s", 0); - sdb_set(expected_spaces, PERTURBATOR, "s", 0); + sdb_set(expected_spaces, "a", "s"); + sdb_set(expected_spaces, "b", "s"); + sdb_set(expected_spaces, "c", "s"); + sdb_set(expected_spaces, PERTURBATOR, "s"); assert_sdb_eq(db, expected, "spaces save (no current, empty stack)"); sdb_free(db); @@ -31,7 +31,7 @@ bool test_spaces_save(void) { db = sdb_new0(); rz_serialize_spaces_save(db, spaces); - sdb_set(expected, "spacestack", "[\"" PERTURBATOR_JSON "\"]", 0); + sdb_set(expected, "spacestack", "[\"" PERTURBATOR_JSON "\"]"); assert_sdb_eq(db, expected, "spaces save (current, empty stack)"); sdb_free(db); @@ -41,7 +41,7 @@ bool test_spaces_save(void) { db = sdb_new0(); rz_serialize_spaces_save(db, spaces); - sdb_set(expected, "spacestack", "[\"" PERTURBATOR_JSON "\",\"a\",\"b\"]", 0); + sdb_set(expected, "spacestack", "[\"" PERTURBATOR_JSON "\",\"a\",\"b\"]"); assert_sdb_eq(db, expected, "spaces save (current, stack)"); sdb_free(db); @@ -52,13 +52,13 @@ bool test_spaces_save(void) { bool test_spaces_load_noname_nostack(void) { Sdb *db = sdb_new0(); - sdb_set(db, "name", "myspaces", 0); - sdb_set(db, "spacestack", "[\"*\"]", 0); + sdb_set(db, "name", "myspaces"); + sdb_set(db, "spacestack", "[\"*\"]"); Sdb *db_spaces = sdb_ns(db, "spaces", true); - sdb_set(db_spaces, "a", "s", 0); - sdb_set(db_spaces, "b", "s", 0); - sdb_set(db_spaces, "c", "s", 0); - sdb_set(db_spaces, PERTURBATOR, "s", 0); + sdb_set(db_spaces, "a", "s"); + sdb_set(db_spaces, "b", "s"); + sdb_set(db_spaces, "c", "s"); + sdb_set(db_spaces, PERTURBATOR, "s"); RzSpaces *spaces = rz_spaces_new("fixed name"); bool loaded = rz_serialize_spaces_load(db, spaces, false, NULL); @@ -97,13 +97,13 @@ bool test_spaces_load_noname_nostack(void) { bool test_spaces_load_name_stack(void) { Sdb *db = sdb_new0(); - sdb_set(db, "name", "myspaces", 0); - sdb_set(db, "spacestack", "[\"a\",\"*\",\"" PERTURBATOR_JSON "\",\"b\",\"" PERTURBATOR_JSON "\"]", 0); + sdb_set(db, "name", "myspaces"); + sdb_set(db, "spacestack", "[\"a\",\"*\",\"" PERTURBATOR_JSON "\",\"b\",\"" PERTURBATOR_JSON "\"]"); Sdb *db_spaces = sdb_ns(db, "spaces", true); - sdb_set(db_spaces, "a", "s", 0); - sdb_set(db_spaces, "b", "s", 0); - sdb_set(db_spaces, "c", "s", 0); - sdb_set(db_spaces, PERTURBATOR, "s", 0); + sdb_set(db_spaces, "a", "s"); + sdb_set(db_spaces, "b", "s"); + sdb_set(db_spaces, "c", "s"); + sdb_set(db_spaces, PERTURBATOR, "s"); RzSpaces *spaces = rz_spaces_new(""); bool loaded = rz_serialize_spaces_load(db, spaces, true, NULL); diff --git a/test/unit/test_serialize_types.c b/test/unit/test_serialize_types.c index c32e70b539e..0bf366304f0 100644 --- a/test/unit/test_serialize_types.c +++ b/test/unit/test_serialize_types.c @@ -12,34 +12,34 @@ Sdb *types_ref_db() { Sdb *db = sdb_new0(); - sdb_set(db, "junker", "struct", 0); - sdb_set(db, "struct.junker", "gillian,seed", 0); - sdb_set(db, "struct.junker.gillian", "char *,0,0", 0); - sdb_set(db, "struct.junker.seed", "uint64_t,8,0", 0); - sdb_set(db, "snatcher", "union", 0); - sdb_set(db, "union.snatcher", "random,hajile", 0); - sdb_set(db, "union.snatcher.random", "int,0,0", 0); - sdb_set(db, "union.snatcher.hajile", "uint32_t,0,0", 0); - sdb_set(db, "human", "typedef", 0); - sdb_set(db, "typedef.human", "union snatcher", 0); - sdb_set(db, "mika", "enum", 0); - sdb_set(db, "enum.mika", "ELIJAH,MODNAR", 0); - sdb_set(db, "enum.mika.MODNAR", "0x539", 0); - sdb_set(db, "enum.mika.ELIJAH", "0x2a", 0); - sdb_set(db, "enum.mika.0x2a", "ELIJAH", 0); - sdb_set(db, "enum.mika.0x539", "MODNAR", 0); - sdb_set(db, "my_sint_t", "type", 0); - sdb_set(db, "type.my_sint_t", "d", 0); - sdb_set(db, "type.my_sint_t.size", "32", 0); - sdb_set(db, "type.my_sint_t.typeclass", "Signed Integral", 0); - sdb_set(db, "my_float_t", "type", 0); - sdb_set(db, "type.my_float_t.size", "16", 0); - sdb_set(db, "type.my_float_t.typeclass", "Floating", 0); + sdb_set(db, "junker", "struct"); + sdb_set(db, "struct.junker", "gillian,seed"); + sdb_set(db, "struct.junker.gillian", "char *,0,0"); + sdb_set(db, "struct.junker.seed", "uint64_t,8,0"); + sdb_set(db, "snatcher", "union"); + sdb_set(db, "union.snatcher", "random,hajile"); + sdb_set(db, "union.snatcher.random", "int,0,0"); + sdb_set(db, "union.snatcher.hajile", "uint32_t,0,0"); + sdb_set(db, "human", "typedef"); + sdb_set(db, "typedef.human", "union snatcher"); + sdb_set(db, "mika", "enum"); + sdb_set(db, "enum.mika", "ELIJAH,MODNAR"); + sdb_set(db, "enum.mika.MODNAR", "0x539"); + sdb_set(db, "enum.mika.ELIJAH", "0x2a"); + sdb_set(db, "enum.mika.0x2a", "ELIJAH"); + sdb_set(db, "enum.mika.0x539", "MODNAR"); + sdb_set(db, "my_sint_t", "type"); + sdb_set(db, "type.my_sint_t", "d"); + sdb_set(db, "type.my_sint_t.size", "32"); + sdb_set(db, "type.my_sint_t.typeclass", "Signed Integral"); + sdb_set(db, "my_float_t", "type"); + sdb_set(db, "type.my_float_t.size", "16"); + sdb_set(db, "type.my_float_t.typeclass", "Floating"); return db; } bool sdb_has_record(Sdb *db, const char *key, const char *value) { - const char *result = sdb_get(db, key, 0); + const char *result = sdb_get(db, key); if (!result) { return false; } @@ -168,7 +168,7 @@ bool test_types_save() { mu_assert_true(sdb_has_record(db, "type.my_sint_t.size", "32"), "atomic type"); mu_assert_true(sdb_has_record(db, "type.my_sint_t.typeclass", "Signed Integral"), "atomic type"); mu_assert_true(sdb_has_record(db, "my_float_t", "type"), "atomic type"); - mu_assert_null(sdb_get(db, "type.my_float_t", 0), "atomic type"); + mu_assert_null(sdb_get(db, "type.my_float_t"), "atomic type"); mu_assert_true(sdb_has_record(db, "type.my_float_t.size", "16"), "atomic type"); mu_assert_true(sdb_has_record(db, "type.my_float_t.typeclass", "Floating"), "atomic type"); diff --git a/test/unit/test_type.c b/test/unit/test_type.c index 707946a39b1..df1bbb02268 100644 --- a/test/unit/test_type.c +++ b/test/unit/test_type.c @@ -11,65 +11,65 @@ static void setup_sdb_for_struct(Sdb *res) { // td "struct kappa {int bar;int cow;};" - sdb_set(res, "kappa", "struct", 0); - sdb_set(res, "struct.kappa", "bar,cow", 0); - sdb_set(res, "struct.kappa.bar", "int32_t,0,0", 0); - sdb_set(res, "struct.kappa.cow", "int32_t,4,0", 0); - - sdb_set(res, "lappa", "struct", 0); - sdb_set(res, "struct.lappa", "bar,cow", 0); - sdb_set(res, "struct.lappa.bar", "int32_t,0,0", 0); - sdb_set(res, "struct.lappa.cow", "struct kappa,4,0", 0); + sdb_set(res, "kappa", "struct"); + sdb_set(res, "struct.kappa", "bar,cow"); + sdb_set(res, "struct.kappa.bar", "int32_t,0,0"); + sdb_set(res, "struct.kappa.cow", "int32_t,4,0"); + + sdb_set(res, "lappa", "struct"); + sdb_set(res, "struct.lappa", "bar,cow"); + sdb_set(res, "struct.lappa.bar", "int32_t,0,0"); + sdb_set(res, "struct.lappa.cow", "struct kappa,4,0"); } static void setup_sdb_for_union(Sdb *res) { // td "union kappa {int bar;int cow;};" - sdb_set(res, "kappa", "union", 0); - sdb_set(res, "union.kappa", "bar,cow", 0); - sdb_set(res, "union.kappa.bar", "int32_t,0,0", 0); - sdb_set(res, "union.kappa.cow", "int32_t,0,0", 0); - - sdb_set(res, "lappa", "union", 0); - sdb_set(res, "union.lappa", "bar,cow", 0); - sdb_set(res, "union.lappa.bar", "int32_t,0,0", 0); - sdb_set(res, "union.lappa.cow", "union kappa,0,0", 0); + sdb_set(res, "kappa", "union"); + sdb_set(res, "union.kappa", "bar,cow"); + sdb_set(res, "union.kappa.bar", "int32_t,0,0"); + sdb_set(res, "union.kappa.cow", "int32_t,0,0"); + + sdb_set(res, "lappa", "union"); + sdb_set(res, "union.lappa", "bar,cow"); + sdb_set(res, "union.lappa.bar", "int32_t,0,0"); + sdb_set(res, "union.lappa.cow", "union kappa,0,0"); } static void setup_sdb_for_enum(Sdb *res) { // td "enum foo { firstCase=1, secondCase=2,};" - sdb_set(res, "foo", "enum", 0); - sdb_set(res, "enum.foo", "firstCase,secondCase", 0); - sdb_set(res, "enum.foo.firstCase", "0x1", 0); - sdb_set(res, "enum.foo.secondCase", "0x2", 0); - sdb_set(res, "enum.foo.0x1", "firstCase", 0); - sdb_set(res, "enum.foo.0x2", "secondCase", 0); + sdb_set(res, "foo", "enum"); + sdb_set(res, "enum.foo", "firstCase,secondCase"); + sdb_set(res, "enum.foo.firstCase", "0x1"); + sdb_set(res, "enum.foo.secondCase", "0x2"); + sdb_set(res, "enum.foo.0x1", "firstCase"); + sdb_set(res, "enum.foo.0x2", "secondCase"); } static void setup_sdb_for_typedef(Sdb *res) { // td "typedef char *string;" - sdb_set(res, "string", "typedef", 0); - sdb_set(res, "typedef.string", "char *", 0); + sdb_set(res, "string", "typedef"); + sdb_set(res, "typedef.string", "char *"); } static void setup_sdb_for_atomic(Sdb *res) { - sdb_set(res, "char", "type", 0); - sdb_set(res, "type.char.size", "8", 0); - sdb_set(res, "type.char", "c", 0); + sdb_set(res, "char", "type"); + sdb_set(res, "type.char.size", "8"); + sdb_set(res, "type.char", "c"); } static void setup_sdb_for_not_found(Sdb *res) { // malformed type states - sdb_set(res, "foo", "enum", 0); - sdb_set(res, "bar", "struct", 0); - sdb_set(res, "quax", "union", 0); - sdb_set(res, "enum.foo", "aa,bb", 0); - sdb_set(res, "struct.bar", "cc,dd", 0); - sdb_set(res, "union.quax", "ee,ff", 0); - - sdb_set(res, "omega", "struct", 0); - sdb_set(res, "struct.omega", "ee,ff,gg", 0); - sdb_set(res, "struct.omega.ee", "0,1", 0); - sdb_set(res, "struct.omega.ff", "", 0); + sdb_set(res, "foo", "enum"); + sdb_set(res, "bar", "struct"); + sdb_set(res, "quax", "union"); + sdb_set(res, "enum.foo", "aa,bb"); + sdb_set(res, "struct.bar", "cc,dd"); + sdb_set(res, "union.quax", "ee,ff"); + + sdb_set(res, "omega", "struct"); + sdb_set(res, "struct.omega", "ee,ff,gg"); + sdb_set(res, "struct.omega.ee", "0,1"); + sdb_set(res, "struct.omega.ff", ""); } static bool test_types_get_base_type_struct(void) { @@ -251,45 +251,45 @@ static bool test_types_get_base_type_not_found(void) { static void setup_sdb_for_base_types_all(Sdb *res) { // td "struct kappa {int bar;int cow;};" - sdb_set(res, "kappa", "struct", 0); - sdb_set(res, "struct.kappa", "bar,cow", 0); - sdb_set(res, "struct.kappa.bar", "int32_t,0,0", 0); - sdb_set(res, "struct.kappa.cow", "int32_t,4,0", 0); + sdb_set(res, "kappa", "struct"); + sdb_set(res, "struct.kappa", "bar,cow"); + sdb_set(res, "struct.kappa.bar", "int32_t,0,0"); + sdb_set(res, "struct.kappa.cow", "int32_t,4,0"); // td "struct theta {long foo;double *bar[5];};" - sdb_set(res, "theta", "struct", 0); - sdb_set(res, "struct.theta", "foo,bar", 0); - sdb_set(res, "struct.theta.foo", "int64_t,0,0", 0); - sdb_set(res, "struct.theta.bar", "double *,8,5", 0); + sdb_set(res, "theta", "struct"); + sdb_set(res, "struct.theta", "foo,bar"); + sdb_set(res, "struct.theta.foo", "int64_t,0,0"); + sdb_set(res, "struct.theta.bar", "double *,8,5"); // td "union omega {int bar;int cow;};" - sdb_set(res, "omega", "union", 0); - sdb_set(res, "union.omega", "bar,cow", 0); - sdb_set(res, "union.omega.bar", "int32_t,0,0", 0); - sdb_set(res, "union.omega.cow", "int32_t,0,0", 0); + sdb_set(res, "omega", "union"); + sdb_set(res, "union.omega", "bar,cow"); + sdb_set(res, "union.omega.bar", "int32_t,0,0"); + sdb_set(res, "union.omega.cow", "int32_t,0,0"); // td "union omicron {char foo;float bar;};" - sdb_set(res, "omicron", "union", 0); - sdb_set(res, "union.omicron", "foo,bar", 0); - sdb_set(res, "union.omicron.bar", "float,0,0", 0); - sdb_set(res, "union.omicron.foo", "char,0,0", 0); + sdb_set(res, "omicron", "union"); + sdb_set(res, "union.omicron", "foo,bar"); + sdb_set(res, "union.omicron.bar", "float,0,0"); + sdb_set(res, "union.omicron.foo", "char,0,0"); // td "enum foo { firstCase=1, secondCase=2,};" - sdb_set(res, "foo", "enum", 0); - sdb_set(res, "enum.foo", "firstCase,secondCase", 0); - sdb_set(res, "enum.foo.firstCase", "0x1", 0); - sdb_set(res, "enum.foo.secondCase", "0x2", 0); - sdb_set(res, "enum.foo.0x1", "firstCase", 0); - sdb_set(res, "enum.foo.0x2", "secondCase", 0); + sdb_set(res, "foo", "enum"); + sdb_set(res, "enum.foo", "firstCase,secondCase"); + sdb_set(res, "enum.foo.firstCase", "0x1"); + sdb_set(res, "enum.foo.secondCase", "0x2"); + sdb_set(res, "enum.foo.0x1", "firstCase"); + sdb_set(res, "enum.foo.0x2", "secondCase"); // td "enum bla { minusFirstCase=0x100, minusSecondCase=0xf000,};" - sdb_set(res, "bla", "enum", 0); - sdb_set(res, "enum.bla", "minusFirstCase,minusSecondCase", 0); - sdb_set(res, "enum.bla.minusFirstCase", "0x100", 0); - sdb_set(res, "enum.bla.minusSecondCase", "0xf000", 0); - sdb_set(res, "enum.bla.0x100", "minusFirstCase", 0); - sdb_set(res, "enum.bla.0xf000", "minusSecondCase", 0); + sdb_set(res, "bla", "enum"); + sdb_set(res, "enum.bla", "minusFirstCase,minusSecondCase"); + sdb_set(res, "enum.bla.minusFirstCase", "0x100"); + sdb_set(res, "enum.bla.minusSecondCase", "0xf000"); + sdb_set(res, "enum.bla.0x100", "minusFirstCase"); + sdb_set(res, "enum.bla.0xf000", "minusSecondCase"); // td typedef char *string; - sdb_set(res, "char", "type", 0); - sdb_set(res, "type.char.size", "8", 0); - sdb_set(res, "type.char", "c", 0); - sdb_set(res, "string", "typedef", 0); - sdb_set(res, "typedef.string", "char *", 0); + sdb_set(res, "char", "type"); + sdb_set(res, "type.char.size", "8"); + sdb_set(res, "type.char", "c"); + sdb_set(res, "string", "typedef"); + sdb_set(res, "typedef.string", "char *"); } // RzBaseType name comparator