mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-3215 removed wchar_t as a keyword and convert any wchar_t typedef to
built-in wchar_t
This commit is contained in:
parent
c4d0c7928b
commit
8c71f9d7fa
3 changed files with 96 additions and 21 deletions
|
@ -297,7 +297,6 @@ public class CreateDefaultGDTArchivesScript extends GhidraScript {
|
||||||
"-DSTRSAFE_LIB",
|
"-DSTRSAFE_LIB",
|
||||||
"-DSTRSAFE_LIB_IMPL",
|
"-DSTRSAFE_LIB_IMPL",
|
||||||
"-DLPSKBINFO=LPARAM",
|
"-DLPSKBINFO=LPARAM",
|
||||||
"-D_WCHAR_T_DEFINED",
|
|
||||||
"-DCONST=const",
|
"-DCONST=const",
|
||||||
"-D_CRT_SECURE_NO_WARNINGS",
|
"-D_CRT_SECURE_NO_WARNINGS",
|
||||||
"-D_CRT_NONSTDC_NO_DEPRECATE",
|
"-D_CRT_NONSTDC_NO_DEPRECATE",
|
||||||
|
@ -517,7 +516,6 @@ public class CreateDefaultGDTArchivesScript extends GhidraScript {
|
||||||
"-DSTRSAFE_LIB",
|
"-DSTRSAFE_LIB",
|
||||||
"-DSTRSAFE_LIB_IMPL",
|
"-DSTRSAFE_LIB_IMPL",
|
||||||
"-DLPSKBINFO=LPARAM",
|
"-DLPSKBINFO=LPARAM",
|
||||||
"-D_WCHAR_T_DEFINED",
|
|
||||||
"-DCONST=const",
|
"-DCONST=const",
|
||||||
"-D_CRT_SECURE_NO_WARNINGS",
|
"-D_CRT_SECURE_NO_WARNINGS",
|
||||||
"-D_CRT_NONSTDC_NO_DEPRECATE",
|
"-D_CRT_NONSTDC_NO_DEPRECATE",
|
||||||
|
@ -776,7 +774,6 @@ public class CreateDefaultGDTArchivesScript extends GhidraScript {
|
||||||
"-D__builtin_va_list=void *",
|
"-D__builtin_va_list=void *",
|
||||||
"-D__DO_NOT_DEFINE_COMPILE",
|
"-D__DO_NOT_DEFINE_COMPILE",
|
||||||
"-D_Complex",
|
"-D_Complex",
|
||||||
"-D_WCHAR_T",
|
|
||||||
"-D__NO_STRING_INLINES",
|
"-D__NO_STRING_INLINES",
|
||||||
"-D__signed__",
|
"-D__signed__",
|
||||||
"-D__extension__=",
|
"-D__extension__=",
|
||||||
|
@ -1027,7 +1024,6 @@ public class CreateDefaultGDTArchivesScript extends GhidraScript {
|
||||||
"-D__builtin_va_list=void *",
|
"-D__builtin_va_list=void *",
|
||||||
"-D__DO_NOT_DEFINE_COMPILE",
|
"-D__DO_NOT_DEFINE_COMPILE",
|
||||||
"-D_Complex",
|
"-D_Complex",
|
||||||
"-D_WCHAR_T",
|
|
||||||
"-D__NO_STRING_INLINES",
|
"-D__NO_STRING_INLINES",
|
||||||
"-D__NO_LONG_DOUBLE_MATH",
|
"-D__NO_LONG_DOUBLE_MATH",
|
||||||
"-D__signed__",
|
"-D__signed__",
|
||||||
|
|
|
@ -221,8 +221,15 @@ 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);
|
dt = new TypedefDataType(getCurrentCategoryPath(), type, dt, dtMgr);
|
||||||
|
}
|
||||||
dt = addDef(types, type, dt);
|
dt = addDef(types, type, dt);
|
||||||
|
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,12 +264,11 @@ public class CParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the BuiltinTypeManager
|
// check the BuiltinTypeManager
|
||||||
// Don't check, left in in case basic types like uint64_t are in builtins
|
BuiltInDataTypeManager builtInMgr = BuiltInDataTypeManager.getDataTypeManager();
|
||||||
// BuiltInDataTypeManager builtInMgr = BuiltInDataTypeManager.getDataTypeManager();
|
DataType bdt = findDataType(builtInMgr, type);
|
||||||
// DataType bdt = findDataType(builtInMgr, type);
|
if (bdt != null) {
|
||||||
// if (bdt != null) {
|
return bdt;
|
||||||
// return bdt;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
possiblyUndefinedType = type;
|
possiblyUndefinedType = type;
|
||||||
return null;
|
return null;
|
||||||
|
@ -1177,8 +1183,6 @@ TOKEN :
|
||||||
|
|
|
|
||||||
<W64 : "__w64">
|
<W64 : "__w64">
|
||||||
|
|
|
|
||||||
<WCHAR : "wchar_t">
|
|
||||||
|
|
|
||||||
<ENUM : "enum">
|
<ENUM : "enum">
|
||||||
|
|
|
|
||||||
<AUTO : "auto">
|
<AUTO : "auto">
|
||||||
|
@ -1605,8 +1609,6 @@ Declaration BuiltInTypeSpecifier(Declaration dec) : {
|
||||||
dec.setDataType(dt);
|
dec.setDataType(dt);
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
<WCHAR> { dec.setDataType(resolveInternal(WideCharDataType.dataType)); }
|
|
||||||
|
|
|
||||||
<SHORT> { dt = dec.getDataType();
|
<SHORT> { dt = dec.getDataType();
|
||||||
if (dt == null) {
|
if (dt == null) {
|
||||||
dt = resolveInternal(ShortDataType.dataType);
|
dt = resolveInternal(ShortDataType.dataType);
|
||||||
|
|
|
@ -15,22 +15,46 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.util.cparser;
|
package ghidra.app.util.cparser;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import generic.test.AbstractGenericTest;
|
|
||||||
import ghidra.app.util.cparser.C.CParser;
|
import ghidra.app.util.cparser.C.CParser;
|
||||||
import ghidra.app.util.cparser.C.ParseException;
|
import ghidra.app.util.cparser.C.ParseException;
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.Array;
|
||||||
|
import ghidra.program.model.data.BuiltInDataType;
|
||||||
|
import ghidra.program.model.data.CategoryPath;
|
||||||
|
import ghidra.program.model.data.CharDataType;
|
||||||
|
import ghidra.program.model.data.DataType;
|
||||||
|
import ghidra.program.model.data.DataTypeComponent;
|
||||||
|
import ghidra.program.model.data.DataTypeConflictHandler;
|
||||||
|
import ghidra.program.model.data.DataTypeManager;
|
||||||
import ghidra.program.model.data.Enum;
|
import ghidra.program.model.data.Enum;
|
||||||
|
import ghidra.program.model.data.FunctionDefinition;
|
||||||
|
import ghidra.program.model.data.GenericCallingConvention;
|
||||||
|
import ghidra.program.model.data.LongLongDataType;
|
||||||
|
import ghidra.program.model.data.ParameterDefinition;
|
||||||
|
import ghidra.program.model.data.Pointer;
|
||||||
|
import ghidra.program.model.data.ShortDataType;
|
||||||
|
import ghidra.program.model.data.StandAloneDataTypeManager;
|
||||||
|
import ghidra.program.model.data.Structure;
|
||||||
|
import ghidra.program.model.data.StructureDataType;
|
||||||
|
import ghidra.program.model.data.TypeDef;
|
||||||
|
import ghidra.program.model.data.TypedefDataType;
|
||||||
|
import ghidra.program.model.data.UnsignedLongDataType;
|
||||||
|
import ghidra.program.model.data.UnsignedLongLongDataType;
|
||||||
|
import ghidra.program.model.data.UnsignedShortDataType;
|
||||||
|
import ghidra.program.model.data.WideCharDataType;
|
||||||
|
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
|
||||||
|
|
||||||
public class CParserTest extends AbstractGenericTest {
|
public class CParserTest extends AbstractGhidraHeadlessIntegrationTest {
|
||||||
|
|
||||||
public CParserTest() {
|
public CParserTest() {
|
||||||
super();
|
super();
|
||||||
|
@ -96,6 +120,59 @@ public class CParserTest extends AbstractGenericTest {
|
||||||
assertEquals(8, pdt32.getLength());
|
assertEquals(8, pdt32.getLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWcharT() throws Exception {
|
||||||
|
|
||||||
|
DataType dt;
|
||||||
|
Structure sdt;
|
||||||
|
DataTypeComponent comp;
|
||||||
|
|
||||||
|
CParser parser;
|
||||||
|
|
||||||
|
parser = new CParser();
|
||||||
|
dt = parser.parse("typedef int wchar_t;");
|
||||||
|
|
||||||
|
assertTrue(dt instanceof WideCharDataType);
|
||||||
|
|
||||||
|
parser = new CParser();
|
||||||
|
dt = parser.parse("struct mystruct {" +
|
||||||
|
" wchar_t defined_wchar_t;" +
|
||||||
|
"};");
|
||||||
|
|
||||||
|
sdt = (Structure) dt;
|
||||||
|
comp = sdt.getComponent(0);
|
||||||
|
assertTrue(comp.getDataType() instanceof WideCharDataType);
|
||||||
|
|
||||||
|
parser = new CParser();
|
||||||
|
dt = parser.parse("typedef int wchar_t;" +
|
||||||
|
"struct mystruct {" +
|
||||||
|
" wchar_t defined_wchar_t;" +
|
||||||
|
"};");
|
||||||
|
|
||||||
|
sdt = (Structure) dt;
|
||||||
|
comp = sdt.getComponent(0);
|
||||||
|
assertTrue(comp.getDataType() instanceof WideCharDataType);
|
||||||
|
|
||||||
|
|
||||||
|
parser = new CParser();
|
||||||
|
dt = parser.parse("typedef short wchar_t;" +
|
||||||
|
" typedef wchar_t foo;");
|
||||||
|
|
||||||
|
assertTrue(dt != null);
|
||||||
|
assertTrue(dt instanceof TypeDef);
|
||||||
|
assertTrue(dt.getName().equals("foo"));
|
||||||
|
assertEquals(2, dt.getLength());
|
||||||
|
assertTrue(((TypeDef) dt).getBaseDataType() instanceof BuiltInDataType);
|
||||||
|
|
||||||
|
parser = new CParser();
|
||||||
|
DataType pdt32 = parser.parse("typedef wchar_t foo;");
|
||||||
|
assertTrue(dt != null);
|
||||||
|
assertTrue(dt instanceof TypeDef);
|
||||||
|
assertTrue(dt.getName().equals("foo"));
|
||||||
|
assertEquals(2, dt.getLength());
|
||||||
|
assertTrue(((TypeDef) dt).getBaseDataType() instanceof BuiltInDataType);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseDataType_NoSubArchive() throws Exception {
|
public void testParseDataType_NoSubArchive() throws Exception {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue