From 0bb29056b849071bedbfed585bb76bb7f4452b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 1 Apr 2024 16:45:38 +0200 Subject: [PATCH] Make RzFlagItem opaque Accessing properties through functions allows the implementation to be swapped out, which is the plan for polymorphic flag sources. --- librz/arch/analysis.c | 5 +- librz/arch/class.c | 2 +- librz/arch/fcn.c | 9 +- librz/arch/filter.c | 20 +- librz/arch/function.c | 32 +-- librz/arch/rtti_itanium.c | 7 +- librz/arch/var.c | 6 +- librz/arch/var_global.c | 4 +- librz/core/analysis_objc.c | 4 +- librz/core/analysis_tp.c | 9 +- librz/core/canalysis.c | 71 +++--- librz/core/carg.c | 2 +- librz/core/cautocmpl.c | 4 +- librz/core/cbin.c | 13 +- librz/core/cdebug.c | 26 +-- librz/core/cfile.c | 11 +- librz/core/cflag.c | 63 +++--- librz/core/cgraph.c | 2 +- librz/core/cil.c | 6 +- librz/core/cmd/cmd.c | 29 +-- librz/core/cmd/cmd_alias.c | 2 +- librz/core/cmd/cmd_analysis.c | 8 +- librz/core/cmd/cmd_block.c | 2 +- librz/core/cmd/cmd_debug.c | 25 +-- librz/core/cmd/cmd_flag.c | 106 ++++----- librz/core/cmd/cmd_meta.c | 2 +- librz/core/cmd/cmd_print.c | 24 ++- librz/core/cmd/cmd_seek.c | 6 +- librz/core/core.c | 42 ++-- librz/core/cprint.c | 12 +- librz/core/disasm.c | 202 ++++++++++-------- librz/core/golang.c | 4 +- librz/core/seek.c | 9 +- librz/core/tui/define.c | 8 +- librz/core/tui/flags.c | 10 +- librz/core/tui/hud.c | 2 +- librz/core/tui/visual.c | 12 +- librz/core/tui/vmenus_graph.c | 4 +- librz/flag/flag.c | 122 ++++++++++- librz/flag/serialize_flag.c | 44 ++-- librz/flag/tags.c | 2 +- librz/include/rz_analysis.h | 6 +- librz/include/rz_flag.h | 28 +-- librz/main/rizin.c | 2 +- librz/main/rz-diff.c | 2 +- test/integration/test_analysis_global_var.c | 24 +-- test/integration/test_cpu_platform_profiles.c | 12 +- test/unit/test_flags.c | 30 +-- test/unit/test_serialize_flag.c | 25 +-- 49 files changed, 632 insertions(+), 470 deletions(-) diff --git a/librz/arch/analysis.c b/librz/arch/analysis.c index 68e9e9ce083..12706ef8813 100644 --- a/librz/arch/analysis.c +++ b/librz/arch/analysis.c @@ -582,7 +582,7 @@ RZ_API bool rz_analysis_noreturn_add(RzAnalysis *analysis, const char *name, ut6 RZ_LOG_ERROR("Cannot find function and flag at address 0x%" PFMT64x "\n", addr); return false; } - tmp_name = fcn ? fcn->name : fi->name; + tmp_name = fcn ? fcn->name : rz_flag_item_get_name(fi); if (fcn) { fcn->is_noreturn = true; } @@ -707,7 +707,8 @@ RZ_API bool rz_analysis_noreturn_at(RzAnalysis *analysis, ut64 addr) { } RzFlagItem *fi = analysis->flag_get(analysis->flb.f, addr); if (fi) { - if (rz_analysis_noreturn_at_name(analysis, fi->realname ? fi->realname : fi->name)) { + const char *rn = rz_flag_item_get_realname(fi); + if (rz_analysis_noreturn_at_name(analysis, rn ? rn : rz_flag_item_get_name(fi))) { return true; } } diff --git a/librz/arch/class.c b/librz/arch/class.c index 82e7d9ea836..7e19dd6bf1a 100644 --- a/librz/arch/class.c +++ b/librz/arch/class.c @@ -566,7 +566,7 @@ static void rz_analysis_class_rename_flag(RzAnalysis *analysis, const char *old_ if (!flag) { return; } - ut64 addr = flag->offset; + ut64 addr = rz_flag_item_get_offset(flag); analysis->flb.unset(analysis->flb.f, flag); analysis->flg_class_set(analysis->flb.f, new_name, addr, 0); } diff --git a/librz/arch/fcn.c b/librz/arch/fcn.c index d7a9444f9a8..ae0c82d63aa 100644 --- a/librz/arch/fcn.c +++ b/librz/arch/fcn.c @@ -156,7 +156,8 @@ static bool isSymbolNextInstruction(RzAnalysis *analysis, RzAnalysisOp *op) { rz_return_val_if_fail(analysis && op && analysis->flb.get_at, false); RzFlagItem *fi = analysis->flb.get_at(analysis->flb.f, op->addr + op->size, false); - return (fi && fi->name && (strstr(fi->name, "imp.") || strstr(fi->name, "sym.") || strstr(fi->name, "entry") || strstr(fi->name, "main"))); + const char *name = fi ? rz_flag_item_get_name(fi) : NULL; + return (fi && name && (strstr(name, "imp.") || strstr(name, "sym.") || strstr(name, "entry") || strstr(name, "main"))); } static bool is_delta_pointer_table(ReadAhead *ra, RzAnalysis *analysis, ut64 addr, ut64 lea_ptr, ut64 *jmptbl_addr, ut64 *casetbl_addr, RzAnalysisOp *jmp_aop) { @@ -474,7 +475,7 @@ static const char *retpoline_reg(RzAnalysis *analysis, ut64 addr) { RzFlagItem *flag = analysis->flag_get(analysis->flb.f, addr); if (flag) { const char *token = "x86_indirect_thunk_"; - const char *thunk = strstr(flag->name, token); + const char *thunk = strstr(rz_flag_item_get_name(flag), token); if (thunk) { return thunk + strlen(token); } @@ -737,7 +738,7 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R if (analysis->opt.nopskip && fcn->addr == at) { RzFlagItem *fi = analysis->flb.get_at(analysis->flb.f, addr, false); - if (!fi || strncmp(fi->name, "sym.", 4)) { + if (!fi || strncmp(rz_flag_item_get_name(fi), "sym.", 4)) { if ((addr + delay.un_idx - oplen) == fcn->addr) { if (rz_analysis_block_relocate(bb, bb->addr + oplen, bb->size - oplen)) { fcn->addr += oplen; @@ -1046,7 +1047,7 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R } { RzFlagItem *fi = analysis->flb.get_at(analysis->flb.f, op.jump, false); - if (fi && strstr(fi->name, "imp.")) { + if (fi && strstr(rz_flag_item_get_name(fi), "imp.")) { gotoBeach(RZ_ANALYSIS_RET_END); } } diff --git a/librz/arch/filter.c b/librz/arch/filter.c index a392df6c289..b408002bf0e 100644 --- a/librz/arch/filter.c +++ b/librz/arch/filter.c @@ -17,10 +17,11 @@ static bool isvalidflag(RzFlagItem *flag) { if (flag) { - if (strstr(flag->name, "main") || strstr(flag->name, "entry")) { + const char *name = rz_flag_item_get_name(flag); + if (strstr(name, "main") || strstr(name, "entry")) { return true; } - if (strchr(flag->name, '.')) { + if (strchr(name, '.')) { return true; } } @@ -234,8 +235,9 @@ static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char // TODO: implement realname with flags, because functions dont hold this yet if (f->realnames) { flag = p->flag_get(f, off); - if (flag && flag->realname) { - name = flag->realname; + const char *rn = flag ? rz_flag_item_get_realname(flag) : NULL; + if (rn) { + name = rn; } } snprintf(str, len, "%s%s%s", data, name, @@ -254,16 +256,16 @@ static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char flag = flag2; } } - if (flag && !strncmp(flag->name, "section.", 8)) { + if (flag && !strncmp(rz_flag_item_get_name(flag), "section.", 8)) { flag = rz_flag_get_i(f, off); } const char *label = fcn ? p->label_get(fcn, off) : NULL; if (label || isvalidflag(flag)) { if (p->notin_flagspace) { - if (p->flagspace == flag->space) { + if (p->flagspace == rz_flag_item_get_space(flag)) { continue; } - } else if (p->flagspace && (p->flagspace != flag->space)) { + } else if (p->flagspace && (p->flagspace != rz_flag_item_get_space(flag))) { ptr = ptr2; continue; } @@ -289,7 +291,7 @@ static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char if (label) { flagname = rz_str_newf(".%s", label); } else { - flagname = rz_str_dup(f->realnames ? flag->realname : flag->name); + flagname = rz_str_dup(f->realnames ? rz_flag_item_get_realname(flag) : rz_flag_item_get_name(flag)); } int maxflagname = p->maxflagnamelen; if (maxflagname > 0 && flagname && strlen(flagname) > maxflagname) { @@ -330,7 +332,7 @@ static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char } } if (p->subrel_addr && !banned && lea) { // TODO: use remove_brackets - int flag_len = strlen(flag->name); + int flag_len = strlen(rz_flag_item_get_name(flag)); char *ptr_end = str + strlen(data) + flag_len - 1; char *ptr_right = ptr_end + 1, *ptr_left, *ptr_esc; bool ansi_found = false; diff --git a/librz/arch/function.c b/librz/arch/function.c index 3ce5b63098b..0764f4dd3c9 100644 --- a/librz/arch/function.c +++ b/librz/arch/function.c @@ -417,7 +417,7 @@ RZ_API RZ_BORROW RzList /**/ *rz_analysis_function_list(Rz #define MIN_MATCH_LEN 4 -static RZ_OWN char *function_name_try_guess(RzTypeDB *typedb, RZ_NONNULL char *name) { +static RZ_OWN char *function_name_try_guess(RzTypeDB *typedb, RZ_NONNULL const char *name) { if (strlen(name) < MIN_MATCH_LEN) { return NULL; } @@ -427,15 +427,15 @@ static RZ_OWN char *function_name_try_guess(RzTypeDB *typedb, RZ_NONNULL char *n return NULL; } -static inline bool is_auto_named(char *func_name, size_t slen) { +static inline bool is_auto_named(const char *func_name, size_t slen) { return slen > 4 && (rz_str_startswith(func_name, "fcn.") || rz_str_startswith(func_name, "loc.")); } -static inline bool has_rz_prefixes(char *func_name, int offset, size_t slen) { +static inline bool has_rz_prefixes(const char *func_name, int offset, size_t slen) { return slen > 4 && (offset + 3 < slen) && func_name[offset + 3] == '.'; } -static char *strip_rz_prefixes(char *func_name, size_t slen) { +static const char *strip_rz_prefixes(const char *func_name, size_t slen) { // strip rizin prefixes (sym, sym.imp, etc') int offset = 0; while (has_rz_prefixes(func_name, offset, slen)) { @@ -444,7 +444,7 @@ static char *strip_rz_prefixes(char *func_name, size_t slen) { return func_name + offset; } -static char *strip_common_prefixes_stdlib(char *func_name) { +static const char *strip_common_prefixes_stdlib(const char *func_name) { // strip common prefixes from standard lib functions if (rz_str_startswith(func_name, "__isoc99_")) { func_name += 9; @@ -456,15 +456,15 @@ static char *strip_common_prefixes_stdlib(char *func_name) { return func_name; } -static char *strip_dll_prefix(char *func_name) { - char *tmp = strstr(func_name, "dll_"); +static const char *strip_dll_prefix(const char *func_name) { + const char *tmp = strstr(func_name, "dll_"); if (tmp) { return tmp + 3; } return func_name; } -static void clean_function_name(char *func_name) { +static void clean_function_name(const char *func_name) { char *last = (char *)rz_str_lchr(func_name, '_'); if (!last || !rz_str_isnumber(last + 1)) { return; @@ -475,7 +475,7 @@ static void clean_function_name(char *func_name) { /** * \brief Checks if the function name was generated by Rizin automatically */ -RZ_API bool rz_analysis_function_is_autonamed(RZ_NONNULL char *name) { +RZ_API bool rz_analysis_function_is_autonamed(RZ_NONNULL const char *name) { size_t len = strlen(name); return (len >= MIN_MATCH_LEN) && (is_auto_named(name, len) || has_rz_prefixes(name, 0, len)); } @@ -490,9 +490,9 @@ RZ_API bool rz_analysis_function_is_autonamed(RZ_NONNULL char *name) { * \param typedb RzTypeDB instance * \param name Function name to check */ -RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL char *name) { +RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL const char *name) { rz_return_val_if_fail(typedb && name, NULL); - char *str = name; + const char *str = name; char *result = NULL; size_t slen = strlen(str); @@ -508,14 +508,14 @@ RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL return result; } - str = strdup(str); - clean_function_name(str); + char *rstr = strdup(str); + clean_function_name(rstr); - if (*str == '_' && (result = function_name_try_guess(typedb, str + 1))) { - free(str); + if (*rstr == '_' && (result = function_name_try_guess(typedb, rstr + 1))) { + free(rstr); return result; } - free(str); + free(rstr); return result; } diff --git a/librz/arch/rtti_itanium.c b/librz/arch/rtti_itanium.c index 11e3ab8da63..2672825be5f 100644 --- a/librz/arch/rtti_itanium.c +++ b/librz/arch/rtti_itanium.c @@ -458,11 +458,12 @@ static RTypeInfoType rtti_itanium_type_info_type_from_flag(RVTableContext *conte RzListIter *iter; RzFlagItem *flag; rz_list_foreach (flags, iter, flag) { - if (strstr(flag->name, VMI_CLASS_TYPE_INFO_NAME)) { + const char *name = rz_flag_item_get_name(flag); + if (strstr(name, VMI_CLASS_TYPE_INFO_NAME)) { return RZ_TYPEINFO_TYPE_VMI_CLASS; - } else if (strstr(flag->name, SI_CLASS_TYPE_INFO_NAME)) { + } else if (strstr(name, SI_CLASS_TYPE_INFO_NAME)) { return RZ_TYPEINFO_TYPE_SI_CLASS; - } else if (strstr(flag->name, CLASS_TYPE_INFO_NAME)) { + } else if (strstr(name, CLASS_TYPE_INFO_NAME)) { return RZ_TYPEINFO_TYPE_CLASS; } } diff --git a/librz/arch/var.c b/librz/arch/var.c index ae3defb4e4b..19d86464f96 100644 --- a/librz/arch/var.c +++ b/librz/arch/var.c @@ -1402,7 +1402,7 @@ RZ_API void rz_analysis_extract_rarg(RzAnalysis *analysis, RzAnalysisOp *op, RzA RzCore *core = (RzCore *)analysis->coreb.core; RzFlagItem *flag = rz_flag_get_by_spaces(core->flags, offset, RZ_FLAGS_FS_IMPORTS, NULL); if (flag) { - callee = rz_analysis_function_name_guess(analysis->typedb, flag->name); + callee = rz_analysis_function_name_guess(analysis->typedb, rz_flag_item_get_name(flag)); if (callee) { const char *cc = rz_analysis_cc_func(analysis, callee); if (cc && !strcmp(fcn->cc, cc)) { @@ -1668,7 +1668,7 @@ RZ_API void rz_analysis_fcn_vars_cache_fini(RzAnalysisFcnVarsCache *cache) { rz_list_free(cache->arg_vars); } -static char *sig_from_debuginfo(RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn, char *fcn_name, const char *fcn_name_pre, const char *fcn_name_post) { +static char *sig_from_debuginfo(RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn, const char *fcn_name, const char *fcn_name_pre, const char *fcn_name_post) { if (!fcn->has_debuginfo || !rz_str_startswith(fcn_name, "dbg.")) return NULL; @@ -1690,7 +1690,7 @@ static char *sig_from_debuginfo(RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunct * \param fcn_name_post The suffix to use to highlight the function name * \return {return} */ -RZ_API char *rz_analysis_fcn_format_sig(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn, RZ_NULLABLE char *fcn_name, +RZ_API char *rz_analysis_fcn_format_sig(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn, RZ_NULLABLE const char *fcn_name, RZ_NULLABLE RzAnalysisFcnVarsCache *reuse_cache, RZ_NULLABLE const char *fcn_name_pre, RZ_NULLABLE const char *fcn_name_post) { fcn_name = !fcn_name ? fcn->name : fcn_name; if (!fcn_name) { diff --git a/librz/arch/var_global.c b/librz/arch/var_global.c index d9f813ab901..d313ae029c2 100644 --- a/librz/arch/var_global.c +++ b/librz/arch/var_global.c @@ -40,7 +40,7 @@ static void global_var_set_type(RzAnalysisVarGlobal *glob, RzType *type) { RzFlagItem *flag = rz_analysis_var_global_get_flag_item(glob); if (flag) { - flag->size = rz_type_db_get_bitsize(glob->analysis->typedb, glob->type) / 8; + rz_flag_item_set_size(flag, rz_type_db_get_bitsize(glob->analysis->typedb, glob->type) / 8); } } @@ -140,7 +140,7 @@ RZ_API RZ_NULLABLE RzFlagItem *rz_analysis_var_global_get_flag_item(RzAnalysisVa return NULL; } RzFlagItem *r = rz_flag_get(a->flb.f, glob->name); - if (r && r->offset != glob->addr) { + if (r && rz_flag_item_get_offset(r) != glob->addr) { return NULL; } return r; diff --git a/librz/core/analysis_objc.c b/librz/core/analysis_objc.c index 94505a402e0..35434ad96d0 100644 --- a/librz/core/analysis_objc.c +++ b/librz/core/analysis_objc.c @@ -500,7 +500,7 @@ static bool flag_with_space_exists_at(RzCore *core, ut64 addr, RzSpace *space) { RzListIter *it; RzFlagItem *fi; rz_list_foreach (existing, it, fi) { - if (fi->space && fi->space == space) { + if (rz_flag_item_get_space(fi) && rz_flag_item_get_space(fi) == space) { // Do not create a flag if there is already a symbol (unstripped bin) return true; } @@ -518,7 +518,7 @@ static void apply_selector_stub_at(RzCore *core, ut64 addr, ut32 size, char *sel // If there is already a function (e.g. from aa), rename it too RzAnalysisFunction *fcn = rz_analysis_get_function_at(core->analysis, addr); if (fcn) { - rz_core_analysis_function_rename(core, addr, fi->name); + rz_core_analysis_function_rename(core, addr, rz_flag_item_get_name(fi)); } } diff --git a/librz/core/analysis_tp.c b/librz/core/analysis_tp.c index 5a17d88c3ce..894f50b482c 100644 --- a/librz/core/analysis_tp.c +++ b/librz/core/analysis_tp.c @@ -449,7 +449,7 @@ static void type_match(RzCore *core, char *fcn_name, ut64 addr, ut64 baddr, cons RzFlagItem *f = rz_flag_get_by_spaces(core->flags, op->ptr, RZ_FLAGS_FS_STRINGS, NULL); if (f) { char formatstr[0x200]; - int read = rz_io_nread_at(core->io, f->offset, (ut8 *)formatstr, RZ_MIN(sizeof(formatstr) - 1, f->size)); + int read = rz_io_nread_at(core->io, rz_flag_item_get_offset(f), (ut8 *)formatstr, RZ_MIN(sizeof(formatstr) - 1, rz_flag_item_get_size(f))); if (read > 0) { formatstr[read] = '\0'; if ((types = parse_format(core, formatstr))) { @@ -649,7 +649,7 @@ void propagate_types_among_used_variables(RzCore *core, HtUP *op_cache, RzAnalys RzILTraceInstruction *cur_instr_trace = rz_analysis_esil_get_instruction_trace(etrace, ctx->cur_idx); if (aop->type == RZ_ANALYSIS_OP_TYPE_CALL || aop->type & RZ_ANALYSIS_OP_TYPE_UCALL) { - char *full_name = NULL; + const char *full_name = NULL; ut64 callee_addr; if (aop->type == RZ_ANALYSIS_OP_TYPE_CALL) { RzAnalysisFunction *fcn_call = rz_analysis_get_fcn_in(core->analysis, aop->jump, -1); @@ -659,8 +659,9 @@ void propagate_types_among_used_variables(RzCore *core, HtUP *op_cache, RzAnalys } } else if (aop->ptr != UT64_MAX) { RzFlagItem *flag = rz_flag_get_by_spaces(core->flags, aop->ptr, RZ_FLAGS_FS_IMPORTS, NULL); - if (flag && flag->realname) { - full_name = flag->realname; + const char *rn = flag ? rz_flag_item_get_realname(flag) : NULL; + if (rn) { + full_name = rn; callee_addr = aop->ptr; } } diff --git a/librz/core/canalysis.c b/librz/core/canalysis.c index f9c8befae15..8a46937199b 100644 --- a/librz/core/canalysis.c +++ b/librz/core/canalysis.c @@ -51,7 +51,7 @@ static char *getFunctionName(RzCore *core, ut64 addr) { } RzFlagItem *flag = rz_core_flag_get_by_spaces(core->flags, addr); - return (flag && flag->name) ? strdup(flag->name) : NULL; + return (flag && rz_flag_item_get_name(flag)) ? strdup(rz_flag_item_get_name(flag)) : NULL; } static char *getFunctionNamePrefix(RzCore *core, ut64 off, const char *name) { @@ -560,31 +560,32 @@ RZ_API RZ_OWN char *rz_core_analysis_function_autoname(RZ_NONNULL RzCore *core, RzList *xrefs = rz_analysis_function_get_xrefs_from(fcn); rz_list_foreach (xrefs, iter, xref) { RzFlagItem *f = rz_flag_get_i(core->flags, xref->to); - if (f && !blacklisted_word(f->name)) { - if (strstr(f->name, ".isatty")) { + const char *name = f ? rz_flag_item_get_name(f) : NULL; + if (name && !blacklisted_word(name)) { + if (strstr(name, ".isatty")) { use_isatty = 1; } - if (strstr(f->name, ".getopt")) { + if (strstr(name, ".getopt")) { use_getopt = 1; } - if (!strncmp(f->name, "method.", 7)) { + if (!strncmp(name, "method.", 7)) { free(do_call); - do_call = strdup(f->name + 7); + do_call = strdup(name + 7); break; } - if (!strncmp(f->name, "str.", 4)) { + if (!strncmp(name, "str.", 4)) { free(do_call); - do_call = strdup(f->name + 4); + do_call = strdup(name + 4); break; } - if (!strncmp(f->name, "sym.imp.", 8)) { + if (!strncmp(name, "sym.imp.", 8)) { free(do_call); - do_call = strdup(f->name + 8); + do_call = strdup(name + 8); break; } - if (!strncmp(f->name, "reloc.", 6)) { + if (!strncmp(name, "reloc.", 6)) { free(do_call); - do_call = strdup(f->name + 6); + do_call = strdup(name + 6); break; } } @@ -595,7 +596,7 @@ RZ_API RZ_OWN char *rz_core_analysis_function_autoname(RZ_NONNULL RzCore *core, RzFlagItem *item = rz_flag_get(core->flags, "main"); free(do_call); // if referenced from entrypoint. this should be main - if (item && item->offset == fcn->addr) { + if (item && rz_flag_item_get_offset(item) == fcn->addr) { return strdup("main"); // main? } return strdup("parse_args"); // main? @@ -624,17 +625,17 @@ RZ_API void rz_core_analysis_function_strings_print(RZ_NONNULL RzCore *core, RZ_ RzList *xrefs = rz_analysis_function_get_xrefs_from(fcn); rz_list_foreach (xrefs, iter, xref) { RzFlagItem *f = rz_flag_get_by_spaces(core->flags, xref->to, RZ_FLAGS_FS_STRINGS, NULL); - if (!f || !f->space || strcmp(f->space->name, RZ_FLAGS_FS_STRINGS)) { + if (!f || !rz_flag_item_get_space(f) || strcmp(rz_flag_item_get_space(f)->name, RZ_FLAGS_FS_STRINGS)) { continue; } if (pj) { pj_o(pj); pj_kn(pj, "addr", xref->from); pj_kn(pj, "ref", xref->to); - pj_ks(pj, "flag", f->name); + pj_ks(pj, "flag", rz_flag_item_get_name(f)); pj_end(pj); } else { - rz_cons_printf("0x%08" PFMT64x " 0x%08" PFMT64x " %s\n", xref->from, xref->to, f->name); + rz_cons_printf("0x%08" PFMT64x " 0x%08" PFMT64x " %s\n", xref->from, xref->to, rz_flag_item_get_name(f)); } } rz_list_free(xrefs); @@ -787,9 +788,9 @@ static void autoname_imp_trampoline(RzCore *core, RzAnalysisFunction *fcn) { RzAnalysisXRef *xref = rz_list_first(xrefs); if (xref->type != RZ_ANALYSIS_XREF_TYPE_CALL) { /* Some fcns don't return */ RzFlagItem *flg = rz_flag_get_i(core->flags, xref->to); - if (flg && rz_str_startswith(flg->name, "sym.imp.")) { + if (flg && rz_str_startswith(rz_flag_item_get_name(flg), "sym.imp.")) { RZ_FREE(fcn->name); - fcn->name = rz_str_newf("sub.%s", flg->name + 8); + fcn->name = rz_str_newf("sub.%s", rz_flag_item_get_name(flg) + 8); } } } @@ -800,12 +801,13 @@ static void autoname_imp_trampoline(RzCore *core, RzAnalysisFunction *fcn) { static void set_fcn_name_from_flag(RzAnalysisFunction *fcn, RzFlagItem *f, const char *fcnpfx) { char tmpbuf[128]; bool nameChanged = false; - if (f && f->name) { + const char *name = f ? rz_flag_item_get_name(f) : NULL; + if (name) { if (!strncmp(fcn->name, "loc.", 4) || !strncmp(fcn->name, "fcn.", 4)) { - rz_analysis_function_rename(fcn, f->name); + rz_analysis_function_rename(fcn, name); nameChanged = true; - } else if (strncmp(f->name, "sect", 4)) { - rz_analysis_function_rename(fcn, f->name); + } else if (strncmp(name, "sect", 4)) { + rz_analysis_function_rename(fcn, name); nameChanged = true; } } @@ -815,7 +817,8 @@ static void set_fcn_name_from_flag(RzAnalysisFunction *fcn, RzFlagItem *f, const } static bool is_entry_flag(RzFlagItem *f) { - return f->space && !strcmp(f->space->name, RZ_FLAGS_FS_SYMBOLS) && rz_str_startswith(f->name, "entry."); + RzSpace *space = rz_flag_item_get_space(f); + return space && !strcmp(space->name, RZ_FLAGS_FS_SYMBOLS) && rz_str_startswith(rz_flag_item_get_name(f), "entry."); } static int __core_analysis_fcn(RzCore *core, ut64 at, ut64 from, int reftype, int depth) { @@ -894,8 +897,8 @@ static int __core_analysis_fcn(RzCore *core, ut64 at, ut64 from, int reftype, in goto error; } else if (fcnlen == RZ_ANALYSIS_RET_END) { /* Function analysis complete */ f = rz_core_flag_get_by_spaces(core->flags, fcn->addr); - if (f && f->name && strncmp(f->name, "sect", 4)) { /* Check if it's already flagged */ - char *new_name = strdup(f->name); + if (f && strncmp(rz_flag_item_get_name(f), "sect", 4)) { /* Check if it's already flagged */ + char *new_name = strdup(rz_flag_item_get_name(f)); if (is_entry_flag(f)) { RzBinSymbol *sym; RzBinObject *o = rz_bin_cur_object(core->bin); @@ -1481,8 +1484,8 @@ RZ_API int rz_core_analysis_esil_fcn(RzCore *core, ut64 at, ut64 from, int refty } static int find_sym_flag(const void *a1, const void *a2, void *user) { - const RzFlagItem *f = (const RzFlagItem *)a2; - return f->space && !strcmp(f->space->name, RZ_FLAGS_FS_SYMBOLS) ? 0 : 1; + const RzSpace *space = rz_flag_item_get_space((const RzFlagItem *)a2); + return space && !strcmp(space->name, RZ_FLAGS_FS_SYMBOLS) ? 0 : 1; } static bool is_skippable_addr(RzCore *core, ut64 addr) { @@ -2381,8 +2384,8 @@ RZ_API int rz_core_analysis_all(RzCore *core) { /* Entries */ item = rz_flag_get(core->flags, "entry0"); if (item) { - rz_core_analysis_fcn(core, item->offset, -1, RZ_ANALYSIS_XREF_TYPE_NULL, depth - 1); - rz_core_analysis_function_rename(core, item->offset, "entry0"); + rz_core_analysis_fcn(core, rz_flag_item_get_offset(item), -1, RZ_ANALYSIS_XREF_TYPE_NULL, depth - 1); + rz_core_analysis_function_rename(core, rz_flag_item_get_offset(item), "entry0"); } else { rz_core_analysis_function_add(core, NULL, core->offset, false); } @@ -2525,7 +2528,7 @@ struct block_flags_stat_t { static bool block_flags_stat(RzFlagItem *fi, void *user) { struct block_flags_stat_t *u = (struct block_flags_stat_t *)user; - size_t piece = (fi->offset - u->from) / u->step; + size_t piece = (rz_flag_item_get_offset(fi) - u->from) / u->step; u->blocks[piece].flags++; return true; } @@ -3361,7 +3364,7 @@ RZ_API bool rz_core_analysis_function_rename(RzCore *core, ut64 addr, const char RzAnalysisFunction *fcn = rz_analysis_get_function_at(core->analysis, addr); if (fcn) { RzFlagItem *flag = rz_flag_get(core->flags, fcn->name); - if (flag && flag->space && strcmp(flag->space->name, RZ_FLAGS_FS_FUNCTIONS) == 0) { + if (flag && rz_flag_item_get_space(flag) && strcmp(rz_flag_item_get_space(flag)->name, RZ_FLAGS_FS_FUNCTIONS) == 0) { // Only flags in the functions fs should be renamed, e.g. we don't want to rename symbol flags. if (!rz_flag_rename(core->flags, flag, name)) { // If the rename failed, it may be because there is already a flag with the target name @@ -5692,8 +5695,8 @@ RZ_API RZ_OWN RzCoreAnalysisName *rz_core_analysis_name(RZ_NONNULL RzCore *core, p->offset = tgt_addr; } else if (f) { p->type = RZ_CORE_ANALYSIS_NAME_TYPE_FLAG; - p->name = strdup(f->name); - p->realname = strdup(f->realname); + p->name = strdup(rz_flag_item_get_name(f)); + p->realname = rz_str_dup(rz_flag_item_get_realname(f)); p->offset = tgt_addr; } else { p->type = RZ_CORE_ANALYSIS_NAME_TYPE_ADDRESS; @@ -5764,7 +5767,7 @@ static void _analysis_calls(RzCore *core, ut64 addr, ut64 addr_end, bool imports bool isValidCall = true; if (imports_only) { RzFlagItem *f = rz_flag_get_i(core->flags, op.jump); - if (!f || !strstr(f->name, "imp.")) { + if (!f || !strstr(rz_flag_item_get_name(f), "imp.")) { isValidCall = false; } } diff --git a/librz/core/carg.c b/librz/core/carg.c index 3193723d9fa..c7f718de38c 100644 --- a/librz/core/carg.c +++ b/librz/core/carg.c @@ -231,7 +231,7 @@ RZ_API void rz_core_print_func_args(RzCore *core) { if (core->flags) { RzFlagItem *item = rz_flag_get_i(core->flags, pcv); if (item) { - fcn_name = item->name; + fcn_name = rz_flag_item_get_name(item); } } } diff --git a/librz/core/cautocmpl.c b/librz/core/cautocmpl.c index aeb55296f44..2363e263cde 100644 --- a/librz/core/cautocmpl.c +++ b/librz/core/cautocmpl.c @@ -349,7 +349,7 @@ static void autocmplt_cmd_arg_flag(RzCore *core, RzLineNSCompletionResult *res, RzListIter *iter; RzList *list = rz_flag_all_list(core->flags, false); rz_list_foreach (list, iter, item) { - char *flag = item->name; + const char *flag = rz_flag_item_get_name(item); if (!strncmp(flag, s, len)) { rz_line_ns_completion_result_add(res, flag); } @@ -359,7 +359,7 @@ static void autocmplt_cmd_arg_flag(RzCore *core, RzLineNSCompletionResult *res, static bool offset_prompt_add_flag(RzFlagItem *fi, void *user) { RzLineNSCompletionResult *res = (RzLineNSCompletionResult *)user; - rz_line_ns_completion_result_add(res, fi->name); + rz_line_ns_completion_result_add(res, rz_flag_item_get_name(fi)); return true; } diff --git a/librz/core/cbin.c b/librz/core/cbin.c index 5a97ff580e1..9147bb330d4 100644 --- a/librz/core/cbin.c +++ b/librz/core/cbin.c @@ -195,7 +195,7 @@ RZ_API void rz_core_bin_export_info(RzCore *core, int mode) { } else if (IS_MODE_SET(mode)) { RzFlagItem *fi = rz_flag_get(core->flags, flagname); if (fi) { - fi->size = rz_num_math(core->num, v); + rz_flag_item_set_size(fi, rz_num_math(core->num, v)); } else { RZ_LOG_ERROR("core: cannot find flag named '%s'\n", flagname); } @@ -1162,7 +1162,7 @@ static void reloc_set_flag(RzCore *core, RzBinReloc *reloc, const char *prefix, } rz_name_filter(flag_name, 0, true); RzFlagItem *existing = rz_flag_get(core->flags, flag_name); - if (existing && existing->offset == flag_addr) { + if (existing && rz_flag_item_get_offset(existing) == flag_addr) { // Mostly important for target flags. // We don't want hundreds of reloc.target.. flags at the same location free(reloc_name); @@ -1527,12 +1527,13 @@ RZ_API bool rz_core_bin_apply_symbols(RzCore *core, RzBinFile *binfile, bool va) } if (fi) { rz_flag_item_set_realname(fi, sn.methname); - if (fi->offset == addr) { + if ((rz_flag_item_get_offset(fi)) == addr) { rz_flag_unset(core->flags, fi); } } else { fi = rz_flag_set(core->flags, sn.methflag, addr, symbol->size); - char *comment = (fi && fi->comment) ? strdup(fi->comment) : NULL; + const char *fcomment = fi ? rz_flag_item_get_comment(fi) : NULL; + char *comment = fcomment ? strdup(fcomment) : NULL; if (comment) { rz_flag_item_set_comment(fi, comment); RZ_FREE(comment); @@ -1546,7 +1547,7 @@ RZ_API bool rz_core_bin_apply_symbols(RzCore *core, RzBinFile *binfile, bool va) RzFlagItem *fi = rz_flag_get(core->flags, fnp); if (fi) { RZ_FREE(fnp); - if (fi->offset == addr) { + if (rz_flag_item_get_offset(fi) == addr) { // we have a duplicate flag which points // at the same address and same name. rz_core_sym_name_fini(&sn); @@ -1562,7 +1563,7 @@ RZ_API bool rz_core_bin_apply_symbols(RzCore *core, RzBinFile *binfile, bool va) fi = rz_flag_set(core->flags, fnp, addr, symbol->size); if (fi) { rz_flag_item_set_realname(fi, n); - fi->demangled = (bool)(size_t)sn.demname; + rz_flag_item_set_demangled(fi, sn.demname != NULL); } else if (fn) { RZ_LOG_WARN("core: cannot set flag with name '%s'\n", fnp); } diff --git a/librz/core/cdebug.c b/librz/core/cdebug.c index bf24af2ed2e..102fadf6cec 100644 --- a/librz/core/cdebug.c +++ b/librz/core/cdebug.c @@ -889,33 +889,33 @@ static void get_backtrace_info(RzCore *core, RzDebugFrame *frame, ut64 addr, *flagdesc = NULL; *flagdesc2 = NULL; if (f) { - if (f->offset != addr) { - int delta = (int)(frame->addr - f->offset); + if (rz_flag_item_get_offset(f) != addr) { + int delta = (int)(frame->addr - rz_flag_item_get_offset(f)); if (delta > 0) { - *flagdesc = rz_str_newf("%s+%d", f->name, delta); + *flagdesc = rz_str_newf("%s+%d", rz_flag_item_get_name(f), delta); } else if (delta < 0) { - *flagdesc = rz_str_newf("%s%d", f->name, delta); + *flagdesc = rz_str_newf("%s%d", rz_flag_item_get_name(f), delta); } else { - *flagdesc = rz_str_newf("%s", f->name); + *flagdesc = rz_str_newf("%s", rz_flag_item_get_name(f)); } } else { - *flagdesc = rz_str_newf("%s", f->name); + *flagdesc = rz_str_newf("%s", rz_flag_item_get_name(f)); } - if (!strchr(f->name, '.')) { + if (!strchr(rz_flag_item_get_name(f), '.')) { f2 = rz_flag_get_at(core->flags, frame->addr - 1, true); } if (f2 && f2 != f) { - if (f2->offset != addr) { - int delta = (int)(frame->addr - 1 - f2->offset); + if (rz_flag_item_get_offset(f2) != addr) { + int delta = (int)(frame->addr - 1 - rz_flag_item_get_offset(f2)); if (delta > 0) { - *flagdesc2 = rz_str_newf("%s+%d", f2->name, delta + 1); + *flagdesc2 = rz_str_newf("%s+%d", rz_flag_item_get_name(f2), delta + 1); } else if (delta < 0) { - *flagdesc2 = rz_str_newf("%s%d", f2->name, delta + 1); + *flagdesc2 = rz_str_newf("%s%d", rz_flag_item_get_name(f2), delta + 1); } else { - *flagdesc2 = rz_str_newf("%s+1", f2->name); + *flagdesc2 = rz_str_newf("%s+1", rz_flag_item_get_name(f2)); } } else { - *flagdesc2 = rz_str_newf("%s", f2->name); + *flagdesc2 = rz_str_newf("%s", rz_flag_item_get_name(f2)); } } } diff --git a/librz/core/cfile.c b/librz/core/cfile.c index cbe5da44390..23d51dd3b96 100644 --- a/librz/core/cfile.c +++ b/librz/core/cfile.c @@ -100,8 +100,11 @@ static bool __rebase_flags(RzFlagItem *flag, void *user) { // Only rebase flags that were in the rebased sections, otherwise it will take too long rz_pvector_foreach (reb->old_sections, it) { sec = *it; - if (__is_inside_section(flag->offset, sec)) { - rz_flag_set(reb->core->flags, flag->name, flag->offset + reb->diff, flag->size); + if (__is_inside_section(rz_flag_item_get_offset(flag), sec)) { + rz_flag_set(reb->core->flags, + rz_flag_item_get_name(flag), + rz_flag_item_get_offset(flag) + reb->diff, + rz_flag_item_get_size(flag)); break; } } @@ -622,7 +625,7 @@ static bool setbpint(RzCore *r, const char *mode, const char *sym) { if (!fi) { return false; } - bp = rz_bp_add_sw(r->dbg->bp, fi->offset, 1, RZ_PERM_X); + bp = rz_bp_add_sw(r->dbg->bp, rz_flag_item_get_offset(fi), 1, RZ_PERM_X); if (bp) { bp->internal = true; #if __linux__ @@ -1088,7 +1091,7 @@ RZ_API bool rz_core_bin_load(RZ_NONNULL RzCore *r, RZ_NULLABLE const char *filen free(name); continue; } - ut64 imp_addr = flag->offset; + ut64 imp_addr = rz_flag_item_get_offset(flag); RzCoreLinkData linkdata = { imp->name, UT64_MAX, r->bin }; rz_id_storage_foreach(r->io->files, (RzIDStorageForeachCb)resolve_import_cb, &linkdata); if (linkdata.addr != UT64_MAX) { diff --git a/librz/core/cflag.c b/librz/core/cflag.c index b20616b2620..0cdfb367f04 100644 --- a/librz/core/cflag.c +++ b/librz/core/cflag.c @@ -20,30 +20,30 @@ struct print_flag_t { static bool print_flag_name(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; - if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { + if (u->in_range && (rz_flag_item_get_offset(flag) < u->range_from || rz_flag_item_get_offset(flag) >= u->range_to)) { return true; } - rz_cons_printf("%s\n", flag->name); + rz_cons_printf("%s\n", rz_flag_item_get_name(flag)); return true; } static bool print_flag_json(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; - if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { + if (u->in_range && (rz_flag_item_get_offset(flag) < u->range_from || rz_flag_item_get_offset(flag) >= u->range_to)) { return true; } - const char *realname = RZ_STR_ISEMPTY(flag->realname) ? flag->name : flag->realname; + const char *realname = RZ_STR_ISEMPTY(rz_flag_item_get_realname(flag)) ? rz_flag_item_get_name(flag) : rz_flag_item_get_realname(flag); pj_o(u->pj); - pj_ks(u->pj, "name", flag->name); + pj_ks(u->pj, "name", rz_flag_item_get_name(flag)); pj_ks(u->pj, "realname", realname); - pj_ki(u->pj, "size", flag->size); - if (flag->alias) { - pj_ks(u->pj, "alias", flag->alias); + pj_ki(u->pj, "size", rz_flag_item_get_size(flag)); + if (rz_flag_item_get_alias(flag)) { + pj_ks(u->pj, "alias", rz_flag_item_get_alias(flag)); } else { - pj_kn(u->pj, "offset", flag->offset); + pj_kn(u->pj, "offset", rz_flag_item_get_offset(flag)); } - if (flag->comment) { - pj_ks(u->pj, "comment", flag->comment); + if (rz_flag_item_get_comment(flag)) { + pj_ks(u->pj, "comment", rz_flag_item_get_comment(flag)); } pj_end(u->pj); return true; @@ -52,15 +52,15 @@ static bool print_flag_json(RzFlagItem *flag, void *user) { static bool print_flag_rizin(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; char *comment_b64 = NULL, *tmp = NULL; - if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { + if (u->in_range && (rz_flag_item_get_offset(flag) < u->range_from || rz_flag_item_get_offset(flag) >= u->range_to)) { return true; } - if (!u->fs || flag->space != u->fs) { - u->fs = flag->space; + if (!u->fs || rz_flag_item_get_space(flag) != u->fs) { + u->fs = rz_flag_item_get_space(flag); rz_cons_printf("fs %s\n", u->fs ? u->fs->name : "*"); } - if (RZ_STR_ISNOTEMPTY(flag->comment)) { - comment_b64 = rz_base64_encode_dyn((const ut8 *)flag->comment, strlen(flag->comment)); + if (RZ_STR_ISNOTEMPTY(rz_flag_item_get_comment(flag))) { + comment_b64 = rz_base64_encode_dyn((const ut8 *)rz_flag_item_get_comment(flag), strlen(rz_flag_item_get_comment(flag))); // prefix the armored string with "base64:" if (comment_b64) { tmp = rz_str_newf("base64:%s", comment_b64); @@ -68,15 +68,15 @@ static bool print_flag_rizin(RzFlagItem *flag, void *user) { comment_b64 = tmp; } } - if (flag->alias) { - rz_cons_printf("fa %s %s\n", flag->name, flag->alias); + if (rz_flag_item_get_alias(flag)) { + rz_cons_printf("fa %s %s\n", rz_flag_item_get_name(flag), rz_flag_item_get_alias(flag)); if (comment_b64) { rz_cons_printf("\"fC %s %s\"\n", - flag->name, rz_str_get(comment_b64)); + rz_flag_item_get_name(flag), rz_str_get(comment_b64)); } } else { rz_cons_printf("f %s %" PFMT64d " 0x%08" PFMT64x " %s\n", - flag->name, flag->size, flag->offset, + rz_flag_item_get_name(flag), rz_flag_item_get_size(flag), rz_flag_item_get_offset(flag), rz_str_get(comment_b64)); } @@ -86,28 +86,29 @@ static bool print_flag_rizin(RzFlagItem *flag, void *user) { static bool print_flag_orig_name(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; - if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { + if (u->in_range && (rz_flag_item_get_offset(flag) < u->range_from || rz_flag_item_get_offset(flag) >= u->range_to)) { return true; } - if (flag->alias) { - const char *n = u->real ? flag->realname : flag->name; - rz_cons_printf("%s %" PFMT64d " %s\n", flag->alias, flag->size, n); + if (rz_flag_item_get_alias(flag)) { + const char *n = u->real ? rz_flag_item_get_realname(flag) : rz_flag_item_get_name(flag); + rz_cons_printf("%s %" PFMT64d " %s\n", rz_flag_item_get_alias(flag), rz_flag_item_get_size(flag), n); } else { - const char *n = u->real ? flag->realname : (u->f->realnames ? flag->realname : flag->name); - rz_cons_printf("0x%08" PFMT64x " %" PFMT64d " %s\n", flag->offset, flag->size, n); + const char *n = u->real ? rz_flag_item_get_realname(flag) : (u->f->realnames ? rz_flag_item_get_realname(flag) : rz_flag_item_get_name(flag)); + rz_cons_printf("0x%08" PFMT64x " %" PFMT64d " %s\n", rz_flag_item_get_offset(flag), rz_flag_item_get_size(flag), n); } return true; } static bool print_flag_table(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; - if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { + if (u->in_range && (rz_flag_item_get_offset(flag) < u->range_from || rz_flag_item_get_offset(flag) >= u->range_to)) { return true; } - if (!RZ_STR_ISEMPTY(flag->name)) { - const char *spaceName = (flag->space && flag->space->name) ? flag->space->name : ""; - const char *realname = RZ_STR_ISEMPTY(flag->realname) ? flag->name : flag->realname; - rz_table_add_rowf(u->tbl, "Xdsss", flag->offset, flag->size, spaceName, flag->name, realname); + if (!RZ_STR_ISEMPTY(rz_flag_item_get_name(flag))) { + RzSpace *space = rz_flag_item_get_space(flag); + const char *spaceName = (space && space->name) ? space->name : ""; + const char *realname = RZ_STR_ISEMPTY(rz_flag_item_get_realname(flag)) ? rz_flag_item_get_name(flag) : rz_flag_item_get_realname(flag); + rz_table_add_rowf(u->tbl, "Xdsss", rz_flag_item_get_offset(flag), rz_flag_item_get_size(flag), spaceName, rz_flag_item_get_name(flag), realname); } return true; } diff --git a/librz/core/cgraph.c b/librz/core/cgraph.c index a24bc85e0c8..723e03d4be7 100644 --- a/librz/core/cgraph.c +++ b/librz/core/cgraph.c @@ -22,7 +22,7 @@ static inline bool is_between(ut64 a, ut64 x, ut64 b) { static inline char *core_flag_name(const RzCore *core, ut64 addr) { RzFlagItem *item = rz_flag_get_i(core->flags, addr); - return item ? strdup(item->name) : rz_str_newf("0x%08" PFMT64x, addr); + return item ? strdup(rz_flag_item_get_name(item)) : rz_str_newf("0x%08" PFMT64x, addr); } static inline void core_graph_dataref(RzCore *core, RzAnalysisFunction *fcn, RzGraph /**/ *graph) { diff --git a/librz/core/cil.c b/librz/core/cil.c index 1f9ffad9da0..df2d87eb697 100644 --- a/librz/core/cil.c +++ b/librz/core/cil.c @@ -217,8 +217,8 @@ RZ_IPI void rz_core_analysis_esil_init_mem_p(RzCore *core) { ut32 size = 0xf0000; RzFlagItem *fi = rz_flag_get(core->flags, "aeim.stack"); if (fi) { - addr = fi->offset; - size = fi->size; + addr = rz_flag_item_get_offset(fi); + size = rz_flag_item_get_size(fi); } else { rz_core_analysis_esil_init_mem(core, NULL, UT64_MAX, UT32_MAX); } @@ -1513,7 +1513,7 @@ RZ_API void rz_core_analysis_esil(RzCore *core, ut64 addr, ut64 size, RZ_NULLABL rz_core_add_string_ref(core, op.addr, dst); } if ((f = rz_core_flag_get_by_spaces(core->flags, dst))) { - rz_meta_set_string(core->analysis, RZ_META_TYPE_COMMENT, cur, f->name); + rz_meta_set_string(core->analysis, RZ_META_TYPE_COMMENT, cur, rz_flag_item_get_name(f)); } else if (rz_core_get_string_at(core, dst, &str, NULL, NULL, true)) { char *str2 = rz_str_newf("esilref: '%s'", str); // HACK avoid format string inside string used later as format diff --git a/librz/core/cmd/cmd.c b/librz/core/cmd/cmd.c index 1b84cb45118..78f7046d3cd 100644 --- a/librz/core/cmd/cmd.c +++ b/librz/core/cmd/cmd.c @@ -140,7 +140,7 @@ struct duplicate_flag_t { static bool duplicate_flag(RzFlagItem *flag, void *u) { struct duplicate_flag_t *user = (struct duplicate_flag_t *)u; /* filter per flag spaces */ - if (!user->word || rz_str_glob(flag->name, user->word)) { + if (!user->word || rz_str_glob(rz_flag_item_get_name(flag), user->word)) { RzFlagItem *cloned_item = rz_flag_item_clone(flag); if (!cloned_item) { return false; @@ -2266,13 +2266,18 @@ static int rz_core_cmd_subst_i(RzCore *core, char *cmd, char *colon, bool *tmpse goto beach; } -struct exec_command_t { - RzCore *core; - const char *cmd; -}; +typedef struct { + ut64 offset; + ut64 size; +} FlagInfo; -static bool copy_into_flagitem_list(RzFlagItem *flg, void *u) { - RzFlagItem *fi = rz_mem_dup(flg, sizeof(RzFlagItem)); +static bool copy_into_flaginfo_list(RzFlagItem *flg, void *u) { + FlagInfo *fi = RZ_NEW(FlagInfo); + if (!fi) { + return false; + } + fi->offset = rz_flag_item_get_offset(flg); + fi->size = rz_flag_item_get_size(flg); rz_list_append(u, fi); return true; } @@ -2550,9 +2555,9 @@ RZ_API int rz_core_cmd_foreach3(RzCore *core, const char *cmd, char *each) { // ut64 off = core->offset; ut64 obs = core->blocksize; RzList *flags = rz_list_newf(free); - rz_flag_foreach_glob(core->flags, glob, copy_into_flagitem_list, flags); + rz_flag_foreach_glob(core->flags, glob, copy_into_flaginfo_list, flags); RzListIter *iter; - RzFlagItem *f; + FlagInfo *f; rz_list_foreach (flags, iter, f) { rz_core_block_size(core, f->size); rz_core_seek(core, f->offset, true); @@ -2936,7 +2941,7 @@ RZ_API int rz_core_cmd_foreach(RzCore *core, const char *cmd, char *each) { } char *buf = NULL; - rz_core_seek(core, flag->offset, true); + rz_core_seek(core, rz_flag_item_get_offset(flag), true); rz_cons_push(); rz_core_cmd(core, cmd, 0); buf = rz_cons_get_buffer_dup(); @@ -4258,8 +4263,8 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_flags_stmt) { break; } - RZ_LOG_DEBUG("iter_flags_stmt: seek to %" PFMT64x "\n", flag->offset); - rz_core_seek(core, flag->offset, true); + RZ_LOG_DEBUG("iter_flags_stmt: seek to %" PFMT64x "\n", rz_flag_item_get_offset(flag)); + rz_core_seek(core, rz_flag_item_get_offset(flag), true); RzCmdStatus cmd_res = handle_ts_stmt_tmpseek(state, command); rz_core_task_yield(&core->tasks); UPDATE_CMD_STATUS_RES(ret, cmd_res, err); diff --git a/librz/core/cmd/cmd_alias.c b/librz/core/cmd/cmd_alias.c index 50fc7f14a78..f35e1a868a7 100644 --- a/librz/core/cmd/cmd_alias.c +++ b/librz/core/cmd/cmd_alias.c @@ -119,7 +119,7 @@ RZ_IPI RzCmdStatus rz_alias_handler(RzCore *core, int argc, const char **argv) { } else { RzFlagItem *flag = rz_flag_get(core->flags, buf + 1); if (flag) { - rz_core_seek(core, flag->offset, true); + rz_core_seek(core, rz_flag_item_get_offset(flag), true); } else { RZ_LOG_ERROR("core: unknown alias '%s'\n", buf + 1); free(buf); diff --git a/librz/core/cmd/cmd_analysis.c b/librz/core/cmd/cmd_analysis.c index 285f94c7eb2..75a6aa67683 100644 --- a/librz/core/cmd/cmd_analysis.c +++ b/librz/core/cmd/cmd_analysis.c @@ -3286,11 +3286,11 @@ RZ_IPI RzCmdStatus rz_analysis_xrefs_from_list_handler(RzCore *core, int argc, c case RZ_OUTPUT_MODE_STANDARD: rz_list_foreach (list, iter, xref) { ut8 buf[16]; - char *desc; + const char *desc; RzAsmOp asmop; RzFlagItem *flag = rz_flag_get_at(core->flags, xref->to, false); if (flag) { - desc = flag->name; + desc = rz_flag_item_get_name(flag); } else { rz_io_read_at(core->io, xref->to, buf, sizeof(buf)); rz_asm_set_pc(core->rasm, xref->to); @@ -3929,7 +3929,7 @@ static void function_print_calls(RzCore *core, RzList /**/ RzAnalysisXRef *xrefi; rz_list_foreach (uniq_xrefs, refiter, xrefi) { RzFlagItem *f = rz_flag_get_i(core->flags, xrefi->to); - char *dst = rz_str_newf((f ? f->name : "0x%08" PFMT64x), xrefi->to); + char *dst = rz_str_newf((f ? rz_flag_item_get_name(f) : "0x%08" PFMT64x), xrefi->to); if (state->mode == RZ_OUTPUT_MODE_JSON) { // Append calee json item pj_o(pj); pj_ks(pj, "name", dst); @@ -6262,7 +6262,7 @@ RZ_IPI RzCmdStatus rz_analyze_xrefs_section_bytes_handler(RzCore *core, int argc static bool analyze_function_at_flag(RzFlagItem *fi, RzCore *core) { bool analyze_recursively = rz_config_get_b(core->config, "analysis.calls"); - rz_core_analysis_function_add(core, NULL, fi->offset, analyze_recursively); + rz_core_analysis_function_add(core, NULL, rz_flag_item_get_offset(fi), analyze_recursively); return true; } diff --git a/librz/core/cmd/cmd_block.c b/librz/core/cmd/cmd_block.c index 0001ba02645..d6af2a8403a 100644 --- a/librz/core/cmd/cmd_block.c +++ b/librz/core/cmd/cmd_block.c @@ -49,7 +49,7 @@ RZ_IPI RzCmdStatus rz_block_flag_handler(RzCore *core, int argc, const char **ar RZ_LOG_ERROR("Cannot find flag named \"%s\"", argv[1]); return RZ_CMD_STATUS_ERROR; } - rz_core_block_size(core, flag->size); + rz_core_block_size(core, rz_flag_item_get_size(flag)); return RZ_CMD_STATUS_OK; } diff --git a/librz/core/cmd/cmd_debug.c b/librz/core/cmd/cmd_debug.c index 2c734cc2cd9..9470ab9590e 100644 --- a/librz/core/cmd/cmd_debug.c +++ b/librz/core/cmd/cmd_debug.c @@ -433,9 +433,10 @@ static int step_until_flag(RzCore *core, const char *flagstr) { pc = rz_debug_reg_get(core->dbg, "PC"); list = rz_flag_get_list(core->flags, pc); rz_list_foreach (list, iter, flag) { - if (flag->realname && strstr(flag->realname, flagstr)) { + const char *rn = rz_flag_item_get_realname(flag); + if (rn && strstr(rn, flagstr)) { rz_cons_printf("[ 0x%08" PFMT64x " ] %s\n", - flag->offset, flag->realname); + rz_flag_item_get_offset(flag), rn); goto beach; } } @@ -1176,21 +1177,21 @@ static void backtrace_vars(RzCore *core, RzList /**/ *frames) { RzFlagItem *fi = rz_flag_get_at(core->flags, f->addr, true); flagdesc[0] = flagdesc2[0] = 0; if (fi) { - if (fi->offset != f->addr) { - int delta = (int)(f->addr - fi->offset); + if (rz_flag_item_get_offset(fi) != f->addr) { + int delta = (int)(f->addr - rz_flag_item_get_offset(fi)); if (delta > 0) { snprintf(flagdesc, sizeof(flagdesc), - "%s+%d", fi->name, delta); + "%s+%d", rz_flag_item_get_name(fi), delta); } else if (delta < 0) { snprintf(flagdesc, sizeof(flagdesc), - "%s%d", fi->name, delta); + "%s%d", rz_flag_item_get_name(fi), delta); } else { snprintf(flagdesc, sizeof(flagdesc), - "%s", fi->name); + "%s", rz_flag_item_get_name(fi)); } } else { snprintf(flagdesc, sizeof(flagdesc), - "%s", fi->name); + "%s", rz_flag_item_get_name(fi)); } } ////////// @@ -1294,12 +1295,12 @@ RZ_IPI void rz_core_debug_bp_add(RzCore *core, ut64 addr, const char *arg_perm, } RzFlagItem *f = rz_core_flag_get_by_spaces(core->flags, addr); if (f) { - if (addr > f->offset) { - char *name = rz_str_newf("%s+0x%" PFMT64x, f->name, addr - f->offset); + if (addr > rz_flag_item_get_offset(f)) { + char *name = rz_str_newf("%s+0x%" PFMT64x, rz_flag_item_get_name(f), addr - rz_flag_item_get_offset(f)); rz_bp_item_set_name(bpi, name); free(name); } else { - bpi->name = strdup(f->name); + bpi->name = strdup(rz_flag_item_get_name(f)); } } else { char *name = rz_str_newf("0x%08" PFMT64x, addr); @@ -1337,7 +1338,7 @@ static void trace_traverse_pre(RTreeNode *n, RTreeVisitor *vis) { if (_core) { RzFlagItem *f = rz_flag_get_at(_core->flags, tn->addr, true); if (f) { - name = f->name; + name = rz_flag_item_get_name(f); } } rz_cons_printf(" 0x%08" PFMT64x " refs %d %s\n", tn->addr, tn->refs, name); diff --git a/librz/core/cmd/cmd_flag.c b/librz/core/cmd/cmd_flag.c index f4ada4c2565..3992f9deb0d 100644 --- a/librz/core/cmd/cmd_flag.c +++ b/librz/core/cmd/cmd_flag.c @@ -27,14 +27,14 @@ static const char *__isOnlySon(RzCore *core, RzList /**/ *flags, c RzFlagItem *f; size_t count = 0; - char *fname = NULL; + const char *fname = NULL; rz_list_foreach (flags, iter, f) { - if (!strncmp(f->name, kw, strlen(kw))) { + if (!strncmp(rz_flag_item_get_name(f), kw, strlen(kw))) { count++; if (count > 1) { return NULL; } - fname = f->name; + fname = rz_flag_item_get_name(f); } } return fname; @@ -48,25 +48,25 @@ static RzList /**/ *__childrenFlagsOf(RzCore *core, RzList /* 0 && strncmp(f->name, prefix, prefix_len)) { + if (prefix_len > 0 && strncmp(rz_flag_item_get_name(f), prefix, prefix_len)) { continue; } - if (prefix_len > strlen(f->name)) { + if (prefix_len > strlen(rz_flag_item_get_name(f))) { continue; } if (rz_cons_is_breaked()) { break; } - const char *name = f->name; + const char *name = rz_flag_item_get_name(f); int name_len = strlen(name); rz_list_foreach (flags, iter2, f2) { - if (prefix_len > strlen(f2->name)) { + if (prefix_len > strlen(rz_flag_item_get_name(f2))) { continue; } - if (prefix_len > 0 && strncmp(f2->name, prefix, prefix_len)) { + if (prefix_len > 0 && strncmp(rz_flag_item_get_name(f2), prefix, prefix_len)) { continue; } - int matching = countMatching(name, f2->name); + int matching = countMatching(name, rz_flag_item_get_name(f2)); if (matching < prefix_len || matching == name_len) { continue; } @@ -87,11 +87,11 @@ static RzList /**/ *__childrenFlagsOf(RzCore *core, RzList /*name, kw, kw_len)) { + if (strncmp(rz_flag_item_get_name(f2), kw, kw_len)) { continue; } if (fname) { - int matching = countMatching(fname, f2->name); + int matching = countMatching(fname, rz_flag_item_get_name(f2)); if (fname_len) { if (matching < fname_len) { fname_len = matching; @@ -100,7 +100,7 @@ static RzList /**/ *__childrenFlagsOf(RzCore *core, RzList /*name; + fname = rz_flag_item_get_name(f2); } } if (fname_len > 0) { @@ -212,7 +212,7 @@ RZ_IPI RzCmdStatus rz_flag_add_handler(RzCore *core, int argc, const char **argv RZ_LOG_ERROR("Cannot create flag \"%s\" at 0x%" PFMT64x " because there is already \"%s\" flag\n", argv[1], - core->offset, item->name); + core->offset, rz_flag_item_get_name(item)); addFlag = false; } if (addFlag) { @@ -321,7 +321,7 @@ RZ_IPI RzCmdStatus rz_flag_relocate_handler(RzCore *core, int argc, const char * static int cmpflag(const void *_a, const void *_b, void *user) { const RzFlagItem *flag1 = _a, *flag2 = _b; - return (flag1->offset - flag2->offset); + return (rz_flag_item_get_offset(flag1) - rz_flag_item_get_offset(flag2)); } RZ_IPI void rz_core_flag_describe(RzCore *core, ut64 addr, bool strict_offset, RzCmdStateOutput *state) { @@ -333,19 +333,19 @@ RZ_IPI void rz_core_flag_describe(RzCore *core, ut64 addr, bool strict_offset, R switch (state->mode) { case RZ_OUTPUT_MODE_JSON: pj_o(pj); - pj_kn(pj, "offset", f->offset); - pj_ks(pj, "name", f->name); + pj_kn(pj, "offset", rz_flag_item_get_offset(f)); + pj_ks(pj, "name", rz_flag_item_get_name(f)); // Print flag's real name if defined - if (f->realname) { - pj_ks(pj, "realname", f->realname); + if (rz_flag_item_get_realname(f)) { + pj_ks(pj, "realname", rz_flag_item_get_realname(f)); } pj_end(pj); break; case RZ_OUTPUT_MODE_STANDARD: { // Print realname if exists and asm.flags.real is enabled - const char *name = core->flags->realnames && f->realname ? f->realname : f->name; - if (f->offset != addr) { - rz_cons_printf("%s + %d\n", name, (int)(addr - f->offset)); + const char *name = core->flags->realnames && rz_flag_item_get_realname(f) ? rz_flag_item_get_realname(f) : rz_flag_item_get_name(f); + if (rz_flag_item_get_offset(f) != addr) { + rz_cons_printf("%s + %d\n", name, (int)(addr - rz_flag_item_get_offset(f))); } else { rz_cons_println(name); } @@ -379,18 +379,18 @@ RZ_IPI RzCmdStatus rz_flag_describe_at_handler(RzCore *core, int argc, const cha switch (state->mode) { case RZ_OUTPUT_MODE_JSON: pj_o(pj); - pj_ks(pj, "name", flag->name); - if (flag->realname) { - pj_ks(pj, "realname", flag->realname); + pj_ks(pj, "name", rz_flag_item_get_name(flag)); + if (rz_flag_item_get_realname(flag)) { + pj_ks(pj, "realname", rz_flag_item_get_realname(flag)); } pj_end(pj); break; case RZ_OUTPUT_MODE_STANDARD: // Print realname if exists and asm.flags.real is enabled - if (core->flags->realnames && flag->realname) { - rz_cons_println(flag->realname); + if (core->flags->realnames && rz_flag_item_get_realname(flag)) { + rz_cons_println(rz_flag_item_get_realname(flag)); } else { - rz_cons_println(flag->name); + rz_cons_println(rz_flag_item_get_name(flag)); } break; default: @@ -410,23 +410,23 @@ RZ_IPI RzCmdStatus rz_flag_describe_closest_handler(RzCore *core, int argc, cons ut64 loff = 0; ut64 uoff = 0; ut64 curseek = core->offset; - char *lmatch = NULL, *umatch = NULL; + const char *lmatch = NULL, *umatch = NULL; RzFlagItem *flag; RzListIter *iter; rz_list_sort(temp, &cmpflag, NULL); rz_list_foreach (temp, iter, flag) { - if (strstr(flag->name, argv[1]) != NULL) { - if (flag->offset < core->offset) { - loff = flag->offset; - lmatch = flag->name; + if (strstr(rz_flag_item_get_name(flag), argv[1]) != NULL) { + if (rz_flag_item_get_offset(flag) < core->offset) { + loff = rz_flag_item_get_offset(flag); + lmatch = rz_flag_item_get_name(flag); continue; } - uoff = flag->offset; - umatch = flag->name; + uoff = rz_flag_item_get_offset(flag); + umatch = rz_flag_item_get_name(flag); break; } } - char *match = (curseek - loff) < (uoff - curseek) ? lmatch : umatch; + const char *match = (curseek - loff) < (uoff - curseek) ? lmatch : umatch; if (match) { if (*match) { rz_cons_println(match); @@ -500,12 +500,12 @@ struct flagbar_t { static bool flagbar_foreach(RzFlagItem *fi, void *user) { struct flagbar_t *u = (struct flagbar_t *)user; ut64 min = 0, max = rz_io_size(u->core->io); - RzIOMap *m = rz_io_map_get(u->core->io, fi->offset); + RzIOMap *m = rz_io_map_get(u->core->io, rz_flag_item_get_offset(fi)); if (m) { min = m->itv.addr; max = m->itv.addr + m->itv.size; } - rz_cons_printf("0x%08" PFMT64x " ", fi->offset); + rz_cons_printf("0x%08" PFMT64x " ", rz_flag_item_get_offset(fi)); RzBarOptions opts = { .unicode = false, .thinline = false, @@ -516,13 +516,13 @@ static bool flagbar_foreach(RzFlagItem *fi, void *user) { .curpos = 0, .color = false }; - RzStrBuf *strbuf = rz_rangebar(&opts, fi->offset, fi->offset + fi->size, min, max, u->cols); + RzStrBuf *strbuf = rz_rangebar(&opts, rz_flag_item_get_offset(fi), rz_flag_item_get_offset(fi) + rz_flag_item_get_size(fi), min, max, u->cols); if (!strbuf) { RZ_LOG_ERROR("Cannot generate rangebar\n"); } else { rz_cons_print(rz_strbuf_drain(strbuf)); } - rz_cons_printf(" %s\n", fi->name); + rz_cons_printf(" %s\n", rz_flag_item_get_name(fi)); return true; } @@ -544,8 +544,8 @@ struct flag_to_flag_t { static bool flag_to_flag_foreach(RzFlagItem *fi, void *user) { struct flag_to_flag_t *u = (struct flag_to_flag_t *)user; - if (fi->offset < u->next && fi->offset > u->offset) { - u->next = fi->offset; + if (rz_flag_item_get_offset(fi) < u->next && rz_flag_item_get_offset(fi) > u->offset) { + u->next = rz_flag_item_get_offset(fi); } return true; } @@ -580,7 +580,7 @@ static void flag_tag_print(RzCore *core, const char *tag, RzCmdStateOutput *stat RzListIter *iter; RzFlagItem *flag; rz_list_foreach (flags, iter, flag) { - pj_s(pj, flag->name); + pj_s(pj, rz_flag_item_get_name(flag)); } pj_end(pj); rz_list_free(flags); @@ -595,7 +595,7 @@ static void flag_tag_print(RzCore *core, const char *tag, RzCmdStateOutput *stat RzListIter *iter; RzFlagItem *flag; rz_list_foreach (flags, iter, flag) { - rz_cons_printf("0x%08" PFMT64x " %s\n", flag->offset, flag->name); + rz_cons_printf("0x%08" PFMT64x " %s\n", rz_flag_item_get_offset(flag), rz_flag_item_get_name(flag)); } rz_list_free(flags); break; @@ -633,7 +633,7 @@ RZ_IPI RzCmdStatus rz_flag_tag_search_handler(RzCore *core, int argc, const char RzListIter *iter; RzFlagItem *flag; rz_list_foreach (flags, iter, flag) { - rz_cons_printf("0x%08" PFMT64x " %s\n", flag->offset, flag->name); + rz_cons_printf("0x%08" PFMT64x " %s\n", rz_flag_item_get_offset(flag), rz_flag_item_get_name(flag)); } return RZ_CMD_STATUS_OK; } @@ -702,7 +702,7 @@ RZ_IPI RzCmdStatus rz_flag_space_move_handler(RzCore *core, int argc, const char RZ_LOG_ERROR("Cannot find any flag at 0x%" PFMT64x ".\n", core->offset); return RZ_CMD_STATUS_ERROR; } - f->space = rz_flag_space_cur(core->flags); + rz_flag_item_set_space(f, rz_flag_space_cur(core->flags)); return RZ_CMD_STATUS_OK; } @@ -777,7 +777,7 @@ RZ_IPI RzCmdStatus rz_flag_exists_handler(RzCore *core, int argc, const char **a RZ_LOG_ERROR("Cannot find flag '%s'\n", argv[1]); return RZ_CMD_STATUS_ERROR; } - RZ_LOG_DEBUG("Find flag '%s' at 0x%" PFMT64x "\n", argv[1], item->offset); + RZ_LOG_DEBUG("Find flag '%s' at 0x%" PFMT64x "\n", argv[1], rz_flag_item_get_offset(item)); return RZ_CMD_STATUS_OK; } @@ -798,9 +798,9 @@ RZ_IPI RzCmdStatus rz_flag_length_handler(RzCore *core, int argc, const char **a return RZ_CMD_STATUS_ERROR; } if (argc < 2) { - rz_cons_printf("0x%08" PFMT64x "\n", item->size); + rz_cons_printf("0x%08" PFMT64x "\n", rz_flag_item_get_size(item)); } else { - item->size = rz_num_math(core->num, argv[1]); + rz_flag_item_set_size(item, rz_num_math(core->num, argv[1])); } return RZ_CMD_STATUS_OK; } @@ -813,7 +813,7 @@ RZ_IPI RzCmdStatus rz_flag_realname_handler(RzCore *core, int argc, const char * return RZ_CMD_STATUS_ERROR; } if (argc < 3) { - rz_cons_printf("%s\n", item->realname); + rz_cons_printf("%s\n", rz_flag_item_get_realname(item)); } else { rz_flag_item_set_realname(item, argv[2]); } @@ -853,8 +853,8 @@ RZ_IPI RzCmdStatus rz_flag_comment_handler(RzCore *core, int argc, const char ** return bool2status(flag_set_comment(item, argv[2])); } else { item = rz_flag_get_i(core->flags, rz_num_math(core->num, argv[1])); - if (item && item->comment) { - rz_cons_println(item->comment); + if (item && rz_flag_item_get_comment(item)) { + rz_cons_println(rz_flag_item_get_comment(item)); } else { RZ_LOG_ERROR("Cannot find the flag\n"); return RZ_CMD_STATUS_ERROR; @@ -892,9 +892,9 @@ RZ_IPI RzCmdStatus rz_flag_hexdump_handler(RzCore *core, int argc, const char ** RZ_LOG_ERROR("Cannot find flag '%s'\n", argv[1]); return RZ_CMD_STATUS_ERROR; } - rz_cons_printf("0x%08" PFMT64x "\n", item->offset); + rz_cons_printf("0x%08" PFMT64x "\n", rz_flag_item_get_offset(item)); // FIXME: Use the API directly instead of calling the command - snprintf(cmd, sizeof(cmd), "px@%" PFMT64d ":%" PFMT64d, item->offset, item->size); + snprintf(cmd, sizeof(cmd), "px@%" PFMT64d ":%" PFMT64d, rz_flag_item_get_offset(item), rz_flag_item_get_size(item)); rz_core_cmd0(core, cmd); return RZ_CMD_STATUS_OK; } diff --git a/librz/core/cmd/cmd_meta.c b/librz/core/cmd/cmd_meta.c index 932444f5e40..cb088cb33b4 100644 --- a/librz/core/cmd/cmd_meta.c +++ b/librz/core/cmd/cmd_meta.c @@ -24,7 +24,7 @@ RZ_IPI void rz_core_meta_comment_add(RzCore *core, const char *comment, ut64 add static const char *meta_get_flag(RzCore *core, ut64 addr) { RzFlagItem *fi; fi = rz_flag_get_i(core->flags, addr); - return fi ? fi->name : NULL; + return fi ? rz_flag_item_get_name(fi) : NULL; } static void meta_variable_comment_print(RzCore *Core, RzAnalysisVar *var, RzCmdStateOutput *state) { diff --git a/librz/core/cmd/cmd_print.c b/librz/core/cmd/cmd_print.c index f74f4819adb..1fc086c8ac0 100644 --- a/librz/core/cmd/cmd_print.c +++ b/librz/core/cmd/cmd_print.c @@ -545,12 +545,13 @@ static void colordump(RzCore *core, const ut8 *block, int len) { if (show_flags) { RzFlagItem *fi = rz_flag_get_i(core->flags, core->offset + j); if (fi) { - if (fi->name[1]) { - ch = fi->name[0]; - ch2 = fi->name[1]; + const char *n = rz_flag_item_get_name(fi); + if (n[0] && n[1]) { + ch = n[0]; + ch2 = n[1]; } else { ch = ' '; - ch2 = fi->name[0]; + ch2 = n[0]; } } else { ch2 = ch; @@ -964,10 +965,10 @@ static void annotated_hexdump(RzCore *core, int len) { if (flagsz) { fend = addr + flagsz; // core->blocksize; } else { - fend = addr + j + flag->size; + fend = addr + j + rz_flag_item_get_size(flag); } free(note[j]); - note[j] = rz_str_prepend(strdup(flag->name), "/"); + note[j] = rz_str_prepend(strdup(rz_flag_item_get_name(flag)), "/"); marks = true; color_idx++; color_idx %= 10; @@ -975,7 +976,7 @@ static void annotated_hexdump(RzCore *core, int len) { if (showSection) { rz_cons_printf("%20s ", ""); } - if (flag->offset == addr + j) { + if (rz_flag_item_get_offset(flag) == addr + j) { if (usecolor) { append(ebytes, Color_INVERT); append(echars, Color_INVERT); @@ -984,7 +985,7 @@ static void annotated_hexdump(RzCore *core, int len) { } } else { // Are we past the current flag? - if (current_flag && addr + j > (current_flag->offset + current_flag->size)) { + if (current_flag && addr + j > (rz_flag_item_get_offset(current_flag) + rz_flag_item_get_size(current_flag))) { setcolor = false; current_flag = NULL; } @@ -1003,8 +1004,9 @@ static void annotated_hexdump(RzCore *core, int len) { } } else if (!hascolor) { hascolor = true; - if (current_flag && current_flag->color) { - char *ansicolor = rz_cons_pal_parse(current_flag->color, NULL); + const char *color = current_flag ? rz_flag_item_get_color(current_flag) : NULL; + if (color) { + char *ansicolor = rz_cons_pal_parse(color, NULL); if (ansicolor) { append(ebytes, ansicolor); append(echars, ansicolor); @@ -3148,7 +3150,7 @@ static void disassembly_as_table(RzTable *t, RzCore *core, ut64 addr, int n_inst rz_io_read_at(core->io, offset, buffer, RZ_MIN(op->size, sizeof(buffer))); char *bytes = rz_hex_bin2strdup(buffer, op->size); RzFlagItem *flag = rz_flag_get_i(core->flags, offset); - char *function_name = flag ? flag->name : ""; + const char *function_name = flag ? rz_flag_item_get_name(flag) : ""; const char *esil = RZ_STRBUF_SAFEGET(&op->esil); char *refs = __op_refs(core, op, 0); char *xrefs = __op_refs(core, op, 1); diff --git a/librz/core/cmd/cmd_seek.c b/librz/core/cmd/cmd_seek.c index 239e1efeb12..3eb00ddec79 100644 --- a/librz/core/cmd/cmd_seek.c +++ b/librz/core/cmd/cmd_seek.c @@ -240,10 +240,10 @@ RZ_IPI RzCmdStatus rz_seek_history_list_handler(RzCore *core, int argc, const ch const char *comment; char *name = NULL; if (f) { - if (f->offset != undo->offset) { - name = rz_str_newf("%s+%" PFMT64d, f->name, undo->offset - f->offset); + if (rz_flag_item_get_offset(f) != undo->offset) { + name = rz_str_newf("%s+%" PFMT64d, rz_flag_item_get_name(f), undo->offset - rz_flag_item_get_offset(f)); } else { - name = strdup(f->name); + name = strdup(rz_flag_item_get_name(f)); } } current_met |= undo->is_current; diff --git a/librz/core/core.c b/librz/core/core.c index 780753403f8..44b872710c8 100644 --- a/librz/core/core.c +++ b/librz/core/core.c @@ -316,11 +316,11 @@ static const char *getName(RzCore *core, ut64 addr) { RzFlagItem *item = rz_flag_get_i(core->flags, addr); if (item) { if (core->flags->realnames) { - return item->realname - ? item->realname - : item->name; + return rz_flag_item_get_realname(item) + ? rz_flag_item_get_realname(item) + : rz_flag_item_get_name(item); } - return item->name; + return rz_flag_item_get_name(item); } return NULL; } @@ -328,13 +328,13 @@ static const char *getName(RzCore *core, ut64 addr) { static char *getNameDelta(RzCore *core, ut64 addr) { RzFlagItem *item = rz_flag_get_at(core->flags, addr, true); if (item) { - if (item->offset != addr) { + if (rz_flag_item_get_offset(item) != addr) { const char *name = core->flags->realnames - ? item->realname - : item->name; - return rz_str_newf("%s+%" PFMT64u, name, addr - item->offset); + ? rz_flag_item_get_realname(item) + : rz_flag_item_get_name(item); + return rz_str_newf("%s+%" PFMT64u, name, addr - rz_flag_item_get_offset(item)); } - return strdup(item->name); + return strdup(rz_flag_item_get_name(item)); } return NULL; } @@ -498,7 +498,7 @@ static const char *str_callback(RzNum *user, ut64 off, int *ok) { if (ok) { *ok = true; } - return item->name; + return rz_flag_item_get_name(item); } } return NULL; @@ -666,7 +666,7 @@ static ut64 num_callback(RzNum *userptr, const char *str, int *ok) { RzFlagItem *flag = rz_flag_get(core->flags, flagName); free(flagName); if (flag) { - return flag->offset + flag->size; + return rz_flag_item_get_offset(flag) + rz_flag_item_get_size(flag); } return UT64_MAX; } @@ -681,7 +681,7 @@ static ut64 num_callback(RzNum *userptr, const char *str, int *ok) { if (str[2] == 'l') { // $fl flag length RzFlagItem *fi = rz_flag_get_i(core->flags, core->offset); if (fi) { - return fi->size; + return rz_flag_item_get_size(fi); } return 0; } @@ -726,7 +726,7 @@ static ut64 num_callback(RzNum *userptr, const char *str, int *ok) { } *ptr = '\0'; RzFlagItem *flag = rz_flag_get(core->flags, bptr); - ret = flag ? flag->size : 0LL; // flag + ret = flag ? rz_flag_item_get_size(flag) : 0LL; // flag free(bptr); free(out); return ret; @@ -820,7 +820,7 @@ static ut64 num_callback(RzNum *userptr, const char *str, int *ok) { } #endif if ((flag = rz_flag_get(core->flags, str))) { - ret = flag->offset; + ret = rz_flag_item_get_offset(flag); if (ok) { *ok = true; } @@ -897,13 +897,13 @@ RZ_API int rz_core_fgets(char *buf, int len, void *user) { static const char *rz_core_print_offname(void *p, ut64 addr) { RzCore *c = (RzCore *)p; RzFlagItem *item = rz_flag_get_i(c->flags, addr); - return item ? item->name : NULL; + return item ? rz_flag_item_get_name(item) : NULL; } static int rz_core_print_offsize(void *p, ut64 addr) { RzCore *c = (RzCore *)p; RzFlagItem *item = rz_flag_get_i(c->flags, addr); - return item ? item->size : -1; + return item ? rz_flag_item_get_size(item) : -1; } /** @@ -983,7 +983,7 @@ RZ_API char *rz_core_analysis_hasrefs(RzCore *core, ut64 value, int mode) { return res; } RzFlagItem *fi = rz_flag_get_i(core->flags, value); - return fi ? strdup(fi->name) : NULL; + return fi ? strdup(rz_flag_item_get_name(fi)) : NULL; } static char *getvalue(ut64 value, int bits) { @@ -1076,7 +1076,7 @@ RZ_API char *rz_core_analysis_hasrefs_to_depth(RzCore *core, ut64 value, PJ *pj, if (flags && !rz_list_empty(flags)) { pj_ka(pj, "flags"); rz_list_foreach (flags, iter, f) { - pj_s(pj, f->name); + pj_s(pj, rz_flag_item_get_name(f)); } pj_end(pj); } @@ -1811,10 +1811,10 @@ static bool prompt_add_offset(RzCore *core, RzStrBuf *sb, bool add_sep) { if (rz_config_get_b(core->config, "scr.prompt.flag")) { const RzFlagItem *f = rz_flag_get_at(core->flags, core->offset, true); if (f) { - if (f->offset < core->offset) { - rz_strbuf_appendf(sb, "%s + %" PFMT64u, f->name, core->offset - f->offset); + if (rz_flag_item_get_offset(f) < core->offset) { + rz_strbuf_appendf(sb, "%s + %" PFMT64u, rz_flag_item_get_name(f), core->offset - rz_flag_item_get_offset(f)); } else { - rz_strbuf_appendf(sb, "%s", f->name); + rz_strbuf_appendf(sb, "%s", rz_flag_item_get_name(f)); } if (rz_config_get_b(core->config, "scr.prompt.flag.only")) { return true; diff --git a/librz/core/cprint.c b/librz/core/cprint.c index e15f2b3f030..76f277f4437 100644 --- a/librz/core/cprint.c +++ b/librz/core/cprint.c @@ -450,12 +450,12 @@ RZ_API RZ_OWN char *rz_core_print_hexdump_byline_str(RZ_NONNULL RzCore *core, bo f = rz_flag_get_at(core->flags, v, true); fn = NULL; if (f) { - st64 delta = (st64)(v - f->offset); + st64 delta = (st64)(v - rz_flag_item_get_offset(f)); if (delta >= 0 && delta < 8192) { - if (v == f->offset) { - fn = strdup(f->name); + if (v == rz_flag_item_get_offset(f)) { + fn = strdup(rz_flag_item_get_name(f)); } else { - fn = rz_str_newf("%s+%" PFMT64d, f->name, v - f->offset); + fn = rz_str_newf("%s+%" PFMT64d, rz_flag_item_get_name(f), v - rz_flag_item_get_offset(f)); } } } @@ -952,14 +952,14 @@ RZ_API RZ_OWN char *rz_core_print_disasm_strings(RZ_NONNULL RzCore *core, RzCore rz_strbuf_appendf(sb, "%s%s%s%s%s%s%s\n", linecolor ? linecolor : "", string2 ? string2 : "", string2 ? " " : "", string, - flag ? " " : "", flag ? flag->name : "", Color_RESET); + flag ? " " : "", flag ? rz_flag_item_get_name(flag) : "", Color_RESET); } else { if (show_offset) { rz_strbuf_appendf(sb, "0x%08" PFMT64x " ", addr); } rz_strbuf_appendf(sb, "%s%s%s%s%s\n", string2 ? string2 : "", string2 ? " " : "", string, - flag ? " " : "", flag ? flag->name : ""); + flag ? " " : "", flag ? rz_flag_item_get_name(flag) : ""); } } } diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 4064cffd1e0..e6f760524c9 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -192,7 +192,7 @@ typedef struct { int lbytes; int show_comment_right; int pre; - char *ocomment; + const char *ocomment; int linesopts; int lastfail; int ocols; @@ -271,7 +271,9 @@ typedef struct { bool sparse; RzPVector /**/ *vec; +#if 0 // TODO: remove RzFlagItem lastflagitem; +#endif } RzDisasmState; static void ds_setup_print_pre(RzDisasmState *ds, bool tail, bool middle); @@ -1052,7 +1054,7 @@ static void ds_build_op_str(RzDisasmState *ds, bool print_color) { if (addr > ds->min_ref_addr) { RzFlagItem *fi = rz_flag_get_i(ds->core->flags, addr); if (fi) { - rz_str_cpy(ox, fi->name); + rz_str_cpy(ox, rz_flag_item_get_name(fi)); rz_str_cat(ox, e); } } @@ -1231,7 +1233,7 @@ static void ds_show_refs(RzDisasmState *ds) { RzFlagItem *fis; rz_list_foreach (fls, iter2, fis) { ds_begin_comment(ds); - ds_comment(ds, true, "; (%s)", fis->name); + ds_comment(ds, true, "; (%s)", rz_flag_item_get_name(fis)); } // ds_align_comment (ds); @@ -1344,13 +1346,13 @@ static void ds_show_xrefs(RzDisasmState *ds) { if (iter != rz_list_tail(xrefs)) { ut64 next_addr = ((RzAnalysisXRef *)rz_list_iter_get_next_data(iter))->from; next_f = rz_flag_get_at(core->flags, next_addr, true); - if (next_f && f->offset == next_f->offset) { - rz_list_append(addrs, rz_num_dup(xrefi->from - f->offset)); + if (next_f && rz_flag_item_get_offset(f) == rz_flag_item_get_offset(next_f)) { + rz_list_append(addrs, rz_num_dup(xrefi->from - rz_flag_item_get_offset(f))); continue; } } - name = strdup(f->name); - rz_list_append(addrs, rz_num_dup(xrefi->from - f->offset)); + name = strdup(rz_flag_item_get_name(f)); + rz_list_append(addrs, rz_num_dup(xrefi->from - rz_flag_item_get_offset(f))); } else { name = strdup("unk"); } @@ -1492,21 +1494,21 @@ static int handleMidFlags(RzCore *core, RzDisasmState *ds, bool print) { } for (int i = 1; i < ds->oplen; i++) { RzFlagItem *fi = rz_flag_get_i(core->flags, ds->at + i); - if (fi && fi->name) { + if (fi && rz_flag_item_get_name(fi)) { if (rz_analysis_find_most_relevant_block_in(core->analysis, ds->at + i)) { ds->midflags = ds->midflags ? RZ_MIDFLAGS_SHOW : RZ_MIDFLAGS_HIDE; } if (ds->midflags == RZ_MIDFLAGS_REALIGN && - ((fi->name[0] == '$') || (fi->realname && fi->realname[0] == '$'))) { + ((rz_flag_item_get_name(fi)[0] == '$') || (rz_flag_item_get_realname(fi) && rz_flag_item_get_realname(fi)[0] == '$'))) { i = 0; - } else if (!strncmp(fi->name, "hit.", 4)) { // use search.prefix ? + } else if (!strncmp(rz_flag_item_get_name(fi), "hit.", 4)) { // use search.prefix ? i = 0; - } else if (!strncmp(fi->name, "str.", 4)) { + } else if (!strncmp(rz_flag_item_get_name(fi), "str.", 4)) { ds->midflags = RZ_MIDFLAGS_REALIGN; - } else if (fi->space && !strcmp(fi->space->name, RZ_FLAGS_FS_RELOCS)) { + } else if (rz_flag_item_get_space(fi) && !strcmp(rz_flag_item_get_space(fi)->name, RZ_FLAGS_FS_RELOCS)) { continue; } else if (ds->midflags == RZ_MIDFLAGS_SYMALIGN) { - if (strncmp(fi->name, "sym.", 4)) { + if (strncmp(rz_flag_item_get_name(fi), "sym.", 4)) { continue; } } @@ -1845,8 +1847,7 @@ static void ds_show_fn_vars_lines( static void ds_show_functions(RzDisasmState *ds) { RzAnalysisFunction *f; RzCore *core = ds->core; - char *fcn_name; - bool fcn_name_alloc = false; // whether fcn_name needs to be freed by this function + const char *fcn_name; if (!ds->show_functions) { return; @@ -1873,8 +1874,8 @@ static void ds_show_functions(RzDisasmState *ds) { // show function's realname in the signature if realnames are enabled if (core->flags->realnames) { RzFlagItem *flag = rz_flag_get(core->flags, fcn_name); - if (flag && flag->realname) { - fcn_name = flag->realname; + if (flag && rz_flag_item_get_realname(flag)) { + fcn_name = rz_flag_item_get_realname(flag); } } @@ -1920,8 +1921,8 @@ static void ds_show_functions(RzDisasmState *ds) { // show function's realname in the signature if realnames are enabled if (core->flags->realnames) { RzFlagItem *flag = rz_flag_get(core->flags, fcn_name); - if (flag && flag->realname) { - fcn_name = flag->realname; + if (flag && rz_flag_item_get_realname(flag)) { + fcn_name = rz_flag_item_get_realname(flag); } } @@ -1947,9 +1948,6 @@ static void ds_show_functions(RzDisasmState *ds) { } ds->show_varsum = o_varsum; rz_analysis_fcn_vars_cache_fini(&vars_cache); - if (fcn_name_alloc) { - free(fcn_name); - } RzListIter *iter; char *imp; @@ -2074,9 +2072,12 @@ static void ds_show_comments_right(RzDisasmState *ds) { if (!comment) { if (vartype) { ds->comment = rz_str_newf("%s; %s", COLOR_ARG(ds, func_var_type), vartype); - } else if (item && item->comment && *item->comment) { - ds->ocomment = item->comment; - ds->comment = strdup(item->comment); + } else { + const char *comment = item ? rz_flag_item_get_comment(item) : NULL; + if (comment && *comment) { + ds->ocomment = comment; + ds->comment = strdup(comment); + } } } else if (vartype) { ds->comment = rz_str_newf("%s; %s %s%s; %s", COLOR_ARG(ds, func_var_type), vartype, COLOR_RESET(ds), COLOR(ds, usercomment), comment); @@ -2111,13 +2112,14 @@ static void ds_show_comments_right(RzDisasmState *ds) { RZ_FREE(ds->comment); ds_newline(ds); /* flag one */ - if (item && item->comment && ds->ocomment != item->comment) { + const char *flagcomment = item ? rz_flag_item_get_comment(item) : NULL; + if (flagcomment && ds->ocomment != flagcomment) { ds_begin_line(ds); theme_print_color(comment); ds_newline(ds); ds_begin_line(ds); rz_cons_strcat(" ; "); - rz_cons_strcat_justify(item->comment, mycols, ';'); + rz_cons_strcat_justify(flagcomment, mycols, ';'); ds_newline(ds); ds_print_color_reset(ds); } @@ -2128,10 +2130,10 @@ static void ds_show_comments_right(RzDisasmState *ds) { static int flagCmp(const void *a, const void *b, void *user) { const RzFlagItem *fa = a; const RzFlagItem *fb = b; - if (fa->realname && fb->realname) { - return strcmp(fa->realname, fb->realname); + if (rz_flag_item_get_realname(fa) && rz_flag_item_get_realname(fb)) { + return strcmp(rz_flag_item_get_realname(fa), rz_flag_item_get_realname(fb)); } - return strcmp(fa->name, fb->name); + return strcmp(rz_flag_item_get_name(fa), rz_flag_item_get_name(fb)); } static void __preline_flag(RzDisasmState *ds, RzFlagItem *flag) { @@ -2140,8 +2142,8 @@ static void __preline_flag(RzDisasmState *ds, RzFlagItem *flag) { ds_pre_line(ds); if (ds->show_color) { bool hasColor = false; - if (flag->color) { - char *color = rz_cons_pal_parse(flag->color, NULL); + if (rz_flag_item_get_color(flag)) { + char *color = rz_cons_pal_parse(rz_flag_item_get_color(flag), NULL); if (color) { rz_cons_strcat(color); free(color); @@ -2172,8 +2174,8 @@ static bool is_sym_dbg_equal(const char *a, const char *b) { } static inline bool is_flag_overlapped(RzFlagItem *flag, RzAnalysisFunction *f) { - const bool name_overlapped = !strcmp(flag->name, f->name) || is_sym_dbg_equal(flag->name, f->name); - return f->addr == flag->offset && name_overlapped; + const bool name_overlapped = !strcmp(rz_flag_item_get_name(flag), f->name) || is_sym_dbg_equal(rz_flag_item_get_name(flag), f->name); + return f->addr == rz_flag_item_get_offset(flag) && name_overlapped; } #define printPre (outline || !*comma) @@ -2204,7 +2206,7 @@ static void ds_show_flags(RzDisasmState *ds, bool overlapped) { // do not show non-overlapped flags that have the same name as the function continue; } - bool no_fcn_lines = (!overlapped && f && f->addr == flag->offset); + bool no_fcn_lines = (!overlapped && f && f->addr == rz_flag_item_get_offset(flag)); if (ds->maxflags && count >= ds->maxflags) { if (printPre) { ds_pre_xrefs(ds, no_fcn_lines); @@ -2213,8 +2215,8 @@ static void ds_show_flags(RzDisasmState *ds, bool overlapped) { break; } count++; - if (!strncmp(flag->name, "case.", 5)) { - sscanf(flag->name + 5, "%63[^.].%d", addr, &case_current); + if (!strncmp(rz_flag_item_get_name(flag), "case.", 5)) { + sscanf(rz_flag_item_get_name(flag) + 5, "%63[^.].%d", addr, &case_current); ut64 saddr = rz_num_math(core->num, addr); if (case_start == -1) { switch_addr = saddr; @@ -2251,8 +2253,8 @@ static void ds_show_flags(RzDisasmState *ds, bool overlapped) { bool hasColor = false; char *color = NULL; if (ds->show_color) { - if (flag->color) { - color = rz_cons_pal_parse(flag->color, NULL); + if (rz_flag_item_get_color(flag)) { + color = rz_cons_pal_parse(rz_flag_item_get_color(flag), NULL); if (color) { rz_cons_strcat(color); ds->lastflag = flag; @@ -2264,10 +2266,10 @@ static void ds_show_flags(RzDisasmState *ds, bool overlapped) { } } - if (flag->realname) { - if (!strncmp(flag->name, "switch.", 7)) { + if (rz_flag_item_get_realname(flag)) { + if (!strncmp(rz_flag_item_get_name(flag), "switch.", 7)) { rz_cons_printf(FLAG_PREFIX "switch"); - } else if (!strncmp(flag->name, "case.", 5)) { + } else if (!strncmp(rz_flag_item_get_name(flag), "case.", 5)) { if (nth > 0) { __preline_flag(ds, flag); } @@ -2288,9 +2290,9 @@ static void ds_show_flags(RzDisasmState *ds, bool overlapped) { } rz_list_free(blocks); } - if (!strncmp(flag->name + 5, "default", 7)) { - rz_cons_printf(FLAG_PREFIX "default:"); // %s:", flag->name); - rz_str_ncpy(addr, flag->name + 5 + strlen("default."), sizeof(addr)); + if (!strncmp(rz_flag_item_get_name(flag) + 5, "default", 7)) { + rz_cons_printf(FLAG_PREFIX "default:"); // %s:", rz_flag_item_get_name(flag)); + rz_str_ncpy(addr, rz_flag_item_get_name(flag) + 5 + strlen("default."), sizeof(addr)); nth = 0; } else { const char *case_prev_name = NULL; @@ -2332,7 +2334,7 @@ static void ds_show_flags(RzDisasmState *ds, bool overlapped) { outline = false; docolon = false; } else { - char *name = strdup(flag->realname ? flag->realname : flag->name); + char *name = strdup(rz_flag_item_get_realname(flag) ? rz_flag_item_get_realname(flag) : rz_flag_item_get_name(flag)); if (name) { rz_str_ansi_filter(name, NULL, NULL, -1); if (!ds->flags_inline || nth == 0) { @@ -2345,16 +2347,16 @@ static void ds_show_flags(RzDisasmState *ds, bool overlapped) { if (outline) { rz_cons_printf("%s:", name); } else { - rz_cons_printf("%s%s", comma, flag->name); + rz_cons_printf("%s%s", comma, rz_flag_item_get_name(flag)); } RZ_FREE(name); } } } else { if (outline) { - rz_cons_printf(FLAG_PREFIX "%s", flag->name); + rz_cons_printf(FLAG_PREFIX "%s", rz_flag_item_get_name(flag)); } else { - rz_cons_printf("%s%s", comma, flag->name); + rz_cons_printf("%s%s", comma, rz_flag_item_get_name(flag)); } } ds_print_color_reset(ds); @@ -2591,10 +2593,11 @@ static void ds_control_flow_comments(RzDisasmState *ds) { case RZ_ANALYSIS_OP_TYPE_CJMP: case RZ_ANALYSIS_OP_TYPE_CALL: item = rz_flag_get_i(ds->core->flags, ds->analysis_op.jump); - if (item && item->comment) { + const char *fcomment = item ? rz_flag_item_get_comment(item) : NULL; + if (item && fcomment) { theme_print_color(comment); ds_align_comment(ds); - rz_cons_printf(" ; ref to %s: %s\n", item->name, item->comment); + rz_cons_printf(" ; ref to %s: %s\n", rz_flag_item_get_name(item), fcomment); ds_print_color_reset(ds); } break; @@ -2669,21 +2672,23 @@ static void ds_print_lines_left(RzDisasmState *ds) { if (ds->show_symbols) { const char *name = ""; int delta = 0; +#if 0 // TODO: make sure this does break some tests, if not add some! if (ds->fcn) { ds->lastflagitem.offset = ds->fcn->addr; ds->lastflagitem.name = ds->fcn->name; ds->lastflag = &ds->lastflagitem; } else { RzFlagItem *fi = rz_flag_get_at(core->flags, ds->at, !ds->lastflag); - if (fi) { // && (!ds->lastflag || fi->offset != ds->at)) - ds->lastflagitem.offset = fi->offset; - ds->lastflagitem.name = fi->name; + if (fi) { // && (!ds->lastflag || rz_flag_item_get_offset(fi) != ds->at)) + ds->lastflagitem.offset = rz_flag_item_get_offset(fi); + ds->lastflagitem.name = rz_flag_item_get_name(fi); ds->lastflag = &ds->lastflagitem; } } - if (ds->lastflag && ds->lastflag->name) { - name = ds->lastflag->name; - delta = ds->at - ds->lastflag->offset; +#endif + if (ds->lastflag && rz_flag_item_get_name(ds->lastflag)) { + name = rz_flag_item_get_name(ds->lastflag); + delta = ds->at - rz_flag_item_get_offset(ds->lastflag); } { char *str = rz_str_newf("%s + %-4d", name, delta); @@ -2765,11 +2770,11 @@ static void ds_print_offset(RzDisasmState *ds) { // probably tooslow RzFlagItem *f = rz_flag_get_at(core->flags, at, 1); if (ds->show_color && f) { // ds->lastflag) { - const char *color = f->color; - if (ds->at >= f->offset && ds->at < f->offset + f->size) { + const char *color = rz_flag_item_get_color(f); + if (ds->at >= rz_flag_item_get_offset(f) && ds->at < rz_flag_item_get_offset(f) + rz_flag_item_get_offset(f)) { // if (rz_itv_inrange (f->itv, ds->at)) if (color && *color) { - char *k = rz_cons_pal_parse(f->color, NULL); + char *k = rz_cons_pal_parse(color, NULL); if (k) { rz_cons_printf("%s", k); hasCustomColor = true; @@ -2793,9 +2798,11 @@ static void ds_print_offset(RzDisasmState *ds) { } if (f) { delta = at - f->addr; +#if 0 // TODO: make sure this does break some tests, if not add some! ds->lastflagitem.name = f->name; ds->lastflagitem.offset = f->addr; ds->lastflag = &ds->lastflagitem; +#endif label = f->name; } else { if (ds->show_reloff_flags) { @@ -2805,16 +2812,16 @@ static void ds_print_offset(RzDisasmState *ds) { ds->lastflag = fi; } if (ds->lastflag) { - if (ds->lastflag->offset == at) { + if (rz_flag_item_get_offset(ds->lastflag) == at) { delta = 0; } else { - delta = at - ds->lastflag->offset; + delta = at - rz_flag_item_get_offset(ds->lastflag); } } else { delta = at - core->offset; } if (ds->lastflag) { - label = ds->lastflag->name; + label = rz_flag_item_get_name(ds->lastflag); } } } @@ -3004,7 +3011,7 @@ static bool ds_print_data_type(RzDisasmState *ds, const ut8 *buf, int ib, int si RzListIter *iter; RzFlagItem *fi; rz_list_foreach (flags, iter, fi) { - rz_cons_printf(" ; %s", fi->name); + rz_cons_printf(" ; %s", rz_flag_item_get_name(fi)); } } } @@ -3415,14 +3422,15 @@ static void ds_print_fcn_name(RzDisasmState *ds) { const char *arch; RzFlagItem *flag = rz_flag_get_by_spaces(ds->core->flags, ds->analysis_op.jump, RZ_FLAGS_FS_CLASSES, RZ_FLAGS_FS_SYMBOLS, NULL); - if (flag && flag->name && ds->opstr && !strstr(ds->opstr, flag->name) && (rz_str_startswith(flag->name, "sym.") || rz_str_startswith(flag->name, "method.")) && (arch = rz_config_get(ds->core->config, "asm.arch")) && strcmp(arch, "dalvik")) { + const char *name = flag ? rz_flag_item_get_name(flag) : NULL; + if (name && ds->opstr && !strstr(ds->opstr, name) && (rz_str_startswith(name, "sym.") || rz_str_startswith(name, "method.")) && (arch = rz_config_get(ds->core->config, "asm.arch")) && strcmp(arch, "dalvik")) { RzFlagItem *flag_sym = flag; - if (ds->core->vmode && (rz_str_startswith(flag->name, "sym.") || (flag_sym = rz_flag_get_by_spaces(ds->core->flags, ds->analysis_op.jump, RZ_FLAGS_FS_SYMBOLS, NULL))) && flag_sym->demangled) { + if (ds->core->vmode && (rz_str_startswith(name, "sym.") || (flag_sym = rz_flag_get_by_spaces(ds->core->flags, ds->analysis_op.jump, RZ_FLAGS_FS_SYMBOLS, NULL))) && rz_flag_item_get_demangled(flag_sym)) { return; } - if (ds->core->flags->realnames && flag->realname) { + if (ds->core->flags->realnames && rz_flag_item_get_realname(flag)) { ds_begin_comment(ds); - ds_comment(ds, true, "; %s", flag->name); + ds_comment(ds, true, "; %s", name); } return; } @@ -3448,7 +3456,7 @@ static void ds_print_fcn_name(RzDisasmState *ds) { ds_comment(ds, true, "; %s-0x%x", f->name, -delta); } else if ((!ds->core->vmode || (!ds->subjmp && !ds->subnames)) && (!ds->opstr || !strstr(ds->opstr, f->name))) { RzFlagItem *flag_sym; - if (ds->core->vmode && (flag_sym = rz_flag_get_by_spaces(ds->core->flags, ds->analysis_op.jump, RZ_FLAGS_FS_SYMBOLS, NULL)) && flag_sym->demangled) { + if (ds->core->vmode && (flag_sym = rz_flag_get_by_spaces(ds->core->flags, ds->analysis_op.jump, RZ_FLAGS_FS_SYMBOLS, NULL)) && rz_flag_item_get_demangled(flag_sym)) { return; } ds_begin_comment(ds); @@ -3948,13 +3956,18 @@ static void ds_print_ptr(RzDisasmState *ds, int len, int idx) { if (subrel_addr && subrel_addr != p) { f2 = rz_core_flag_get_by_spaces(core->flags, subrel_addr); f2_in_opstr = f2 && ds->opstr && - ((f2->name && strstr(ds->opstr, f2->name)) || - (f2->realname && strstr(ds->opstr, f2->realname))); + ((rz_flag_item_get_name(f2) && strstr(ds->opstr, rz_flag_item_get_name(f2))) || + (rz_flag_item_get_realname(f2) && strstr(ds->opstr, rz_flag_item_get_realname(f2)))); } refaddr = p; - if (!flag_printed && !is_filtered_flag(ds, f->name) && (!ds->opstr || (!strstr(ds->opstr, f->name) && !strstr(ds->opstr, f->realname))) && !f2_in_opstr) { + if (!flag_printed && + !is_filtered_flag(ds, rz_flag_item_get_name(f)) && + (!ds->opstr || + (!strstr(ds->opstr, rz_flag_item_get_name(f)) && + !(rz_flag_item_get_realname(f) && strstr(ds->opstr, rz_flag_item_get_realname(f))))) && + !f2_in_opstr) { ds_begin_comment(ds); - ds_comment(ds, true, "; %s", f->name); + ds_comment(ds, true, "; %s", rz_flag_item_get_name(f)); ds->printed_flag_addr = p; flag_printed = true; } @@ -3990,7 +4003,7 @@ static void ds_print_ptr(RzDisasmState *ds, int len, int idx) { char *msg2 = NULL; RzFlagItem *f2_ = rz_flag_get_i(core->flags, n); if (f2_) { - flag = f2_->name; + flag = rz_flag_item_get_name(f2_); } else { msg2 = calloc(sizeof(char), len); rz_io_read_at(core->io, n, (ut8 *)msg2, len - 1); @@ -4018,7 +4031,7 @@ static void ds_print_ptr(RzDisasmState *ds, int len, int idx) { ds_begin_nl_comment(ds); ds_comment_start(ds, "; ["); if (f && f2_in_opstr) { - ds_comment_middle(ds, "%s", f->name); + ds_comment_middle(ds, "%s", rz_flag_item_get_name(f)); flag_printed = true; } else { ds_comment_middle(ds, "0x%" PFMT64x, refaddr); @@ -4081,9 +4094,10 @@ static void ds_print_ptr(RzDisasmState *ds, int len, int idx) { if (!string_printed) { ds_print_str(ds, msg, len, refaddr); } - } else if (!flag_printed && (!ds->opstr || (!strstr(ds->opstr, f->name) && !strstr(ds->opstr, f->realname)))) { + } else if (!flag_printed && + (!ds->opstr || (!strstr(ds->opstr, rz_flag_item_get_name(f)) && !(rz_flag_item_get_realname(f) && strstr(ds->opstr, rz_flag_item_get_realname(f)))))) { ds_begin_nl_comment(ds); - ds_comment(ds, true, "; %s", f->name); + ds_comment(ds, true, "; %s", rz_flag_item_get_name(f)); ds->printed_flag_addr = refaddr; } } else { @@ -4359,8 +4373,8 @@ static int myregwrite(RzAnalysisEsil *esil, const char *name, ut64 *val) { RZ_FREE(type); if ((ds->printed_flag_addr == UT64_MAX || *val != ds->printed_flag_addr) && (ds->show_emu_strflag || !emu_str_printed)) { RzFlagItem *fi = rz_flag_get_i(esil->analysis->flb.f, *val); - if (fi && (!ds->opstr || !strstr(ds->opstr, fi->name))) { - msg = rz_str_appendf(msg, "%s%s", msg && *msg ? " " : "", fi->name); + if (fi && (!ds->opstr || !strstr(ds->opstr, rz_flag_item_get_name(fi)))) { + msg = rz_str_appendf(msg, "%s%s", msg && *msg ? " " : "", rz_flag_item_get_name(fi)); } } } @@ -4399,7 +4413,7 @@ static void ds_pre_emulation(RzDisasmState *ds) { if (!f) { return; } - ut64 base = f->offset; + ut64 base = rz_flag_item_get_offset(f); RzAnalysisEsil *esil = ds->core->analysis->esil; int i, end = ds->core->offset - base; int maxemu = 1024 * 1024; @@ -4679,7 +4693,7 @@ static void ds_print_esil_analysis(RzDisasmState *ds) { } else { RzFlagItem *item = rz_flag_get_i(core->flags, pcv); if (item) { - fcn_name = item->name; + fcn_name = rz_flag_item_get_name(item); } } if (fcn_name) { @@ -4792,7 +4806,7 @@ static void ds_print_calls_hints(RzDisasmState *ds) { } RzAnalysis *analysis = ds->core->analysis; char *name; - char *full_name = NULL; + const char *full_name = NULL; if (ds->analysis_op.type == RZ_ANALYSIS_OP_TYPE_CALL) { // RzAnalysisFunction *fcn = rz_analysis_get_fcn_in (analysis, ds->analysis_op.jump, -1); RzAnalysisFunction *fcn = fcnIn(ds, ds->analysis_op.jump, -1); @@ -4801,8 +4815,8 @@ static void ds_print_calls_hints(RzDisasmState *ds) { } } else if (ds->analysis_op.ptr != UT64_MAX) { RzFlagItem *flag = rz_flag_get_i(ds->core->flags, ds->analysis_op.ptr); - if (flag && flag->space && !strcmp(flag->space->name, RZ_FLAGS_FS_IMPORTS)) { - full_name = flag->realname; + if (flag && rz_flag_item_get_space(flag) && !strcmp(rz_flag_item_get_space(flag)->name, RZ_FLAGS_FS_IMPORTS)) { + full_name = rz_flag_item_get_realname(flag); } } if (!full_name) { @@ -4974,19 +4988,19 @@ static bool set_jump_realname(RzDisasmState *ds, ut64 addr, const char **kw, con return false; } RzFlagItem *flag_sym = rz_flag_get_by_spaces(f, addr, RZ_FLAGS_FS_FUNCTIONS, RZ_FLAGS_FS_SYMBOLS, NULL); - if (!flag_sym || !flag_sym->realname) { + if (!flag_sym || !rz_flag_item_get_realname(flag_sym)) { // nothing to replace return false; } - if (!flag_sym->demangled && !f->realnames) { + if (!rz_flag_item_get_demangled(flag_sym) && !f->realnames) { // realname is not demangled and we don't want to show non-demangled realnames return false; } - *name = flag_sym->realname; + *name = rz_flag_item_get_realname(flag_sym); RzFlagItem *flag_mthd = rz_flag_get_by_spaces(f, addr, RZ_FLAGS_FS_CLASSES, NULL); if (!f->realnames) { // for asm.flags.real, we don't want these prefixes - if (flag_mthd && flag_mthd->name && rz_str_startswith(flag_mthd->name, "method.")) { + if (flag_mthd && rz_flag_item_get_name(flag_mthd) && rz_str_startswith(rz_flag_item_get_name(flag_mthd), "method.")) { *kw = "method "; } else { *kw = "sym "; @@ -5052,10 +5066,10 @@ static void ds_opstr_sub_jumps(RzDisasmState *ds) { } else if (f && !set_jump_realname(ds, addr, &kw, &name)) { RzFlagItem *flag = rz_core_flag_get_by_spaces(f, addr); if (flag) { - if (strchr(flag->name, '.')) { - name = flag->name; - if (f->realnames && flag->realname) { - name = flag->realname; + if (strchr(rz_flag_item_get_name(flag), '.')) { + name = rz_flag_item_get_name(flag); + if (f->realnames && rz_flag_item_get_realname(flag)) { + name = rz_flag_item_get_realname(flag); } } } @@ -5949,7 +5963,7 @@ RZ_API int rz_core_print_disasm_json(RzCore *core, ut64 addr, ut8 *buf, int nb_b pj_k(pj, "flags"); pj_a(pj); rz_list_foreach (flags, iter2, flag) { - pj_s(pj, flag->name); + pj_s(pj, rz_flag_item_get_name(flag)); } pj_end(pj); } @@ -6199,7 +6213,7 @@ RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut3 unsigned int seggrn = rz_config_get_i(core->config, "asm.seggrn"); rz_print_offset_sg(core->print, at, 0, show_offseg, seggrn, show_offdec, 0, NULL); } - rz_cons_printf(" %s:\n", item->name); + rz_cons_printf(" %s:\n", rz_flag_item_get_name(item)); } } // do not show flags in pie } diff --git a/librz/core/golang.c b/librz/core/golang.c index 0f0c9d5fe57..398a8b11925 100644 --- a/librz/core/golang.c +++ b/librz/core/golang.c @@ -513,7 +513,7 @@ static ut32 core_recover_golang_functions_go_1_2(RzCore *core, GoPcLnTab *pclnta static bool analyse_golang_symgo_function(RzFlagItem *fi, void *user) { RzCore *core = (RzCore *)user; - rz_core_analysis_fcn(core, fi->offset, UT64_MAX, RZ_ANALYSIS_XREF_TYPE_NULL, 1); + rz_core_analysis_fcn(core, rz_flag_item_get_offset(fi), UT64_MAX, RZ_ANALYSIS_XREF_TYPE_NULL, 1); return true; } @@ -690,7 +690,7 @@ static bool recover_string_at(GoStrRecover *ctx, ut64 str_addr, ut64 str_size) { // skip possible pointers that matches to symbols flags, because these are already handled. RzFlagItem *fi = rz_flag_get_by_spaces(ctx->core->flags, str_addr, RZ_FLAGS_FS_SYMBOLS, NULL); - if (fi && !strncmp(fi->name, "sym.", 4)) { + if (fi && !strncmp(rz_flag_item_get_name(fi), "sym.", 4)) { return false; } diff --git a/librz/core/seek.c b/librz/core/seek.c index 5685401e495..ed2abf0d397 100644 --- a/librz/core/seek.c +++ b/librz/core/seek.c @@ -181,13 +181,14 @@ struct seek_flag_offset_t { static bool seek_flag_offset(RzFlagItem *fi, void *user) { struct seek_flag_offset_t *u = (struct seek_flag_offset_t *)user; + ut64 fi_off = rz_flag_item_get_offset(fi); if (u->is_next) { - if (fi->offset < *u->next && fi->offset > u->offset) { - *u->next = fi->offset; + if (fi_off < *u->next && fi_off > u->offset) { + *u->next = fi_off; } } else { - if (fi->offset > *u->next && fi->offset < u->offset) { - *u->next = fi->offset; + if (fi_off > *u->next && fi_off < u->offset) { + *u->next = fi_off; } } return true; diff --git a/librz/core/tui/define.c b/librz/core/tui/define.c index 367ab1a2357..608a26afd4f 100644 --- a/librz/core/tui/define.c +++ b/librz/core/tui/define.c @@ -197,7 +197,7 @@ RZ_IPI void rz_core_visual_define(RzCore *core, const char *args, int distance) if (op->jump != UT64_MAX) { RzFlagItem *item = rz_flag_get_i(core->flags, op->jump); if (item) { - const char *ptr = rz_str_lchr(item->name, '.'); + const char *ptr = rz_str_lchr(rz_flag_item_get_name(item), '.'); if (ptr) { man = strdup(ptr + 1); } @@ -248,7 +248,7 @@ RZ_IPI void rz_core_visual_define(RzCore *core, const char *args, int distance) rz_core_analysis_function_rename(core, tgt_addr, newname); free(newname); } else if (f) { - char *msg = rz_str_newf("Rename flag %s to: ", f->name); + char *msg = rz_str_newf("Rename flag %s to: ", rz_flag_item_get_name(f)); char *newname = rz_cons_input(msg); free(msg); rz_flag_rename(core->flags, f, newname); @@ -286,12 +286,12 @@ RZ_IPI void rz_core_visual_define(RzCore *core, const char *args, int distance) RzFlagItem *item = rz_flag_get_i(core->flags, off); if (item) { char cmd[128]; - rz_cons_printf("Current flag size is: %" PFMT64d "\n", item->size); + rz_cons_printf("Current flag size is: %" PFMT64d "\n", rz_flag_item_get_size(item)); rz_cons_show_cursor(true); rz_cons_flush(); rz_line_set_prompt(line, "new size: "); if (rz_cons_fgets(cmd, sizeof(cmd), 0, NULL) > 0) { - item->size = rz_num_math(core->num, cmd); + rz_flag_item_set_size(item, rz_num_math(core->num, cmd)); rz_cons_set_raw(1); rz_cons_show_cursor(false); } diff --git a/librz/core/tui/flags.c b/librz/core/tui/flags.c index fcb15aa169e..be535a6f790 100644 --- a/librz/core/tui/flags.c +++ b/librz/core/tui/flags.c @@ -22,16 +22,16 @@ enum { static int flag_name_sort(const void *a, const void *b, void *user) { const RzFlagItem *fa = (const RzFlagItem *)a; const RzFlagItem *fb = (const RzFlagItem *)b; - return strcmp(fa->name, fb->name); + return strcmp(rz_flag_item_get_name(fa), rz_flag_item_get_name(fb)); } static int flag_offset_sort(const void *a, const void *b, void *user) { const RzFlagItem *fa = (const RzFlagItem *)a; const RzFlagItem *fb = (const RzFlagItem *)b; - if (fa->offset < fb->offset) { + if (rz_flag_item_get_offset(fa) < rz_flag_item_get_offset(fb)) { return -1; } - if (fa->offset > fb->offset) { + if (rz_flag_item_get_offset(fa) > rz_flag_item_get_offset(fb)) { return 1; } return 0; @@ -82,7 +82,7 @@ RZ_IPI int rz_core_visual_trackflags(RzCore *core) { sort_flags(l, sort); rz_list_foreach (l, iter, fi) { if (option == i) { - fs2 = fi->name; + fs2 = rz_flag_item_get_name(fi); hit = 1; } if ((i >= option - delta) && ((i < option + delta) || ((option < delta) && (i < (delta << 1))))) { @@ -91,7 +91,7 @@ RZ_IPI int rz_core_visual_trackflags(RzCore *core) { rz_cons_printf(Color_INVERT); } rz_cons_printf(" %c %03d 0x%08" PFMT64x " %4" PFMT64d " %s\n", - cur ? '>' : ' ', i, fi->offset, fi->size, fi->name); + cur ? '>' : ' ', i, rz_flag_item_get_offset(fi), rz_flag_item_get_size(fi), rz_flag_item_get_name(fi)); if (cur && hasColor) { rz_cons_printf(Color_RESET); } diff --git a/librz/core/tui/hud.c b/librz/core/tui/hud.c index aa485f4a18c..04fe8075e33 100644 --- a/librz/core/tui/hud.c +++ b/librz/core/tui/hud.c @@ -100,7 +100,7 @@ RZ_IPI bool rz_core_visual_hudclasses(RzCore *core) { static bool hudstuff_append(RzFlagItem *fi, void *user) { RzList *list = (RzList *)user; - char *s = rz_str_newf("0x%08" PFMT64x " %s", fi->offset, fi->name); + char *s = rz_str_newf("0x%08" PFMT64x " %s", rz_flag_item_get_offset(fi), rz_flag_item_get_name(fi)); if (s) { rz_list_append(list, s); } diff --git a/librz/core/tui/visual.c b/librz/core/tui/visual.c index 7424163c7fa..eb720d78a6b 100644 --- a/librz/core/tui/visual.c +++ b/librz/core/tui/visual.c @@ -1014,8 +1014,8 @@ static bool fill_hist_offset(RzCore *core, RzLine *line, RzCoreSeekItem *csi) { ut64 off = csi->offset; RzFlagItem *f = rz_flag_get_at(core->flags, off, false); char *command = NULL; - if (f && f->offset == off && f->offset > 0) { - command = rz_str_newf("%s", f->name); + if (f && rz_flag_item_get_offset(f) == off && rz_flag_item_get_offset(f) > 0) { + command = rz_str_newf("%s", rz_flag_item_get_name(f)); } else { command = rz_str_newf("0x%" PFMT64x, off); } @@ -1217,7 +1217,7 @@ RZ_IPI int rz_core_visual_xrefs(RzCore *core, bool xref_to, bool fcnInsteadOfAdd } else { RzFlagItem *f = rz_flag_get_at(core->flags, xaddr1, true); if (f) { - name = rz_str_newf("%s + %" PFMT64d, f->name, xaddr1 - f->offset); + name = rz_str_newf("%s + %" PFMT64d, rz_flag_item_get_name(f), xaddr1 - rz_flag_item_get_offset(f)); } else { name = strdup("unk"); } @@ -3198,11 +3198,11 @@ RZ_IPI void rz_core_visual_title(RzCore *core, int color) { f = rz_flag_get_at(core->flags, addr, showDelta); } if (f) { - if (f->offset == addr || !f->offset) { - snprintf(pos, sizeof(pos), "@ %s", f->name); + if (rz_flag_item_get_offset(f) == addr || !rz_flag_item_get_offset(f)) { + snprintf(pos, sizeof(pos), "@ %s", rz_flag_item_get_name(f)); } else { snprintf(pos, sizeof(pos), "@ %s+%d # 0x%" PFMT64x, - f->name, (int)(addr - f->offset), addr); + rz_flag_item_get_name(f), (int)(addr - rz_flag_item_get_offset(f)), addr); } } else { RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, addr, 0); diff --git a/librz/core/tui/vmenus_graph.c b/librz/core/tui/vmenus_graph.c index 365ed0f77fc..0f2aec6d93b 100644 --- a/librz/core/tui/vmenus_graph.c +++ b/librz/core/tui/vmenus_graph.c @@ -81,7 +81,7 @@ static RzList /**/ *__xrefs(RzCore *core, ut64 addr RzCoreVisualViewGraphItem *item = RZ_NEW0(RzCoreVisualViewGraphItem); RzFlagItem *f = rz_flag_get_at(core->flags, xref->from, 0); item->addr = xref->from; - item->name = f ? f->name : NULL; + item->name = f ? rz_flag_item_get_name(f) : NULL; RzAnalysisFunction *rf = rz_analysis_get_fcn_in(core->analysis, xref->from, 0); item->fcn = rf; if (rf) { @@ -108,7 +108,7 @@ static RzList /**/ *__refs(RzCore *core, ut64 addr) RzCoreVisualViewGraphItem *item = RZ_NEW0(RzCoreVisualViewGraphItem); RzFlagItem *f = rz_flag_get_at(core->flags, xref->to, 0); item->addr = xref->to; - item->name = f ? f->name : NULL; + item->name = f ? rz_flag_item_get_name(f) : NULL; RzAnalysisFunction *rf = rz_analysis_get_fcn_in(core->analysis, xref->to, 0); if (rf) { item->name = rf->name; diff --git a/librz/flag/flag.c b/librz/flag/flag.c index 35ee385c090..c3b2cd5cf54 100644 --- a/librz/flag/flag.c +++ b/librz/flag/flag.c @@ -9,6 +9,18 @@ RZ_LIB_VERSION(rz_flag); +struct rz_flag_item_t { + RZ_NONNULL char *name; /* unique name, escaped to avoid issues with rizin shell */ + char *realname; /* real name, without any escaping */ + bool demangled; /* real name from demangling? */ + ut64 offset; /* offset flagged by this item */ + ut64 size; /* size of the flag item */ + RzSpace *space; /* flag space this item belongs to */ + char *color; /* item color */ + char *comment; /* item comment */ + char *alias; /* used to define a flag based on a math expression (e.g. foo + 3) */ +}; + #define IS_FI_NOTIN_SPACE(f, i) (rz_flag_space_cur(f) && (i)->space != rz_flag_space_cur(f)) #define IS_FI_IN_SPACE(fi, sp) (!(sp) || (fi)->space == (sp)) #define STRDUP_OR_NULL(s) (!RZ_STR_ISEMPTY(s) ? strdup(s) : NULL) @@ -667,35 +679,135 @@ RZ_API RzFlagItem *rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size) return NULL; } -/* add/replace/remove the alias of a flag item */ +/** + * \return the absolute address the flag is located at + */ +RZ_API ut64 rz_flag_item_get_offset(const RzFlagItem *item) { + rz_return_val_if_fail(item, UT64_MAX); + return item->offset; +} + +/** + * \return number of bytes covered by the flag + */ +RZ_API ut64 rz_flag_item_get_size(const RzFlagItem *item) { + rz_return_val_if_fail(item, 0); + return item->size; +} + +/* + * \brief set the number of bytes covered by the flag + */ +RZ_API void rz_flag_item_set_size(RzFlagItem *item, ut64 size) { + rz_return_if_fail(item); + item->size = size; +} + +/** + * \return the flag space that \p item belongs to + */ +RZ_API RzSpace *rz_flag_item_get_space(const RzFlagItem *item) { + return item->space; +} + +/** + * \brief assign the space that \p item belongs to + */ +RZ_API void rz_flag_item_set_space(RzFlagItem *item, RzSpace *space) { + item->space = space; +} + +/** + * \return the name of the flag that \p item is an alias of + */ +RZ_API RZ_NULLABLE const char *rz_flag_item_get_alias(const RzFlagItem *item) { + return item->alias; +} + +/** + * \brief add/replace/remove the alias of a flag item + */ RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias) { rz_return_if_fail(item); free(item->alias); item->alias = RZ_STR_ISEMPTY(alias) ? NULL : strdup(alias); } -/* add/replace/remove the comment of a flag item */ +/** + * \return the comment for the given flag item + */ +RZ_API RZ_NULLABLE const char *rz_flag_item_get_comment(const RzFlagItem *item) { + return item->comment; +} + +/** + * \brief add/replace/remove the comment of a flag item + */ RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment) { rz_return_if_fail(item); free(item->comment); item->comment = RZ_STR_ISEMPTY(comment) ? NULL : strdup(comment); } -/* add/replace/remove the realname of a flag item */ +/** + * \return the unique name of the flag + */ +RZ_API RZ_NONNULL const char *rz_flag_item_get_name(const RzFlagItem *item) { + rz_return_val_if_fail(item, NULL); + return item->name; +} + +/** + * \return the realname, usually the non-escaped version of the name + */ +RZ_API RZ_NULLABLE const char *rz_flag_item_get_realname(const RzFlagItem *item) { + rz_return_val_if_fail(item, NULL); + return item->realname; +} + +/** + * \brief add/replace/remove the realname of a flag item + */ RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname) { rz_return_if_fail(item); free_item_realname(item); item->realname = RZ_STR_ISEMPTY(realname) ? NULL : strdup(realname); } -/* add/replace/remove the color of a flag item */ -RZ_API const char *rz_flag_item_set_color(RzFlagItem *item, const char *color) { +/** + * \return the color of the flag item + */ +RZ_API RZ_NULLABLE const char *rz_flag_item_get_color(const RzFlagItem *item) { + rz_return_val_if_fail(item, NULL); + return item->color; +} + +/** + * \brief add/replace/remove the color of a flag item + */ +RZ_API RZ_NULLABLE const char *rz_flag_item_set_color(RzFlagItem *item, const char *color) { rz_return_val_if_fail(item, NULL); free(item->color); item->color = (color && *color) ? strdup(color) : NULL; return item->color; } +/** + * \return whether the realname of the flag is demangled + */ +RZ_API bool rz_flag_item_get_demangled(const RzFlagItem *item) { + rz_return_val_if_fail(item, false); + return item->demangled; +} + +/* + * \brief set whether the realname of \p item is demangled + */ +RZ_API void rz_flag_item_set_demangled(RzFlagItem *item, bool demangled) { + rz_return_if_fail(item); + item->demangled = demangled; +} + /* change the name of a flag item, if the new name is available. * true is returned if everything works well, false otherwise */ RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name) { diff --git a/librz/flag/serialize_flag.c b/librz/flag/serialize_flag.c index fce4d7b9ea8..234b2337b04 100644 --- a/librz/flag/serialize_flag.c +++ b/librz/flag/serialize_flag.c @@ -94,26 +94,26 @@ static bool flag_save_cb(RzFlagItem *flag, void *user) { return false; } pj_o(j); - if (flag->realname) { - pj_ks(j, "realname", flag->realname); + if (rz_flag_item_get_realname(flag)) { + pj_ks(j, "realname", rz_flag_item_get_realname(flag)); } - pj_kb(j, "demangled", flag->demangled); - pj_kn(j, "offset", flag->offset); - pj_kn(j, "size", flag->size); - if (flag->space) { - pj_ks(j, "space", flag->space->name); + pj_kb(j, "demangled", rz_flag_item_get_demangled(flag)); + pj_kn(j, "offset", rz_flag_item_get_offset(flag)); + pj_kn(j, "size", rz_flag_item_get_size(flag)); + if (rz_flag_item_get_space(flag)) { + pj_ks(j, "space", rz_flag_item_get_space(flag)->name); } - if (flag->color) { - pj_ks(j, "color", flag->color); + if (rz_flag_item_get_color(flag)) { + pj_ks(j, "color", rz_flag_item_get_color(flag)); } - if (flag->comment) { - pj_ks(j, "comment", flag->comment); + if (rz_flag_item_get_comment(flag)) { + pj_ks(j, "comment", rz_flag_item_get_comment(flag)); } - if (flag->alias) { - pj_ks(j, "alias", flag->alias); + if (rz_flag_item_get_alias(flag)) { + pj_ks(j, "alias", rz_flag_item_get_alias(flag)); } pj_end(j); - sdb_set(db, flag->name, pj_string(j), 0); + sdb_set(db, rz_flag_item_get_name(flag), pj_string(j), 0); pj_free(j); return true; } @@ -155,7 +155,17 @@ static bool flag_load_cb(void *user, const char *k, const char *v) { return false; } - RzFlagItem proto = { 0 }; + struct { + char *name; + char *realname; + bool demangled; + ut64 offset; + ut64 size; + RzSpace *space; + char *color; + char *comment; + char *alias; + } proto = { 0 }; bool offset_set = false; bool size_set = false; @@ -224,8 +234,8 @@ static bool flag_load_cb(void *user, const char *k, const char *v) { if (proto.realname) { rz_flag_item_set_realname(item, proto.realname); } - item->demangled = proto.demangled; - item->space = proto.space; + rz_flag_item_set_demangled(item, proto.demangled); + rz_flag_item_set_space(item, proto.space); if (proto.color) { rz_flag_item_set_color(item, proto.color); } diff --git a/librz/flag/tags.c b/librz/flag/tags.c index effc17a9948..10d2d6a1b9d 100644 --- a/librz/flag/tags.c +++ b/librz/flag/tags.c @@ -43,7 +43,7 @@ static bool iter_glob_flag(RzFlagItem *fi, void *user) { const char *word; rz_list_foreach (u->words, iter, word) { - if (rz_str_glob(fi->name, word)) { + if (rz_str_glob(rz_flag_item_get_name(fi), word)) { rz_list_append(u->res, fi); } } diff --git a/librz/include/rz_analysis.h b/librz/include/rz_analysis.h index bd9cf62de0b..c6630a25275 100644 --- a/librz/include/rz_analysis.h +++ b/librz/include/rz_analysis.h @@ -1560,8 +1560,8 @@ RZ_API bool rz_analysis_function_contains(RzAnalysisFunction *fcn, ut64 addr); // returns true if function bytes were modified RZ_API bool rz_analysis_function_was_modified(RZ_NONNULL RzAnalysisFunction *fcn); -RZ_API bool rz_analysis_function_is_autonamed(RZ_NONNULL char *name); -RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL char *name); +RZ_API bool rz_analysis_function_is_autonamed(RZ_NONNULL const char *name); +RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL const char *name); /* analysis.c */ RZ_API RzAnalysis *rz_analysis_new(void); @@ -1869,7 +1869,7 @@ RZ_API RZ_OWN RzAnalysisFcnVarsCache *rz_analysis_fcn_vars_cache_from_fcn( RZ_NONNULL RZ_BORROW RzAnalysisFunction *fcn); RZ_API void rz_analysis_fcn_vars_cache_fini(RzAnalysisFcnVarsCache *cache); -RZ_API char *rz_analysis_fcn_format_sig(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn, RZ_NULLABLE char *fcn_name, +RZ_API char *rz_analysis_fcn_format_sig(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn, RZ_NULLABLE const char *fcn_name, RZ_NULLABLE RzAnalysisFcnVarsCache *reuse_cache, RZ_NULLABLE const char *fcn_name_pre, RZ_NULLABLE const char *fcn_name_post); RZ_API void rz_analysis_fcn_vars_add_types(RzAnalysis *analysis, RZ_NONNULL RzAnalysisFunction *fcn); diff --git a/librz/include/rz_flag.h b/librz/include/rz_flag.h index bd8e47f32c7..af5c9da0b75 100644 --- a/librz/include/rz_flag.h +++ b/librz/include/rz_flag.h @@ -31,17 +31,7 @@ typedef struct rz_flags_at_offset_t { RzList /**/ *flags; /* list of RzFlagItem at offset */ } RzFlagsAtOffset; -typedef struct rz_flag_item_t { - char *name; /* unique name, escaped to avoid issues with rizin shell */ - char *realname; /* real name, without any escaping */ - bool demangled; /* real name from demangling? */ - ut64 offset; /* offset flagged by this item */ - ut64 size; /* size of the flag item */ - RzSpace *space; /* flag space this item belongs to */ - char *color; /* item color */ - char *comment; /* item comment */ - char *alias; /* used to define a flag based on a math expression (e.g. foo + 3) */ -} RzFlagItem; +typedef struct rz_flag_item_t RzFlagItem; typedef struct rz_flag_t { RzSpaces spaces; /* handle flag spaces */ @@ -113,11 +103,23 @@ RZ_API void rz_flag_unset_all(RzFlag *f); RZ_API void rz_flag_unset_all_in_space(RzFlag *f, const char *space_name); RZ_API RzFlagItem *rz_flag_set(RzFlag *fo, const char *name, ut64 addr, ut32 size); RZ_API RzFlagItem *rz_flag_set_next(RzFlag *fo, const char *name, ut64 addr, ut32 size); -RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias); RZ_API void rz_flag_item_free(RzFlagItem *item); +RZ_API ut64 rz_flag_item_get_offset(const RzFlagItem *item); +RZ_API ut64 rz_flag_item_get_size(const RzFlagItem *item); +RZ_API void rz_flag_item_set_size(RzFlagItem *item, ut64 size); +RZ_API RzSpace *rz_flag_item_get_space(const RzFlagItem *item); +RZ_API void rz_flag_item_set_space(RzFlagItem *item, RzSpace *space); +RZ_API RZ_NULLABLE const char *rz_flag_item_get_alias(const RzFlagItem *item); +RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias); +RZ_API RZ_NULLABLE const char *rz_flag_item_get_comment(const RzFlagItem *item); RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment); +RZ_API RZ_NONNULL const char *rz_flag_item_get_name(const RzFlagItem *item); +RZ_API RZ_NULLABLE const char *rz_flag_item_get_realname(const RzFlagItem *item); RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname); -RZ_API const char *rz_flag_item_set_color(RzFlagItem *item, const char *color); +RZ_API RZ_NULLABLE const char *rz_flag_item_get_color(const RzFlagItem *item); +RZ_API RZ_NULLABLE const char *rz_flag_item_set_color(RzFlagItem *item, const char *color); +RZ_API bool rz_flag_item_get_demangled(const RzFlagItem *item); +RZ_API void rz_flag_item_set_demangled(RzFlagItem *item, bool demangled); RZ_API RzFlagItem *rz_flag_item_clone(RzFlagItem *item); RZ_API int rz_flag_unset_glob(RzFlag *f, const char *name); RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name); diff --git a/librz/main/rizin.c b/librz/main/rizin.c index e6e14904480..ef077855429 100644 --- a/librz/main/rizin.c +++ b/librz/main/rizin.c @@ -1294,7 +1294,7 @@ RZ_API int rz_main_rizin(int argc, const char **argv) { if (!debug && o && !o->regstate) { RzFlagItem *fi = rz_flag_get(r->flags, "entry0"); if (fi) { - rz_core_seek(r, fi->offset, true); + rz_core_seek(r, rz_flag_item_get_offset(fi), true); } else { if (o) { RzBinObject *obj = rz_bin_cur_object(r->bin); diff --git a/librz/main/rz-diff.c b/librz/main/rz-diff.c index fbead524b21..9080bf23163 100644 --- a/librz/main/rz-diff.c +++ b/librz/main/rz-diff.c @@ -2212,7 +2212,7 @@ static bool convert_offset_from_input(RzCore *core, const char *input, ut64 *off RzFlagItem *fi = rz_flag_get(core->flags, input); if (fi) { - *offset = fi->offset; + *offset = rz_flag_item_get_offset(fi); return true; } diff --git a/test/integration/test_analysis_global_var.c b/test/integration/test_analysis_global_var.c index 52edffa026e..904f2f212f4 100644 --- a/test/integration/test_analysis_global_var.c +++ b/test/integration/test_analysis_global_var.c @@ -30,9 +30,9 @@ bool test_rz_analysis_global_var() { mu_assert_true(added, "add global var"); flag = rz_analysis_var_global_get_flag_item(glob); mu_assert_notnull(flag, "global var flag_item"); - mu_assert_eq(flag->offset, glob->addr, "flag item addr"); - mu_assert_streq(flag->name, "foo", "flag item name"); - mu_assert_streq(flag->space->name, RZ_FLAGS_FS_GLOBALS, "flag space"); + mu_assert_eq(rz_flag_item_get_offset(flag), glob->addr, "flag item addr"); + mu_assert_streq(rz_flag_item_get_name(flag), "foo", "flag item name"); + mu_assert_streq(rz_flag_item_get_space(flag)->name, RZ_FLAGS_FS_GLOBALS, "flag space"); glob = NULL; glob = rz_analysis_var_global_get_byaddr_at(analysis, 0x1337); @@ -64,7 +64,7 @@ bool test_rz_analysis_global_var() { glob = rz_analysis_var_global_get_byname(analysis, "bar"); mu_assert_notnull(glob, "get global var by addr"); mu_assert_streq(glob->name, "bar", "global var name"); - mu_assert_streq(flag->name, "bar", "global flag_item name"); + mu_assert_streq(rz_flag_item_get_name(flag), "bar", "global flag_item name"); RzFlagItem *flag2 = rz_analysis_var_global_get_flag_item(glob); mu_assert_ptreq(flag2, flag, "still same flag"); @@ -119,8 +119,8 @@ bool test_rz_analysis_global_var() { mu_assert_true(added, "add global var"); flag = rz_analysis_var_global_get_flag_item(glob); mu_assert_notnull(flag, "global var flag_item"); - mu_assert_eq(flag->offset, glob->addr, "flag item addr"); - mu_assert_streq(flag->name, "bar", "flag item name"); + mu_assert_eq(rz_flag_item_get_offset(flag), glob->addr, "flag item addr"); + mu_assert_streq(rz_flag_item_get_name(flag), "bar", "flag item name"); glob = NULL; glob = rz_analysis_var_global_get_byname(analysis, "bar"); @@ -148,8 +148,8 @@ bool test_rz_analysis_global_var() { flag = rz_analysis_var_global_get_flag_item(glob); mu_assert_notnull(flag, "global var flag_item"); - mu_assert_eq(flag->offset, glob->addr, "flag item addr"); - mu_assert_streq(flag->name, "crab", "flag item name"); + mu_assert_eq(rz_flag_item_get_offset(flag), glob->addr, "flag item addr"); + mu_assert_streq(rz_flag_item_get_name(flag), "crab", "flag item name"); rz_type_parser_free(parser); rz_core_free(core); @@ -169,9 +169,9 @@ bool test_flag_confusion_space_name() { rz_analysis_var_global_add(analysis, glob); RzFlagItem *fi = rz_analysis_var_global_get_flag_item(glob); mu_assert_notnull(fi, "global var flag_item"); - mu_assert_eq(fi->offset, glob->addr, "flag item addr"); - mu_assert_streq(fi->name, "foo", "flag item name"); - mu_assert_streq(fi->space->name, RZ_FLAGS_FS_GLOBALS, "flag space"); + mu_assert_eq(rz_flag_item_get_offset(fi), glob->addr, "flag item addr"); + mu_assert_streq(rz_flag_item_get_name(fi), "foo", "flag item name"); + mu_assert_streq(rz_flag_item_get_space(fi)->name, RZ_FLAGS_FS_GLOBALS, "flag space"); rz_flag_space_set(core->flags, "ulu-mulu"); RzFlagItem *fii = rz_analysis_var_global_get_flag_item(glob); @@ -198,7 +198,7 @@ bool test_flag_confusion_addr() { rz_analysis_var_global_add(analysis, glob); RzFlagItem *fi = rz_analysis_var_global_get_flag_item(glob); - rz_flag_set(core->flags, fi->name, 0x31337, fi->size); + rz_flag_set(core->flags, rz_flag_item_get_name(fi), 0x31337, rz_flag_item_get_size(fi)); fi = rz_analysis_var_global_get_flag_item(glob); mu_assert_null(fi, "flag lost"); diff --git a/test/integration/test_cpu_platform_profiles.c b/test/integration/test_cpu_platform_profiles.c index f6625970d0a..a85883d98c6 100644 --- a/test/integration/test_cpu_platform_profiles.c +++ b/test/integration/test_cpu_platform_profiles.c @@ -26,9 +26,9 @@ bool test_cpu_profiles() { rz_platform_profile_add_flag_every_io(core->analysis->arch_target->profile, core->flags); RzFlagItem *item = rz_flag_get(core->flags, "DDRB"); - mu_assert_eq(item->offset, 0x00000004, "Flag DDRB not found"); + mu_assert_eq(rz_flag_item_get_offset(item), 0x00000004, "Flag DDRB not found"); item = rz_flag_get(core->flags, "PORTB"); - mu_assert_eq(item->offset, 0x00000005, "Flag PORTB not found"); + mu_assert_eq(rz_flag_item_get_offset(item), 0x00000005, "Flag PORTB not found"); // 3. Save into the project char *tmpdir = rz_file_tmpdir(); @@ -56,9 +56,9 @@ bool test_cpu_profiles() { // 7. Check the values again item = rz_flag_get(core->flags, "DDRB"); - mu_assert_eq(item->offset, 0x00000004, "Flag DDRB not found"); + mu_assert_eq(rz_flag_item_get_offset(item), 0x00000004, "Flag DDRB not found"); item = rz_flag_get(core->flags, "PORTB"); - mu_assert_eq(item->offset, 0x00000005, "Flag PORTB not found"); + mu_assert_eq(rz_flag_item_get_offset(item), 0x00000005, "Flag PORTB not found"); free(tmpdir); rz_core_free(core); @@ -83,7 +83,7 @@ bool test_platform_profiles() { rz_platform_index_add_flags_comments(core); RzFlagItem *item = rz_flag_get(core->flags, "AUX_MU_IER_REG"); - mu_assert_eq(item->offset, 0x7e215044, "Flag AUX_MU_IER_REG not found"); + mu_assert_eq(rz_flag_item_get_offset(item), 0x7e215044, "Flag AUX_MU_IER_REG not found"); const char *comment = rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, 0x7e804000); mu_assert_streq(comment, "Broadcom Serial Controller 1 (BSC)", "Comment unequal!"); @@ -115,7 +115,7 @@ bool test_platform_profiles() { comment = rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, 0x7e804000); mu_assert_streq(comment, "Broadcom Serial Controller 1 (BSC)", "Comment not found"); item = rz_flag_get(core->flags, "AUX_MU_IER_REG"); - mu_assert_eq(item->offset, 0x7e215044, "Flag AUX_MU_IER_REG not found"); + mu_assert_eq(rz_flag_item_get_offset(item), 0x7e215044, "Flag AUX_MU_IER_REG not found"); free(tmpdir); rz_core_free(core); diff --git a/test/unit/test_flags.c b/test/unit/test_flags.c index 1afff21745b..810d35557d6 100644 --- a/test/unit/test_flags.c +++ b/test/unit/test_flags.c @@ -47,15 +47,15 @@ bool test_rz_flag_by_spaces(void) { fi = rz_flag_get_by_spaces(flags, 1024, "sp2", "sp4", NULL); mu_assert_notnull(fi, "should be retrieved"); - mu_assert_streq(fi->name, "foo3", "first defined in sp2 should be get"); + mu_assert_streq(rz_flag_item_get_name(fi), "foo3", "first defined in sp2 should be get"); fi = rz_flag_get_by_spaces(flags, 1024, NULL); mu_assert_notnull(fi, "something should be retrieved"); - mu_assert_streq(fi->name, "foo1", "a random one should be get (the first)"); + mu_assert_streq(rz_flag_item_get_name(fi), "foo1", "a random one should be get (the first)"); fi = rz_flag_get_by_spaces(flags, 1024, "sp5", "sp8", "sp1", "sp3", "sp10", NULL); mu_assert_notnull(fi, "something should be retrieved"); - mu_assert_streq(fi->name, "foo1", "first defined in sp1 should be get"); + mu_assert_streq(rz_flag_item_get_name(fi), "foo1", "first defined in sp1 should be get"); rz_flag_free(flags); mu_end; @@ -136,33 +136,33 @@ bool test_rz_flag_set_next() { RzFlagItem *fi = rz_flag_set_next(flag, "catastasis", 0x100, 0); mu_assert_notnull(fi, "set flag"); - mu_assert_streq(fi->name, "catastasis", "flag_name"); + mu_assert_streq(rz_flag_item_get_name(fi), "catastasis", "flag_name"); RzFlagItem *fi2 = rz_flag_set_next(flag, "catastasis", 0xfa1afe1, 0); mu_assert_notnull(fi2, "set flag"); - mu_assert_streq(fi2->name, "catastasis.fa1afe1", "flag_name"); + mu_assert_streq(rz_flag_item_get_name(fi2), "catastasis.fa1afe1", "flag_name"); fi = rz_flag_set_next(flag, "catastasis", (ut64)-1, 0); mu_assert_notnull(fi, "set flag"); - mu_assert_streq(fi->name, "catastasis.ffffffffffffffff", "flag_name"); + mu_assert_streq(rz_flag_item_get_name(fi), "catastasis.ffffffffffffffff", "flag_name"); fi = rz_flag_set_next(flag, "catastasis", 0xfa1afe1, 0); mu_assert_ptreq(fi, fi2, "set matching"); fi = rz_flag_set_next(flag, "catastasis", 0xfa1afe1, 10); mu_assert_notnull(fi, "set flag"); - mu_assert_streq(fi->name, "catastasis.0", "flag_name"); + mu_assert_streq(rz_flag_item_get_name(fi), "catastasis.0", "flag_name"); fi = rz_flag_set_next(flag, "catastasis", 0xfa1afe1, 8); mu_assert_notnull(fi, "set flag"); - mu_assert_streq(fi->name, "catastasis.1", "flag_name"); + mu_assert_streq(rz_flag_item_get_name(fi), "catastasis.1", "flag_name"); fi = rz_flag_set_next(flag, "catastasis.fa1afe1", 0x200, 0); mu_assert_notnull(fi, "set flag"); - mu_assert_streq(fi->name, "catastasis.fa1afe1.200", "flag_name"); + mu_assert_streq(rz_flag_item_get_name(fi), "catastasis.fa1afe1.200", "flag_name"); RzList *all = rz_flag_all_list(flag, false); mu_assert_eq(rz_list_length(all), 6, "all flags count"); - mu_assert_streq(((RzFlagItem *)rz_list_get_n(all, 0))->name, "catastasis", "flag name"); - mu_assert_streq(((RzFlagItem *)rz_list_get_n(all, 1))->name, "catastasis.fa1afe1.200", "flag name"); - mu_assert_streq(((RzFlagItem *)rz_list_get_n(all, 2))->name, "catastasis.fa1afe1", "flag name"); - mu_assert_streq(((RzFlagItem *)rz_list_get_n(all, 3))->name, "catastasis.0", "flag name"); - mu_assert_streq(((RzFlagItem *)rz_list_get_n(all, 4))->name, "catastasis.1", "flag name"); - mu_assert_streq(((RzFlagItem *)rz_list_get_n(all, 5))->name, "catastasis.ffffffffffffffff", "flag name"); + mu_assert_streq(rz_flag_item_get_name(rz_list_get_n(all, 0)), "catastasis", "flag name"); + mu_assert_streq(rz_flag_item_get_name(rz_list_get_n(all, 1)), "catastasis.fa1afe1.200", "flag name"); + mu_assert_streq(rz_flag_item_get_name(rz_list_get_n(all, 2)), "catastasis.fa1afe1", "flag name"); + mu_assert_streq(rz_flag_item_get_name(rz_list_get_n(all, 3)), "catastasis.0", "flag name"); + mu_assert_streq(rz_flag_item_get_name(rz_list_get_n(all, 4)), "catastasis.1", "flag name"); + mu_assert_streq(rz_flag_item_get_name(rz_list_get_n(all, 5)), "catastasis.ffffffffffffffff", "flag name"); rz_list_free(all); rz_flag_free(flag); diff --git a/test/unit/test_serialize_flag.c b/test/unit/test_serialize_flag.c index 9f4598e6a83..3ab4c89b808 100644 --- a/test/unit/test_serialize_flag.c +++ b/test/unit/test_serialize_flag.c @@ -45,7 +45,7 @@ RzFlag *ref_0_flag() { rz_flag_space_set(flag, "reveries"); RzFlagItem *foobars = rz_flag_set(flag, "foobars", 0x1337, 0x10); - foobars->demangled = true; + rz_flag_item_set_demangled(foobars, true); rz_flag_item_set_realname(foobars, "Foobars"); rz_flag_item_set_color(foobars, "white"); rz_flag_item_set_comment(foobars, "windowpane"); @@ -143,23 +143,24 @@ typedef struct { static bool flag_cmp(RzFlagItem *actual, RzFlagItem *expected) { mu_assert_notnull(expected, "flag"); - assert_streq_null(actual->realname, expected->realname, "flag realname"); - mu_assert_eq(actual->demangled, expected->demangled, "flag demangled"); - mu_assert_eq_fmt(actual->offset, expected->offset, "flag offset", "0x%" PFMT64x); - mu_assert_eq_fmt(actual->size, expected->size, "flag size", "0x%" PFMT64x); - mu_assert_eq(!actual->space, !expected->space, "flag space null"); - if (expected->space) { - mu_assert_streq(actual->space->name, expected->space->name, "flag space"); + assert_streq_null(rz_flag_item_get_realname(actual), rz_flag_item_get_realname(expected), "flag realname"); + mu_assert_eq(rz_flag_item_get_demangled(actual), rz_flag_item_get_demangled(expected), "flag demangled"); + mu_assert_eq_fmt(rz_flag_item_get_offset(actual), rz_flag_item_get_offset(expected), "flag offset", "0x%" PFMT64x); + mu_assert_eq_fmt(rz_flag_item_get_size(actual), rz_flag_item_get_size(expected), "flag size", "0x%" PFMT64x); + RzSpace *expected_space = rz_flag_item_get_space(expected); + mu_assert_eq(!rz_flag_item_get_space(actual), !expected_space, "flag space null"); + if (expected_space) { + mu_assert_streq(rz_flag_item_get_space(actual)->name, expected_space->name, "flag space"); } - assert_streq_null(actual->color, expected->color, "flag color"); - assert_streq_null(actual->comment, expected->comment, "flag comment"); - assert_streq_null(actual->alias, expected->alias, "flag alias"); + assert_streq_null(rz_flag_item_get_color(actual), rz_flag_item_get_color(expected), "flag color"); + assert_streq_null(rz_flag_item_get_comment(actual), rz_flag_item_get_comment(expected), "flag comment"); + assert_streq_null(rz_flag_item_get_alias(actual), rz_flag_item_get_alias(expected), "flag alias"); return true; } static bool flag_cmp_cb(RzFlagItem *fi, void *user) { FlagCmpCtx *ctx = user; - RzFlagItem *fo = rz_flag_get(ctx->other, fi->name); + RzFlagItem *fo = rz_flag_get(ctx->other, rz_flag_item_get_name(fi)); if (!flag_cmp(fi, fo)) { ctx->equal = false; return false;