Ghidra is a software reverse engineering (SRE) framework
GP-5764 added option to RecoverClassesFromRTTIScript enabling users to not force vfunctions to be thiscalls.
ghidra007cee04048cba7
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionDefinitionUpdatesScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionDefinitionUpdatesScript.javaindex bbfe26013e..fac617cfba 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionDefinitionUpdatesScript.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionDefinitionUpdatesScript.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -47,7 +47,7 @@ public class ApplyClassFunctionDefinitionUpdatesScript extends GhidraScript {}RecoveredClassHelper classHelper = new RecoveredClassHelper(currentProgram, state.getTool(),- this, false, false, false, monitor);+ this, false, false, false, true, monitor);DataTypeManagerService dtms = state.getTool().getService(DataTypeManagerService.class);List<DataType> selectedDatatypes = dtms.getSelectedDatatypes();diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionSignatureUpdatesScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionSignatureUpdatesScript.javaindex 22cd12c5ab..659e23b4d9 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionSignatureUpdatesScript.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionSignatureUpdatesScript.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -47,7 +47,7 @@ public class ApplyClassFunctionSignatureUpdatesScript extends GhidraScript {}RecoveredClassHelper classHelper = new RecoveredClassHelper(currentProgram, state.getTool(),- this, false, false, false, monitor);+ this, false, false, false, true, monitor);if (currentAddress == null) {println("Cursor must be in a class function.");diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.javaindex 9885eb50e1..40722b0f64 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java@@ -123,6 +123,9 @@ public class RecoverClassesFromRTTIScript extends GhidraScript {// bookmark all constructor/destructor functions recognized by scriptprivate static final boolean BOOKMARK_FOUND_FUNCTIONS = true;+ // make vfunctions this calls+ private static final boolean MAKE_VFUNCTIONS_THISCALLS = true;+// show a graph of class hierarchies after script is complete// no parent = blue vertex// single parent = green vertex@@ -193,7 +196,7 @@ public class RecoverClassesFromRTTIScript extends GhidraScript {nameVfunctions = !hasDebugSymbols;recoverClassesFromRTTI = new RTTIWindowsClassRecoverer(currentProgram, state.getTool(),this, BOOKMARK_FOUND_FUNCTIONS, USE_SHORT_TEMPLATE_NAMES_IN_STRUCTURE_FIELDS,- nameVfunctions, hasDebugSymbols, monitor);+ nameVfunctions, MAKE_VFUNCTIONS_THISCALLS, hasDebugSymbols, monitor);}else if (isPE() && isGcc()) {@@ -214,7 +217,7 @@ public class RecoverClassesFromRTTIScript extends GhidraScript {recoverClassesFromRTTI = new RTTIGccClassRecoverer(currentProgram, state.getTool(),this, BOOKMARK_FOUND_FUNCTIONS, USE_SHORT_TEMPLATE_NAMES_IN_STRUCTURE_FIELDS,- nameVfunctions, hasDebugSymbols, monitor);+ nameVfunctions, MAKE_VFUNCTIONS_THISCALLS, hasDebugSymbols, monitor);}else if (isGcc()) {@@ -242,7 +245,7 @@ public class RecoverClassesFromRTTIScript extends GhidraScript {nameVfunctions = !hasDebugSymbols;recoverClassesFromRTTI = new RTTIGccClassRecoverer(currentProgram, state.getTool(),this, BOOKMARK_FOUND_FUNCTIONS, USE_SHORT_TEMPLATE_NAMES_IN_STRUCTURE_FIELDS,- nameVfunctions, hasDebugSymbols, monitor);+ nameVfunctions, MAKE_VFUNCTIONS_THISCALLS, hasDebugSymbols, monitor);}else {println("This script will not work on this program type");diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.javaindex e43cf65d3e..ca938ff1e8 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java@@ -41,10 +41,11 @@ public class RTTIClassRecoverer extends RecoveredClassHelper {RTTIClassRecoverer(Program program, ServiceProvider serviceProvider, FlatProgramAPI api,boolean createBookmarks, boolean useShortTemplates, boolean nameVfunctions,- boolean hasDebugSymbols, TaskMonitor monitor) throws Exception {+ boolean makeVfunctionsThisCalls,boolean hasDebugSymbols, TaskMonitor monitor)+ throws Exception {super(program, serviceProvider, api, createBookmarks, useShortTemplates, nameVfunctions,- monitor);+ makeVfunctionsThisCalls,monitor);this.hasDebugSymbols = hasDebugSymbols;diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.javaindex 632f47c912..555dfec4b0 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java@@ -107,10 +107,11 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer {public RTTIGccClassRecoverer(Program program, ServiceProvider serviceProvider,FlatProgramAPI api, boolean createBookmarks, boolean useShortTemplates,- boolean nameVfunctions, boolean isDwarfLoaded, TaskMonitor monitor) throws Exception {+ boolean nameVfunctions, boolean makeVfunctionsThisCalls, boolean isDwarfLoaded,+ TaskMonitor monitor) throws Exception {super(program, serviceProvider, api, createBookmarks, useShortTemplates, nameVfunctions,- isDwarfLoaded, monitor);+ makeVfunctionsThisCalls,isDwarfLoaded, monitor);this.isDwarfLoaded = isDwarfLoaded;diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.javaindex 247c427aa5..33c3633578 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.java@@ -72,10 +72,11 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer {public RTTIWindowsClassRecoverer(Program program, ServiceProvider serviceProvider,FlatProgramAPI api, boolean createBookmarks, boolean useShortTemplates,- boolean nameVFunctions, boolean isPDBLoaded, TaskMonitor monitor) throws Exception {+ boolean nameVFunctions, boolean makeVfunctionsThisCalls, boolean isPDBLoaded,+ TaskMonitor monitor) throws Exception {super(program, serviceProvider, api, createBookmarks, useShortTemplates, nameVFunctions,- isPDBLoaded, monitor);+ makeVfunctionsThisCalls, isPDBLoaded, monitor);this.isPDBLoaded = isPDBLoaded;}diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.javaindex 4b6a9d907d..1687a77c2a 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java@@ -137,11 +137,14 @@ public class RecoveredClassHelper {protected final boolean createBookmarks;protected final boolean useShortTemplates;protected final boolean nameVfunctions;+ protected final boolean makeVfunctionsThisCalls;+public HashMap<Address, Set<Function>> allVfunctions = new HashMap<>();public RecoveredClassHelper(Program program, ServiceProvider serviceProvider,FlatProgramAPI api, boolean createBookmarks, boolean useShortTemplates,- boolean nameVunctions, TaskMonitor monitor) throws Exception {+ boolean nameVunctions, boolean makeVfunctionsThisCalls, TaskMonitor monitor)+ throws Exception {this.monitor = monitor;this.program = program;@@ -156,6 +159,7 @@ public class RecoveredClassHelper {this.createBookmarks = createBookmarks;this.useShortTemplates = useShortTemplates;this.nameVfunctions = nameVunctions;+ this.makeVfunctionsThisCalls = makeVfunctionsThisCalls;globalNamespace = (GlobalNamespace) program.getGlobalNamespace();@@ -4770,8 +4774,10 @@ public class RecoveredClassHelper {// can't put external functions into a namespace from this programif (!vfunction.isExternal()) {- // if not already, make it a this call- makeFunctionThiscall(vfunction);+ // check script option and if not already, make it a this call+ if (makeVfunctionsThisCalls) {+ makeFunctionThiscall(vfunction);+ }// put symbol on the virtual functionSymbol vfunctionSymbol = vfunction.getSymbol();