From cab8ed6068aaa8dcab4c72c82c6009c99b6dfc5f Mon Sep 17 00:00:00 2001 From: Emerson Pinter Date: Mon, 19 Aug 2024 22:27:30 -0300 Subject: [PATCH] feat: cache vfunctions list The vfunctions are collected and compared in two loops against all the recoveredClasses, this takes time if the binary have many classes. This commit makes the vfunctions list and the vftable address to be stored in a map, making the vfunctions list and create happen only once. --- .../classrecovery/RecoveredClassHelper.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java index f36c713735..e62e551dae 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java @@ -137,6 +137,7 @@ public class RecoveredClassHelper { protected final boolean createBookmarks; protected final boolean useShortTemplates; protected final boolean nameVfunctions; + public HashMap> allVfunctions = new HashMap<>(); public RecoveredClassHelper(Program program, ServiceProvider serviceProvider, FlatProgramAPI api, boolean createBookmarks, boolean useShortTemplates, @@ -478,20 +479,25 @@ public class RecoveredClassHelper { return functionToLoadPcodeOps.get(function); } - public Set getAllVfunctions(List
vftableAddresses) - throws CancelledException { - - Set allVfunctionsSet = new HashSet(); - + public Set getAllVfunctions(List
vftableAddresses) throws CancelledException { if (vftableAddresses.isEmpty()) { - return allVfunctionsSet; + return Collections.emptySet(); } + + Set vfunctionSet = new HashSet<>(); for (Address vftableAddress : vftableAddresses) { monitor.checkCancelled(); - allVfunctionsSet.addAll(getVfunctions(vftableAddress)); + if (!allVfunctions.containsKey(vftableAddress)) { + List funcList = getVfunctions(vftableAddress); + if (funcList == null) { + funcList = new ArrayList<>(); + } + allVfunctions.put(vftableAddress, new HashSet<>(funcList)); + } + vfunctionSet.addAll(allVfunctions.get(vftableAddress)); } - return allVfunctionsSet; + return vfunctionSet; } public Set getAllClassFunctionsWithVtableRef(List
vftables)