diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java index b1be3d4172..fa5e7774f6 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java @@ -179,8 +179,6 @@ public class RecoverClassesFromRTTIScript extends GhidraScript { RTTIClassRecoverer recoverClassesFromRTTI; - ExtraScriptUtils extraUtils; - boolean nameVfunctions = false; @Override diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/EditStructureUtils.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/EditStructureUtils.java index 79b8cb7a57..26e380621d 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/EditStructureUtils.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/EditStructureUtils.java @@ -22,9 +22,9 @@ import ghidra.program.model.data.*; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; -public class EditStructureUtils { +class EditStructureUtils { - EditStructureUtils() { + private EditStructureUtils() { } @@ -42,7 +42,7 @@ public class EditStructureUtils { * internal struct, false otherwise * @throws CancelledException if cancelled */ - public boolean hasReplaceableComponentsAtOffset(Structure containingStruct, int offset, + static boolean hasReplaceableComponentsAtOffset(Structure containingStruct, int offset, Structure newInternalStruct, TaskMonitor monitor) throws CancelledException { DataTypeComponent[] newStructComponents = newInternalStruct.getComponents(); @@ -95,7 +95,7 @@ public class EditStructureUtils { * @return true if there are at least length undefined size 1 components at the given offset in the given structure * @throws CancelledException if cancelled */ - public boolean hasEnoughUndefined1sAtOffset(Structure structure, int offset, int length, + static boolean hasEnoughUndefined1sAtOffset(Structure structure, int offset, int length, TaskMonitor monitor) throws CancelledException { if (structure.getLength() < offset + length) { @@ -128,7 +128,7 @@ public class EditStructureUtils { * @return true if successfully cleared from offset to offset+length, false otherwise * @throws CancelledException if cancelled */ - public boolean clearLengthAtOffset(Structure structure, int offset, int length, + static boolean clearLengthAtOffset(Structure structure, int offset, int length, TaskMonitor monitor) throws CancelledException { if (structure.getLength() < offset + length) { @@ -143,17 +143,10 @@ public class EditStructureUtils { monitor.checkCanceled(); - DataTypeComponent component = structure.getComponentAt(offset); - DataType dataType = component.getDataType(); + DataTypeComponent component = structure.getComponentContaining(offset); - // return false if it would clear too much - if (offset + dataType.getLength() > endOfClear) { - return false; - } - - offsetsToClear.add(offset); - offset += dataType.getLength(); - continue; + offsetsToClear.add(component.getOffset()); + offset = component.getOffset() + component.getLength(); } @@ -178,11 +171,12 @@ public class EditStructureUtils { * @param dataType the given data type * @return true if given data type is undefined size 1, false otherwise */ - public boolean isUndefined1(DataType dataType) { + static boolean isUndefined1(DataType dataType) { - if (isUndefined(dataType) && dataType.getLength() == 1) { + if (Undefined.isUndefined(dataType) && dataType.getLength() == 1) { return true; } + return false; } @@ -191,7 +185,7 @@ public class EditStructureUtils { * @param dataType the given data type * @return true if given data type is undefined of any size, false otherwise */ - public boolean isUndefined(DataType dataType) { + static boolean isUndefined(DataType dataType) { if (dataType.getName().contains("undefined")) { return true; } @@ -199,41 +193,46 @@ public class EditStructureUtils { } /** - * Method to determine if there are at least the given length of undefined (any size) components at the given offset in the given structure + * Method to determine if there are at least the given length of undefined (any size) components + * at the given offset in the given structure. This is only valid for non-packed structures. * @param structure the given structure * @param offset the given offset * @param length the total length of undefined components to check for starting at given offset * @param monitor task monitor * @return true if there are at least total length of undefined components at the given offset in the given structure * @throws CancelledException if cancelled + * @throws IllegalArgumentException if a packed structure is passed in */ - public boolean hasEnoughUndefinedsOfAnyLengthAtOffset(Structure structure, int offset, + static boolean hasEnoughUndefinedsOfAnyLengthAtOffset(Structure structure, int offset, int length, TaskMonitor monitor) throws CancelledException { - if (structure.getLength() < offset + length) { - return false; + if (structure.isPackingEnabled()) { + throw new IllegalArgumentException( + "Packed structures are not supported by this method"); } int endOfRange = offset + length; + if (offset < 0 || length <= 0 || structure.getLength() < endOfRange) { + return false; + } + while (offset < endOfRange) { monitor.checkCanceled(); - DataTypeComponent component = structure.getComponentAt(offset); + DataTypeComponent component = structure.getComponentContaining(offset); + DataType dataType = component.getDataType(); - if (isUndefined(dataType)) { - - offset += dataType.getLength(); - if (offset > endOfRange) { - return false; - } - - continue; + if (!Undefined.isUndefined(dataType)) { + return false; } - return false; + + offset = component.getOffset() + component.getLength(); + } + return true; } @@ -251,7 +250,7 @@ public class EditStructureUtils { * @throws IllegalArgumentException if issue inserting data type into structure * @throws CancelledException if cancelled */ - public Structure addDataTypeToStructure(Structure structure, int offset, + static Structure addDataTypeToStructure(Structure structure, int offset, DataType dataType, String fieldName, TaskMonitor monitor) throws CancelledException, IllegalArgumentException { @@ -292,7 +291,7 @@ public class EditStructureUtils { * @return true if the given structure has room at the given offset to have a component of the given length added to it * @throws CancelledException if cancelled */ - public boolean canAdd(Structure structureDataType, int offset, int lengthToAdd, + static boolean canAdd(Structure structureDataType, int offset, int lengthToAdd, TaskMonitor monitor) throws CancelledException { @@ -332,7 +331,7 @@ public class EditStructureUtils { * @return the number of undefined size 1 components in the given structure before the given offset * @throws CancelledException if cancelled */ - public int getNumberOfUndefinedsBeforeOffset(Structure structure, int offset, + static int getNumberOfUndefinedsBeforeOffset(Structure structure, int offset, TaskMonitor monitor) throws CancelledException { if (structure.getNumComponents() == 0) { @@ -364,7 +363,7 @@ public class EditStructureUtils { * @return the number of undefined size 1 components starting at the given offset in the given structure * @throws CancelledException if cancelled */ - public int getNumberOfUndefinedsStartingAtOffset(Structure structure, int offset, + static int getNumberOfUndefinedsStartingAtOffset(Structure structure, int offset, TaskMonitor monitor) throws CancelledException { int numUndefineds = 0; diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtraScriptUtils.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtendedFlatProgramAPI.java similarity index 96% rename from Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtraScriptUtils.java rename to Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtendedFlatProgramAPI.java index 9f2e10ff17..c2791db137 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtraScriptUtils.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/ExtendedFlatProgramAPI.java @@ -34,19 +34,13 @@ import ghidra.program.model.symbol.*; import ghidra.util.exception.*; import ghidra.util.task.TaskMonitor; -public class ExtraScriptUtils extends FlatProgramAPI { +public class ExtendedFlatProgramAPI extends FlatProgramAPI { - Program program; - TaskMonitor taskMonitor; - int defaultPointerSize; + final int defaultPointerSize; - ExtraScriptUtils(Program program, TaskMonitor taskMonitor) { - this.program = program; - this.taskMonitor = taskMonitor; - - currentProgram = program; - monitor = taskMonitor; + ExtendedFlatProgramAPI(Program program, TaskMonitor taskMonitor) { + super(program, taskMonitor); defaultPointerSize = program.getDefaultPointerSize(); } @@ -66,7 +60,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { int numComponents = data.getNumComponents(); for (int ii = 0; ii < numComponents; ++ii) { - taskMonitor.checkCanceled(); + monitor.checkCanceled(); Data component = data.getComponent(ii); if (!component.isPointer()) { @@ -125,7 +119,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { } // check for or create function pointer if valid function pointed to - Data data = program.getListing().getDefinedDataAt(address); + Data data = currentProgram.getListing().getDefinedDataAt(address); if (data != null) { if (data.isPointer() && getPointedToFunction(address) != null) { return true; @@ -143,10 +137,12 @@ public class ExtraScriptUtils extends FlatProgramAPI { clearListing(address); return false; } + catch (CancelledException e) { + throw e; + } catch (Exception e) { return false; } - } return false; @@ -165,8 +161,8 @@ public class ExtraScriptUtils extends FlatProgramAPI { return false; } - DataType nullPointer = program.getDataTypeManager().getPointer(null); - Listing listing = program.getListing(); + DataType nullPointer = currentProgram.getDataTypeManager().getPointer(null); + Listing listing = currentProgram.getListing(); Data d = listing.getDefinedDataAt(address); if (d == null) { try { @@ -316,7 +312,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { */ public Function createFunctionBefore(Address address, Byte expectedFiller) { - PseudoDisassembler pseudoDisassembler = new PseudoDisassembler(program); + PseudoDisassembler pseudoDisassembler = new PseudoDisassembler(currentProgram); Instruction instructionBefore = getInstructionBefore(address); @@ -419,7 +415,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { public int getNumberOfSameFillerBytesStartingAtAddress(Address firstAddress) throws CancelledException, MemoryAccessException { - AddressSetView validMemory = program.getMemory().getLoadedAndInitializedAddressSet(); + AddressSetView validMemory = currentProgram.getMemory().getLoadedAndInitializedAddressSet(); if (firstAddress == null) { return 0; @@ -511,6 +507,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { return false; } catch (CancelledException e) { + // FIXME: this should not be caught by this method and should propogate return false; } @@ -526,10 +523,12 @@ public class ExtraScriptUtils extends FlatProgramAPI { public AddressSet getSubroutineAddresses(Program program, Address address) throws CancelledException { + // FIXME: Should not be passing program arg + // Create a new address set to hold the entire selection. AddressSet subroutineAddresses = new AddressSet(); - IsolatedEntrySubModel model = new IsolatedEntrySubModel(program); + IsolatedEntrySubModel model = new IsolatedEntrySubModel(currentProgram); CodeBlock[] codeBlocksContaining = model.getCodeBlocksContaining(address, monitor); for (CodeBlock element : codeBlocksContaining) { @@ -556,6 +555,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { return; } + // FIXME: if you pass a Function arg you should use its program not currentProgram ReturnParameterImpl returnType = new ReturnParameterImpl(function.getSignature().getReturnType(), currentProgram); @@ -607,7 +607,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { int addressSize = address.getSize(); if (addressSize == 64 && getIboIf64bit) { ImageBaseOffset32DataType ibo32 = - new ImageBaseOffset32DataType(program.getDataTypeManager()); + new ImageBaseOffset32DataType(currentProgram.getDataTypeManager()); int length = ibo32.getLength(); DumbMemBufferImpl compMemBuffer = new DumbMemBufferImpl(currentProgram.getMemory(), address); @@ -654,7 +654,8 @@ public class ExtraScriptUtils extends FlatProgramAPI { List symbolList = new ArrayList(); - SymbolIterator symbols = program.getSymbolTable().getSymbols(namespace); + // FIXME: if you are going to pass namespace arg you should use its program not currentProgram + SymbolIterator symbols = currentProgram.getSymbolTable().getSymbols(namespace); while (symbols.hasNext()) { monitor.checkCanceled(); @@ -764,8 +765,9 @@ public class ExtraScriptUtils extends FlatProgramAPI { List
referenceAddresses = new ArrayList
(); + // FIXME: if you pass a function arg you should use its program, not currentProgram ReferenceIterator referencesToFunctionBIterator = - program.getReferenceManager().getReferencesTo(bFunction.getEntryPoint()); + currentProgram.getReferenceManager().getReferencesTo(bFunction.getEntryPoint()); while (referencesToFunctionBIterator.hasNext()) { @@ -995,7 +997,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { */ public void removeAllSymbolsAtAddress(Address address) throws CancelledException { - SymbolTable symbolTable = program.getSymbolTable(); + SymbolTable symbolTable = currentProgram.getSymbolTable(); Symbol primarySymbol = symbolTable.getPrimarySymbol(address); @@ -1031,7 +1033,8 @@ public class ExtraScriptUtils extends FlatProgramAPI { */ public boolean hasSymbolsInNamespace(Namespace namespace) { - SymbolIterator namespaceSymbols = program.getSymbolTable().getSymbols(namespace); + // FIXME: if you are going to use a Namespace arg you should its program not currentProgram + SymbolIterator namespaceSymbols = currentProgram.getSymbolTable().getSymbols(namespace); if (namespaceSymbols.hasNext()) { return true; @@ -1047,8 +1050,7 @@ public class ExtraScriptUtils extends FlatProgramAPI { * @return CategoryPath for new categoryName * @throws CancelledException if cancelled */ - public CategoryPath createDataTypeCategoryPath(CategoryPath parent, String categoryName) - throws CancelledException { + public CategoryPath createDataTypeCategoryPath(CategoryPath parent, String categoryName) throws CancelledException { CategoryPath dataTypePath; @@ -1072,7 +1074,6 @@ public class ExtraScriptUtils extends FlatProgramAPI { int index = 0; String newCategoryName = new String(); while (index < categoryName.length()) { - monitor.checkCanceled(); if (categoryName.substring(index).startsWith("::") && !insideBrackets) { diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java index 4916548b85..6b4c6f963f 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java @@ -154,7 +154,7 @@ public class RTTIClassRecoverer extends RecoveredClassUtils { // if class is non-virtual have to search for an existing class datatype if (!recoveredClass.hasVftable()) { DataType[] possibleExistingClassStructures = - extraUtils.getDataTypes(recoveredClass.getName()); + extendedFlatAPI.getDataTypes(recoveredClass.getName()); if (possibleExistingClassStructures.length == 0) { continue; } diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java index 445a67e0a6..b9405909ab 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java @@ -241,7 +241,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { recoveredClasses = recoverClassesFromVftables(vftableSymbols, true, true); // find all typeinfo symbols and get their class namespace and create RecoveredClass object - List typeinfoSymbols = extraUtils.getListOfSymbolsInAddressSet( + List typeinfoSymbols = extendedFlatAPI.getListOfSymbolsInAddressSet( program.getAddressFactory().getAddressSet(), "typeinfo", true); // create class objects for each typeinfo struct and make a class to typeinfo mapping for each @@ -312,7 +312,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { } } - Address specialTypeinfoRef = extraUtils.getSingleReferencedAddress(typeinfoAddress); + Address specialTypeinfoRef = extendedFlatAPI.getSingleReferencedAddress(typeinfoAddress); if (specialTypeinfoRef == null) { if (DEBUG) { Msg.debug(this, @@ -441,7 +441,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { listOfVtableSymbols = findVtablesUsingTypeinfoRefs(); } else { - listOfVtableSymbols = extraUtils.getListOfSymbolsInAddressSet( + listOfVtableSymbols = extendedFlatAPI.getListOfSymbolsInAddressSet( program.getAddressFactory().getAddressSet(), VTABLE_LABEL, false); } @@ -484,7 +484,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { for (Address typeinfoRef : typeinfoReferencesNotInTypeinfoStructs) { monitor.checkCanceled(); - Address typeinfoAddress = extraUtils.getPointer(typeinfoRef); + Address typeinfoAddress = extendedFlatAPI.getPointer(typeinfoRef); if (typeinfoAddress == null) { continue; @@ -546,7 +546,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { // check for appropriately sized long that is value 0 to make sure the // vtable the typeinfo ref is in is the main one and skip otherwise since non-zero // ones are internal vtables that will get processed with the main one - if (!extraUtils.hasNumZeros(longBeforeTypeinfoRef, defaultPointerSize)) { + if (!extendedFlatAPI.hasNumZeros(longBeforeTypeinfoRef, defaultPointerSize)) { return null; } @@ -573,7 +573,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { private Address getPointerToDefinedMemory(Address address) { - Address pointer = extraUtils.getPointer(address); + Address pointer = extendedFlatAPI.getPointer(address); if (pointer == null) { return null; } @@ -909,7 +909,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { private Symbol getVTTBefore(Address address) throws CancelledException { // get all symbols named VTT and get the one directly before the given address - List vttSymbols = extraUtils.getListOfSymbolsInAddressSet( + List vttSymbols = extendedFlatAPI.getListOfSymbolsInAddressSet( program.getAddressFactory().getAddressSet(), "VTT", true); return getSymbolOnListBeforeAddress(address, vttSymbols); @@ -1127,7 +1127,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { return false; } - Reference[] referencesTo = extraUtils.getReferencesTo(address); + Reference[] referencesTo = extendedFlatAPI.getReferencesTo(address); if (referencesTo.length > 0) { return false; } @@ -1156,7 +1156,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { return false; } - List
referenceFromAddresses = extraUtils.getReferenceFromAddresses(address); + List
referenceFromAddresses = extendedFlatAPI.getReferenceFromAddresses(address); if (referenceFromAddresses.size() > 0) { return false; @@ -1221,7 +1221,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { return false; } - if (extraUtils.hasNumZeros(vftableAddress, defaultPointerSize)) { + if (extendedFlatAPI.hasNumZeros(vftableAddress, defaultPointerSize)) { return true; } @@ -1230,7 +1230,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { if (!data.isPointer()) { return false; } - Address referencedAddress = extraUtils.getSingleReferencedAddress(vftableAddress); + Address referencedAddress = extendedFlatAPI.getSingleReferencedAddress(vftableAddress); if (referencedAddress == null) { return false; } @@ -1314,7 +1314,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { // create a pointer and check to see if it is a reference to a valid memory location try { api.createData(address, pointer); - Address referencedAddress = extraUtils.getSingleReferencedAddress(address); + Address referencedAddress = extendedFlatAPI.getSingleReferencedAddress(address); // if it isn't a valid pointer, clear what we just created and increment to offset so // the next can be checked @@ -1372,7 +1372,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { for (Address typeinfoAddress : typeinfoAddresses) { - Address specialTypeinfoRef = extraUtils.getSingleReferencedAddress(typeinfoAddress); + Address specialTypeinfoRef = extendedFlatAPI.getSingleReferencedAddress(typeinfoAddress); if (specialTypeinfoRef == null) { continue; } @@ -1583,7 +1583,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { } Address stringReference = - extraUtils.getSingleReferencedAddress(address.add(typeinfoNameComponent.getOffset())); + extendedFlatAPI.getSingleReferencedAddress(address.add(typeinfoNameComponent.getOffset())); Data stringData = api.getDataAt(stringReference); if (stringData == null) { @@ -1610,7 +1610,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { List
typeinfoAddresses = new ArrayList
(); - List typeinfoSymbols = extraUtils.getListOfSymbolsInAddressSet( + List typeinfoSymbols = extendedFlatAPI.getListOfSymbolsInAddressSet( program.getAddressFactory().getAddressSet(), "typeinfo", true); Iterator typeinfoIterator = typeinfoSymbols.iterator(); @@ -2102,7 +2102,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { */ private RecoveredClass getParentClassFromParentTypeInfoRef(Address parentTypeinfoRef) { - Address parentAddress = extraUtils.getSingleReferencedAddress(parentTypeinfoRef); + Address parentAddress = extendedFlatAPI.getSingleReferencedAddress(parentTypeinfoRef); if (parentAddress == null) { return null; } @@ -2191,7 +2191,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { int offset = 0; - Address address = extraUtils.getAddress(startAddress, offset); + Address address = extendedFlatAPI.getAddress(startAddress, offset); MemoryBlock currentMemoryBlock = program.getMemory().getBlock(startAddress); @@ -2205,10 +2205,10 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { return null; } - Address possibleTypeinfo = extraUtils.getPointer(address); + Address possibleTypeinfo = extendedFlatAPI.getPointer(address); if (possibleTypeinfo == null) { offset += defaultPointerSize; - address = extraUtils.getAddress(startAddress, offset); + address = extendedFlatAPI.getAddress(startAddress, offset); continue; } @@ -2218,7 +2218,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { return address; } offset += defaultPointerSize; - address = extraUtils.getAddress(startAddress, offset); + address = extendedFlatAPI.getAddress(startAddress, offset); } @@ -2235,7 +2235,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { List vftableSymbols = new ArrayList(); // find all vtable symbols - List listOfVtableSymbols = extraUtils.getListOfSymbolsInAddressSet( + List listOfVtableSymbols = extendedFlatAPI.getListOfSymbolsInAddressSet( program.getAddressFactory().getAddressSet(), VTABLE_LABEL, true); Iterator vtableIterator = listOfVtableSymbols.iterator(); @@ -2269,7 +2269,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { continue; } - Address vftableAddress = extraUtils.getAddress(typeinfoAddress, defaultPointerSize); + Address vftableAddress = extendedFlatAPI.getAddress(typeinfoAddress, defaultPointerSize); // no valid address here so continue if (vftableAddress == null) { //createNewClass(vtableNamespace, false); @@ -2350,7 +2350,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { recoveredClasses.add(recoveredClass); } - Address specialTypeinfoRef = extraUtils.getSingleReferencedAddress(typeinfoAddress); + Address specialTypeinfoRef = extendedFlatAPI.getSingleReferencedAddress(typeinfoAddress); if (specialTypeinfoRef == null) { if (DEBUG) { Msg.debug(this, @@ -2652,7 +2652,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { * @return true if the given address could be a valid null pointer, false if not */ private boolean isPossibleNullPointer(Address address) throws CancelledException { - if (!extraUtils.hasNumZeros(address, defaultPointerSize)) { + if (!extendedFlatAPI.hasNumZeros(address, defaultPointerSize)) { return false; } return true; @@ -2665,7 +2665,7 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { */ private boolean isPossibleFunctionPointer(Address address) { - Address possibleFunctionPointer = extraUtils.getPointer(address); + Address possibleFunctionPointer = extendedFlatAPI.getPointer(address); if (possibleFunctionPointer == null) { return false; } @@ -2857,9 +2857,11 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { DataType classVftablePointer = vfPointerDataTypes.get(vftableAddress); // simple case the offset for vftablePtr is 0 - if (structUtils.canAdd(classStructureDataType, 0, classVftablePointer.getLength(), + if (EditStructureUtils.canAdd(classStructureDataType, 0, + classVftablePointer.getLength(), monitor)) { - classStructureDataType = structUtils.addDataTypeToStructure(classStructureDataType, + classStructureDataType = + EditStructureUtils.addDataTypeToStructure(classStructureDataType, 0, classVftablePointer, CLASS_VTABLE_PTR_FIELD_EXT, monitor); } @@ -2903,10 +2905,11 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { " : structure should exist but doesn't."); } - if (structUtils.canAdd(classStructureDataType, parentOffset, + if (EditStructureUtils.canAdd(classStructureDataType, parentOffset, baseClassStructure.getLength(), monitor)) { classStructureDataType = - structUtils.addDataTypeToStructure(classStructureDataType, parentOffset, + EditStructureUtils.addDataTypeToStructure(classStructureDataType, + parentOffset, baseClassStructure, baseClassStructure.getName(), monitor); } } @@ -2917,7 +2920,8 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { int dataOffset = getDataOffset(recoveredClass, classStructureDataType); int dataLen = UNKNOWN; if (dataOffset != NONE) { - dataLen = structUtils.getNumberOfUndefinedsStartingAtOffset(classStructureDataType, + dataLen = + EditStructureUtils.getNumberOfUndefinedsStartingAtOffset(classStructureDataType, dataOffset, monitor); } @@ -2927,7 +2931,8 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer { classStructureDataType, dataLen, dataOffset); if (recoveredClassDataStruct != null) { - classStructureDataType = structUtils.addDataTypeToStructure(classStructureDataType, + classStructureDataType = EditStructureUtils.addDataTypeToStructure( + classStructureDataType, dataOffset, recoveredClassDataStruct, "data", monitor); } diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.java index 86e25347e8..7644501cff 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIWindowsClassRecoverer.java @@ -176,7 +176,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { figureOutClassDataMembers(recoveredClasses); if (USE_SHORT_TEMPLATE_NAMES_IN_STRUCTURE_FIELDS) { - extraUtils.createShortenedTemplateNamesForClasses(recoveredClasses); + extendedFlatAPI.createShortenedTemplateNamesForClasses(recoveredClasses); } createAndApplyClassStructures(recoveredClasses); @@ -313,7 +313,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { continue; } - Data data = extraUtils.getDataAt(symbol.getAddress()); + Data data = extendedFlatAPI.getDataAt(symbol.getAddress()); if (data != null && data.getDataType().getName().contains(RTTI_BASE_COMPLETE_OBJECT_LOADER_DATA_NAME)) { completeObjectLocatorSymbols.add(symbol); @@ -352,7 +352,8 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { int sizeOfDt = completeObjLocatorDataType.getLength(); api.clearListing(address, address.add(sizeOfDt)); - Data completeObjectLocator = extraUtils.createData(address, completeObjLocatorDataType); + Data completeObjectLocator = + extendedFlatAPI.createData(address, completeObjLocatorDataType); if (completeObjectLocator == null) { return null; } @@ -379,7 +380,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { continue; } - Data data = extraUtils.getDataAt(symbol.getAddress()); + Data data = extendedFlatAPI.getDataAt(symbol.getAddress()); if (data != null && data.getDataType().getName().contains(RTTI_BASE_CLASS_DESCRIPTOR_DATA_NAME)) { baseClassDescriptorSymbols.add(symbol); @@ -417,7 +418,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { api.clearListing(baseClassDescriptorAddress, baseClassDescriptorAddress.add(sizeOfDt)); Data baseClassDescArray = - extraUtils.createData(baseClassDescriptorAddress, baseClassDescriptor); + extendedFlatAPI.createData(baseClassDescriptorAddress, baseClassDescriptor); if (baseClassDescArray == null) { return null; } @@ -441,19 +442,19 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { for (int i = 0; i < numBaseClasses; i++) { monitor.checkCanceled(); - //TODO: extraUtils.getReferencedAddress(address, getIboIf64bit); + //TODO: extendedFlatAPI.getReferencedAddress(address, getIboIf64bit); Address baseClassDescriptorAddress = getReferencedAddress(address.add(i * 4)); - Data baseClassDescriptor = extraUtils.getDataAt(baseClassDescriptorAddress); + Data baseClassDescriptor = extendedFlatAPI.getDataAt(baseClassDescriptorAddress); if (baseClassDescriptor == null || !baseClassDescriptor.getDataType() .getName() .equals( RTTI_BASE_CLASS_DESCRIPTOR_DATA_NAME)) { - int num1 = extraUtils.getInt(baseClassDescriptorAddress.add(8)); - int num2 = extraUtils.getInt(baseClassDescriptorAddress.add(12)); - int num3 = extraUtils.getInt(baseClassDescriptorAddress.add(16)); - int num4 = extraUtils.getInt(baseClassDescriptorAddress.add(20)); + int num1 = extendedFlatAPI.getInt(baseClassDescriptorAddress.add(8)); + int num2 = extendedFlatAPI.getInt(baseClassDescriptorAddress.add(12)); + int num3 = extendedFlatAPI.getInt(baseClassDescriptorAddress.add(16)); + int num4 = extendedFlatAPI.getInt(baseClassDescriptorAddress.add(20)); baseClassDescriptor = createBaseClassDescriptor(baseClassDescriptorAddress); if (baseClassDescriptor != null) { @@ -530,10 +531,10 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { private Address createClassHierarchyDescriptor(Address address, Namespace classNamespace) throws CancelledException, MemoryAccessException, InvalidInputException, Exception { - //TODO: extraUtils.getReferencedAddress(address, getIboIf64bit); + //TODO: extendedFlatAPI.getReferencedAddress(address, getIboIf64bit); Address classHierarchyDescriptorAddress = getReferencedAddress(address); - Data classHierarchyStructure = extraUtils.getDataAt(classHierarchyDescriptorAddress); + Data classHierarchyStructure = extendedFlatAPI.getDataAt(classHierarchyDescriptorAddress); if (classHierarchyStructure != null && classHierarchyStructure.getDataType() @@ -578,7 +579,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { classHierarchyDescriptorAddress.add(sizeOfDt)); Data classHierarchyStructure = - extraUtils.createData(classHierarchyDescriptorAddress, classHDatatype); + extendedFlatAPI.createData(classHierarchyDescriptorAddress, classHDatatype); if (classHierarchyStructure == null) { return null; } @@ -611,13 +612,13 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { symbolTable.getPrimarySymbol(classHierarchyDescriptorAddress); Namespace classNamespace = classHierarchyDescriptorSymbol.getParentNamespace(); - int numBaseClasses = extraUtils.getInt(classHierarchyDescriptorAddress.add(8)); + int numBaseClasses = extendedFlatAPI.getInt(classHierarchyDescriptorAddress.add(8)); - //TODO: extraUtils.getReferencedAddress(address, getIboIf64bit); + //TODO: extendedFlatAPI.getReferencedAddress(address, getIboIf64bit); Address baseClassArrayAddress = getReferencedAddress(classHierarchyDescriptorAddress.add(12)); - Data baseClassDescArray = extraUtils.getDataAt(baseClassArrayAddress); + Data baseClassDescArray = extendedFlatAPI.getDataAt(baseClassArrayAddress); if (baseClassDescArray != null && baseClassDescArray.isArray()) { baseClassArrayAddresses.add(baseClassArrayAddress); @@ -681,7 +682,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { api.clearListing(baseClassArrayAddress, baseClassArrayAddress.add(numBaseClasses * sizeOfDt)); Data baseClassDescArray = - extraUtils.createData(baseClassArrayAddress, baseClassDescArrayDT); + extendedFlatAPI.createData(baseClassArrayAddress, baseClassDescArrayDT); if (baseClassDescArray == null) { return null; @@ -718,7 +719,8 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { continue; } - Reference[] referencesTo = extraUtils.getReferencesTo(completeObjectLocatorAddress); + Reference[] referencesTo = + extendedFlatAPI.getReferencesTo(completeObjectLocatorAddress); if (referencesTo.length == 0) { Msg.debug(this, "No refs to " + completeObjectLocatorAddress.toString()); continue; @@ -802,7 +804,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { // this will work whether there is a created reference or not int addressSize = address.getSize(); if (addressSize == 32) { - long offset = extraUtils.getInt(address); + long offset = extendedFlatAPI.getInt(address); return address.getNewAddress(offset); } @@ -810,7 +812,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { // this currently will workn only if there is a created reference // TODO: get ibo bytes and figure out what the ibo ref address would be if (addressSize == 64) { - Reference refs[] = extraUtils.getReferencesFrom(address); + Reference refs[] = extendedFlatAPI.getReferencesFrom(address); if (refs.length == 0) { return null; } @@ -853,7 +855,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { findVftableReferencesNotInFunction(vftableSymbols); if (unusedVftableReferences.size() > 0) { - extraUtils.createUndefinedFunctions(unusedVftableReferences); + extendedFlatAPI.createUndefinedFunctions(unusedVftableReferences); } // create these automatically if found @@ -915,7 +917,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { // Create Data Type Manager Category for given class // TODO: make this global and check it for null CategoryPath classPath = - extraUtils.createDataTypeCategoryPath(classDataTypesCategoryPath, + extendedFlatAPI.createDataTypeCategoryPath(classDataTypesCategoryPath, classNameWithNamespace); RecoveredClass nonVftableClass = @@ -960,7 +962,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { */ private List getListOfClassHierarchyDescriptors() throws CancelledException { - List classHierarchyDescriptorList = extraUtils.getListOfSymbolsInAddressSet( + List classHierarchyDescriptorList = extendedFlatAPI.getListOfSymbolsInAddressSet( getInitializedMemory(), RTTI_CLASS_HIERARCHY_DESCRIPTOR_LABEL, false); return classHierarchyDescriptorList; @@ -989,13 +991,13 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { Address vftableAddress = vftableIterator.next(); Address ptrToColAddress = vftableAddress.subtract(defaultPointerSize); - Data pointerToCompleteObjLocator = extraUtils.getDataAt(vftableAddress); + Data pointerToCompleteObjLocator = extendedFlatAPI.getDataAt(vftableAddress); if (pointerToCompleteObjLocator == null) { pointerToCompleteObjLocator = - extraUtils.createData(ptrToColAddress, pointerDataType); + extendedFlatAPI.createData(ptrToColAddress, pointerDataType); } - Address colAddress = extraUtils.getReferencedAddress(ptrToColAddress, false); + Address colAddress = extendedFlatAPI.getReferencedAddress(ptrToColAddress, false); if (colAddress == null) { Msg.debug(this, recoveredClass.getName() + @@ -1005,7 +1007,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { Address addressOfOffset = colAddress.add(4); - int offset = extraUtils.getInt(addressOfOffset); + int offset = extendedFlatAPI.getInt(addressOfOffset); recoveredClass.addClassOffsetToVftableMapping(offset, vftableAddress); } @@ -1150,7 +1152,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { List classHierarchy = new ArrayList(); - List symbols = extraUtils.getListOfSymbolsByNameInNamespace( + List symbols = extendedFlatAPI.getListOfSymbolsByNameInNamespace( RTTI_BASE_CLASS_ARRAY_LABEL, recoveredClass.getClassNamespace(), false); @@ -1167,7 +1169,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { Address pointerAddress = rttiBaseClassDescriptorArray.getComponent(i).getAddress(); Address baseClassDescriptorAddress = - extraUtils.getSingleReferencedAddress(pointerAddress); + extendedFlatAPI.getSingleReferencedAddress(pointerAddress); if (baseClassDescriptorAddress == null) { return classHierarchy; @@ -1218,11 +1220,11 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { private int getClassInheritanceFlag(Namespace classNamespace) throws CancelledException, MemoryAccessException, AddressOutOfBoundsException { - List symbols = extraUtils.getListOfSymbolsByNameInNamespace( + List symbols = extendedFlatAPI.getListOfSymbolsByNameInNamespace( RTTI_CLASS_HIERARCHY_DESCRIPTOR_LABEL, classNamespace, false); if (symbols.size() >= 1) { - return (extraUtils.getInt(symbols.get(0).getAddress().add(4))); + return (extendedFlatAPI.getInt(symbols.get(0).getAddress().add(4))); } return NONE; @@ -1353,7 +1355,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { // iterate over base class array and for each parent class of the given recovered class // get the mdisp, pdisp, vdisp info - List baseClassArray = extraUtils.getListOfSymbolsByNameInNamespace( + List baseClassArray = extendedFlatAPI.getListOfSymbolsByNameInNamespace( RTTI_BASE_CLASS_ARRAY_LABEL, recoveredClass.getClassNamespace(), false); // this should never happen @@ -1386,7 +1388,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { Address pointerAddress = baseClassArrayData.getComponent(i).getAddress(); Address baseClassDescriptorAddress = - extraUtils.getReferencedAddress(pointerAddress, true); + extendedFlatAPI.getReferencedAddress(pointerAddress, true); if (baseClassArrayAddress == null) { continue; } @@ -1591,7 +1593,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { getTargetAddressFromPcodeOp(offsetPcodeOpPair.getPcodeOp()); Address vbtableAddress = - extraUtils.getSingleReferencedAddress(listingAddress); + extendedFlatAPI.getSingleReferencedAddress(listingAddress); if (vbtableAddress == null) { continue; @@ -1950,7 +1952,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { if (possibleVftable == null) { Function referencedFunction = - extraUtils.getReferencedFunction(classReferenceAddress, true); + extendedFlatAPI.getReferencedFunction(classReferenceAddress, true); if (referencedFunction == null) { continue; } @@ -2298,7 +2300,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { Address pointerAddress = baseClassArrayData.getComponent(i).getAddress(); Address baseClassDescriptorAddress = - extraUtils.getReferencedAddress(pointerAddress, true); + extendedFlatAPI.getReferencedAddress(pointerAddress, true); if (baseClassDescriptorAddress == null) { continue; } @@ -2361,7 +2363,8 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { dataLength = baseClassStructure.getLength() - lengthOfVirtualParent; } - if (structUtils.canAdd(classStructureDataType, baseClassOffset, dataLength, + if (EditStructureUtils.canAdd(classStructureDataType, baseClassOffset, + dataLength, monitor)) { classStructureDataType = addIndividualComponentsToStructure(classStructureDataType, @@ -2371,10 +2374,11 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { } // else copy whole baseClass structure to the class Structure - if (structUtils.canAdd(classStructureDataType, baseClassOffset, + if (EditStructureUtils.canAdd(classStructureDataType, baseClassOffset, baseClassStructure.getLength(), monitor)) { classStructureDataType = - structUtils.addDataTypeToStructure(classStructureDataType, baseClassOffset, + EditStructureUtils.addDataTypeToStructure(classStructureDataType, + baseClassOffset, baseClassStructure, baseClassStructure.getName(), monitor); } @@ -2390,11 +2394,12 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { baseClassOffset = api.getInt(recoveredClass.getVbtableAddress().add(vdisp)) + pdisp; - if (structUtils.canAdd(classStructureDataType, baseClassOffset, + if (EditStructureUtils.canAdd(classStructureDataType, baseClassOffset, baseClassStructure.getLength(), monitor)) { classStructureDataType = - structUtils.addDataTypeToStructure(classStructureDataType, baseClassOffset, + EditStructureUtils.addDataTypeToStructure(classStructureDataType, + baseClassOffset, baseClassStructure, baseClassStructure.getName(), monitor); } @@ -2422,9 +2427,10 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { DataType classVftablePointer = vfPointerDataTypes.get(vftableAddress); - if (structUtils.canAdd(classStructureDataType, offset.intValue(), + if (EditStructureUtils.canAdd(classStructureDataType, offset.intValue(), classVftablePointer.getLength(), monitor)) { - classStructureDataType = structUtils.addDataTypeToStructure(classStructureDataType, + classStructureDataType = EditStructureUtils.addDataTypeToStructure( + classStructureDataType, offset.intValue(), classVftablePointer, CLASS_VTABLE_PTR_FIELD_EXT, monitor); } @@ -2440,7 +2446,8 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { int dataOffset = getDataOffset(recoveredClass, classStructureDataType); int dataLen = UNKNOWN; if (dataOffset != NONE) { - dataLen = structUtils.getNumberOfUndefinedsStartingAtOffset(classStructureDataType, + dataLen = + EditStructureUtils.getNumberOfUndefinedsStartingAtOffset(classStructureDataType, dataOffset, monitor); } @@ -2450,7 +2457,8 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { classStructureDataType, dataLen, dataOffset); if (recoveredClassDataStruct != null) { - classStructureDataType = structUtils.addDataTypeToStructure(classStructureDataType, + classStructureDataType = + EditStructureUtils.addDataTypeToStructure(classStructureDataType, dataOffset, recoveredClassDataStruct, classStructureDataType.getName() + "_data", monitor); } @@ -2517,11 +2525,12 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { monitor.checkCanceled(); // if enough empty bytes - add class vftable pointer - if (structUtils.canAdd(classStructureDataType, vftableOffset, + if (EditStructureUtils.canAdd(classStructureDataType, vftableOffset, classVftablePointer.getLength(), monitor)) { classStructureDataType = - structUtils.addDataTypeToStructure(classStructureDataType, vftableOffset, + EditStructureUtils.addDataTypeToStructure(classStructureDataType, + vftableOffset, classVftablePointer, CLASS_VTABLE_PTR_FIELD_EXT, monitor); addedVftablePointer = true; @@ -2638,7 +2647,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { return false; } int numUndefined1s = - structUtils.getNumberOfUndefinedsStartingAtOffset(structure, 0, monitor); + EditStructureUtils.getNumberOfUndefinedsStartingAtOffset(structure, 0, monitor); if (structure.getLength() == numUndefined1s) { return true; } @@ -2685,7 +2694,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { Address pointerAddress = baseClassArrayData.getComponent(i).getAddress(); Address baseClassDescriptorAddress = - extraUtils.getReferencedAddress(pointerAddress, true); + extendedFlatAPI.getReferencedAddress(pointerAddress, true); if (baseClassDescriptorAddress == null) { continue; } @@ -2735,7 +2744,7 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { */ private Data getBaseClassArray(RecoveredClass recoveredClass) throws CancelledException { - List baseClassArray = extraUtils.getListOfSymbolsByNameInNamespace( + List baseClassArray = extendedFlatAPI.getListOfSymbolsByNameInNamespace( RTTI_BASE_CLASS_ARRAY_LABEL, recoveredClass.getClassNamespace(), false); if (baseClassArray.size() != 1) { @@ -2792,9 +2801,11 @@ public class RTTIWindowsClassRecoverer extends RTTIClassRecoverer { DataType vbaseStructPointer = dataTypeManager.getPointer(vbtableStructure); int dataLength = vbaseStructPointer.getLength(); - if (structUtils.canAdd(classStructureDataType, vbtableOffset, dataLength, monitor)) { + if (EditStructureUtils.canAdd(classStructureDataType, vbtableOffset, dataLength, + monitor)) { - classStructureDataType = structUtils.addDataTypeToStructure(classStructureDataType, + classStructureDataType = + EditStructureUtils.addDataTypeToStructure(classStructureDataType, vbtableOffset, vbaseStructPointer, "vbtablePtr", monitor); } diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClass.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClass.java index 80b386f1cd..97797660b6 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClass.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClass.java @@ -95,7 +95,6 @@ public class RecoveredClass { private static final int NONE = -1; TaskMonitor monitor = TaskMonitor.DUMMY; - EditStructureUtils structUtils; RecoveredClass(String name, CategoryPath classPath, Namespace classNamespace, @@ -105,7 +104,6 @@ public class RecoveredClass { this.classNamespace = classNamespace; this.dataTypeManager = dataTypeManager; - this.structUtils = new EditStructureUtils(); } public String getName() { @@ -531,11 +529,11 @@ public class RecoveredClass { // if the new component is a non-empty structure, check to see if the current // structure has undefined or equivalent components and replace with new struct if so if (newComponentDataType instanceof Structure) { - if (structUtils.hasReplaceableComponentsAtOffset(computedClassStructure, + if (EditStructureUtils.hasReplaceableComponentsAtOffset(computedClassStructure, offset, (Structure) newComponentDataType, monitor)) { boolean successfulClear = - structUtils.clearLengthAtOffset(computedClassStructure, offset, + EditStructureUtils.clearLengthAtOffset(computedClassStructure, offset, length, monitor); if (successfulClear) { @@ -547,13 +545,14 @@ public class RecoveredClass { } // if current component is undefined size 1 and new component is not undefined size 1 - // then replace it - if (structUtils.isUndefined1(currentComponentDataType) && - !structUtils.isUndefined1(newComponentDataType)) { - if (structUtils.hasEnoughUndefinedsOfAnyLengthAtOffset(computedClassStructure, + // and there are enough undefineds for it to fit, then replace it + if (EditStructureUtils.isUndefined1(currentComponentDataType) && + !EditStructureUtils.isUndefined1(newComponentDataType)) { + if (EditStructureUtils.hasEnoughUndefinedsOfAnyLengthAtOffset( + computedClassStructure, offset, length, monitor)) { boolean successfulClear = - structUtils.clearLengthAtOffset(computedClassStructure, offset, + EditStructureUtils.clearLengthAtOffset(computedClassStructure, offset, length, monitor); if (successfulClear) { @@ -567,13 +566,14 @@ public class RecoveredClass { // if new component is not an undefined data type and the current componenent(s) // that make up new component length are all undefineds then clear and replace // the current component(s) with the new one - if (structUtils.isUndefined(currentComponentDataType) && - !structUtils.isUndefined(newComponentDataType)) { + if (Undefined.isUndefined(currentComponentDataType) && + !Undefined.isUndefined(newComponentDataType)) { - if (structUtils.hasEnoughUndefinedsOfAnyLengthAtOffset(computedClassStructure, + if (EditStructureUtils.hasEnoughUndefinedsOfAnyLengthAtOffset( + computedClassStructure, offset, length, monitor)) { boolean successfulClear = - structUtils.clearLengthAtOffset(computedClassStructure, offset, + EditStructureUtils.clearLengthAtOffset(computedClassStructure, offset, length, monitor); if (successfulClear) { @@ -601,7 +601,7 @@ public class RecoveredClass { continue; } - if (structUtils.isUndefined1(dataType)) { + if (EditStructureUtils.isUndefined1(dataType)) { dataType = new Undefined1DataType(); DataTypeComponent component = computedClassStructure.getComponentAt(offset.intValue()); diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassUtils.java b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassUtils.java index d6cecc9c09..d69c960e48 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassUtils.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassUtils.java @@ -130,8 +130,7 @@ public class RecoveredClassUtils { int defaultPointerSize; SymbolTable symbolTable; - ExtraScriptUtils extraUtils; - EditStructureUtils structUtils; + ExtendedFlatProgramAPI extendedFlatAPI; DecompilerScriptUtils decompilerUtils; CategoryPath classDataTypesCategoryPath; @@ -157,10 +156,10 @@ public class RecoveredClassUtils { this.tool = tool; this.api = api; - extraUtils = new ExtraScriptUtils(program, monitor); + extendedFlatAPI = new ExtendedFlatProgramAPI(program, monitor); this.classDataTypesCategoryPath = - extraUtils.createDataTypeCategoryPath(CategoryPath.ROOT, DTM_CLASS_DATA_FOLDER_NAME); + extendedFlatAPI.createDataTypeCategoryPath(CategoryPath.ROOT, DTM_CLASS_DATA_FOLDER_NAME); this.createBookmarks = createBookmarks; this.useShortTemplates = useShortTemplates; @@ -170,7 +169,6 @@ public class RecoveredClassUtils { globalNamespace = (GlobalNamespace) program.getGlobalNamespace(); decompilerUtils = new DecompilerScriptUtils(program, tool, monitor); - structUtils = new EditStructureUtils(); dataTypeManager = program.getDataTypeManager(); symbolTable = program.getSymbolTable(); @@ -417,7 +415,7 @@ public class RecoveredClassUtils { if (allConstructorsAndDestructors.contains(calledFunction)) { // get list of refs to this function from the calling function List
referencesToFunctionBFromFunctionA = - extraUtils.getReferencesToFunctionBFromFunctionA(function, + extendedFlatAPI.getReferencesToFunctionBFromFunctionA(function, referencedFunction); // add them to list of ref address pairs Iterator
iterator = referencesToFunctionBFromFunctionA.iterator(); @@ -654,7 +652,7 @@ public class RecoveredClassUtils { monitor.checkCanceled(); Address vftableRef = vftableRefIterator.next(); - Address vftableAddress = extraUtils.getSingleReferencedAddress(vftableRef); + Address vftableAddress = extendedFlatAPI.getSingleReferencedAddress(vftableRef); if (vftableAddress == null) { continue; @@ -1234,11 +1232,11 @@ public class RecoveredClassUtils { DataType dataType = function.getParameter(i).getDataType(); - if (!extraUtils.isPointerToEmptyStructure(dataType)) { + if (!extendedFlatAPI.isPointerToEmptyStructure(dataType)) { continue; } - PointerDataType ptrUndefined = extraUtils.createPointerToUndefinedDataType(dataType); + PointerDataType ptrUndefined = extendedFlatAPI.createPointerToUndefinedDataType(dataType); if (ptrUndefined != null) { function.getParameter(i).setDataType(ptrUndefined, SourceType.ANALYSIS); } @@ -1247,9 +1245,9 @@ public class RecoveredClassUtils { // Next check the return type to see if it is the empty structure DataType returnType = function.getReturnType(); - if (extraUtils.isPointerToEmptyStructure(returnType)) { + if (extendedFlatAPI.isPointerToEmptyStructure(returnType)) { PointerDataType ptrUndefined = - extraUtils.createPointerToUndefinedDataType(returnType); + extendedFlatAPI.createPointerToUndefinedDataType(returnType); if (ptrUndefined != null) { function.setReturnType(ptrUndefined, SourceType.ANALYSIS); } @@ -1664,7 +1662,7 @@ public class RecoveredClassUtils { return possibleParentConstructors; } - Address minVftableReference = extraUtils.getMinimumAddressOnList(vftableReferenceList); + Address minVftableReference = extendedFlatAPI.getMinimumAddressOnList(vftableReferenceList); Iterator iterator = refAddrPairList.iterator(); while (iterator.hasNext()) { @@ -1738,7 +1736,7 @@ public class RecoveredClassUtils { return possibleParentDestructors; } - Address maxVftableReference = extraUtils.getMaximumAddressOnList(vftableReferenceList); + Address maxVftableReference = extendedFlatAPI.getMaximumAddressOnList(vftableReferenceList); Iterator iterator = refAddrPairList.iterator(); while (iterator.hasNext()) { @@ -1746,7 +1744,7 @@ public class RecoveredClassUtils { ReferenceAddressPair refAddrPair = iterator.next(); Address sourceAddr = refAddrPair.getSource(); if (sourceAddr.compareTo(maxVftableReference) > 0) { - Function calledFunction = extraUtils.getFunctionAt(refAddrPair.getDestination()); + Function calledFunction = extendedFlatAPI.getFunctionAt(refAddrPair.getDestination()); if (calledFunction != null) { possibleParentDestructors.add(calledFunction); } @@ -1930,7 +1928,7 @@ public class RecoveredClassUtils { } // If not already, make function a thiscall - extraUtils.makeFunctionThiscall(constructorFunction); + extendedFlatAPI.makeFunctionThiscall(constructorFunction); recoveredClass.addConstructor(constructorFunction); addToAllConstructors(constructorFunction); @@ -1948,7 +1946,7 @@ public class RecoveredClassUtils { throws InvalidInputException, DuplicateNameException { //If not already, make function a thiscall - extraUtils.makeFunctionThiscall(inlinedConstructorFunction); + extendedFlatAPI.makeFunctionThiscall(inlinedConstructorFunction); recoveredClass.addInlinedConstructor(inlinedConstructorFunction); addToAllInlinedConstructors(inlinedConstructorFunction); @@ -1965,7 +1963,7 @@ public class RecoveredClassUtils { throws InvalidInputException, DuplicateNameException { //If not already, make function a thiscall - extraUtils.makeFunctionThiscall(destructorFunction); + extendedFlatAPI.makeFunctionThiscall(destructorFunction); recoveredClass.addDestructor(destructorFunction); addToAllDestructors(destructorFunction); @@ -1983,7 +1981,7 @@ public class RecoveredClassUtils { throws InvalidInputException, DuplicateNameException { //If not already, make function a thiscall - extraUtils.makeFunctionThiscall(inlinedDestructorFunction); + extendedFlatAPI.makeFunctionThiscall(inlinedDestructorFunction); recoveredClass.addInlinedDestructor(inlinedDestructorFunction); addToAllInlinedDestructors(inlinedDestructorFunction); @@ -2068,7 +2066,7 @@ public class RecoveredClassUtils { Address constructorReference = constructorIterator.next(); RecoveredClass recoveredClass = referenceToClassMap.get(constructorReference); - Function constructor = extraUtils.getReferencedFunction(constructorReference, true); + Function constructor = extendedFlatAPI.getReferencedFunction(constructorReference, true); if (recoveredClass.getIndeterminateList().contains(constructor)) { addConstructorToClass(recoveredClass, constructor); @@ -2265,7 +2263,7 @@ public class RecoveredClassUtils { ReferenceAddressPair referenceAddressPair = calledFunctionIterator.next(); Address calledFunctionAddress = referenceAddressPair.getDestination(); - Function calledFunction = extraUtils.getFunctionAt(calledFunctionAddress); + Function calledFunction = extendedFlatAPI.getFunctionAt(calledFunctionAddress); if (calledFunction.isThunk()) { calledFunction = calledFunction.getThunkedFunction(true); @@ -2299,7 +2297,7 @@ public class RecoveredClassUtils { ReferenceAddressPair referenceAddressPair = calledFunctionIterator.next(); Address calledFunctionAddress = referenceAddressPair.getDestination(); - Function calledFunction = extraUtils.getFunctionAt(calledFunctionAddress); + Function calledFunction = extendedFlatAPI.getFunctionAt(calledFunctionAddress); if (calledFunction.isThunk()) { calledFunction = calledFunction.getThunkedFunction(true); @@ -2512,7 +2510,7 @@ public class RecoveredClassUtils { Address destructorReference = destructorIterator.next(); RecoveredClass recoveredClass = referenceToClassMap.get(destructorReference); - Function destructor = extraUtils.getReferencedFunction(destructorReference, true); + Function destructor = extendedFlatAPI.getReferencedFunction(destructorReference, true); if (recoveredClass.getIndeterminateList().contains(destructor)) { addDestructorToClass(recoveredClass, destructor); @@ -2638,7 +2636,7 @@ public class RecoveredClassUtils { String className = namespace.getName(); String classNameWithNamespace = namespace.getName(true); - CategoryPath classPath = extraUtils.createDataTypeCategoryPath(classDataTypesCategoryPath, + CategoryPath classPath = extendedFlatAPI.createDataTypeCategoryPath(classDataTypesCategoryPath, classNameWithNamespace); RecoveredClass newClass = @@ -2843,7 +2841,7 @@ public class RecoveredClassUtils { while (referencesIterator.hasNext()) { monitor.checkCanceled(); Address vftableReference = referencesIterator.next(); - Function functionContaining = extraUtils.getFunctionContaining(vftableReference); + Function functionContaining = extendedFlatAPI.getFunctionContaining(vftableReference); if (functionContaining != null) { vftableRefToFunctionMapping.put(vftableReference, functionContaining); } @@ -2893,7 +2891,7 @@ public class RecoveredClassUtils { Data vftableData = program.getListing().getDefinedDataAt(vftableAddress); // now make sure the array or the structure is all pointers - if (!extraUtils.isArrayOrStructureOfAllPointers(vftableData)) { + if (!extendedFlatAPI.isArrayOrStructureOfAllPointers(vftableData)) { // if it isn't an array of pointers then we don't know the size of the vftable // If undefined or pointers not in array or struct then see if what they are // pointing to are in the class already to determine size of array @@ -2927,12 +2925,12 @@ public class RecoveredClassUtils { monitor.checkCanceled(); Address functionPointerAddress = vftableData.getComponent(i).getAddress(); - if (allowNullFunctionPtrs && extraUtils.isNullPointer(functionPointerAddress)) { + if (allowNullFunctionPtrs && extendedFlatAPI.isNullPointer(functionPointerAddress)) { virtualFunctionList.add(null); continue; } - Function function = extraUtils.getPointedToFunction(functionPointerAddress); + Function function = extendedFlatAPI.getPointedToFunction(functionPointerAddress); if (function != null) { virtualFunctionList.add(function); @@ -2979,7 +2977,7 @@ public class RecoveredClassUtils { boolean stillInCurrentTable = true; while (address != null && currentBlock.contains(address) && stillInCurrentTable && - extraUtils.isFunctionPointer(address, allowNullFunctionPtrs)) { + extendedFlatAPI.isFunctionPointer(address, allowNullFunctionPtrs)) { numFunctionPointers++; address = address.add(defaultPointerSize); Symbol symbol = program.getSymbolTable().getPrimarySymbol(address); @@ -3068,7 +3066,7 @@ public class RecoveredClassUtils { program.getListing().getInstructionContaining(vftableReference); if (instructionContaining != null) { boolean functionCreated = - extraUtils.createFunction(program, vftableReference); + extendedFlatAPI.createFunction(program, vftableReference); if (!functionCreated) { notInFunctionVftableRefs.add(vftableReference); @@ -3124,7 +3122,7 @@ public class RecoveredClassUtils { } else { boolean functionCreated = - extraUtils.createFunction(prog, addr); + extendedFlatAPI.createFunction(prog, addr); if (!functionCreated) { notInFunctionVftableRefs.add(addr); } @@ -3791,7 +3789,7 @@ public class RecoveredClassUtils { if (!badFIDNamespaces.contains(symbol.getParentNamespace())) { badFIDNamespaces.add(symbol.getParentNamespace()); } - extraUtils.addUniqueStringToPlateComment(functionAddress, + extendedFlatAPI.addUniqueStringToPlateComment(functionAddress, "***** Removed Bad FID Symbol *****"); if (!badFIDFunctions.contains(function)) { @@ -3799,7 +3797,7 @@ public class RecoveredClassUtils { } findAndRemoveBadStructuresFromFunction(function, namespace); - extraUtils.removeAllSymbolsAtAddress(functionAddress); + extendedFlatAPI.removeAllSymbolsAtAddress(functionAddress); } return; @@ -3810,7 +3808,7 @@ public class RecoveredClassUtils { if (bookmarkComment.contains("Multiple Matches")) { // See if any contain the class name and if so add "resolved" and if not if (doAnySymbolsHaveMatchingName(functionAddress, name)) { - extraUtils.addUniqueStringToPlateComment(functionAddress, + extendedFlatAPI.addUniqueStringToPlateComment(functionAddress, "***** Resolved FID Conflict *****"); if (!resolvedFIDFunctions.contains(function)) { @@ -3820,7 +3818,7 @@ public class RecoveredClassUtils { findAndRemoveBadStructuresFromFunction(function, namespace); } else { - extraUtils.addUniqueStringToPlateComment(functionAddress, + extendedFlatAPI.addUniqueStringToPlateComment(functionAddress, "***** Removed Bad FID Symbol(s) *****"); if (!badFIDFunctions.contains(function)) { @@ -3830,7 +3828,7 @@ public class RecoveredClassUtils { findAndRemoveBadStructuresFromFunction(function, namespace); } - extraUtils.removeAllSymbolsAtAddress(functionAddress); + extendedFlatAPI.removeAllSymbolsAtAddress(functionAddress); return; } } @@ -3943,7 +3941,7 @@ public class RecoveredClassUtils { monitor.checkCanceled(); DataType dataType = function.getParameter(i).getDataType(); if (!dataType.getName().equals(namespace.getName()) && - extraUtils.isPointerToEmptyStructure(dataType)) { + extendedFlatAPI.isPointerToEmptyStructure(dataType)) { Pointer ptr = (Pointer) dataType; Structure structure = (Structure) ptr.getDataType(); @@ -3973,7 +3971,7 @@ public class RecoveredClassUtils { for (int i = 0; i < parameterCount; i++) { monitor.checkCanceled(); DataType paramDataType = function.getParameter(i).getDataType(); - Structure baseDataType = extraUtils.getBaseStructureDataType(paramDataType); + Structure baseDataType = extendedFlatAPI.getBaseStructureDataType(paramDataType); if (baseDataType != null && badStructureDataTypes.contains(baseDataType)) { // To remove from this param we have to remove the function from its namespace @@ -3983,7 +3981,7 @@ public class RecoveredClassUtils { } else { PointerDataType ptrUndefined = - extraUtils.createPointerToUndefinedDataType(paramDataType); + extendedFlatAPI.createPointerToUndefinedDataType(paramDataType); if (ptrUndefined != null) { function.getParameter(i).setDataType(ptrUndefined, SourceType.ANALYSIS); } @@ -4008,7 +4006,7 @@ public class RecoveredClassUtils { DataType returnType = function.getReturnType(); if (!returnType.getName().equals(namespace.getName()) && - extraUtils.isPointerToEmptyStructure(returnType)) { + extendedFlatAPI.isPointerToEmptyStructure(returnType)) { Pointer ptr = (Pointer) returnType; Structure structure = (Structure) ptr.getDataType(); @@ -4030,10 +4028,10 @@ public class RecoveredClassUtils { throws InvalidInputException { DataType returnType = function.getReturnType(); - Structure baseDataType = extraUtils.getBaseStructureDataType(returnType); + Structure baseDataType = extendedFlatAPI.getBaseStructureDataType(returnType); if (baseDataType != null && badStructureDataTypes.contains(baseDataType)) { PointerDataType ptrUndefined = - extraUtils.createPointerToUndefinedDataType(returnType); + extendedFlatAPI.createPointerToUndefinedDataType(returnType); if (ptrUndefined != null) { function.setReturnType(ptrUndefined, SourceType.ANALYSIS); } @@ -4052,13 +4050,13 @@ public class RecoveredClassUtils { private boolean doAnySymbolsHaveMatchingName(Address address, String name) throws CancelledException { - String simpleName = extraUtils.removeTemplate(name); + String simpleName = extendedFlatAPI.removeTemplate(name); SymbolIterator it = symbolTable.getSymbolsAsIterator(address); for (Symbol symbol : it) { monitor.checkCanceled(); - String simpleSymbolName = extraUtils.removeTemplate(symbol.getName()); + String simpleSymbolName = extendedFlatAPI.removeTemplate(symbol.getName()); simpleSymbolName = removeSingleQuotes(simpleSymbolName); simpleSymbolName = removeFIDConflict(simpleSymbolName); simpleSymbolName = removeSingleQuotes(simpleSymbolName); @@ -4150,7 +4148,7 @@ public class RecoveredClassUtils { throws CancelledException { List orderedReferenceAddressPairsFromCallingFunction = - extraUtils.getOrderedReferenceAddressPairsFromCallingFunction(constructor); + extendedFlatAPI.getOrderedReferenceAddressPairsFromCallingFunction(constructor); // if there are no calls from the function then return false if (orderedReferenceAddressPairsFromCallingFunction.size() == 0) { @@ -4224,9 +4222,9 @@ public class RecoveredClassUtils { monitor.checkCanceled(); Function vfunction = vfunctionIterator.next(); - if (extraUtils.doesFunctionACallAnyListedFunction(vfunction, + if (extendedFlatAPI.doesFunctionACallAnyListedFunction(vfunction, recoveredClass.getConstructorList()) && - !extraUtils.doesFunctionACallAnyListedFunction(vfunction, + !extendedFlatAPI.doesFunctionACallAnyListedFunction(vfunction, allOtherConstructors)) { cloneToClassMap.put(vfunction, recoveredClass); } @@ -4269,13 +4267,13 @@ public class RecoveredClassUtils { if (calledFunctions.size() != 2 && calledFunctions.size() != 3) { return false; } - if (!extraUtils.getCalledFunctionByCallOrder(caller, 1).equals(firstCalled)) { + if (!extendedFlatAPI.getCalledFunctionByCallOrder(caller, 1).equals(firstCalled)) { return false; } RecoveredClass recoveredClass = cloneFunctionToClassMap.get(caller); List constructorList = recoveredClass.getConstructorList(); - Function secondFunction = extraUtils.getCalledFunctionByCallOrder(caller, 2); + Function secondFunction = extendedFlatAPI.getCalledFunctionByCallOrder(caller, 2); if (secondFunction.isThunk()) { secondFunction = secondFunction.getThunkedFunction(true); } @@ -4314,7 +4312,7 @@ public class RecoveredClassUtils { // The second call is a class constructor and we know it is called // from the cloneFunction or it wouldn't be a cloneFunction Function firstCalledFunction = - extraUtils.getCalledFunctionByCallOrder(cloneFunction, 1); + extendedFlatAPI.getCalledFunctionByCallOrder(cloneFunction, 1); if (firstCalledFunction == null) { continue; } @@ -4406,7 +4404,7 @@ public class RecoveredClassUtils { Namespace badNamespace = badNamespaceIterator.next(); // delete empty namespace and parent namespaces - if (!extraUtils.hasSymbolsInNamespace(badNamespace)) { + if (!extendedFlatAPI.hasSymbolsInNamespace(badNamespace)) { removeEmptyNamespaces(badNamespace); } } @@ -4427,7 +4425,7 @@ public class RecoveredClassUtils { Namespace parentNamespace = namespace.getParentNamespace(); namespace.getSymbol().delete(); - while (parentNamespace != null && !extraUtils.hasSymbolsInNamespace(parentNamespace)) { + while (parentNamespace != null && !extendedFlatAPI.hasSymbolsInNamespace(parentNamespace)) { monitor.checkCanceled(); namespace = parentNamespace; @@ -4472,7 +4470,7 @@ public class RecoveredClassUtils { throws CancelledException { DataType dataType = dataTypeManager.getDataType(folderPath, structureName); - if (extraUtils.isEmptyStructure(dataType)) { + if (extendedFlatAPI.isEmptyStructure(dataType)) { dataTypeManager.remove(dataType, monitor); Category classCategory = dataTypeManager.getCategory(folderPath); @@ -5281,7 +5279,7 @@ public class RecoveredClassUtils { } // get first called function and verify it is on cd list Function firstCalledFunction = - extraUtils.getCalledFunctionByCallOrder(deletingDestructor, 1); + extendedFlatAPI.getCalledFunctionByCallOrder(deletingDestructor, 1); if (firstCalledFunction == null || !recoveredClass.getConstructorOrDestructorFunctions() .contains( @@ -5291,7 +5289,7 @@ public class RecoveredClassUtils { // get second one and if operator_delete has not been assigned yet, assign it Function secondCalledFunction = - extraUtils.getCalledFunctionByCallOrder(deletingDestructor, 2); + extendedFlatAPI.getCalledFunctionByCallOrder(deletingDestructor, 2); if (secondCalledFunction == null) { return null; } @@ -5338,7 +5336,7 @@ public class RecoveredClassUtils { throws CancelledException, InvalidInputException, DuplicateNameException { // don't continue checking if it doesn't call operator_delete - if (!extraUtils.doesFunctionACallFunctionB(virtualFunction, operatorDeleteFunction)) { + if (!extendedFlatAPI.doesFunctionACallFunctionB(virtualFunction, operatorDeleteFunction)) { return; } @@ -5354,7 +5352,7 @@ public class RecoveredClassUtils { Function function = functionIterator.next(); //Type 4 - class c/d called from other than first vfunction - if (extraUtils.doesFunctionACallFunctionB(virtualFunction, function)) { + if (extendedFlatAPI.doesFunctionACallFunctionB(virtualFunction, function)) { recoveredClass.addDeletingDestructor(virtualFunction); addDestructorToClass(recoveredClass, function); recoveredClass.removeIndeterminateConstructorOrDestructor(function); @@ -5389,7 +5387,7 @@ public class RecoveredClassUtils { continue; } - Function referencedFunction = extraUtils.getReferencedFunction(codeUnitAddress, true); + Function referencedFunction = extendedFlatAPI.getReferencedFunction(codeUnitAddress, true); if (referencedFunction == null) { continue; } @@ -5515,7 +5513,7 @@ public class RecoveredClassUtils { String fieldname = dataTypeComponent.getFieldName(); - structureDataType = structUtils.addDataTypeToStructure(structureDataType, + structureDataType = EditStructureUtils.addDataTypeToStructure(structureDataType, startOffset + dataComponentOffset, dataTypeComponent.getDataType(), fieldname, monitor); } @@ -5544,7 +5542,7 @@ public class RecoveredClassUtils { String fieldname = dataTypeComponent.getFieldName(); - structureDataType = structUtils.addDataTypeToStructure(structureDataType, + structureDataType = EditStructureUtils.addDataTypeToStructure(structureDataType, startOffset + dataComponentOffset, dataTypeComponent.getDataType(), fieldname, monitor); } @@ -5811,9 +5809,9 @@ public class RecoveredClassUtils { // get first called function and verify is not a c/d function in current class or // any class get second called function and verify it is operator delete Function firstCalledFunction = - extraUtils.getCalledFunctionByCallOrder(vFunction, 1); + extendedFlatAPI.getCalledFunctionByCallOrder(vFunction, 1); Function secondCalledFunction = - extraUtils.getCalledFunctionByCallOrder(vFunction, 2); + extendedFlatAPI.getCalledFunctionByCallOrder(vFunction, 2); if (firstCalledFunction != null && secondCalledFunction != null && !recoveredClass.getConstructorOrDestructorFunctions() .contains( @@ -6095,7 +6093,7 @@ public class RecoveredClassUtils { Map referenceToClassMap = getReferenceToClassMap(recoveredClass, inlineFunction); List
referencesToFunctions = - extraUtils.getReferencesToFunctions(referenceToClassMap); + extendedFlatAPI.getReferencesToFunctions(referenceToClassMap); // if some of the references are to functions figure out if they are // constructors destructors or add them to list of indetermined @@ -6110,7 +6108,7 @@ public class RecoveredClassUtils { monitor.checkCanceled(); Address functionReference = functionReferenceIterator.next(); Function function = - extraUtils.getReferencedFunction(functionReference, true); + extendedFlatAPI.getReferencedFunction(functionReference, true); if (function == null) { continue; } @@ -6240,7 +6238,7 @@ public class RecoveredClassUtils { } int dataLength = - structUtils.getNumberOfUndefinedsBeforeOffset(structure, endOfData, monitor); + EditStructureUtils.getNumberOfUndefinedsBeforeOffset(structure, endOfData, monitor); if (dataLength < 0) { return NONE; } @@ -6276,7 +6274,7 @@ public class RecoveredClassUtils { boolean callsKnownConstructor = callsKnownConstructor(indeterminateFunction); boolean callsKnownDestrutor = callsKnownDestructor(indeterminateFunction); boolean callsAtexit = - extraUtils.doesFunctionACallFunctionB(indeterminateFunction, atexit); + extendedFlatAPI.doesFunctionACallFunctionB(indeterminateFunction, atexit); if (callsKnownConstructor && !callsKnownDestrutor) { addConstructorToClass(recoveredClass, indeterminateFunction); @@ -6384,7 +6382,7 @@ public class RecoveredClassUtils { public void findFunctionsUsingAtexit() throws CancelledException, InvalidInputException { Function atexitFunction = null; - List atexitFunctions = extraUtils.getGlobalFunctions("_atexit"); + List atexitFunctions = extendedFlatAPI.getGlobalFunctions("_atexit"); if (atexitFunctions.size() != 1) { return; } @@ -6399,13 +6397,13 @@ public class RecoveredClassUtils { Reference ref = referenceIterator.next(); Address fromAddress = ref.getFromAddress(); - Function function = extraUtils.getFunctionContaining(fromAddress); + Function function = extendedFlatAPI.getFunctionContaining(fromAddress); if (function == null) { AddressSet subroutineAddresses = - extraUtils.getSubroutineAddresses(program, fromAddress); + extendedFlatAPI.getSubroutineAddresses(program, fromAddress); Address minAddress = subroutineAddresses.getMinAddress(); - function = extraUtils.createFunction(minAddress, null); + function = extendedFlatAPI.createFunction(minAddress, null); if (function == null) { continue; } @@ -6440,9 +6438,9 @@ public class RecoveredClassUtils { continue; } - Function calledFunction = extraUtils.getFunctionAt(calledAddress); + Function calledFunction = extendedFlatAPI.getFunctionAt(calledAddress); if (calledFunction == null) { - calledFunction = extraUtils.createFunction(calledAddress, null); + calledFunction = extendedFlatAPI.createFunction(calledAddress, null); if (calledFunction == null) { continue; } @@ -6493,7 +6491,7 @@ public class RecoveredClassUtils { Address vftableAddress = vftableIterator.next(); // this gets the first function pointer in the vftable - Function firstVirtualFunction = extraUtils.getPointedToFunction(vftableAddress); + Function firstVirtualFunction = extendedFlatAPI.getPointedToFunction(vftableAddress); processDeletingDestructor(recoveredClass, firstVirtualFunction); } } @@ -6539,7 +6537,7 @@ public class RecoveredClassUtils { monitor.checkCanceled(); Address vftableAddress = vftableAddressIterator.next(); - Function firstVirtualFunction = extraUtils.getPointedToFunction(vftableAddress); + Function firstVirtualFunction = extendedFlatAPI.getPointedToFunction(vftableAddress); List virtualFunctions = recoveredClass.getVirtualFunctions(vftableAddress); @@ -6646,7 +6644,7 @@ public class RecoveredClassUtils { Function function = functionIterator.next(); - if (extraUtils.doesFunctionACallFunctionB(firstVirtualFunction, function)) { + if (extendedFlatAPI.doesFunctionACallFunctionB(firstVirtualFunction, function)) { recoveredClass.addDeletingDestructor(firstVirtualFunction); addDestructorToClass(recoveredClass, function); recoveredClass.removeIndeterminateConstructorOrDestructor(function); @@ -7011,7 +7009,7 @@ public class RecoveredClassUtils { // if the computed class struct has field name (ie from pdb) use it otherwise create one if (definedComponent.getFieldName() == null) { - fieldName = "offset_" + extraUtils.toHexString(offset, false, true); + fieldName = "offset_" + extendedFlatAPI.toHexString(offset, false, true); } else { fieldName = definedComponent.getFieldName(); @@ -7047,7 +7045,7 @@ public class RecoveredClassUtils { for (DataTypeComponent component : definedComponents) { monitor.checkCanceled(); - classStructureDataType = structUtils.addDataTypeToStructure( + classStructureDataType = EditStructureUtils.addDataTypeToStructure( classStructureDataType, component.getOffset(), component.getDataType(), component.getFieldName(), monitor); } @@ -7200,7 +7198,7 @@ public class RecoveredClassUtils { } String classNameWithNamespace = classNamespace.getName(true); - CategoryPath classPath = extraUtils.createDataTypeCategoryPath( + CategoryPath classPath = extendedFlatAPI.createDataTypeCategoryPath( classDataTypesCategoryPath, classNameWithNamespace); // check that the given vftable data type is in the right ClassDataTypes/