Skip to content

Commit

Permalink
Fix rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Sep 25, 2024
1 parent eeed837 commit 9c63920
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 102 deletions.
6 changes: 3 additions & 3 deletions librz/arch/isa/hexagon/hexagon_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,15 +1206,15 @@ RZ_API bool hexagon_decode_iword(RZ_OUT RzAnalysisInsnWord *iword, ut64 addr, co

set_iword_properties(aop->type, iword);
if (iword->props & RZ_ANALYSIS_IWORD_CALL && aop->jump != UT64_MAX) {
set_u_add(iword->call_targets, aop->jump);
rz_set_u_add(iword->call_targets, aop->jump);
} else if (aop->jump != UT64_MAX) {
set_u_add(iword->jump_targets, aop->jump);
rz_set_u_add(iword->jump_targets, aop->jump);
}

if (hic->pkt_info.last_insn) {
if (aop->type != RZ_ANALYSIS_OP_TYPE_RET && !rz_analysis_op_is_jump(aop)) {
ut64 next_iword_addr = addr + iword->size_bytes;
set_u_add(iword->jump_targets, next_iword_addr);
rz_set_u_add(iword->jump_targets, next_iword_addr);
}
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions librz/arch/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: 2010-2020 nibble <nibble.ds@gmail.com>
// SPDX-License-Identifier: LGPL-3.0-only

#include <rz_util/set.h>
#include <rz_util/rz_set.h>
#include <rz_analysis.h>
#include <rz_util.h>
#include <rz_list.h>
Expand Down Expand Up @@ -700,8 +700,8 @@ RZ_API RZ_OWN RzAnalysisInsnWord *rz_analysis_insn_word_new() {
}
iword->asm_str = rz_strbuf_new("");
iword->insns = rz_pvector_new(rz_analysis_op_free);
iword->jump_targets = set_u_new();
iword->call_targets = set_u_new();
iword->jump_targets = rz_set_u_new();
iword->call_targets = rz_set_u_new();
if (!iword->asm_str || !iword->insns || !iword->jump_targets) {
rz_analysis_insn_word_free(iword);
return NULL;
Expand All @@ -722,8 +722,8 @@ RZ_API void rz_analysis_insn_word_setup(RZ_BORROW RZ_NONNULL RzAnalysisInsnWord
rz_analysis_insn_word_fini(iword);
iword->asm_str = rz_strbuf_new("");
iword->insns = rz_pvector_new(rz_analysis_op_free);
iword->jump_targets = set_u_new();
iword->call_targets = set_u_new();
iword->jump_targets = rz_set_u_new();
iword->call_targets = rz_set_u_new();
if (!iword->asm_str || !iword->insns || !iword->jump_targets) {
rz_analysis_insn_word_fini(iword);
}
Expand All @@ -735,8 +735,8 @@ RZ_API void rz_analysis_insn_word_fini(RZ_OWN RZ_NULLABLE RzAnalysisInsnWord *iw
}
rz_strbuf_free(iword->asm_str);
rz_pvector_free(iword->insns);
set_u_free(iword->jump_targets);
set_u_free(iword->call_targets);
rz_set_u_free(iword->jump_targets);
rz_set_u_free(iword->call_targets);
rz_il_op_effect_free(iword->il_op);
rz_mem_memzero(iword, sizeof(RzAnalysisInsnWord));
}
16 changes: 8 additions & 8 deletions librz/core/cgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <rz_core.h>
#include <rz_util/rz_graph_drawable.h>
#include "core_private.h"
#include <rz_util/set.h>
#include <rz_util/rz_iterator.h>
#include <rz_util/rz_set.h>
#include <rz_util/rz_assert.h>
#include <rz_util/rz_str.h>
#include <rz_util/ht_uu.h>
Expand Down Expand Up @@ -1357,18 +1358,17 @@ RZ_API RZ_OWN RzGraph /*<RzGraphNodeInfo *>*/ *rz_core_graph_cfg_iwords(RZ_NONNU
}
// Add all neighbors to graph
RzAnalysisInsnWord target_iword = { 0 };
SetUIter it;
set_u_iter_reset(it);
set_u_foreach(cur_iword.jump_targets, it) {
ut64 target = it.v;
RzIterator *iter = rz_set_u_as_iter(cur_iword.jump_targets);
ut64 *target;
rz_iterator_foreach(iter, target) {
rz_analysis_insn_word_setup(&target_iword);
if (decode_iword_at(core, target, buf, sizeof(buf), &target_iword) <= 0) {
if (decode_iword_at(core, *target, buf, sizeof(buf), &target_iword) <= 0) {
rz_analysis_insn_word_fini(&target_iword);
continue;
}
bool target_within_fcn = fcn ? rz_analysis_function_contains(fcn, target) : true;
bool target_within_fcn = fcn ? rz_analysis_function_contains(fcn, *target) : true;
bool found = false;
ht_uu_find(nodes_visited, target, &found);
ht_uu_find(nodes_visited, *target, &found);
if (!found && target_within_fcn) {
rz_vector_push(to_visit, &target);
}
Expand Down
4 changes: 2 additions & 2 deletions librz/include/rz_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,8 @@ typedef struct {
ut64 addr; ///< Address the instruction word is located.
RzStrBuf *asm_str; ///< The whole asm string. Single instructions are separated by a newline.
RzPVector /*<RzAnalysisOp *>*/ *insns; ///< Instructions forming the instruction word.
SetU *jump_targets; ///< Set of addresses this iword possibly jumps to. This includes the next instr. word if there is any.
SetU *call_targets; ///< Set of addresses this iword calls.
RzSetU *jump_targets; ///< Set of addresses this iword possibly jumps to. This includes the next instr. word if there is any.
RzSetU *call_targets; ///< Set of addresses this iword calls.
RzAnalysisLiftedILOp il_op; ///< The complete IL operation of this instr. word.
RzAnalysisIWordProperties props; ///< Properties of this instruction word.
} RzAnalysisInsnWord;
Expand Down
8 changes: 0 additions & 8 deletions librz/util/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ RZ_API void rz_set_u_add(RZ_NONNULL RzSetU *set, ut64 u) {
ht_up_insert(set, u, (void *)1);
}

/**
* \brief Get the size of set \s.
*/
RZ_API ut64 set_u_size(SetU *s) {
rz_return_val_if_fail(s, 0);
return s->count;
}

/**
* \brief Check if hash set \p set contains element \p u.
*/
Expand Down
75 changes: 1 addition & 74 deletions test/unit/test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

#include <rz_util.h>
#include <rz_util/set.h>
#include <rz_util/rz_set.h>
#include "minunit.h"

bool test_file_slurp(void) {
Expand Down Expand Up @@ -63,80 +63,7 @@ bool test_leading_zeros(void) {
mu_end;
}

bool test_set_u(void) {
SetU *set_u = set_u_new();
set_u_add(set_u, 0x5050505);
set_u_add(set_u, 0x5050505);
set_u_add(set_u, 0x6060606);
set_u_add(set_u, 0x7070707);
set_u_add(set_u, 0x7070707);
mu_assert_eq(set_u_size(set_u), 3, "Length wrong.");
mu_assert_true(set_u_contains(set_u, 0x5050505), "Value was not added.");
mu_assert_true(set_u_contains(set_u, 0x6060606), "Value was not added.");
mu_assert_true(set_u_contains(set_u, 0x7070707), "Value was not added.");

set_u_delete(set_u, 0x7070707);
mu_assert_false(set_u_contains(set_u, 0x7070707), "Value was not deleted.");
mu_assert_eq(set_u_size(set_u), 2, "Length wrong.");

// Double delete
set_u_delete(set_u, 0x7070707);
mu_assert_eq(set_u_size(set_u), 2, "Length wrong.");

size_t x = 0;
SetUIter it;
set_u_iter_reset(it);
set_u_foreach(set_u, it) {
x++;
bool matches = it.v == 0x5050505 || it.v == 0x6060606;
mu_assert_true(matches, "Set contained ill-formed value.");
}
mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times.");

set_u_delete(set_u, 0x6060606);
mu_assert_eq(set_u_size(set_u), 1, "Length wrong.");
set_u_delete(set_u, 0x5050505);
mu_assert_eq(set_u_size(set_u), 0, "Length wrong.");

set_u_iter_reset(it);
set_u_foreach(set_u, it) {
mu_assert("Should not be reached.", false);
}
set_u_add(set_u, 0x53e0);
set_u_add(set_u, 0x53bc);
x = 0;
set_u_iter_reset(it);
set_u_foreach(set_u, it) {
x++;
}
mu_assert_eq(x, 2, "Foreach hasn't iterated the correct number of times.");
set_u_delete(set_u, 0x53e0);
set_u_delete(set_u, 0x53bc);

set_u_add(set_u, 0);
set_u_add(set_u, 1);
set_u_add(set_u, 2);
set_u_add(set_u, 3);

// Add an address as key which is far away from the heap addresses.
set_u_add(set_u, 100000000);
mu_assert_true(set_u_contains(set_u, 100000000), "Not contained.");
mu_assert_eq(set_u->count, 5, "count");
mu_assert_false(set_u_contains(set_u, 6), "should not be here.");

x = 0;
set_u_iter_reset(it);
set_u_foreach(set_u, it) {
x++;
}
mu_assert_eq(x, 5, "Foreach hasn't iterated the correct number of times.");

set_u_free(set_u);
mu_end;
}

int all_tests() {
mu_run_test(test_set_u);
mu_run_test(test_file_slurp);
mu_run_test(test_leading_zeros);
return tests_passed != tests_run;
Expand Down

0 comments on commit 9c63920

Please sign in to comment.