GP-1996 - code refactor to make op new and delete discovery more generic.

This commit is contained in:
ghidra007 2022-05-26 22:12:07 +00:00
parent 864321a060
commit d8396e7592
5 changed files with 458 additions and 438 deletions

View File

@ -1,72 +0,0 @@
/* ###
* IP: GHIDRA
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Developer script to generate test data. Not for general use.
//@category TestScripts
import java.util.*;
import classrecovery.*;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*;
public class FindOperatorDeletesAndNewsScript extends GhidraScript {
@Override
public void run() throws Exception {
if (currentProgram == null) {
println("There is no open program");
return;
}
RecoveredClassHelper classHelper = new RecoveredClassHelper(currentProgram, currentLocation,
state.getTool(), this, false, false, false, monitor);
List<Address> discoveredOperatorDeletes =
getFunctionAddressList(classHelper.findOperatorDeletes());
BookmarkManager bookmarkMgr = currentProgram.getBookmarkManager();
for (Address operatorDelete : discoveredOperatorDeletes) {
monitor.checkCanceled();
bookmarkMgr.setBookmark(operatorDelete, BookmarkType.NOTE, "TEST",
"Found operator_delete");
}
List<Address> discoveredOperatorNews =
getFunctionAddressList(classHelper.findOperatorNews());
for (Address operatorNew : discoveredOperatorNews) {
monitor.checkCanceled();
bookmarkMgr.setBookmark(operatorNew, BookmarkType.NOTE, "TEST", "Found operator_new");
}
}
private List<Address> getFunctionAddressList(Set<Function> functions) {
List<Address> addresses = new ArrayList<Address>();
for (Function function : functions) {
addresses.add(function.getEntryPoint());
}
return addresses;
}
}

View File

@ -847,28 +847,6 @@ public class ExtendedFlatProgramAPI extends FlatProgramAPI {
return pdt;
}
/**
* Method to retrieve the minimum address on the given list
* @param list the list of addresses
* @return the minimum address on the given list
*/
public Address getMinimumAddressOnList(List<Address> list) {
Collections.sort(list);
return list.get(0);
}
/**
* Method to retrieve the maximum address on the given list
* @param list the list of addresses
* @return the maximum address on the given list
*/
public Address getMaximumAddressOnList(List<Address> list) {
Collections.sort(list, Collections.reverseOrder());
return list.get(0);
}
/**
* Method to retrieve the referenced Functions from the given referenceToClassMap
* @param referenceToClassMap map of addresses that contain a reference to either a vftable or

View File

@ -117,8 +117,6 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer {
return recoveredClasses;
}
createCalledFunctionMap(recoveredClasses);
createClassHierarchyListAndMapForGcc();
if (isDwarfLoaded) {
@ -1849,12 +1847,6 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer {
private void processConstructorAndDestructors()
throws CancelledException, InvalidInputException, DuplicateNameException, Exception {
// find deleting destructors using various mechanisms
// findDeletingDestructors(recoveredClasses);
// use atexit param list to find more destructors
// findDestructorsUsingAtexitCalledFunctions(recoveredClasses);
// figure out which are inlined and put on separate list to be processed later
separateInlinedConstructorDestructors(recoveredClasses);

View File

@ -131,14 +131,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer {
return recoveredClasses;
}
//TODO: decide whether to update to only include possible cds not all functions that
// have ref to vftable
// if decide to be more restrictive then need to move the method that weeds out inlines and
// from the class cd lists
createCalledFunctionMap(recoveredClasses);
// figure out class hierarchies using either RTTI or vftable refs
monitor.setMessage("Assigning class inheritance and hierarchies");
assignClassInheritanceAndHierarchies(recoveredClasses);
@ -1283,11 +1276,16 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer {
private void processConstructorAndDestructors(List<RecoveredClass> recoveredClasses)
throws CancelledException, InvalidInputException, DuplicateNameException, Exception {
// update the global lists and class lists to narrow the cd lists
trimConstructorDestructorLists(recoveredClasses);
List<Address> allVftables = getAllVftables();
// update the class lists to narrow the class objects possible cd lists and indeterminate
// lists to remove functions that are also on vfunction lists
trimConstructorDestructorLists(recoveredClasses, allVftables);
determineOperatorDeleteAndNewFunctions(allVftables);
// find deleting destructors
findDeletingDestructors(recoveredClasses);
findDeletingDestructors(recoveredClasses, allVftables);
// use atexit param list to find more destructors
findDestructorsUsingAtexitCalledFunctions(recoveredClasses);