Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6846 Added C99 fixed-length and pointer-length BuiltIn integer data types. Revised CParser, DWARF and PDB parsers to leverage these datatypes.

ghidra1fd8d504eb6a7
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeImporter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeImporter.java
index af1b6347e5..ef57d83d67 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeImporter.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeImporter.java
@@ -1236,12 +1236,13 @@ public class DWARFDataTypeImporter {
* pointing to the destination and omit creating a Ghidra typedef.
* <p>
* If the typedef points (via a pointer) to a function definition type that doesn't
- * have a name yet, update the function defintion with the name from this typedef
+ * have a name yet, update the function definition with the name from this typedef
* and elide this typedef.
* <p>
* If the typedef points to a base type (eg int, float, etc), let the base type factory
* create the typedef as it can do it better if there are size specifiers in the typedef name
- * (eg. int64_t).
+ * (eg. int64_t). Standard typedefs may be replaced by a Ghidra BuiltIn or alternative
+ * typedef that leverage a BuiltIn for well-known cases.
*
*/
private DWARFDataType makeDataTypeForTypedef(DIEAggregate diea)
@@ -1294,9 +1295,14 @@ public class DWARFDataTypeImporter {
TypedefDataType typedefDT = new TypedefDataType(typedefDNI.getParentCP(),
typedefDNI.getName(), refdDT.dataType, dataTypeManager);
- updateMapping(refdDT.dataType, typedefDT.getDataType());
+ DataType resultDT = DataTypeUtilities.getTypedefReplacement(typedefDT, true);
- return new DWARFDataType(typedefDT, typedefDNI, diea.getOffset());
+// TODO: Original code appeared to update mapping with no real impact
+// TODO: Re-examine what should be done for updateMapping if anything.
+// updateMapping(refdDT.dataType,
+// resultDT instanceof TypeDef tdResult ? tdResult.getDataType() : resultDT);
+
+ return new DWARFDataType(resultDT, typedefDNI, diea.getOffset());
}
/*
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeManager.java
index 831ec171b5..dd70c7c923 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeManager.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataTypeManager.java
@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
import ghidra.app.util.bin.format.dwarf.DWARFDataTypeImporter.DWARFDataType;
import ghidra.app.util.bin.format.dwarf.expression.DWARFExpressionException;
import ghidra.program.database.DbObject;
+import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.data.*;
import ghidra.program.model.lang.CompilerSpec;
import ghidra.program.model.listing.Program;
@@ -443,7 +444,9 @@ public class DWARFDataTypeManager {
}
if (name != null /* mangledName also will be non-null */) {
- dt = new TypedefDataType(prog.getRootDNI().asCategoryPath(), name, dt, dataTypeManager);
+ TypedefDataType typedef =
+ new TypedefDataType(prog.getRootDNI().asCategoryPath(), name, dt, dataTypeManager);
+ dt = DataTypeUtilities.getTypedefReplacement(typedef, true);
dt = dataTypeManager.addDataType(dt, DataTypeConflictHandler.DEFAULT_HANDLER);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoTypeManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoTypeManager.java
index f110559c78..f3b08b1f81 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoTypeManager.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/golang/rtti/GoTypeManager.java
@@ -791,16 +791,16 @@ public class GoTypeManager {
case Float32 -> AbstractFloatDataType.getFloatDataType(32 / 8, null);
case Float64 -> AbstractFloatDataType.getFloatDataType(64 / 8, null);
case Int -> AbstractIntegerDataType.getSignedDataType(ptrSize, dtm); // depends on arch
- case Int8 -> AbstractIntegerDataType.getSignedDataType(8 / 8, null);
- case Int16 -> AbstractIntegerDataType.getSignedDataType(16 / 8, null);
- case Int32 -> AbstractIntegerDataType.getSignedDataType(32 / 8, null);
- case Int64 -> AbstractIntegerDataType.getSignedDataType(64 / 8, null);
+ case Int8 -> Int8TDataType.dataType;
+ case Int16 -> Int16TDataType.dataType;
+ case Int32 -> Int32TDataType.dataType;
+ case Int64 -> Int64TDataType.dataType;
case Uint -> AbstractIntegerDataType.getUnsignedDataType(ptrSize, dtm); // depends on arch
- case Uint8 -> AbstractIntegerDataType.getUnsignedDataType(8 / 8, null);
- case Uint16 -> AbstractIntegerDataType.getUnsignedDataType(16 / 8, null);
- case Uint32 -> AbstractIntegerDataType.getUnsignedDataType(32 / 8, null);
- case Uint64 -> AbstractIntegerDataType.getUnsignedDataType(64 / 8, null);
- case Uintptr -> AbstractIntegerDataType.getUnsignedDataType(ptrSize, dtm); // depends on arch
+ case Uint8 -> UInt8TDataType.dataType;
+ case Uint16 -> UInt16TDataType.dataType;
+ case Uint32 -> UInt32TDataType.dataType;
+ case Uint64 -> UInt64TDataType.dataType;
+ case Uintptr -> UnsignedPointerSizedIntegerDataType.dataType.clone(dtm);
case String -> buildStringStruct();
case Pointer, UnsafePointer -> getVoidPtrDT(); // depends on arch
default -> null;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledDataType.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledDataType.java
index 0474f0fed0..6eeef67874 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledDataType.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledDataType.java
@@ -312,52 +312,50 @@ public class DemangledDataType extends DemangledType {
}
else if (INT8.equals(name)) {
if (isUnsigned()) {
- dt = new TypedefDataType("__uint8",
- AbstractIntegerDataType.getUnsignedDataType(1, dataTypeManager));
+ dt = new TypedefDataType("__uint8", UInt8TDataType.dataType.clone(dataTypeManager));
}
else {
- dt = new TypedefDataType(INT8,
- AbstractIntegerDataType.getSignedDataType(1, dataTypeManager));
+ dt = new TypedefDataType(INT8, Int8TDataType.dataType.clone(dataTypeManager));
}
}
else if (INT16.equals(name)) {
if (isUnsigned()) {
dt = new TypedefDataType("__uint16",
- AbstractIntegerDataType.getUnsignedDataType(2, dataTypeManager));
+ UInt16TDataType.dataType.clone(dataTypeManager));
}
else {
dt = new TypedefDataType(INT16,
- AbstractIntegerDataType.getSignedDataType(2, dataTypeManager));
+ Int16TDataType.dataType.clone(dataTypeManager));
}
}
else if (INT32.equals(name)) {
if (isUnsigned()) {
dt = new TypedefDataType("__uint32",
- AbstractIntegerDataType.getUnsignedDataType(4, dataTypeManager));
+ UInt32TDataType.dataType.clone(dataTypeManager));
}
else {
dt = new TypedefDataType(INT32,
- AbstractIntegerDataType.getSignedDataType(4, dataTypeManager));
+ Int32TDataType.dataType.clone(dataTypeManager));
}
}
else if (INT64.equals(name)) {
if (isUnsigned()) {
dt = new TypedefDataType("__uint64",
- AbstractIntegerDataType.getUnsignedDataType(8, dataTypeManager));
+ UInt64TDataType.dataType.clone(dataTypeManager));
}
else {
dt = new TypedefDataType(INT64,
- AbstractIntegerDataType.getSignedDataType(8, dataTypeManager));
+ Int64TDataType.dataType.clone(dataTypeManager));
}
}
else if (INT128.equals(name)) {
if (isUnsigned()) {
dt = new TypedefDataType("__uint128",
- AbstractIntegerDataType.getUnsignedDataType(16, dataTypeManager));
+ UnsignedInteger16DataType.dataType.clone(dataTypeManager));
}
else {
dt = new TypedefDataType(INT128,
- AbstractIntegerDataType.getSignedDataType(16, dataTypeManager));
+ Integer16DataType.dataType.clone(dataTypeManager));
}
}
else if (UNDEFINED.equals(name)) {
diff --git a/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/C/C.jj b/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/C/C.jj
index e8ee3b0f7c..3b990dbaa8 100644
--- a/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/C/C.jj
+++ b/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/C/C.jj
@@ -81,6 +81,7 @@ PARSER_BEGIN(CParser)
package ghidra.app.util.cparser.C;
+import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
import ghidra.program.model.lang.CompilerSpec;
@@ -225,13 +226,9 @@ public class CParser {
}
}
- // TODO: for builtin-Types, override with the built-in
- // wchar_t, etc...
- if (type.equals("wchar_t")) {
- dt = WideCharDataType.dataType;
- } else {
- dt = new TypedefDataType(getCurrentCategoryPath(), type, dt, dtMgr);
- }
+ TypedefDataType td = new TypedefDataType(getCurrentCategoryPath(), type, dt, dtMgr);
+ dt = DataTypeUtilities.getTypedefReplacement(td, false);
+
dt = addDef(types, type, dt);
return dt;
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/CParserTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/CParserTest.java
index d0096b59a4..dde1e49fd8 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/CParserTest.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/util/cparser/CParserTest.java
@@ -42,50 +42,148 @@ public class CParserTest extends AbstractGhidraHeadlessIntegrationTest {
DataType pdt = parser.parse("typedef long int32_t;");
assertTrue(pdt != null);
- assertTrue(pdt instanceof TypeDef);
+ assertTrue(pdt instanceof Int32TDataType);
assertTrue(pdt.getName().equals("int32_t"));
DataType dt = parser.getDataTypeManager().getDataType("/int32_t");
assertTrue(dt != null);
- assertTrue(dt instanceof TypeDef);
+ assertTrue(dt instanceof Int32TDataType);
dt = parser.parse("struct mystruct {" +
- " int field1;" +
- " char field2;" +
- " };");
+ " int32_t field1;" +
+ " char field2;" +
+ " };");
assertTrue(dt != null);
assertTrue(dt instanceof Structure);
Structure sdt = (Structure) dt;
DataTypeComponent comp = sdt.getComponent(0);
assertEquals("field1", comp.getFieldName());
- assertEquals(comp.getDataType().getName(),"int");
+ assertEquals("int32_t", comp.getDataType().getName());
comp = sdt.getComponent(1);
assertEquals("field2", comp.getFieldName());
assertEquals(comp.getDataType().getName(),"char");
}
@Test
- public void testLongLong() throws Exception {
+ public void testReplacement1() throws Exception {
+ CParser parser = new CParser();
+
+ DataType pdt = parser.parse("typedef long __int32_t;");
+ assertTrue(pdt instanceof TypeDef);
+ assertEquals("typedef __int32_t int32_t", pdt.toString());
+
+ pdt = parser.parse("typedef __int32_t int32_t;");
+ assertTrue(pdt instanceof Int32TDataType);
+ assertTrue(pdt.getName().equals("int32_t"));
+ assertEquals("int32_t", pdt.toString());
+
+ DataType dt = parser.getDataTypeManager().getDataType("/int32_t");
+ assertTrue(dt != null);
+ assertTrue(dt instanceof Int32TDataType);
+
+ dt = parser.parse("struct mystruct {" +
+ " int32_t field1;" +
+ " char field2;" +
+ " };");
+
+ assertTrue(dt != null);
+ assertTrue(dt instanceof Structure);
+ Structure sdt = (Structure) dt;
+ DataTypeComponent comp = sdt.getComponent(0);
+ assertEquals("field1", comp.getFieldName());
+ assertEquals("int32_t", comp.getDataType().getName());
+ comp = sdt.getComponent(1);
+ assertEquals("field2", comp.getFieldName());
+ assertEquals(comp.getDataType().getName(), "char");
+ }
+
+ @Test
+ public void testReplacement2() throws Exception {
+ CParser parser = new CParser();
+
+ DataType pdt = parser.parse("typedef long int32_t;");
+ assertTrue(pdt instanceof Int32TDataType);
+ assertTrue(pdt.getName().equals("int32_t"));
+ assertEquals("int32_t", pdt.toString());
+
+ pdt = parser.parse("typedef int32_t __int32_t;");
+ assertTrue(pdt instanceof TypeDef);
+ assertEquals("typedef __int32_t int32_t", pdt.toString());
+ assertTrue(pdt.getName().equals("__int32_t"));
+ DataType dt = parser.getDataTypeManager().getDataType("/__int32_t");
+ assertTrue(dt != null);
+ assertTrue(dt instanceof TypeDef);
+
+ dt = parser.parse("struct mystruct {" +
+ " __int32_t field1;" +
+ " char field2;" +
+ " };");
+
+ assertTrue(dt != null);
+ assertTrue(dt instanceof Structure);
+ Structure sdt = (Structure) dt;
+ DataTypeComponent comp = sdt.getComponent(0);
+ assertEquals("field1", comp.getFieldName());
+ assertEquals("__int32_t", comp.getDataType().getName());
+ comp = sdt.getComponent(1);
+ assertEquals("field2", comp.getFieldName());
+ assertEquals(comp.getDataType().getName(), "char");
+ }
+
+ @Test
+ public void testLongInt() throws Exception {
CParser parser;
+ parser = new CParser(); // uses default data organization (i.e., x86-32)
+ DataType pdt32 = parser.parse("typedef unsigned long int u_int32_t;");
+
+ assertTrue(pdt32 instanceof TypeDef);
+ assertTrue(pdt32.getName().equals("u_int32_t"));
+ assertEquals(4, pdt32.getLength());
+
+ // replaced with `typedef uint32_t u_int32_t`
+ DataType dt = ((TypeDef) pdt32).getBaseDataType();
+ assertTrue(dt instanceof UInt32TDataType);
+
+ dt = parser.getDataTypeManager().getDataType("/u_int32_t");
+ assertTrue(dt instanceof TypeDef);
+ assertEquals(4, dt.getLength());
+ dt = parser.getDataTypeManager().getDataType("/uint32_t");
+ assertTrue(dt instanceof UInt32TDataType);
+ assertEquals(4, dt.getLength());
+
parser = new CParser();
- DataType pdt64 = parser.parse("typedef unsigned long int uint64_t;");
+ pdt32 = parser.parse("typedef unsigned long int foo_t;");
+ assertTrue(pdt32 instanceof TypeDef);
+ assertTrue(pdt32.getName().equals("foo_t"));
+ assertEquals(4, pdt32.getLength());
+
+ dt = parser.getDataTypeManager().getDataType("/foo_t");
+ assertTrue(dt instanceof TypeDef);
+ assertEquals(4, dt.getLength());
+ }
+
+ @Test
+ public void testLongLong() throws Exception {
+ CParser parser;
- assertTrue(pdt64 != null);
- assertTrue(pdt64 instanceof TypeDef);
+ parser = new CParser(); // uses default data organization (i.e., x86-32)
+ DataType pdt64 = parser.parse("typedef unsigned long long uint64_t;");
+
+ assertTrue(pdt64 instanceof UInt64TDataType);
assertTrue(pdt64.getName().equals("uint64_t"));
- assertEquals(4, pdt64.getLength());
+ assertEquals(8, pdt64.getLength());
DataType dt = parser.getDataTypeManager().getDataType("/uint64_t");
- assertTrue(dt != null);
- assertTrue(dt instanceof TypeDef);
+ assertTrue(dt instanceof UInt64TDataType);
+ assertEquals(8, dt.getLength());
parser = new CParser();
- DataType pdt32 = parser.parse("typedef unsigned long long int uint64_t;");
- assertTrue(pdt32 != null);
- assertTrue(pdt32 instanceof TypeDef);
- assertTrue(pdt32.getName().equals("uint64_t"));
- assertEquals(8, pdt32.getLength());
+ pdt64 = parser.parse("typedef unsigned long long int uint64_t;");
+ assertTrue(pdt64 instanceof UInt64TDataType);
+ assertTrue(pdt64.getName().equals("uint64_t"));
+ assertEquals(8, pdt64.getLength());
+
}
@Test
@@ -118,8 +216,8 @@ public class CParserTest extends AbstractGhidraHeadlessIntegrationTest {
CParser parser;
- parser = new CParser();
- dt = parser.parse("typedef int wchar_t;");
+ parser = new CParser(); // uses default data organization (i.e., x86-32)
+ dt = parser.parse("typedef short wchar_t;");
assertTrue(dt instanceof WideCharDataType);
@@ -394,7 +492,7 @@ public class CParserTest extends AbstractGhidraHeadlessIntegrationTest {
dt = dtMgr.getDataType("/int32_t");
assertTrue(dt != null);
- assertTrue(dt instanceof TypeDef);
+ assertTrue(dt instanceof Int32TDataType);
// typedef long unsigned int LUI_size_t;
dt = dtMgr.getDataType("/LUI_size_t");
diff --git a/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/CParserTest.h b/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/CParserTest.h
index 350877d7d7..d4d09ee4c6 100644
--- a/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/CParserTest.h
+++ b/Ghidra/Features/Base/src/test/resources/ghidra/app/util/cparser/CParserTest.h
@@ -439,8 +439,10 @@ enum __attribute__((enum_extensibility(open))) OpenEnum {
typedef int (__cdecl * _onexit_t)(void);
-typedef int int32_t;
-typedef long int64_t;
+typedef int __int32_t;
+typedef __int32_t int32_t;
+typedef long __int64_t;
+typedef __int64_t int64_t;
static __inline __attribute__((always_inline)) int
__checkint(int val, int* err) {
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyTypeDefs.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyTypeDefs.java
index 380a9bad14..23838d2b9b 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyTypeDefs.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyTypeDefs.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.
@@ -21,7 +21,7 @@ import java.util.List;
import org.xml.sax.SAXParseException;
import ghidra.app.util.importer.MessageLog;
-import ghidra.program.model.data.TypedefDataType;
+import ghidra.program.model.data.DataType;
import ghidra.program.model.symbol.SymbolUtilities;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -109,7 +109,8 @@ class ApplyTypeDefs {
continue;
}
- TypedefDataType typedef =
+ // The createtypeDef method may perform a replacement with a BuiltIn datatype
+ DataType typedef =
pdbParser.createTypeDef(datatypeName, baseDataType.getDataType());
pdbParser.cacheDataType(datatypeName, typedef); // cache with namespace-based name
}
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbDataTypeParser.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbDataTypeParser.java
index 08afa07fbd..08a78bee4d 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbDataTypeParser.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbDataTypeParser.java
@@ -52,25 +52,22 @@ class PdbDataTypeParser {
cachePrimitiveDataType(new TypedefDataType("wchar", WideCharDataType.dataType));
- cachePrimitiveDataType(new TypedefDataType("__int8",
- AbstractIntegerDataType.getSignedDataType(1, programDataTypeMgr)));
- cachePrimitiveDataType(new TypedefDataType("__uint8",
- AbstractIntegerDataType.getUnsignedDataType(1, programDataTypeMgr)));
-
- cachePrimitiveDataType(new TypedefDataType("__int16",
- AbstractIntegerDataType.getSignedDataType(2, programDataTypeMgr)));
- cachePrimitiveDataType(new TypedefDataType("__uint16",
- AbstractIntegerDataType.getUnsignedDataType(2, programDataTypeMgr)));
-
- cachePrimitiveDataType(new TypedefDataType("__int32",
- AbstractIntegerDataType.getSignedDataType(4, programDataTypeMgr)));
- cachePrimitiveDataType(new TypedefDataType("__uint32",
- AbstractIntegerDataType.getUnsignedDataType(2, programDataTypeMgr)));
-
- cachePrimitiveDataType(new TypedefDataType("__int64",
- AbstractIntegerDataType.getSignedDataType(8, programDataTypeMgr)));
- cachePrimitiveDataType(new TypedefDataType("__uint64",
- AbstractIntegerDataType.getUnsignedDataType(8, programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__int8", Int8TDataType.dataType.clone(programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__uint8", UInt8TDataType.dataType.clone(programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__int16", Int16TDataType.dataType.clone(programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__uint16", UInt16TDataType.dataType.clone(programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__int32", Int32TDataType.dataType.clone(programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__uint32", UInt32TDataType.dataType.clone(programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__int64", Int64TDataType.dataType.clone(programDataTypeMgr)));
+ cachePrimitiveDataType(
+ new TypedefDataType("__uint64", UInt64TDataType.dataType.clone(programDataTypeMgr)));
}
/**
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParser.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParser.java
index b98adad4c8..07c5f2a9ac 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParser.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParser.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.
@@ -31,6 +31,7 @@ import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.pdb.PdbProgramAttributes;
import ghidra.framework.*;
import ghidra.framework.options.Options;
+import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
@@ -760,10 +761,11 @@ public class PdbParser {
return new UnionDataType(getCategory(path.getParent(), true), path.getName(), dataMgr);
}
- TypedefDataType createTypeDef(String name, DataType baseDataType) {
+ DataType createTypeDef(String name, DataType baseDataType) {
SymbolPath path = new SymbolPath(name);
- return new TypedefDataType(getCategory(path.getParent(), true), path.getName(),
+ TypeDef td = new TypedefDataType(getCategory(path.getParent(), true), path.getName(),
baseDataType, dataMgr);
+ return DataTypeUtilities.getTypedefReplacement(td, true);
}
EnumDataType createEnum(String name, int length) {
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbPrimitiveTypeApplicator.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbPrimitiveTypeApplicator.java
index eb5286a2ee..88bc499e8f 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbPrimitiveTypeApplicator.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbPrimitiveTypeApplicator.java
@@ -19,6 +19,7 @@ import java.util.*;
import ghidra.app.util.bin.format.pdb2.pdbreader.PdbLog;
import ghidra.app.util.bin.format.pdb2.pdbreader.type.PrimitiveMsType;
+import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.data.*;
import ghidra.util.exception.AssertException;
@@ -462,8 +463,9 @@ public class PdbPrimitiveTypeApplicator {
}
private DataType createTypedef(String name, DataType dataType) {
- DataType typedefDataType = new TypedefDataType(name, dataType);
- return resolve(typedefDataType);
+ TypeDef typedefDataType = new TypedefDataType(name, dataType);
+ DataType dt = DataTypeUtilities.getTypedefReplacement(typedefDataType, true);
+ return resolve(dt);
}
DataType createTypedefNamedSizedType(String name, int size) {
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TypedefSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TypedefSymbolApplier.java
index 1c4e6e6147..2f067b038c 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TypedefSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TypedefSymbolApplier.java
@@ -22,6 +22,7 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.symbol.AbstractUserDefinedTypeM
import ghidra.app.util.bin.format.pdb2.pdbreader.type.AbstractComplexMsType;
import ghidra.app.util.bin.format.pdb2.pdbreader.type.AbstractMsType;
import ghidra.app.util.pdb.PdbNamespaceUtils;
+import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.model.data.*;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.CancelledException;
@@ -120,10 +121,10 @@ public class TypedefSymbolApplier extends MsSymbolApplier
symbolPath = PdbNamespaceUtils.convertToGhidraPathName(symbolPath);
CategoryPath categoryPath =
applicator.getTypedefsCategory(applicator.getCurrentModuleNumber(), symbolPath);
- DataType typedef = new TypedefDataType(categoryPath.getParent(), categoryPath.getName(),
+ TypeDef typedef = new TypedefDataType(categoryPath.getParent(), categoryPath.getName(),
dataType, applicator.getDataTypeManager());
-
- return applicator.resolve(typedef);
+ DataType dt = DataTypeUtilities.getTypedefReplacement(typedef, true);
+ return applicator.resolve(dt);
}
private AbstractUserDefinedTypeMsSymbol getValidatedSymbol(MsSymbolIterator iter,
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java
index 8dae1301cc..7cb59e0d09 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeUtilities.java
@@ -63,6 +63,71 @@ public class DataTypeUtilities {
cPrimitiveNameMap.put("long double", LongDoubleDataType.dataType);
}
+ private static Map<String, DataType> cTypedefBuiltInNameRemap = new HashMap<>();
+ static {
+ cTypedefBuiltInNameRemap.put("int8_t", Int8TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int8_t", Int8TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int8", Int8TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("int_fast8_t", Int8TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("uint8_t", UInt8TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint8_t", UInt8TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint8", UInt8TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("uint_fast8_t", UInt8TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("u_int8_t", UInt8TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("int16_t", Int16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int16_t", Int16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int16", Int16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("int_fast16_t", Int16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("_G_int16_t", Int16TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("uint16_t", UInt16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint16_t", UInt16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint16", UInt16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("uint_fast16_t", UInt16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("u_int16_t", UInt16TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("_G_uint16_t", UInt16TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("int32_t", Int32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int32_t", Int32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int32", Int32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("int_fast32_t", Int32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("_G_int32_t", Int32TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("uint32_t", UInt32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint32_t", UInt32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint32", UInt32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("uint_fast32_t", UInt32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("u_int32_t", UInt32TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("_G_uint32_t", UInt32TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("int64_t", Int64TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int64_t", Int64TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__int64", Int64TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("int_fast64_t", Int64TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("uint64_t", UInt64TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint64_t", UInt64TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uint64", UInt64TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("uint_fast64_t", UInt64TDataType.dataType);
+ cTypedefBuiltInNameRemap.put("u_int64_t", UInt64TDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("intptr_t", PointerSizedIntegerDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__intptr_t", PointerSizedIntegerDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("uintptr_t", UnsignedPointerSizedIntegerDataType.dataType);
+ cTypedefBuiltInNameRemap.put("__uintptr_t", UnsignedPointerSizedIntegerDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("wchar_t", WideCharDataType.dataType);
+ cTypedefBuiltInNameRemap.put("wchar", WideCharDataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("char16_t", WideChar16DataType.dataType);
+
+ cTypedefBuiltInNameRemap.put("char32_t", WideChar32DataType.dataType);
+
+ }
+
// TODO: Should we drop the handling of "_" use in conflict name. It's unclear
// when/if this was ever used in the generation of a conflict name.
// NOTE: It is assumed that all BuiltInDataType types (other then possibly Pointers)
@@ -77,6 +142,95 @@ public class DataTypeUtilities {
private static final Pattern DATATYPE_POINTER_ARRAY_PATTERN =
Pattern.compile("(( \\*\\d*)|(\\[\\d+\\]))+$");
+ /**
+ * Get a BuiltIn {@link TypeDef} replacement, if one exists, for the specified fabricated
+ * typedef. It is important that the supplied typedef has the correct target
+ * {@link DataTypeManager} and associated {@link DataOrganization} so that a proper replacement
+ * verification may be performed.
+ * <p>
+ * This method is intended to be used by parsers prior to resolving or applying a fabricated
+ * fixed-length typedef to allow a portable implementation to be used in its place. If one
+ * exists, this ensures that its size will not change when moving between different architectures.
+ *
+ * @param typedef {@link TypeDef} data type to consider for replacement
+ * @param enforceSizeMatch if true, size of replacement must match specified typedef
+ * @return replacement data type or the original typedef if a replacement was not found
+ * @throws IllegalArgumentException if typedef was not constructed or cloned for a specific
+ * data type manager.
+ */
+ public static DataType getTypedefReplacement(TypeDef typedef, boolean enforceSizeMatch) {
+
+ DataTypeManager dtm = typedef.getDataTypeManager();
+ if (dtm == null) {
+ throw new IllegalArgumentException(
+ "typedef does not target a specific data type manager");
+ }
+
+ // Check for direct replacement of typedef with BuiltIn of same name
+ DataType directReplacement = getValidReplacement(typedef, enforceSizeMatch, dtm);
+ if (directReplacement != null && directReplacement.getName().equals(typedef.getName())) {
+ return directReplacement;
+ }
+
+ // Handle as possible typedef to BuiltIn replacement
+ DataType refDt = typedef.getDataType();
+ if (refDt instanceof TypeDef td) {
+ DataType replacementDt = getTypedefReplacement(td, enforceSizeMatch);
+ if (replacementDt != td) {
+ return new TypedefDataType(typedef.getCategoryPath(), typedef.getName(), refDt,
+ dtm);
+ }
+ }
+
+ // Handle as typedef replacement based on remap if directReplacement differs from refDt
+ if (directReplacement != null && !directReplacement.equals(refDt)) {
+ return new TypedefDataType(typedef.getCategoryPath(), typedef.getName(),
+ directReplacement, dtm);
+ }
+
+ return typedef;
+ }
+
+ /**
+ * Get valid typedef replacement
+ * @param typedef typedef to be replaced (should not reference another typedef)
+ * @param enforceSizeMatch if true size of replacement must match specified typedef
+ * @param dtm data type manager
+ * @return replacement data type or the null if a replacement was not found
+ */
+ private static DataType getValidReplacement(TypeDef typedef, boolean enforceSizeMatch,
+ DataTypeManager dtm) {
+
+ DataType replacementDt = cTypedefBuiltInNameRemap.get(typedef.getName());
+ if (replacementDt == null) {
+ return null;
+ }
+
+ if (enforceSizeMatch) {
+ if (replacementDt.hasLanguageDependantLength()) {
+ replacementDt = replacementDt.clone(dtm);
+ }
+ if (typedef.getLength() != replacementDt.getLength()) {
+ return null;
+ }
+ }
+
+ DataType tdDt = typedef.getBaseDataType();
+
+ if (replacementDt instanceof AbstractIntegerDataType intDt) {
+ if (tdDt instanceof AbstractIntegerDataType tdIntDt) {
+ if (intDt.isSigned() == tdIntDt.isSigned()) {
+ return replacementDt = replacementDt.clone(dtm);
+ }
+ }
+ }
+ else if (replacementDt instanceof DataTypeWithCharset) {
+ // Unsure what other constraints should be placed on valid replacement
+ return replacementDt = replacementDt.clone(dtm);
+ }
+ return null;
+ }
+
public static Collection<DataType> getContainedDataTypes(DataType rootDataType) {
HashMap<String, DataType> dataTypeMap = new HashMap<>();
Queue<DataType> unprocessedDataTypes = new LinkedList<>();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeWriter.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeWriter.java
index b3623623a7..8b7a9b27ab 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeWriter.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeWriter.java
@@ -33,7 +33,11 @@ import ghidra.util.task.TaskMonitor;
*/
public class DataTypeWriter {
- // list of Ghidra built-in type names which correspond to C primitive types
+ // list of type names which correspond to C/C++ compiler primitive types
+ // TODO: Specified INTEGRAL_TYPES only impact treatment of typedefs whose name
+ // matches or ends with a specified name. It's unclear if this is an appropriate
+ // check for suppressing a typedef.
+ // NOTE: '__int64' is only a primitive type for MSVC where 'unsigned __int64' is allowed.
private static String[] INTEGRAL_TYPES = { "char", "short", "int", "long", "long long",
"__int64", "float", "double", "long double", "void" };
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int16TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int16TDataType.java
new file mode 100644
index 0000000000..bda2921f11
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int16TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 16-bit signed integer (C99 Standard type {@code int16_t})
+ */
+public class Int16TDataType extends AbstractSignedIntegerDataType {
+
+ public final static Int16TDataType dataType = new Int16TDataType();
+
+ public Int16TDataType() {
+ this(null);
+ }
+
+ public Int16TDataType(DataTypeManager dtm) {
+ super("int16_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 2;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Signed 16-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public UInt16TDataType getOppositeSignednessDataType() {
+ return UInt16TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public Int16TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new Int16TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, true, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int32TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int32TDataType.java
new file mode 100644
index 0000000000..5232ec78f0
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int32TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 32-bit signed integer (C99 Standard type {@code int32_t})
+ */
+public class Int32TDataType extends AbstractSignedIntegerDataType {
+
+ public final static Int32TDataType dataType = new Int32TDataType();
+
+ public Int32TDataType() {
+ this(null);
+ }
+
+ public Int32TDataType(DataTypeManager dtm) {
+ super("int32_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 4;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Signed 32-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public UInt32TDataType getOppositeSignednessDataType() {
+ return UInt32TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public Int32TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new Int32TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, true, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int64TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int64TDataType.java
new file mode 100644
index 0000000000..11840b1449
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int64TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 64-bit signed integer (C99 Standard type {@code int64_t})
+ */
+public class Int64TDataType extends AbstractSignedIntegerDataType {
+
+ public final static Int64TDataType dataType = new Int64TDataType();
+
+ public Int64TDataType() {
+ this(null);
+ }
+
+ public Int64TDataType(DataTypeManager dtm) {
+ super("int64_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 8;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Signed 64-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public UInt64TDataType getOppositeSignednessDataType() {
+ return UInt64TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public Int64TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new Int64TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, true, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int8TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int8TDataType.java
new file mode 100644
index 0000000000..df3bc5a03b
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Int8TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 8-bit signed integer (C99 Standard type {@code int8_t})
+ */
+public class Int8TDataType extends AbstractSignedIntegerDataType {
+
+ public final static Int8TDataType dataType = new Int8TDataType();
+
+ public Int8TDataType() {
+ this(null);
+ }
+
+ public Int8TDataType(DataTypeManager dtm) {
+ super("int8_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 1;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Signed 8-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public UInt8TDataType getOppositeSignednessDataType() {
+ return UInt8TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public Int8TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new Int8TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, true, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/PointerSizedIntegerDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/PointerSizedIntegerDataType.java
new file mode 100644
index 0000000000..f20f17c0c7
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/PointerSizedIntegerDataType.java
@@ -0,0 +1,70 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * Pointer-sized signed integer
+ */
+public class PointerSizedIntegerDataType extends AbstractSignedIntegerDataType {
+
+ public final static PointerSizedIntegerDataType dataType = new PointerSizedIntegerDataType();
+
+ public PointerSizedIntegerDataType() {
+ this(null);
+ }
+
+ public PointerSizedIntegerDataType(DataTypeManager dtm) {
+ super("intptr_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return getDataOrganization().getPointerSize();
+ }
+
+ @Override
+ public boolean hasLanguageDependantLength() {
+ return true;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Signed Pointer-Sized Integer (compiler-specific size)";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public UnsignedPointerSizedIntegerDataType getOppositeSignednessDataType() {
+ return UnsignedPointerSizedIntegerDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public PointerSizedIntegerDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new PointerSizedIntegerDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, true, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt16TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt16TDataType.java
new file mode 100644
index 0000000000..e2877eda53
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt16TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 16-bit unsigned integer (C99 Standard type {@code uint16_t})
+ */
+public class UInt16TDataType extends AbstractUnsignedIntegerDataType {
+
+ public final static UInt16TDataType dataType = new UInt16TDataType();
+
+ public UInt16TDataType() {
+ this(null);
+ }
+
+ public UInt16TDataType(DataTypeManager dtm) {
+ super("uint16_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 2;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Unsigned 16-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public Int16TDataType getOppositeSignednessDataType() {
+ return Int16TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public UInt16TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new UInt16TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, false, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt32TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt32TDataType.java
new file mode 100644
index 0000000000..06b1b010cf
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt32TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 32-bit unsigned integer (C99 Standard type {@code uint32_t})
+ */
+public class UInt32TDataType extends AbstractUnsignedIntegerDataType {
+
+ public final static UInt32TDataType dataType = new UInt32TDataType();
+
+ public UInt32TDataType() {
+ this(null);
+ }
+
+ public UInt32TDataType(DataTypeManager dtm) {
+ super("uint32_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 4;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Unsigned 32-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public Int32TDataType getOppositeSignednessDataType() {
+ return Int32TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public UInt32TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new UInt32TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, false, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt64TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt64TDataType.java
new file mode 100644
index 0000000000..bc6718fe4f
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt64TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 64-bit unsigned integer (C99 Standard type {@code uint64_t})
+ */
+public class UInt64TDataType extends AbstractUnsignedIntegerDataType {
+
+ public final static UInt64TDataType dataType = new UInt64TDataType();
+
+ public UInt64TDataType() {
+ this(null);
+ }
+
+ public UInt64TDataType(DataTypeManager dtm) {
+ super("uint64_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 8;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Unsigned 64-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public Int64TDataType getOppositeSignednessDataType() {
+ return Int64TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public UInt64TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new UInt64TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, false, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt8TDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt8TDataType.java
new file mode 100644
index 0000000000..4197bb9ddd
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UInt8TDataType.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * 8-bit unsigned integer (C99 Standard type {@code uint8_t})
+ */
+public class UInt8TDataType extends AbstractUnsignedIntegerDataType {
+
+ public final static UInt8TDataType dataType = new UInt8TDataType();
+
+ public UInt8TDataType() {
+ this(null);
+ }
+
+ public UInt8TDataType(DataTypeManager dtm) {
+ super("uint8_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return 1;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Unsigned 8-bit Integer";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public Int8TDataType getOppositeSignednessDataType() {
+ return Int8TDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public UInt8TDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new UInt8TDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, false, dataOrganization, false);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UnsignedPointerSizedIntegerDataType.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UnsignedPointerSizedIntegerDataType.java
new file mode 100644
index 0000000000..2803467f5d
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/UnsignedPointerSizedIntegerDataType.java
@@ -0,0 +1,71 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+/**
+ * Pointer-sized unsigned integer
+ */
+public class UnsignedPointerSizedIntegerDataType extends AbstractUnsignedIntegerDataType {
+
+ public final static UnsignedPointerSizedIntegerDataType dataType =
+ new UnsignedPointerSizedIntegerDataType();
+
+ public UnsignedPointerSizedIntegerDataType() {
+ this(null);
+ }
+
+ public UnsignedPointerSizedIntegerDataType(DataTypeManager dtm) {
+ super("uintptr_t", dtm);
+ }
+
+ @Override
+ public int getLength() {
+ return getDataOrganization().getPointerSize();
+ }
+
+ @Override
+ public boolean hasLanguageDependantLength() {
+ return true;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Unsigned Pointer-Sized Integer (compiler-specific size)";
+ }
+
+ @Override
+ public String getCDeclaration() {
+ return null;
+ }
+
+ @Override
+ public PointerSizedIntegerDataType getOppositeSignednessDataType() {
+ return PointerSizedIntegerDataType.dataType.clone(getDataTypeManager());
+ }
+
+ @Override
+ public UnsignedPointerSizedIntegerDataType clone(DataTypeManager dtm) {
+ if (dtm == getDataTypeManager()) {
+ return this;
+ }
+ return new UnsignedPointerSizedIntegerDataType(dtm);
+ }
+
+ @Override
+ public String getCTypeDeclaration(DataOrganization dataOrganization) {
+ return getCTypeDeclaration(this, false, dataOrganization, false);
+ }
+}