Ghidra is a software reverse engineering (SRE) framework
GP-4822 - PDB Universal - add char8_t
ghizard45b86dfacf9a
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/PrimitiveMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/PrimitiveMsType.javaindex 8996da53e6..58e4a44985 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/PrimitiveMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/PrimitiveMsType.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.@@ -483,6 +483,51 @@ public class PrimitiveMsType extends AbstractMsType {typeSize = 16;break;+ //=======================================+ // 8-bit char8_t type from C++20 standard+ // Note that std::is_same_v<unsigned char, char8_t> is suppose to return false+ //=======================================+ // char8_t+ case 0x007c:+ typeString = "T_CHAR8";+ typeSize = 1;+ break;+ // 16-bit pointer to a char8_t+ case 0x017c:+ typeString = "T_PCHAR8";+ typeSize = 2;+ break;+ // 16:16 far pointer to a char8_t+ case 0x027c:+ typeString = "T_PFCHAR8";+ typeSize = 4;+ break;+ // 16:16 huge pointer to a char8_t+ case 0x037c:+ typeString = "T_PHCHAR8";+ typeSize = 4;+ break;+ // 32-bit pointer to a char8_t+ case 0x047c:+ typeString = "T_32PCHAR8";+ typeSize = 4;+ break;+ // 16:32 pointer to a char8_t+ case 0x057c:+ typeString = "T_32PFCHAR8";+ typeSize = 6;+ break;+ // 64-bit pointer to a char8_t+ case 0x067c:+ typeString = "T_64PCHAR8";+ typeSize = 8;+ break;+ // 128-bit near pointer to a char8_t (LLVM doc on 0x0700)+ case 0x077c:+ typeString = "T_128PCHAR8";+ typeSize = 16;+ break;+//=======================================// 8-bit int types//=======================================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.javaindex 8934c10f44..eb5286a2ee 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@@ -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.@@ -39,7 +39,9 @@ public class PdbPrimitiveTypeApplicator {private DataType voidGhidraPrimitive = null;private DataType charGhidraPrimitive = null;private DataType signedCharGhidraPrimitive = null;+ // Note that std::is_same_v<unsigned char, char8_t> is suppose to return falseprivate DataType unsignedCharGhidraPrimitive = null;+ private DataType char8GhidraPrimitive = null;//private Map<Integer, DataType> booleanGhidraPrimitives = new HashMap<>();private Map<Integer, DataType> integralGhidraPrimitives = new HashMap<>();@@ -108,6 +110,19 @@ public class PdbPrimitiveTypeApplicator {return unsignedCharGhidraPrimitive;}+ // 8-bit char8_t type from C++20 standard+ // Note that std::is_same_v<unsigned char, char8_t> is suppose to return false+ // So we are creating and storing off a separate type here. Whether ghidra thinks they are+ // the same or not is up to the type system or up to our changing what we do in these two+ // methods (the one above and this one). If we care to make them different, then do it here.+ DataType getChar8Type() {+ if (char8GhidraPrimitive == null) {+ DataType dataType = new UnsignedCharDataType(getDataTypeManager());+ char8GhidraPrimitive = resolve(dataType);+ }+ return char8GhidraPrimitive;+ }+DataType getUnicode16Type() {// For now, we are returning WideChar16 for Unicode16.return new WideChar16DataType(getDataTypeManager());diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PrimitiveTypeApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PrimitiveTypeApplier.javaindex 4b6abbd9cf..c5401e96e0 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PrimitiveTypeApplier.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PrimitiveTypeApplier.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.@@ -426,6 +426,50 @@ public class PrimitiveTypeApplier extends MsDataTypeApplier {primitiveApplicator.getUnicode32Type());break;+ //=======================================+ // 8-bit char8_t type from C++20 standard+ // Note that std::is_same_v<unsigned char, char8_t> is suppose to return false+ //=======================================+ // char8_t+ case 0x007c:+ primitiveDataType = primitiveApplicator.getChar8Type();+ break;+ // 16-bit pointer to a char8_t+ case 0x017c:+ primitiveDataType = primitiveApplicator.get16NearPointerType(type,+ primitiveApplicator.getChar8Type());+ break;+ // 16:16 far pointer to a char8_t+ case 0x027c:+ primitiveDataType = primitiveApplicator.get1616FarPointerType(type,+ primitiveApplicator.getChar8Type());+ break;+ // 16:16 huge pointer to a char8_t+ case 0x037c:+ primitiveDataType = primitiveApplicator.get1616HugePointerType(type,+ primitiveApplicator.getChar8Type());+ break;+ // 32-bit pointer to a char8_t+ case 0x047c:+ primitiveDataType = primitiveApplicator.get32PointerType(type,+ primitiveApplicator.getChar8Type());+ break;+ // 16:32 pointer to a char8_t+ case 0x057c:+ primitiveDataType = primitiveApplicator.get1632PointerType(type,+ primitiveApplicator.getChar8Type());+ break;+ // 64-bit pointer to a char8_t+ case 0x067c:+ primitiveDataType = primitiveApplicator.get64PointerType(type,+ primitiveApplicator.getChar8Type());+ break;+ // 128-bit near pointer to a char8_t (LLVM doc on 0x0700)+ case 0x077c:+ primitiveDataType = primitiveApplicator.get128PointerType(type,+ primitiveApplicator.getChar8Type());+ break;+//=======================================// 8-bit int types//=======================================