mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GP-4812 update vfunctions to use void* this instead of formal signature
This commit is contained in:
parent
7e9a24c6bc
commit
12fcbe63bc
1 changed files with 98 additions and 64 deletions
|
@ -432,9 +432,11 @@ public class RecoveredClassHelper {
|
|||
continue;
|
||||
}
|
||||
Address functionAddress = reference.getFromAddress();
|
||||
Function secondHalfOfFunction = extendedFlatAPI.getReferencedFunction(functionAddress);
|
||||
Function secondHalfOfFunction =
|
||||
extendedFlatAPI.getReferencedFunction(functionAddress);
|
||||
if (secondHalfOfFunction != null) {
|
||||
Map<Address,Function> functionCallMap2 = getFunctionCallMap(secondHalfOfFunction,false);
|
||||
Map<Address, Function> functionCallMap2 =
|
||||
getFunctionCallMap(secondHalfOfFunction, false);
|
||||
for (Address addr : functionCallMap2.keySet()) {
|
||||
monitor.checkCancelled();
|
||||
functionCallMap.put(addr, functionCallMap2.get(addr));
|
||||
|
@ -2264,7 +2266,8 @@ public class RecoveredClassHelper {
|
|||
for (Function calledFunction : calledFunctions) {
|
||||
monitor.checkCancelled();
|
||||
|
||||
if (getAllConstructors().contains(calledFunction) || getAllInlinedConstructors().contains(calledFunction)) {
|
||||
if (getAllConstructors().contains(calledFunction) ||
|
||||
getAllInlinedConstructors().contains(calledFunction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2272,8 +2275,6 @@ public class RecoveredClassHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to determine if the given function calls a known denstructor or inlined destructor
|
||||
* @param Set of called functions
|
||||
|
@ -2286,7 +2287,8 @@ public class RecoveredClassHelper {
|
|||
for (Function calledFunction : calledFunctions) {
|
||||
monitor.checkCancelled();
|
||||
|
||||
if (getAllDestructors().contains(calledFunction) || getAllInlinedDestructors().contains(calledFunction)) {
|
||||
if (getAllDestructors().contains(calledFunction) ||
|
||||
getAllInlinedDestructors().contains(calledFunction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2294,7 +2296,8 @@ public class RecoveredClassHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean callsOwnFunction(RecoveredClass recoveredClass, Set<Function> calledFunctions) throws CancelledException {
|
||||
private boolean callsOwnFunction(RecoveredClass recoveredClass, Set<Function> calledFunctions)
|
||||
throws CancelledException {
|
||||
|
||||
for (Function calledFunction : calledFunctions) {
|
||||
monitor.checkCancelled();
|
||||
|
@ -2306,10 +2309,8 @@ public class RecoveredClassHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
private Set<Function> getCalledFunctions(Function callingFunction) throws CancelledException {
|
||||
|
||||
|
||||
Set<Function> calledFunctions = new HashSet<Function>();
|
||||
|
||||
InstructionIterator instructions = callingFunction.getProgram()
|
||||
|
@ -2571,7 +2572,8 @@ public class RecoveredClassHelper {
|
|||
* @param recoveredClass the given class object
|
||||
* @return true if class has a vbase destructor, false if not
|
||||
*/
|
||||
private boolean hasValidVbaseDestructor(RecoveredClass recoveredClass) throws CancelledException {
|
||||
private boolean hasValidVbaseDestructor(RecoveredClass recoveredClass)
|
||||
throws CancelledException {
|
||||
Function vBaseDestructor = recoveredClass.getVBaseDestructor();
|
||||
|
||||
StringBuffer string = new StringBuffer();
|
||||
|
@ -4453,7 +4455,7 @@ public class RecoveredClassHelper {
|
|||
String nameField = vfunction.getName();
|
||||
|
||||
FunctionDefinition functionDataType =
|
||||
new FunctionDefinitionDataType(vfunction, true);
|
||||
new FunctionDefinitionDataType(vfunction, false);
|
||||
|
||||
if (!vfunction.getName().equals(functionDefName)) {
|
||||
functionDataType.setName(functionDefName);
|
||||
|
@ -4467,24 +4469,38 @@ public class RecoveredClassHelper {
|
|||
|
||||
nameField = DEFAULT_VFUNCTION_PREFIX + vfunctionNumber;
|
||||
|
||||
// get function sig from child class
|
||||
// get function sig from a child class
|
||||
Function childVirtualFunction =
|
||||
getChildVirtualFunction(recoveredClass, vftableAddress, vfunctionNumber);
|
||||
getChildVirtualFunction(recoveredClass, vfunctionNumber);
|
||||
|
||||
// if it is null it will just use the purecall function definition since
|
||||
// it can't find a child one to use to replace it
|
||||
if (childVirtualFunction != null) {
|
||||
functionDataType =
|
||||
new FunctionDefinitionDataType(childVirtualFunction, true);
|
||||
new FunctionDefinitionDataType(childVirtualFunction, false);
|
||||
functionDataType.setReturnType(childVirtualFunction.getReturnType());
|
||||
Symbol childFunctionSymbol =
|
||||
symbolTable.getPrimarySymbol(childVirtualFunction.getEntryPoint());
|
||||
|
||||
// if the child function has a default name, rename the function definition
|
||||
// data type to the "vfunction<vfunctionNumber>" name
|
||||
if (childFunctionSymbol.getSource() == SourceType.DEFAULT) {
|
||||
if (childFunctionSymbol.getSource() != SourceType.DEFAULT) {
|
||||
nameField = childFunctionSymbol.getName();
|
||||
}
|
||||
}
|
||||
functionDataType.setName(nameField);
|
||||
}
|
||||
}
|
||||
comment = recoveredClass.getName() + " pure " + comment;
|
||||
}
|
||||
|
||||
ParameterDefinition[] arguments = functionDataType.getArguments();
|
||||
|
||||
// if the vfunction is a thiscall then replace the classStruct* this with voidPtr
|
||||
// so that it can be used generically for all related members of the class family
|
||||
if (arguments.length > 0 && arguments[0].getName().equals("this")) {
|
||||
VoidDataType voidDT = new VoidDataType();
|
||||
PointerDataType voidPtr = new PointerDataType(voidDT);
|
||||
ParameterDefinition parameterDefinition = arguments[0];
|
||||
parameterDefinition.setDataType(voidPtr);
|
||||
}
|
||||
|
||||
PointerDataType functionPointerDataType =
|
||||
|
@ -4515,9 +4531,12 @@ public class RecoveredClassHelper {
|
|||
* @param recoveredClass the given class
|
||||
* @param virtualFunctionNumber the virtual function offset into the table
|
||||
* @return a child class virtual function at the given offset
|
||||
* @throws CancelledException if cancelled
|
||||
*/
|
||||
private Function getChildVirtualFunction(RecoveredClass recoveredClass, Address vftableAddress,
|
||||
int virtualFunctionNumber) {
|
||||
private Function getChildVirtualFunction(RecoveredClass recoveredClass,
|
||||
int virtualFunctionNumber) throws CancelledException {
|
||||
|
||||
Function nonThisFunction = null;
|
||||
|
||||
List<RecoveredClass> childClasses = recoveredClass.getChildClasses();
|
||||
if (childClasses.isEmpty()) {
|
||||
|
@ -4526,16 +4545,18 @@ public class RecoveredClassHelper {
|
|||
|
||||
// The child functions should all have the same function signature so just get any one of them
|
||||
// if for some reason they don't, still have to pick one and let user decide how to update
|
||||
RecoveredClass childClass = childClasses.get(0);
|
||||
for (RecoveredClass childClass : childClasses) {
|
||||
monitor.checkCancelled();
|
||||
|
||||
List<Address> childVftableAddresses = childClass.getVftableAddresses();
|
||||
if (childVftableAddresses.isEmpty()) {
|
||||
return null;
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the correct child vftable for the given parent class
|
||||
for (Address childVftableAddress : childVftableAddresses) {
|
||||
RecoveredClass parentForVftable = childClass.getVftableBaseClass(childVftableAddress);
|
||||
RecoveredClass parentForVftable =
|
||||
childClass.getVftableBaseClass(childVftableAddress);
|
||||
if (parentForVftable == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -4543,12 +4564,23 @@ public class RecoveredClassHelper {
|
|||
List<Function> childVirtualFunctionsForGivenParent =
|
||||
childClass.getVirtualFunctions(childVftableAddress);
|
||||
if (childVirtualFunctionsForGivenParent.size() < virtualFunctionNumber) {
|
||||
return null;
|
||||
continue;
|
||||
}
|
||||
return childVirtualFunctionsForGivenParent.get(virtualFunctionNumber - 1);
|
||||
Function vfunction =
|
||||
childVirtualFunctionsForGivenParent.get(virtualFunctionNumber - 1);
|
||||
Parameter[] parameters = vfunction.getParameters();
|
||||
if (parameters.length == 0) {
|
||||
continue;
|
||||
}
|
||||
if (parameters[0].getName().equals("this")) {
|
||||
return vfunction;
|
||||
}
|
||||
|
||||
nonThisFunction = vfunction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return nonThisFunction; //or null if no vfunctions at all which should never happen
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5436,11 +5468,13 @@ public class RecoveredClassHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean callsOwnConstructorOrDestructor(RecoveredClass recoveredClass, Function function) throws CancelledException {
|
||||
private boolean callsOwnConstructorOrDestructor(RecoveredClass recoveredClass,
|
||||
Function function) throws CancelledException {
|
||||
|
||||
Set<Function> calledFunctions = getCalledFunctions(function);
|
||||
|
||||
List<Function> constructorOrDestructorFunctions = recoveredClass.getConstructorOrDestructorFunctions();
|
||||
List<Function> constructorOrDestructorFunctions =
|
||||
recoveredClass.getConstructorOrDestructorFunctions();
|
||||
for (Function cdFunction : constructorOrDestructorFunctions) {
|
||||
monitor.checkCancelled();
|
||||
|
||||
|
@ -7622,7 +7656,7 @@ public class RecoveredClassHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
FunctionSignature listingFunctionSignature = vfunction.getSignature(true);
|
||||
FunctionSignature listingFunctionSignature = vfunction.getSignature(false);
|
||||
|
||||
FunctionDefinition componentFunctionDefinition =
|
||||
getComponentFunctionDefinition(structureComponent);
|
||||
|
@ -8195,7 +8229,7 @@ public class RecoveredClassHelper {
|
|||
vfunction = vfunction.getThunkedFunction(true);
|
||||
}
|
||||
|
||||
FunctionSignature listingFunctionSignature = vfunction.getSignature(true);
|
||||
FunctionSignature listingFunctionSignature = vfunction.getSignature(false);
|
||||
|
||||
if (listingFunctionSignature.getName().contains("purecall")) {
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue