Skip to content

Ghidra is a software reverse engineering (SRE) framework

Merge remote-tracking branch 'origin/GP-1670_ghidra007_RecoveredClass_ReplaceInStructureBug--SQUASHED' into patch

ghidra1f2706bb1de85
diff --cc Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java
index 7d5c7ccb93,c5c75b6926..1ad132cb0c
--- a/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java
+++ b/Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java
@@@ -5530,36 -5489,39 +5530,38 @@@ public class RecoveredClassHelper
}
/**
- * Method to add the given structure component to the given structure at the given offset
- * @param structureDataType the structure to add to
- * @param structureToAdd the structure to add
- * @param startOffset the starting offset where to add
- * @param endOffset the ending offset of the added structure
- * @return the updated structure
+ * Method to add the structure components from the given structureToAdd from the given starting
+ * offset to the given ending offset of the to the given structure at the given offset
+ * @param structure the structure to add to
+ * @param structureToAdd the structure to add a subset of components from to the given structure
+ * @param startOffset the starting offset of where to start adding in the container structure
+ * @param dataLength the total length of the data components to add
+ * @return true if the structure was updated or false if the components cannot be added
* @throws CancelledException if cancelled
*/
- public Structure addIndividualComponentsToStructure(Structure structureDataType,
- Structure structureToAdd, int startOffset, int endOffset) throws CancelledException {
+ public boolean addIndividualComponentsToStructure(Structure structure, Structure structureToAdd,
+ int startOffset, int dataLength) throws CancelledException {
- DataTypeComponent[] definedComponents = structureToAdd.getDefinedComponents();
- for (int ii = 0; ii < definedComponents.length; ii++) {
+ // this check does not allow growing of structure. It only allows adding to the structure if
+ // the block of components to add will fit at the given offset
- if (!EditStructureUtils.canAdd(structure, startOffset, dataLength, false,
- monitor)) {
++ if (!EditStructureUtils.canAdd(structure, startOffset, dataLength, false, monitor)) {
+ return false;
+ }
- monitor.checkCanceled();
+ for (DataTypeComponent dataTypeComponent : structureToAdd.getDefinedComponents()) {
- DataTypeComponent dataTypeComponent = structureToAdd.getComponent(ii);
+ monitor.checkCanceled();
- int dataComponentOffset = dataTypeComponent.getOffset();
- if (endOffset != NONE && (dataComponentOffset + startOffset) >= endOffset) {
- return structureDataType;
+ // only copy the components up to the given total dataLength to copy
+ if ((dataTypeComponent.getOffset() + dataTypeComponent.getLength()) > dataLength) {
+ break;
}
- String fieldname = dataTypeComponent.getFieldName();
-
- structureDataType = EditStructureUtils.addDataTypeToStructure(structureDataType,
- startOffset + dataComponentOffset, dataTypeComponent.getDataType(), fieldname,
- monitor);
+ structure.replaceAtOffset(startOffset + dataTypeComponent.getOffset(),
+ dataTypeComponent.getDataType(), -1, dataTypeComponent.getFieldName(),
+ dataTypeComponent.getComment());
}
- return structureDataType;
+ return true;
}