Skip to content

Commit

Permalink
Fix rz_core_analysis_bytes() API use
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Feb 21, 2024
1 parent f1c401a commit 5b11678
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/core/Cutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,10 @@ PRzAnalysisBytes CutterCore::getRzAnalysisBytesSingle(RVA addr)
rz_io_read_at(core->io, addr, buf, sizeof(buf));

auto seek = seekTemp(addr);
auto vec = fromOwned(rz_core_analysis_bytes(core, addr, buf, sizeof(buf), 1));
auto abiter = fromOwned(rz_core_analysis_bytes(core, addr, buf, sizeof(buf), 1));
auto ab =
abiter ? reinterpret_cast<RzAnalysisBytes *>(rz_iterator_next(abiter.get())) : nullptr;

auto ab = vec && rz_pvector_len(vec.get()) > 0
? reinterpret_cast<RzAnalysisBytes *>(rz_pvector_pop_front(vec.get()))
: nullptr;
return { ab, rz_analysis_bytes_free };
}

Expand Down Expand Up @@ -1027,18 +1026,10 @@ RVA CutterCore::nextOpAddr(RVA startAddr, int count)
{
CORE_LOCK();
auto seek = seekTemp(startAddr);
auto vec = fromOwned(rz_core_analysis_bytes(core, core->offset, core->block,
(int)core->blocksize, count + 1));
auto consumed =
rz_core_analysis_ops_size(core, core->offset, core->block, (int)core->blocksize, count);

RVA addr = startAddr + 1;
if (!vec) {
return addr;
}
auto ab = reinterpret_cast<RzAnalysisBytes *>(rz_pvector_tail(vec.get()));
if (!(ab && ab->op)) {
return addr;
}
addr = ab->op->addr;
RVA addr = startAddr + consumed;
return addr;
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/RizinCpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ static inline auto fromOwned(RZ_OWN RzList *data) -> UniquePtrCP<decltype(data),
return { data, {} };
}

static inline auto fromOwned(RZ_OWN RzIterator *data)
-> UniquePtrCP<decltype(data), &rz_iterator_free>
{
return { data, {} };
}

// Rizin list iteration macros
// deprecated, prefer using CutterPVector and CutterRzList instead
#define CutterRzListForeach(list, it, type, x) \
Expand Down

0 comments on commit 5b11678

Please sign in to comment.