-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ghidra uses some scripts written in Java to fixup some analysis corner cases (see Ghidra/Features/Base/ghidra_scripts), but currently rz-ghidra is not able to use them, which causes some decompiling issues. This change makes an attempt to fixup one of the corner cases. Details about the issue can be found in #202. We try to solve the issue by adding a hook before decompiling action, but after the initialization of the RizinArchitecture. The hook function uses rizin to analyse shared return calls to relocs, and fixup the P-Code using setFlowOverride() API provided by Ghidra. Fix #202
- Loading branch information
Showing
8 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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> | ||
#include <flow.hh> | ||
#include <override.hh> | ||
|
||
using namespace ghidra; | ||
|
||
void PcodeFixupPreprocessor::fixupSharedReturnJumpToRelocs(RzAnalysisFunction *function, Funcdata *func, RzCore *core, RizinArchitecture &arch) | ||
{ | ||
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) | ||
{ | ||
// 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); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-FileCopyrightText: 2024 Crabtux <[email protected]> | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#ifndef PCODE_PREPROCESSOR_H | ||
#define PCODE_PREPROCESSOR_H | ||
|
||
#include "RizinArchitecture.h" | ||
|
||
#include <rz_core.h> | ||
|
||
class PcodeFixupPreprocessor | ||
{ | ||
public: | ||
static void fixupSharedReturnJumpToRelocs(RzAnalysisFunction *function, ghidra::Funcdata *func, RzCore *core, RizinArchitecture &arch); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdio.h> | ||
|
||
int getNum(void); | ||
int calc(int a, int b); | ||
|
||
int main(void){ | ||
int c = getNum(); | ||
|
||
if (c > 2) | ||
return calc(c, 2); | ||
else | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters