From 527cee1b76d4a9769e520002ec7df1aca48ab76b Mon Sep 17 00:00:00 2001 From: Emerson Pinter Date: Mon, 19 Aug 2024 20:32:51 -0300 Subject: [PATCH 1/3] 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/3] 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<>()); } From 5f0e660c64502d3959366851f03b3dda35ccab7a Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Fri, 13 Sep 2024 08:48:16 -0400 Subject: [PATCH 3/3] GP-0: Fix concurrency issue in TraceRmiTarget. --- .../plugin/core/debug/service/tracermi/TraceRmiTarget.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/service/tracermi/TraceRmiTarget.java b/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/service/tracermi/TraceRmiTarget.java index 673c3a444b..f4e0807698 100644 --- a/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/service/tracermi/TraceRmiTarget.java +++ b/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/service/tracermi/TraceRmiTarget.java @@ -809,12 +809,14 @@ public class TraceRmiTarget extends AbstractTarget { public MatchedMethod getBest(String name, ActionName action, Supplier> preferredSupplier) { - return map.computeIfAbsent(name, n -> chooseBest(action, preferredSupplier.get())); + return getBest(name, action, preferredSupplier.get()); } public MatchedMethod getBest(String name, ActionName action, List preferred) { - return map.computeIfAbsent(name, n -> chooseBest(action, preferred)); + synchronized (map) { + return map.computeIfAbsent(name, n -> chooseBest(action, preferred)); + } } private MatchedMethod chooseBest(ActionName name, List preferred) {