diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/CommitDialog.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/CommitDialog.png index ed14f0cc2c..4c4ce221e7 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/CommitDialog.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/CommitDialog.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DataTypeManager.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DataTypeManager.png index 9c0184df11..350313c5c1 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DataTypeManager.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DataTypeManager.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DisassociateDialog.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DisassociateDialog.png index 906206d70f..6426868cbc 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DisassociateDialog.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/DisassociateDialog.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FavoriteDts.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FavoriteDts.png index 5368f27b6c..5b7cb6a0dc 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FavoriteDts.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FavoriteDts.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FindDataTypesBySize.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FindDataTypesBySize.png index 13e21e5ed8..7fe6f46aa4 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FindDataTypesBySize.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/FindDataTypesBySize.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/MergeErrorDialog.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/MergeErrorDialog.png index 5813d6e57f..307b4dc034 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/MergeErrorDialog.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/MergeErrorDialog.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/PreviewWindow.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/PreviewWindow.png index 9d79b7df64..7019669931 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/PreviewWindow.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/PreviewWindow.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/RevertDialog.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/RevertDialog.png index a897e616a2..0d78cd4f7b 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/RevertDialog.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/RevertDialog.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/SearchResults.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/SearchResults.png index bff1b63aab..0cab53ed93 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/SearchResults.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/SearchResults.png differ diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/UpdateDialog.png b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/UpdateDialog.png index bea0f431b6..4796fe421b 100644 Binary files a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/UpdateDialog.png and b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/images/UpdateDialog.png differ diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java index 0c55620640..c440262c29 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java @@ -1283,14 +1283,16 @@ abstract public class DataTypeManagerDB implements DataTypeManager { resolvedDataType = resolveDataTypeNoSource(dataType); } else if (!sourceArchive.getSourceArchiveID().equals(getUniversalID()) && - (sourceArchive.getArchiveType() == ArchiveType.PROGRAM || - sourceArchive.getArchiveType() == ArchiveType.TEMPORARY)) { - // dataTypes from a program or temporary archive don't carry over their identity + !sourceArchive.getArchiveType().isValidSourceArchive()) { + + // dataTypes from a invalid source (program, built-in, temporary) archive + // don't carry over their identity resolvedDataType = resolveDataTypeNoSource(dataType); } else { resolvedDataType = resolveDataTypeWithSource(dataType); } + cacheResolvedDataType(dataType, resolvedDataType); if (resolvedDataType instanceof DataTypeDB) { setCachedEquivalence((DataTypeDB) resolvedDataType, dataType); @@ -4594,8 +4596,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager { } } - private record DedupedConflicts(int processCnt, int replaceCnt) { - } + private record DedupedConflicts(int processCnt, int replaceCnt) {} private DedupedConflicts doDedupeConflicts(DataType dataType) { diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ArchiveType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ArchiveType.java index 020a0ebb6e..398de44892 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ArchiveType.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/ArchiveType.java @@ -4,9 +4,9 @@ * 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. @@ -27,4 +27,11 @@ public enum ArchiveType { public boolean isBuiltIn() { return this == BUILT_IN; } + + /** + * {@return true if this type is a valid type of source archive for adding types to the program} + */ + public boolean isValidSourceArchive() { + return this == FILE || this == PROJECT; + } } diff --git a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/DataTypeManagerPluginScreenShots.java b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/DataTypeManagerPluginScreenShots.java index 58b9e4ecd5..290421e0a4 100644 --- a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/DataTypeManagerPluginScreenShots.java +++ b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/DataTypeManagerPluginScreenShots.java @@ -79,17 +79,6 @@ public class DataTypeManagerPluginScreenShots extends GhidraScreenShotGenerator captureIsolatedProvider(DataTypesProvider.class, 500, 400); } - @Test - public void testDataTypeTreeWithAssociations() { - DataTypesProvider provider = getProvider(DataTypesProvider.class); - GTree tree = (GTree) getInstanceField("archiveGTree", provider); - GTreeNode rootNode = tree.getViewRoot(); - GTreeNode child = rootNode.getChild("WinHelloCPP.exe"); - child = child.getChild("basetsd.h"); - tree.expandPath(child); - captureIsolatedProvider(DataTypesProvider.class, 500, 400); - } - @Test public void testDisassociateDialog() { DataTypeManagerPlugin plugin = getPlugin(tool, DataTypeManagerPlugin.class); @@ -196,8 +185,8 @@ public class DataTypeManagerPluginScreenShots extends GhidraScreenShotGenerator @Test public void testFindDataTypes() { - performAction("Find Data Types", "DataTypeManagerPlugin", false); - JDialog d = waitForJDialog("Find Data Types"); + performAction("Find Data Types by Name", "DataTypeManagerPlugin", false); + JDialog d = waitForJDialog("Find Data Types by Name"); captureDialog(); pressButtonByText(d, "Cancel"); } @@ -260,7 +249,8 @@ public class DataTypeManagerPluginScreenShots extends GhidraScreenShotGenerator closeNonProgramArchives(); closeProvider(DataTypesProvider.class); - runSwing(() -> performAction("Find Data Types", "DataTypeManagerPlugin", false), false); + runSwing(() -> performAction("Find Data Types by Name", "DataTypeManagerPlugin", false), + false); final DialogComponentProvider dialog = getDialog(); runSwing(() -> { @@ -281,41 +271,26 @@ public class DataTypeManagerPluginScreenShots extends GhidraScreenShotGenerator DataTypeManagerPlugin plugin = getPlugin(tool, DataTypeManagerPlugin.class); List list = new ArrayList<>(); Set set = new HashSet<>(); - createChangedDatatypesFromArchive(list, set); + StandAloneDataTypeManager sourceDtm = createChangedDatatypesFromArchive(list, set); - DataTypeManager dtm = program.getDataTypeManager(); + DataType dt1 = sourceDtm.getDataType("/MyDataType1"); - StandAloneDataTypeManager sourceDTM = new StandAloneDataTypeManager("MyArhcive"); - StructureDataType sdt1 = new StructureDataType("MyDataType1", 0); - sdt1.add(new PointerDataType(new StringDataType()), "name", null); - sdt1.add(new IntegerDataType(), "age", null); - sdt1.add(new PointerDataType(new VoidDataType()), "data", null); + Structure struct = tx(program, () -> { + DataTypeManager dtm = program.getDataTypeManager(); + return (Structure) dtm.addDataType(dt1, null); + }); - StructureDataType sdt2 = new StructureDataType("MyDataType2", 0); - sdt2.add(new PointerDataType(new IntegerDataType())); - sdt2.add(new IntegerDataType()); - sdt2.add(new WordDataType()); + tx(sourceDtm, () -> { + ((Structure) dt1).add(new IntegerDataType(), "id", null); + }); - int id = sourceDTM.startTransaction("Test"); - DataType dt1 = sourceDTM.addDataType(sdt1, null); - sourceDTM.endTransaction(id, true); - - int txID = program.startTransaction("Test"); - Structure struct = (Structure) dtm.addDataType(dt1, null); - program.endTransaction(txID, true); - - id = sourceDTM.startTransaction("Test2"); - ((Structure) dt1).add(new IntegerDataType(), "id", null); - sourceDTM.endTransaction(id, true); - - DataTypeSyncInfo sync1 = new DataTypeSyncInfo(struct, sourceDTM); + DataTypeSyncInfo sync1 = new DataTypeSyncInfo(struct, sourceDtm); list.add(sync1); set.add(sync1); - final DataTypeSyncDialog dialog = + DataTypeSyncDialog dialog = new DataTypeSyncDialog(plugin, "WinHelloCPP.exe", "MyArchive", list, set, "Update", "Update DataType Changes From Archive \"MyArchive\" To \"WinHelloCpp.exe\" "); - showModalDialogInTool(dialog); runSwing(() -> { @@ -360,11 +335,18 @@ public class DataTypeManagerPluginScreenShots extends GhidraScreenShotGenerator return null;// cannot get here } - private void createChangedDatatypesFromArchive(List list, + private StandAloneDataTypeManager createChangedDatatypesFromArchive(List list, Set set) { DataTypeManager dtm = program.getDataTypeManager(); - StandAloneDataTypeManager sourceDTM = new StandAloneDataTypeManager("MyArhcive"); + StandAloneDataTypeManager sourceDtm = new StandAloneDataTypeManager("MyArhcive") { + @Override + public ArchiveType getType() { + // Need to not be the default TEMPORARY type so that the universal ID of our data + // types will be maintained. This is needed to associate the types. + return ArchiveType.FILE; + } + }; StructureDataType sdt1 = new StructureDataType("MyDataType1", 0); sdt1.add(new PointerDataType(new StringDataType()), "name", null); sdt1.add(new IntegerDataType(), "age", null); @@ -375,27 +357,26 @@ public class DataTypeManagerPluginScreenShots extends GhidraScreenShotGenerator sdt2.add(new IntegerDataType()); sdt2.add(new WordDataType()); - int id = sourceDTM.startTransaction("Test"); - DataType dt1 = sourceDTM.addDataType(sdt1, null); - DataType dt2 = sourceDTM.addDataType(sdt2, null); - sourceDTM.endTransaction(id, true); + int id = sourceDtm.startTransaction("Test"); + DataType dt1 = sourceDtm.addDataType(sdt1, null); + DataType dt2 = sourceDtm.addDataType(sdt2, null); + sourceDtm.endTransaction(id, true); + + tx(program, () -> { - int txID = program.startTransaction("Test"); - try { Structure struct = (Structure) dtm.addDataType(dt1, null); struct.add(new IntegerDataType(), "id", null); Structure struct2 = (Structure) dtm.addDataType(dt2, null); struct2.add(new IntegerDataType()); - DataTypeSyncInfo sync1 = new DataTypeSyncInfo(struct, sourceDTM); - DataTypeSyncInfo sync2 = new DataTypeSyncInfo(struct2, sourceDTM); + DataTypeSyncInfo sync1 = new DataTypeSyncInfo(struct, sourceDtm); + DataTypeSyncInfo sync2 = new DataTypeSyncInfo(struct2, sourceDtm); list.add(sync1); list.add(sync2); set.add(sync1); - } - finally { - program.endTransaction(txID, true); - } + }); + + return sourceDtm; } private void showModalDialogInTool(final DialogComponentProvider dialog) {