mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-1660 updated ApplyFunctionDef script to get selected func defs from
dtman.
This commit is contained in:
parent
9c04807c8c
commit
b026a5f53a
1 changed files with 26 additions and 26 deletions
|
@ -33,11 +33,9 @@ import java.util.List;
|
||||||
|
|
||||||
import classrecovery.RecoveredClassHelper;
|
import classrecovery.RecoveredClassHelper;
|
||||||
import ghidra.app.script.GhidraScript;
|
import ghidra.app.script.GhidraScript;
|
||||||
import ghidra.program.model.data.FunctionDefinition;
|
import ghidra.app.services.DataTypeManagerService;
|
||||||
import ghidra.program.model.data.Structure;
|
import ghidra.program.model.data.*;
|
||||||
import ghidra.program.model.listing.Function;
|
import ghidra.program.model.listing.Function;
|
||||||
import ghidra.program.model.symbol.Namespace;
|
|
||||||
import ghidra.program.model.symbol.Symbol;
|
|
||||||
|
|
||||||
public class ApplyClassFunctionDefinitionUpdatesScript extends GhidraScript {
|
public class ApplyClassFunctionDefinitionUpdatesScript extends GhidraScript {
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,28 +49,35 @@ public class ApplyClassFunctionDefinitionUpdatesScript extends GhidraScript {
|
||||||
RecoveredClassHelper classHelper = new RecoveredClassHelper(currentProgram, currentLocation,
|
RecoveredClassHelper classHelper = new RecoveredClassHelper(currentProgram, currentLocation,
|
||||||
state.getTool(), this, false, false, false, false, monitor);
|
state.getTool(), this, false, false, false, false, monitor);
|
||||||
|
|
||||||
Namespace classNamespace = classHelper.getClassNamespace(currentAddress);
|
DataTypeManagerService dtms = state.getTool().getService(DataTypeManagerService.class);
|
||||||
if (classNamespace == null) {
|
List<DataType> selectedDatatypes = dtms.getSelectedDatatypes();
|
||||||
println(
|
if (selectedDatatypes.size() == 0) {
|
||||||
"Either cannot retrieve class namespace or cursor is not in a member of a class namepace");
|
println("Please select the class function definition(s) you wish to apply.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Symbol> classVftableSymbols = classHelper.getClassVftableSymbols(classNamespace);
|
List<FunctionDefinition> classFunctionDefinitions = new ArrayList<FunctionDefinition>();
|
||||||
if (classVftableSymbols.isEmpty()) {
|
for (DataType selectedDataType : selectedDatatypes) {
|
||||||
println("There are no vftables in this class");
|
monitor.checkCanceled();
|
||||||
return;
|
|
||||||
|
if (!(selectedDataType instanceof FunctionDefinition)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
println(
|
FunctionDefinition functionDefinition = (FunctionDefinition) selectedDataType;
|
||||||
"Applying differing function definitions for class " + classNamespace.getName(true));
|
String pathName = functionDefinition.getPathName();
|
||||||
|
if (!pathName.contains("ClassDataTypes")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
classFunctionDefinitions.add(functionDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
List<FunctionDefinition> classFunctionDefinitions =
|
|
||||||
classHelper.getClassFunctionDefinitions(classNamespace);
|
|
||||||
if (classFunctionDefinitions.isEmpty()) {
|
if (classFunctionDefinitions.isEmpty()) {
|
||||||
println("Class " + classNamespace.getName() + " has no function definitions to apply.");
|
println(
|
||||||
|
"Selected function definition(s) must be in a subfolder of the ClassDataTypes folder in the DataTypeManager.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Object> changedItems = new ArrayList<Object>();
|
List<Object> changedItems = new ArrayList<Object>();
|
||||||
|
|
||||||
for (FunctionDefinition functionDef : classFunctionDefinitions) {
|
for (FunctionDefinition functionDef : classFunctionDefinitions) {
|
||||||
|
@ -84,14 +89,9 @@ public class ApplyClassFunctionDefinitionUpdatesScript extends GhidraScript {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedItems == null) {
|
if (changedItems == null || changedItems.isEmpty()) {
|
||||||
println("Class " + classNamespace.getName() + " has no function definitions to apply.");
|
println(
|
||||||
return;
|
"There were no differences between the selected function definitions and the items that could be updated.");
|
||||||
}
|
|
||||||
|
|
||||||
if (changedItems.isEmpty()) {
|
|
||||||
println("No differences found for class " + classNamespace.getName(true) +
|
|
||||||
" between its function definition data types and the associated function signatures in the listing.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue