Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0 added datatype archive spot-check ID tests

ghidra109e41bf32030
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeArchiveIDTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeArchiveIDTest.java
index de570004ea..d8176ec876 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeArchiveIDTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeArchiveIDTest.java
@@ -26,27 +26,33 @@ import org.junit.Test;
import generic.jar.ResourceFile;
import generic.test.AbstractGenericTest;
import ghidra.framework.Application;
-import ghidra.program.model.data.FileDataTypeManager;
+import ghidra.program.model.data.*;
public class DataTypeArchiveIDTest extends AbstractGenericTest {
+ private static final String WIN_VS12_32_GDT_PATH = "typeinfo/win32/windows_vs12_32.gdt";
+ private static final String WIN_VS12_64_GDT_PATH = "typeinfo/win32/windows_vs12_64.gdt";
+ private static final String GENERIC_CLIB_32_GDT_PATH = "typeinfo/generic/generic_clib.gdt";
+ private static final String GENERIC_CLIB_64_GDT_PATH = "typeinfo/generic/generic_clib_64.gdt";
+ private static final String MAC_OS_10_9_GDT_PATH = "typeinfo/mac_10.9/mac_osx.gdt";
+
private static final HashMap<String, String> archiveIdMap = new HashMap<>();
static {
- archiveIdMap.put("typeinfo/win32/windows_vs12_32.gdt", "2644092282468053077");
- archiveIdMap.put("typeinfo/win32/windows_vs12_64.gdt", "3193696833254024484");
- archiveIdMap.put("typeinfo/generic/generic_clib_64.gdt", "3193699959493190971");
- archiveIdMap.put("typeinfo/generic/generic_clib.gdt", "2644097909188870631");
- archiveIdMap.put("typeinfo/mac_10.9/mac_osx.gdt", "2650667045259492112");
+ archiveIdMap.put(WIN_VS12_32_GDT_PATH, "2644092282468053077");
+ archiveIdMap.put(WIN_VS12_64_GDT_PATH, "3193696833254024484");
+ archiveIdMap.put(GENERIC_CLIB_32_GDT_PATH, "2644097909188870631");
+ archiveIdMap.put(GENERIC_CLIB_64_GDT_PATH, "3193699959493190971");
+ archiveIdMap.put(MAC_OS_10_9_GDT_PATH, "2650667045259492112");
}
@Test
- public void testIDMatch() throws IOException {
+ public void testArchiveIDMatch() throws IOException {
HashSet<String> notFound = new HashSet<>(archiveIdMap.keySet());
- for (ResourceFile dtFile : Application.findFilesByExtensionInApplication(".gdt")) {
+ for (ResourceFile gdtFile : Application.findFilesByExtensionInApplication(".gdt")) {
- String path = dtFile.getAbsolutePath();
+ String path = gdtFile.getAbsolutePath();
if (!path.contains("/data/typeinfo/")) {
continue; // only verify standard archives
}
@@ -61,7 +67,7 @@ public class DataTypeArchiveIDTest extends AbstractGenericTest {
notFound.remove(path);
- FileDataTypeManager dtm = FileDataTypeManager.openFileArchive(dtFile, false);
+ FileDataTypeManager dtm = FileDataTypeManager.openFileArchive(gdtFile, false);
try {
assertEquals("Archive UniversalID mismatch: " + path, oldID,
dtm.getUniversalID().toString());
@@ -81,4 +87,90 @@ public class DataTypeArchiveIDTest extends AbstractGenericTest {
}
+ private void verifyArchive(DataType dt, String gdtPath) {
+ SourceArchive sourceArchive = dt.getSourceArchive();
+ assertEquals(archiveIdMap.get(gdtPath), sourceArchive.getSourceArchiveID().toString());
+ int ix = gdtPath.lastIndexOf('/');
+ String gdtName = gdtPath.substring(ix + 1);
+ ix = gdtName.indexOf(".gdt");
+ gdtName = gdtName.substring(0, ix); // strip-off file extension
+ assertEquals(gdtName, sourceArchive.getName());
+ }
+
+ @Test
+ public void spotCheckWindowsVS12_32() throws IOException {
+ ResourceFile gdtFile = Application.getModuleDataFile(WIN_VS12_32_GDT_PATH);
+ FileDataTypeManager dtm = FileDataTypeManager.openFileArchive(gdtFile, false);
+ try {
+ DataType dt = dtm.getDataType("/winsock.h/fd_set");
+ assertNotNull(dt);
+ assertEquals("2592696207400888580", dt.getUniversalID().toString());
+ verifyArchive(dt, WIN_VS12_32_GDT_PATH);
+ }
+ finally {
+ dtm.close();
+ }
+ }
+
+
+ @Test
+ public void spotCheckWindowsVS12_64() throws IOException {
+ ResourceFile gdtFile = Application.getModuleDataFile(WIN_VS12_64_GDT_PATH);
+ FileDataTypeManager dtm = FileDataTypeManager.openFileArchive(gdtFile, false);
+ try {
+ DataType dt = dtm.getDataType("/winsock.h/fd_set");
+ assertNotNull(dt);
+ assertEquals("3193696894570554681", dt.getUniversalID().toString());
+ verifyArchive(dt, WIN_VS12_64_GDT_PATH);
+ }
+ finally {
+ dtm.close();
+ }
+ }
+
+ @Test
+ public void spotCheckGenericCLib32() throws IOException {
+ ResourceFile gdtFile = Application.getModuleDataFile(GENERIC_CLIB_32_GDT_PATH);
+ FileDataTypeManager dtm = FileDataTypeManager.openFileArchive(gdtFile, false);
+ try {
+ DataType dt = dtm.getDataType("/select.h/fd_set");
+ assertNotNull(dt);
+ assertEquals("2592696207400888580", dt.getUniversalID().toString());
+ verifyArchive(dt, GENERIC_CLIB_32_GDT_PATH);
+ }
+ finally {
+ dtm.close();
+ }
+ }
+
+ @Test
+ public void spotCheckGenericCLib64() throws IOException {
+ ResourceFile gdtFile = Application.getModuleDataFile(GENERIC_CLIB_64_GDT_PATH);
+ FileDataTypeManager dtm = FileDataTypeManager.openFileArchive(gdtFile, false);
+ try {
+ DataType dt = dtm.getDataType("/select.h/fd_set");
+ assertNotNull(dt);
+ assertEquals("3193700096632251689", dt.getUniversalID().toString());
+ verifyArchive(dt, GENERIC_CLIB_64_GDT_PATH);
+ }
+ finally {
+ dtm.close();
+ }
+ }
+
+ @Test
+ public void spotCheckMacOS10_9() throws IOException {
+ ResourceFile gdtFile = Application.getModuleDataFile(MAC_OS_10_9_GDT_PATH);
+ FileDataTypeManager dtm = FileDataTypeManager.openFileArchive(gdtFile, false);
+ try {
+ DataType dt = dtm.getDataType("/_fd_def.h/fd_set");
+ assertNotNull(dt);
+ assertEquals("3015963966244190568", dt.getUniversalID().toString());
+ verifyArchive(dt, MAC_OS_10_9_GDT_PATH);
+ }
+ finally {
+ dtm.close();
+ }
+ }
+
}