Skip to content

Commit

Permalink
Reuse rz_list_foreach_cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Crabtux committed Mar 16, 2024
1 parent 7dc95ed commit 6066870
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/PcodeFixupPreprocessor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2024 Crabtux <[email protected]>
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "RizinLoadImage.h"
#include "RizinUtils.h"
#include "PcodeFixupPreprocessor.h"

#include <funcdata.hh>
Expand All @@ -11,24 +13,15 @@ using namespace ghidra;

void PcodeFixupPreprocessor::fixupSharedReturnJumpToRelocs(RzAnalysisFunction *function, Funcdata *func, RzCore *core, RizinArchitecture &arch)
{
RzList *refs = rz_analysis_function_get_xrefs_from(function);

RzListIter *it;
RzAnalysisXRef *xref;

// C++ has more strict type checking than C, which stops us from implicitly casting void * to RzListIter *.
// Expand the rz_list_foreach macro manually.
if (refs) for (it = refs->head; it && (xref = (RzAnalysisXRef *)it->elem, 1); it = it->next)
{
RzList *xrefs = rz_analysis_function_get_xrefs_from(function);
rz_list_foreach_cpp<RzAnalysisXRef>(xrefs, [&](RzAnalysisXRef *xref){
// To ensure the instruction is a `jmp` instruction
if (xref->type != RZ_ANALYSIS_XREF_TYPE_CODE)
continue;

// If the target location is a imported function, then do the patch.
RzBinReloc *reloc = rz_core_get_reloc_to(core, xref->to);
if (reloc != nullptr && reloc->import != nullptr)
if (xref->type == RZ_ANALYSIS_XREF_TYPE_CODE)
{
func->getOverride().insertFlowOverride(Address(arch.getDefaultCodeSpace(), xref->from), Override::CALL_RETURN);
// If the target location is a imported function, then do the patch.
RzBinReloc *reloc = rz_core_get_reloc_to(core, xref->to);
if (reloc != nullptr && reloc->import != nullptr)
func->getOverride().insertFlowOverride(Address(arch.getDefaultCodeSpace(), xref->from), Override::CALL_RETURN);
}
}
});
}

0 comments on commit 6066870

Please sign in to comment.