Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_df_structures: add types support #36

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 48 additions & 10 deletions ghidra/import_df_structures.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public AnalysisMode getScriptAnalysisMode() {
private Category dtc, dtcStd, dtcEnums, dtcVTables, dtcVMethods;
private DataType dtUint8, dtUint16, dtUint32, dtUint64;
private DataType dtInt8, dtInt16, dtInt32, dtInt64;
private DataType dtInt, dtLong, dtSizeT;
private DataType dtString, dtFStream, dtVectorBool, dtDeque;
private DataType dtInt, dtLong, dtULong, dtSizeT;
private DataType dtString, dtFStream, dtMutex, dtConditionVariable, dtFuture, dtVectorBool, dtDeque;
private Structure classTypeInfo, subClassTypeInfo, vmiClassTypeInfo;
private Address classVTable, subClassVTable, vmiClassVTable;
private int baseClassPadding;
Expand All @@ -80,14 +80,6 @@ protected void run() throws Exception {
labelGlobals();
annotateGlobalTable();
cleanUpDemangler();

updateProgressMajor("Waiting for auto analysis...");
var am = AutoAnalysisManager.getAnalysisManager(currentProgram);
am.setIgnoreChanges(false); // change from SUSPENDED to ENABLED mode
am.reAnalyzeAll(null); // force full program analysis
am.waitForAnalysis(AnalysisPriority.CODE_ANALYSIS.priority(), monitor);

setThunkNamespaces();
}

private void updateProgressMajor(String message) throws Exception {
Expand Down Expand Up @@ -303,13 +295,22 @@ private void createStdDataTypes() throws Exception {
var stringDataType = new StructureDataType("string", 0);
var bitVecDataType = new StructureDataType("vector<bool>", 0);
var fStreamDataType = new StructureDataType("fstream", 0);
var mutexDataType = new StructureDataType("mutex", 0);
var conditionVariableDataType = new StructureDataType("conditionVariable", 0);
var futureDataType = new StructureDataType("future", 0);
var dequeDataType = new StructureDataType("deque", 0);
stringDataType.setToDefaultAligned();
stringDataType.setPackingEnabled(true);
bitVecDataType.setToDefaultAligned();
bitVecDataType.setPackingEnabled(true);
fStreamDataType.setToDefaultAligned();
fStreamDataType.setPackingEnabled(true);
mutexDataType.setToDefaultAligned();
mutexDataType.setPackingEnabled(true);
conditionVariableDataType.setToDefaultAligned();
conditionVariableDataType.setPackingEnabled(true);
mutexDataType.setToDefaultAligned();
mutexDataType.setPackingEnabled(true);
dequeDataType.setToDefaultAligned();
dequeDataType.setPackingEnabled(true);

Expand All @@ -322,6 +323,9 @@ private void createStdDataTypes() throws Exception {
this.dtLong = createDataType(dtcStd, "long",
AbstractIntegerDataType.getSignedDataType(currentProgram.getDefaultPointerSize(), dtm));

this.dtULong = createDataType(dtcStd, "ulong",
AbstractIntegerDataType.getUnsignedDataType(currentProgram.getDefaultPointerSize(), dtm));

var rep = new StructureDataType("_string_rep", 0);
rep.setToDefaultAligned();
rep.setPackingEnabled(true);
Expand Down Expand Up @@ -356,6 +360,16 @@ private void createStdDataTypes() throws Exception {
dequeDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
dequeDataType.add(Undefined.getUndefinedDataType(10 * currentProgram.getDefaultPointerSize()));

// sizes for these types obtained using gcc 10.5 via godbolt
mutexDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
mutexDataType.add((currentProgram.getDefaultPointerSize() == 8) ? 40 : 24);

conditionVariableDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
conditionVariableDataType.add(Undefined.getUndefinedDataType(48));

futureDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
futureDataType.add(Undefined.getUndefinedDataType(2 * currentProgram.getDefaultPointerSize()));

this.baseClassPadding = 1;

Structure typeInfo = new StructureDataType("type_info", 0);
Expand Down Expand Up @@ -405,6 +419,7 @@ private void createStdDataTypes() throws Exception {
break;
case "Portable Executable (PE)":
this.dtLong = createDataType(dtcStd, "long", AbstractIntegerDataType.getSignedDataType(4, dtm));
this.dtULong = createDataType(dtcStd, "ulong", AbstractIntegerDataType.getUnsignedDataType(4, dtm));

var stringVal = new UnionDataType("_string_val");
stringVal.setToDefaultAligned();
Expand All @@ -425,13 +440,26 @@ private void createStdDataTypes() throws Exception {
dequeDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
dequeDataType.add(Undefined.getUndefinedDataType(5 * currentProgram.getDefaultPointerSize()));

// these sizes were obtained using msvc 19.36
mutexDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
mutexDataType.add(Undefined.getUndefinedDataType(8 * currentProgram.getDefaultPointerSize() + 16));

conditionVariableDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
conditionVariableDataType.add(Undefined.getUndefinedDataType(8 * currentProgram.getDefaultPointerSize() + 8));

futureDataType.setExplicitMinimumAlignment(currentProgram.getDefaultPointerSize());
futureDataType.add(Undefined.getUndefinedDataType(2 * currentProgram.getDefaultPointerSize()));

this.baseClassPadding = currentProgram.getDefaultPointerSize();

break;
default:
throw new Exception("unexpected exe format " + currentProgram.getExecutableFormat());
}
this.dtFStream = createDataType(dtcStd, fStreamDataType);
this.dtMutex = createDataType(dtcStd, mutexDataType);
this.dtConditionVariable = createDataType(dtcStd, conditionVariableDataType);
this.dtFuture = createDataType(dtcStd, futureDataType);
this.dtString = createDataType(dtcStd, stringDataType);
this.dtVectorBool = createDataType(dtcStd, bitVecDataType);
this.dtDeque = createDataType(dtcStd, dequeDataType);
Expand Down Expand Up @@ -1324,6 +1352,12 @@ private DataType getDataType(TypeDef.Field f) throws Exception {
return dtString;
case "stl-fstream":
return dtFStream;
case "stl-mutex":
return dtMutex;
case "stl-condition-variable":
return dtConditionVariable;
case "stl-future":
return dtFuture;
}
break;
case "container":
Expand Down Expand Up @@ -1374,6 +1408,10 @@ private DataType getDataType(TypeDef.Field f) throws Exception {
return dtUint64;
case "long":
return dtLong;
case "ulong":
return dtULong;
case "size_t":
return dtSizeT;
}
break;
case "pointer":
Expand Down