From 527cee1b76d4a9769e520002ec7df1aca48ab76b Mon Sep 17 00:00:00 2001 From: Emerson Pinter Date: Mon, 19 Aug 2024 20:32:51 -0300 Subject: [PATCH 1/2] fix: stop recursion if function was already processed Fixes issue #6832 --- .../classrecovery/RecoveredClassHelper.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java index ddacceaac8..b483c10e3b 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java @@ -407,9 +407,9 @@ public class RecoveredClassHelper { * @return a map of the given functions calling addresses to the called functions * @throws CancelledException if cancelled */ - public Map getFunctionCallMap(Function function, boolean getThunkedFunction) + public Map getFunctionCallMap(Function function, boolean getThunkedFunction, Set
visited) throws CancelledException { - + visited.add(function.getEntryPoint()); Map functionCallMap = new HashMap(); InstructionIterator instructions = @@ -435,9 +435,9 @@ public class RecoveredClassHelper { Address functionAddress = reference.getFromAddress(); Function secondHalfOfFunction = extendedFlatAPI.getReferencedFunction(functionAddress); - if (secondHalfOfFunction != null) { + if (secondHalfOfFunction != null && !visited.contains(secondHalfOfFunction.getEntryPoint())) { Map functionCallMap2 = - getFunctionCallMap(secondHalfOfFunction, false); + getFunctionCallMap(secondHalfOfFunction, false, visited); for (Address addr : functionCallMap2.keySet()) { monitor.checkCancelled(); functionCallMap.put(addr, functionCallMap2.get(addr)); @@ -449,6 +449,10 @@ public class RecoveredClassHelper { return functionCallMap; } + public Map getFunctionCallMap(Function function, boolean getThunkedFunction) throws CancelledException { + return getFunctionCallMap(function, getThunkedFunction, new HashSet<>()); + } + public void updateNamespaceToClassMap(Namespace namespace, RecoveredClass recoveredClass) { namespaceToClassMap.put(namespace, recoveredClass); } From 150fe43efd80575fbe0ac4150137697a4790c13d Mon Sep 17 00:00:00 2001 From: ghidra007 Date: Wed, 11 Sep 2024 19:31:12 +0000 Subject: [PATCH 2/2] GP-4865/PR-6833 added missing javadoc, minor format improvement --- .../classrecovery/RecoveredClassHelper.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java index b483c10e3b..c6d1e0c2c5 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java @@ -404,11 +404,14 @@ public class RecoveredClassHelper { * @param function the given function * @param getThunkedFunction if true, use the thunked function in the map, if false use the * directly called function from the calling function even if it is a thunk + * @param visited the set of function entry point addresses already processed * @return a map of the given functions calling addresses to the called functions * @throws CancelledException if cancelled */ - public Map getFunctionCallMap(Function function, boolean getThunkedFunction, Set
visited) + public Map getFunctionCallMap(Function function, boolean getThunkedFunction, + Set
visited) throws CancelledException { + visited.add(function.getEntryPoint()); Map functionCallMap = new HashMap(); @@ -435,7 +438,8 @@ public class RecoveredClassHelper { Address functionAddress = reference.getFromAddress(); Function secondHalfOfFunction = extendedFlatAPI.getReferencedFunction(functionAddress); - if (secondHalfOfFunction != null && !visited.contains(secondHalfOfFunction.getEntryPoint())) { + if (secondHalfOfFunction != null && + !visited.contains(secondHalfOfFunction.getEntryPoint())) { Map functionCallMap2 = getFunctionCallMap(secondHalfOfFunction, false, visited); for (Address addr : functionCallMap2.keySet()) { @@ -449,7 +453,8 @@ public class RecoveredClassHelper { return functionCallMap; } - public Map getFunctionCallMap(Function function, boolean getThunkedFunction) throws CancelledException { + public Map getFunctionCallMap(Function function, boolean getThunkedFunction) + throws CancelledException { return getFunctionCallMap(function, getThunkedFunction, new HashSet<>()); }