From 48adb5ec25de83e74a2ff1497885c2eab43a0242 Mon Sep 17 00:00:00 2001 From: emteere <47253321+emteere@users.noreply.github.com> Date: Thu, 7 Aug 2025 12:59:34 +0000 Subject: [PATCH] GP-5917 Use a hashset for functions to reduce reduntant decompiler use in functions that have more than one possible switch --- .../core/analysis/DecompilerSwitchAnalyzer.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.java index 85673203a0..48f44d5e0b 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.java @@ -57,7 +57,7 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer { // cache for pcode callother injection payloads private HashMap injectPayloadCache = new HashMap<>(); - private boolean hitNonReturningFunction = false; + private boolean hitNonReturningThunkFunction = false; //================================================================================================== @@ -103,12 +103,12 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer { return true; } - List definedFunctions = new ArrayList<>(); - List undefinedFunctions = new ArrayList<>(); + Collection definedFunctions = new HashSet<>(); + Collection undefinedFunctions = new HashSet<>(); findFunctions(program, locations, definedFunctions, undefinedFunctions, monitor); - if (hitNonReturningFunction) { - hitNonReturningFunction = false; + if (hitNonReturningThunkFunction) { + hitNonReturningThunkFunction = false; // if hit a non-returning function, code needs to be fixed up // before wasting time on analyzing potentially bad code // This will also clean out locations that were thunks for the next go round. @@ -209,8 +209,9 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer { } // kids, don't do thunks if (function.isThunk()) { + // unless they are non-returning if (function.hasNoReturn()) { - hitNonReturningFunction = true; + hitNonReturningThunkFunction = true; } continue; } @@ -428,7 +429,7 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer { program.getFunctionManager().getFunctionContaining(location); if (fixupFunc != null) { CreateFunctionCmd.fixupFunctionBody(program, fixupFunc, monitor); - // send function back, so non-returning nature will be picked up by decompiler + // send function back, so non-returning nature will be picked up if (fixupFunc.hasNoReturn()) { return fixupFunc; }