From 680a7640cd88254f106cd6c6ff0e7525aa2c2a3d Mon Sep 17 00:00:00 2001 From: johanngan Date: Sun, 13 Nov 2022 18:30:31 -0600 Subject: [PATCH] Handle conditional computed jumps in SwitchOverride.java SwitchOverride.java is one of the recommended ways to fix switch statements in the decompiler when there are too many branches (GhidraDocs/GhidraClass/Advanced/improvingDisassemblyAndDecompilation) Currently the indirect jump is only allowed to be an unconditional computed jump (or a call). However, compilers can sometimes implement switch statements using conditional indirect jumps (via conditional loads, conditional adds, etc.) if the target architecture supports them (e.g., ARM). In this case, SwitchOverride.java will fail because the instruction flow type will be RefType.CONDITIONAL_COMPUTED_JUMP rather than the expected RefType.COMPUTED_JUMP, even though both should be equally acceptable. --- Ghidra/Features/Decompiler/ghidra_scripts/SwitchOverride.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/SwitchOverride.java b/Ghidra/Features/Decompiler/ghidra_scripts/SwitchOverride.java index 68d35baa88..bb29b513c4 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/SwitchOverride.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/SwitchOverride.java @@ -83,7 +83,7 @@ public class SwitchOverride extends GhidraScript { FlowType flowType = instr.getFlowType(); - if (flowType == RefType.COMPUTED_JUMP) { + if (flowType.isJump() && flowType.isComputed()) { return true; } if (flowType.isCall()) {