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
* @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 {
visited.add(function.getEntryPoint());
Map<Address, Function> functionCallMap = new HashMap<Address, Function>();
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<Address, Function> 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<Address, Function> getFunctionCallMap(Function function, boolean getThunkedFunction) throws CancelledException {
return getFunctionCallMap(function, getThunkedFunction, new HashSet<>());
}
public void updateNamespaceToClassMap(Namespace namespace, RecoveredClass recoveredClass) {
namespaceToClassMap.put(namespace, recoveredClass);
}