diff --git a/src/PcodeFixupPreprocessor.cpp b/src/PcodeFixupPreprocessor.cpp index c798c39c..e28ff671 100644 --- a/src/PcodeFixupPreprocessor.cpp +++ b/src/PcodeFixupPreprocessor.cpp @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2024 Crabtux // SPDX-License-Identifier: LGPL-3.0-or-later +#include "RizinLoadImage.h" +#include "RizinUtils.h" #include "PcodeFixupPreprocessor.h" #include @@ -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(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); } - } + }); }