fix: stop recursion if function was already processed

Fixes issue #6832
This commit is contained in:
Emerson Pinter 2024-08-19 20:32:51 -03:00 committed by ghidra007
parent 3edd98fc69
commit 527cee1b76

View file

@ -407,9 +407,9 @@ public class RecoveredClassHelper {
* @return a map of the given functions calling addresses to the called functions * @return a map of the given functions calling addresses to the called functions
* @throws CancelledException if cancelled * @throws CancelledException if cancelled
*/ */
public Map<Address, Function> getFunctionCallMap(Function function, boolean getThunkedFunction) public Map<Address, Function> getFunctionCallMap(Function function, boolean getThunkedFunction, Set<Address> visited)
throws CancelledException { throws CancelledException {
visited.add(function.getEntryPoint());
Map<Address, Function> functionCallMap = new HashMap<Address, Function>(); Map<Address, Function> functionCallMap = new HashMap<Address, Function>();
InstructionIterator instructions = InstructionIterator instructions =
@ -435,9 +435,9 @@ public class RecoveredClassHelper {
Address functionAddress = reference.getFromAddress(); Address functionAddress = reference.getFromAddress();
Function secondHalfOfFunction = Function secondHalfOfFunction =
extendedFlatAPI.getReferencedFunction(functionAddress); extendedFlatAPI.getReferencedFunction(functionAddress);
if (secondHalfOfFunction != null) { if (secondHalfOfFunction != null && !visited.contains(secondHalfOfFunction.getEntryPoint())) {
Map<Address, Function> functionCallMap2 = Map<Address, Function> functionCallMap2 =
getFunctionCallMap(secondHalfOfFunction, false); getFunctionCallMap(secondHalfOfFunction, false, visited);
for (Address addr : functionCallMap2.keySet()) { for (Address addr : functionCallMap2.keySet()) {
monitor.checkCancelled(); monitor.checkCancelled();
functionCallMap.put(addr, functionCallMap2.get(addr)); functionCallMap.put(addr, functionCallMap2.get(addr));
@ -449,6 +449,10 @@ public class RecoveredClassHelper {
return functionCallMap; return functionCallMap;
} }
public Map<Address, Function> getFunctionCallMap(Function function, boolean getThunkedFunction) throws CancelledException {
return getFunctionCallMap(function, getThunkedFunction, new HashSet<>());
}
public void updateNamespaceToClassMap(Namespace namespace, RecoveredClass recoveredClass) { public void updateNamespaceToClassMap(Namespace namespace, RecoveredClass recoveredClass) {
namespaceToClassMap.put(namespace, recoveredClass); namespaceToClassMap.put(namespace, recoveredClass);
} }