Remove rz_list_get_top/bottom & rz_list_get_head/tail_data (#4348)
This commit is contained in:
parent
30eef53291
commit
c7ddd77546
17 changed files with 27 additions and 69 deletions
|
|
@ -522,7 +522,7 @@ RZ_API HexLoopAttr hex_get_loop_flag(const HexPkt *p) {
|
|||
* \param pkt The packet which predecessor will be updated.
|
||||
*/
|
||||
static void make_next_packet_valid(HexState *state, const HexPkt *pkt) {
|
||||
HexInsnContainer *tmp = rz_list_get_top(pkt->bin);
|
||||
HexInsnContainer *tmp = rz_list_last(pkt->bin);
|
||||
if (!tmp) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ static RZ_BORROW RzBinSymbol *le_add_symbol(rz_bin_le_obj_t *bin, ut32 ordinal,
|
|||
if (rz_list_empty(bin->symbols)) {
|
||||
ordinal = 1;
|
||||
} else {
|
||||
ordinal = ((RzBinSymbol *)rz_list_get_tail_data(bin->symbols))->ordinal + 1;
|
||||
ordinal = ((RzBinSymbol *)rz_list_last(bin->symbols))->ordinal + 1;
|
||||
}
|
||||
}
|
||||
if (!rz_list_append(bin->symbols, sym)) {
|
||||
|
|
|
|||
|
|
@ -2374,7 +2374,7 @@ static int walk_exports(struct MACH0_(obj_t) * bin, RExportsIterator iterator, v
|
|||
rz_list_push(states, root);
|
||||
|
||||
do {
|
||||
RTrieState *state = rz_list_get_top(states);
|
||||
RTrieState *state = rz_list_last(states);
|
||||
p = state->node;
|
||||
ut64 len = read_uleb128(&p, end);
|
||||
if (len == UT64_MAX) {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ RZ_API RzCFValueDict *rz_cf_value_dict_parse(RzBuffer *file_buf, ut64 offset, ut
|
|||
|
||||
switch (r) {
|
||||
case YXML_ELEMSTART: {
|
||||
RzCFParseState *state = (RzCFParseState *)rz_list_get_top(stack);
|
||||
RzCFParseState *state = (RzCFParseState *)rz_list_last(stack);
|
||||
RzCFParseState *next_state = NULL;
|
||||
|
||||
if (!strcmp(x.elem, "dict")) {
|
||||
|
|
@ -189,7 +189,7 @@ RZ_API RzCFValueDict *rz_cf_value_dict_parse(RzBuffer *file_buf, ut64 offset, ut
|
|||
}
|
||||
case YXML_ELEMEND: {
|
||||
RzCFParseState *state = (RzCFParseState *)rz_list_pop(stack);
|
||||
RzCFParseState *next_state = (RzCFParseState *)rz_list_get_top(stack);
|
||||
RzCFParseState *next_state = (RzCFParseState *)rz_list_last(stack);
|
||||
if (!state || !next_state) {
|
||||
goto beach;
|
||||
}
|
||||
|
|
@ -317,7 +317,7 @@ RZ_API RzCFValueDict *rz_cf_value_dict_parse(RzBuffer *file_buf, ut64 offset, ut
|
|||
break;
|
||||
}
|
||||
case YXML_CONTENT: {
|
||||
RzCFParseState *state = (RzCFParseState *)rz_list_get_top(stack);
|
||||
RzCFParseState *state = (RzCFParseState *)rz_list_last(stack);
|
||||
if (state->phase == RZ_CF_STATE_IN_IGNORE) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -877,7 +877,7 @@ RZ_API ut32 rz_core_asm_bwdis_len(RzCore *core, int *instr_len, ut64 *start_addr
|
|||
*instr_len = 0;
|
||||
}
|
||||
if (hits && rz_list_length(hits) > 0) {
|
||||
hit = rz_list_get_bottom(hits);
|
||||
hit = rz_list_first(hits);
|
||||
if (start_addr) {
|
||||
*start_addr = hit->addr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to) {
|
|||
old_sp = cur_sp;
|
||||
prev_call = false;
|
||||
} else if (prev_ret) {
|
||||
RzDebugFrame *head = rz_list_get_bottom(core->dbg->call_frames);
|
||||
RzDebugFrame *head = rz_list_first(core->dbg->call_frames);
|
||||
if (head && head->addr != pc) {
|
||||
eprintf("*");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4426,7 +4426,7 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_instrs_stmt) {
|
|||
RZ_LOG_ERROR("core: No basic block contains current address\n");
|
||||
return RZ_CMD_STATUS_INVALID;
|
||||
}
|
||||
RzAnalysisBlock *bb = rz_list_get_top(bbl);
|
||||
RzAnalysisBlock *bb = rz_list_last(bbl);
|
||||
rz_analysis_block_ref(bb);
|
||||
rz_list_free(bbl);
|
||||
|
||||
|
|
|
|||
|
|
@ -3739,7 +3739,7 @@ static bool core_walk_function_blocks(RzCore *core, RzAnalysisFunction *f, RzCmd
|
|||
|
||||
if (rz_list_length(f->bbs) >= 1) {
|
||||
ut32 fcn_size = rz_analysis_function_realsize(f);
|
||||
b = rz_list_get_top(f->bbs);
|
||||
b = rz_list_last(f->bbs);
|
||||
if (b->size > fcn_size) {
|
||||
b->size = fcn_size;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1190,7 +1190,7 @@ static void print_rop(RzCore *core, RzList /*<RzCoreAsmHit *>*/ *hitlist, PJ *pj
|
|||
}
|
||||
pj_end(pj);
|
||||
if (db && hit) {
|
||||
const ut64 addr = ((RzCoreAsmHit *)rz_list_get_head_data(hitlist))->addr;
|
||||
const ut64 addr = ((RzCoreAsmHit *)rz_list_first(hitlist))->addr;
|
||||
// rz_cons_printf ("Gadget size: %d\n", (int)size);
|
||||
const char *key = rz_strf(tmpbuf, "0x%08" PFMT64x, addr);
|
||||
rop_classify(core, db, ropList, key, size);
|
||||
|
|
@ -1205,7 +1205,7 @@ static void print_rop(RzCore *core, RzList /*<RzCoreAsmHit *>*/ *hitlist, PJ *pj
|
|||
// Print gadgets in a 'linear manner', each sequence
|
||||
// on one line.
|
||||
rz_cons_printf("0x%08" PFMT64x ":",
|
||||
((RzCoreAsmHit *)rz_list_get_head_data(hitlist))->addr);
|
||||
((RzCoreAsmHit *)rz_list_first(hitlist))->addr);
|
||||
rz_list_foreach (hitlist, iter, hit) {
|
||||
ut8 *buf = malloc(hit->len);
|
||||
rz_io_read_at(core->io, hit->addr, buf, hit->len);
|
||||
|
|
@ -1231,7 +1231,7 @@ static void print_rop(RzCore *core, RzList /*<RzCoreAsmHit *>*/ *hitlist, PJ *pj
|
|||
rz_analysis_op_fini(&aop);
|
||||
}
|
||||
if (db && hit) {
|
||||
const ut64 addr = ((RzCoreAsmHit *)rz_list_get_head_data(hitlist))->addr;
|
||||
const ut64 addr = ((RzCoreAsmHit *)rz_list_first(hitlist))->addr;
|
||||
// rz_cons_printf ("Gadget size: %d\n", (int)size);
|
||||
const char *key = rz_strf(tmpbuf, "0x%08" PFMT64x, addr);
|
||||
rop_classify(core, db, ropList, key, size);
|
||||
|
|
@ -1285,7 +1285,7 @@ static void print_rop(RzCore *core, RzList /*<RzCoreAsmHit *>*/ *hitlist, PJ *pj
|
|||
rz_analysis_op_fini(&aop);
|
||||
}
|
||||
if (db && hit) {
|
||||
const ut64 addr = ((RzCoreAsmHit *)rz_list_get_head_data(hitlist))->addr;
|
||||
const ut64 addr = ((RzCoreAsmHit *)rz_list_first(hitlist))->addr;
|
||||
// rz_cons_printf ("Gadget size: %d\n", (int)size);
|
||||
const char *key = rz_strf(tmpbuf, "0x%08" PFMT64x, addr);
|
||||
rop_classify(core, db, ropList, key, size);
|
||||
|
|
@ -1510,7 +1510,7 @@ static int rz_core_search_rop(RzCore *core, RzInterval search_itv, int opt, cons
|
|||
if (gadgetSdb) {
|
||||
RzListIter *iter;
|
||||
|
||||
RzCoreAsmHit *hit = (RzCoreAsmHit *)rz_list_get_head_data(hitlist);
|
||||
RzCoreAsmHit *hit = (RzCoreAsmHit *)rz_list_first(hitlist);
|
||||
char *headAddr = rz_str_newf("%" PFMT64x, hit->addr);
|
||||
if (!headAddr) {
|
||||
result = false;
|
||||
|
|
|
|||
|
|
@ -665,7 +665,7 @@ static void set_offset_hint(RzCore *core, RzAnalysisOp *op, RZ_BORROW RzTypePath
|
|||
// possible member offset and the global variable at the laddr
|
||||
RzList *paths = rz_analysis_type_paths_by_address(core->analysis, laddr + offimm);
|
||||
if (paths && rz_list_length(paths)) {
|
||||
RzTypePathTuple *match = rz_list_get_top(paths);
|
||||
RzTypePathTuple *match = rz_list_last(paths);
|
||||
rz_analysis_hint_set_offset(core->analysis, at, match->path->path);
|
||||
}
|
||||
rz_list_free(paths);
|
||||
|
|
@ -693,7 +693,7 @@ static void resolve_global_var_types(RzCore *core, ut64 at, struct GVTAnalysisCo
|
|||
|
||||
// TODO: Handle register based arg for types offset/path propagation
|
||||
if (vtpaths && rz_list_length(vtpaths) && ctx->var && ctx->var->storage.type == RZ_ANALYSIS_VAR_STORAGE_STACK) {
|
||||
RzTypePathTuple *vtpath = rz_list_get_top(vtpaths);
|
||||
RzTypePathTuple *vtpath = rz_list_last(vtpaths);
|
||||
// if a var addr matches with compound type, change its type and name
|
||||
// var int local_e0h --> var struct foo
|
||||
if (!*resolved) {
|
||||
|
|
@ -706,10 +706,10 @@ static void resolve_global_var_types(RzCore *core, ut64 at, struct GVTAnalysisCo
|
|||
vtpath->root = NULL;
|
||||
}
|
||||
} else if (stpaths && rz_list_length(stpaths)) {
|
||||
RzTypePathTuple *stpath = rz_list_get_top(stpaths);
|
||||
RzTypePathTuple *stpath = rz_list_last(stpaths);
|
||||
set_offset_hint(core, ctx->aop, stpath, ctx->src_addr, at - ret, ctx->src_imm);
|
||||
} else if (dtpaths && rz_list_length(dtpaths)) {
|
||||
RzTypePathTuple *dtpath = rz_list_get_top(dtpaths);
|
||||
RzTypePathTuple *dtpath = rz_list_last(dtpaths);
|
||||
set_offset_hint(core, ctx->aop, dtpath, ctx->dst_addr, at - ret, ctx->dst_imm);
|
||||
}
|
||||
rz_list_free(stpaths);
|
||||
|
|
|
|||
|
|
@ -809,7 +809,7 @@ static void add_library(DWORD pid, LPVOID lpBaseOfDll, HANDLE hFile, char *dllna
|
|||
}
|
||||
|
||||
static void *last_library(void) {
|
||||
return lib_list ? rz_list_get_tail_data(lib_list) : NULL;
|
||||
return lib_list ? rz_list_last(lib_list) : NULL;
|
||||
}
|
||||
|
||||
static bool breaked = false;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ static const char *str_callback(RzNum *user, ut64 off, int *ok) {
|
|||
}
|
||||
if (f) {
|
||||
const RzList *list = rz_flag_get_list(f, off);
|
||||
RzFlagItem *item = rz_list_get_top(list);
|
||||
RzFlagItem *item = rz_list_last(list);
|
||||
if (item) {
|
||||
if (ok) {
|
||||
*ok = true;
|
||||
|
|
@ -317,7 +317,7 @@ RZ_API RzFlagItem *rz_flag_get(RzFlag *f, const char *name) {
|
|||
RZ_API RzFlagItem *rz_flag_get_i(RzFlag *f, ut64 off) {
|
||||
rz_return_val_if_fail(f, NULL);
|
||||
const RzList *list = rz_flag_get_list(f, off);
|
||||
return list ? evalFlag(f, rz_list_get_top(list)) : NULL;
|
||||
return list ? evalFlag(f, rz_list_last(list)) : NULL;
|
||||
}
|
||||
|
||||
/* return the first flag that matches an offset ordered by the order of
|
||||
|
|
@ -341,7 +341,7 @@ RZ_API RzFlagItem *rz_flag_get_by_spaces(RzFlag *f, ut64 off, ...) {
|
|||
goto beach;
|
||||
}
|
||||
if (rz_list_length(list) == 1) {
|
||||
ret = rz_list_get_top(list);
|
||||
ret = rz_list_last(list);
|
||||
goto beach;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,15 +93,11 @@ RZ_API void rz_list_split_iter(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *i
|
|||
RZ_API bool rz_list_join(RZ_NONNULL RzList *list1, RZ_NONNULL RzList *list2);
|
||||
RZ_API RZ_BORROW void *rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n);
|
||||
RZ_API ut32 rz_list_del_n(RZ_NONNULL RzList *list, ut32 n);
|
||||
RZ_API RZ_BORROW void *rz_list_get_top(RZ_NONNULL const RzList *list);
|
||||
RZ_API RZ_BORROW void *rz_list_get_bottom(RZ_NONNULL const RzList *list);
|
||||
RZ_API RZ_BORROW RzListIter *rz_list_iterator(RZ_NONNULL const RzList *list);
|
||||
RZ_API RZ_BORROW RzListIter *rz_list_push(RZ_NONNULL RzList *list, void *item);
|
||||
RZ_API RZ_OWN void *rz_list_pop(RZ_NONNULL RzList *list);
|
||||
RZ_API RZ_OWN void *rz_list_pop_head(RZ_NONNULL RzList *list);
|
||||
RZ_API void rz_list_reverse(RZ_NONNULL RzList *list);
|
||||
RZ_API RZ_BORROW void *rz_list_get_head_data(RZ_NONNULL RzList *list);
|
||||
RZ_API RZ_BORROW void *rz_list_get_tail_data(RZ_NONNULL RzList *list);
|
||||
RZ_API RZ_OWN RzList *rz_list_clone(RZ_NONNULL const RzList *list);
|
||||
RZ_API RZ_OWN char *rz_list_to_str(RZ_NONNULL RzList *list, char ch);
|
||||
RZ_API RZ_OWN RzList *rz_list_of_sdblist(SdbList *sl);
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ RZ_API void rz_reg_arena_pop(RzReg *reg) {
|
|||
}
|
||||
a = rz_list_pop(reg->regset[i].pool);
|
||||
rz_reg_arena_free(a);
|
||||
a = rz_list_get_tail_data(reg->regset[i].pool);
|
||||
a = rz_list_last(reg->regset[i].pool);
|
||||
if (a) {
|
||||
reg->regset[i].arena = a;
|
||||
reg->regset[i].cur = rz_list_tail(reg->regset[i].pool);
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ static bool parse_reg_profile_str(RZ_OUT RzList /*<RzRegProfileAlias *>*/ *alias
|
|||
}
|
||||
if (rz_str_strchr(line, "#")) {
|
||||
RzList *line_and_cmt = rz_str_split_duplist_n_regex(line, "\\#", 0, true);
|
||||
char *raw_comment = strdup(rz_list_get_top(line_and_cmt));
|
||||
char *raw_comment = strdup(rz_list_last(line_and_cmt));
|
||||
if (!raw_comment) {
|
||||
RZ_LOG_WARN("Comment could not be split from register definition. Line: \"%s\"\n", line);
|
||||
continue;
|
||||
|
|
@ -299,7 +299,7 @@ static bool parse_reg_profile_str(RZ_OUT RzList /*<RzRegProfileAlias *>*/ *alias
|
|||
RZ_LOG_WARN("Could not prepend # to comment. Line: \"%s\".\n", line);
|
||||
continue;
|
||||
}
|
||||
toks = rz_str_split_duplist_n_regex(rz_list_get_bottom(line_and_cmt), "\\s+", 0, true);
|
||||
toks = rz_str_split_duplist_n_regex(rz_list_first(line_and_cmt), "\\s+", 0, true);
|
||||
rz_list_append(toks, comment);
|
||||
rz_list_free(line_and_cmt);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -476,26 +476,6 @@ RZ_API ut32 rz_list_del_n(RZ_NONNULL RzList *list, ut32 n) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the last element of the list
|
||||
*
|
||||
**/
|
||||
RZ_API RZ_BORROW void *rz_list_get_top(RZ_NONNULL const RzList *list) {
|
||||
rz_return_val_if_fail(list, NULL);
|
||||
|
||||
return list->tail ? list->tail->elem : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the first element of the list
|
||||
*
|
||||
**/
|
||||
RZ_API RZ_BORROW void *rz_list_get_bottom(RZ_NONNULL const RzList *list) {
|
||||
rz_return_val_if_fail(list, NULL);
|
||||
|
||||
return list->head ? list->head->elem : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reverses the list
|
||||
*
|
||||
|
|
@ -515,24 +495,6 @@ RZ_API void rz_list_reverse(RZ_NONNULL RzList *list) {
|
|||
list->tail = tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the data of the first element of the list
|
||||
*
|
||||
**/
|
||||
RZ_API RZ_BORROW void *rz_list_get_head_data(RZ_NONNULL RzList *list) {
|
||||
rz_return_val_if_fail(list, NULL);
|
||||
return rz_list_iter_get_data(list->head);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the data of the last element of the list
|
||||
*
|
||||
**/
|
||||
RZ_API RZ_BORROW void *rz_list_get_tail_data(RZ_NONNULL RzList *list) {
|
||||
rz_return_val_if_fail(list, NULL);
|
||||
return rz_list_iter_get_data(list->tail);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Shallow copies of the list (but doesn't free its elements)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ bool test_dwarf_cpp_empty_line_info(void) { // this should work for dwarf2 aswel
|
|||
bin->cur, NULL, false);
|
||||
mu_assert_notnull(li, "line info");
|
||||
mu_assert_eq(rz_list_length(li->units), 25, "line units count");
|
||||
RzBinDwarfLineUnit *lunit = rz_list_get_tail_data(li->units);
|
||||
RzBinDwarfLineUnit *lunit = rz_list_last(li->units);
|
||||
mu_assert_notnull(lunit, "line unit");
|
||||
|
||||
RzBinDwarfLineUnitHdr *hdr = &lunit->hdr;
|
||||
|
|
|
|||
Loading…
Reference in a new issue