WIP
This commit is contained in:
parent
b0b4683f7d
commit
35a220de3f
5237
game_re/gh_types.h
5237
game_re/gh_types.h
File diff suppressed because it is too large
Load Diff
|
@ -6,6 +6,7 @@
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <d3d8.h>
|
#include <d3d8.h>
|
||||||
|
#include <dinput.h>
|
||||||
#else
|
#else
|
||||||
#include "win32_shim.h"
|
#include "win32_shim.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,6 +22,7 @@ typedef uint16_t word;
|
||||||
typedef uint32_t dword;
|
typedef uint32_t dword;
|
||||||
typedef unsigned long ulong;
|
typedef unsigned long ulong;
|
||||||
typedef unsigned char uchar;
|
typedef unsigned char uchar;
|
||||||
|
typedef unsigned long uint;
|
||||||
|
|
||||||
struct undefined3 {
|
struct undefined3 {
|
||||||
uint8_t _0;
|
uint8_t _0;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,7 @@ dlgs.h
|
||||||
excpt.h
|
excpt.h
|
||||||
float.h
|
float.h
|
||||||
guiddef.h
|
guiddef.h
|
||||||
|
Guiddef.h
|
||||||
imm.h
|
imm.h
|
||||||
io.h
|
io.h
|
||||||
jmorecfg.h
|
jmorecfg.h
|
||||||
|
@ -48,7 +49,6 @@ rpcnsip.h
|
||||||
rpcnterr.h
|
rpcnterr.h
|
||||||
servprov.h
|
servprov.h
|
||||||
shellapi.h
|
shellapi.h
|
||||||
snddef.h
|
|
||||||
stdarg.h
|
stdarg.h
|
||||||
stdint.h
|
stdint.h
|
||||||
stdio.h
|
stdio.h
|
||||||
|
|
|
@ -13,6 +13,6 @@ public class DumpTypes extends GhidraScript {
|
||||||
@Override
|
@Override
|
||||||
protected void run() throws Exception {
|
protected void run() throws Exception {
|
||||||
TypeDumper dumper = new TypeDumper(this);
|
TypeDumper dumper = new TypeDumper(this);
|
||||||
dumper.run();
|
dumper.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Source code is decompiled from a .class file using FernFlower decompiler.
|
// Source code is decompiled from a .class file using FernFlower decompiler.
|
||||||
package re3lib;
|
package re3lib;
|
||||||
|
|
||||||
|
import ghidra.app.script.GhidraScript;
|
||||||
|
import ghidra.app.script.ScriptMessage;
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
import ghidra.program.model.data.Enum;
|
import ghidra.program.model.data.Enum;
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.Msg;
|
||||||
|
@ -18,7 +20,7 @@ public class DataTypeWriter {
|
||||||
private static String[] INTEGRAL_MODIFIERS = new String[] { "signed", "unsigned", "const", "static", "volatile",
|
private static String[] INTEGRAL_MODIFIERS = new String[] { "signed", "unsigned", "const", "static", "volatile",
|
||||||
"mutable" };
|
"mutable" };
|
||||||
private static String EOL = System.getProperty("line.separator");
|
private static String EOL = System.getProperty("line.separator");
|
||||||
|
|
||||||
private Writer writer;
|
private Writer writer;
|
||||||
private DataTypeManager dtm;
|
private DataTypeManager dtm;
|
||||||
private DataOrganization dataOrganization;
|
private DataOrganization dataOrganization;
|
||||||
|
@ -30,7 +32,7 @@ public class DataTypeWriter {
|
||||||
final DataType dataType;
|
final DataType dataType;
|
||||||
final String code;
|
final String code;
|
||||||
final Set<String> dependencies;
|
final Set<String> dependencies;
|
||||||
|
|
||||||
Block(DataType dataType, String code, Set<String> dependencies) {
|
Block(DataType dataType, String code, Set<String> dependencies) {
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
@ -108,18 +110,18 @@ public class DataTypeWriter {
|
||||||
public void write(List<DataType> dataTypes, TaskMonitor monitor, boolean throwExceptionOnInvalidType)
|
public void write(List<DataType> dataTypes, TaskMonitor monitor, boolean throwExceptionOnInvalidType)
|
||||||
throws IOException, CancelledException {
|
throws IOException, CancelledException {
|
||||||
monitor.initialize((long) dataTypes.size());
|
monitor.initialize((long) dataTypes.size());
|
||||||
|
|
||||||
// Step 1: Create blocks for each data type
|
// Step 1: Create blocks for each data type
|
||||||
Map<String, Block> blocks = new HashMap<>();
|
Map<String, Block> blocks = new HashMap<>();
|
||||||
|
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (DataType dataType : dataTypes) {
|
for (DataType dataType : dataTypes) {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
|
|
||||||
if (dataType == null || blacklistedTypes.contains(dataType.getDisplayName())) {
|
if (dataType == null || blacklistedTypes.contains(dataType.getDisplayName())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Block block = createBlock(dataType);
|
Block block = createBlock(dataType);
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
|
@ -131,30 +133,34 @@ public class DataTypeWriter {
|
||||||
}
|
}
|
||||||
Msg.error(this, "Failed to process data type: " + dataType.getDisplayName(), e);
|
Msg.error(this, "Failed to process data type: " + dataType.getDisplayName(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
++cnt;
|
++cnt;
|
||||||
monitor.setProgress((long) cnt);
|
monitor.setProgress((long) cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Topological sort and write
|
// Step 2: Topological sort and write
|
||||||
List<Block> sortedBlocks = topologicalSort(blocks);
|
List<Block> sortedBlocks = topologicalSort(blocks);
|
||||||
for (Block block : sortedBlocks) {
|
for (Block block : sortedBlocks) {
|
||||||
writer.write(block.code);
|
writer.write(block.code);
|
||||||
writer.write(EOL);
|
writer.write(EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Block createBlock(DataType dt) throws IOException {
|
private Block createBlock(DataType dt) throws IOException {
|
||||||
if (dt instanceof FunctionDefinition || dt instanceof FactoryDataType) {
|
if (dt instanceof FactoryDataType) {
|
||||||
return null; // Skip these types
|
return null; // Skip only factory types
|
||||||
}
|
}
|
||||||
|
|
||||||
dt = dt.clone(this.dtm);
|
dt = dt.clone(this.dtm);
|
||||||
Set<String> dependencies = new HashSet<>();
|
Set<String> dependencies = new HashSet<>();
|
||||||
StringBuilder code = new StringBuilder();
|
StringBuilder code = new StringBuilder();
|
||||||
|
|
||||||
|
if (dt.getDisplayName().contains("HIE_tduLinkedObject")) {
|
||||||
|
System.out.println("DEBUG " + dt.getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
if (dt.equals(DataType.DEFAULT)) {
|
if (dt.equals(DataType.DEFAULT)) {
|
||||||
code.append("typedef unsigned char ").append(DataType.DEFAULT.getName()).append(";");
|
code.append("typedef unsigned char ").append(DataType.DEFAULT.getName()).append(";");
|
||||||
} else if (dt instanceof Dynamic) {
|
} else if (dt instanceof Dynamic) {
|
||||||
|
@ -175,16 +181,18 @@ public class DataTypeWriter {
|
||||||
writeTypeDefBlock((TypeDef) dt, code, dependencies);
|
writeTypeDefBlock((TypeDef) dt, code, dependencies);
|
||||||
} else if (dt instanceof BuiltInDataType) {
|
} else if (dt instanceof BuiltInDataType) {
|
||||||
writeBuiltInBlock((BuiltInDataType) dt, code, dependencies);
|
writeBuiltInBlock((BuiltInDataType) dt, code, dependencies);
|
||||||
|
} else if (dt instanceof FunctionDefinition) {
|
||||||
|
return null;
|
||||||
} else {
|
} else {
|
||||||
code.append(comment("Unable to write datatype. Type unrecognized: " + dt.getClass()));
|
code.append(comment("Unable to write datatype. Type unrecognized: " + dt.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Block(dt, code.toString(), dependencies);
|
return new Block(dt, code.toString(), dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeStructureBlock(Structure struct, StringBuilder code, Set<String> dependencies) {
|
private void writeStructureBlock(Structure struct, StringBuilder code, Set<String> dependencies) {
|
||||||
String structName = struct.getDisplayName();
|
String structName = struct.getDisplayName();
|
||||||
|
|
||||||
// Struct definition
|
// Struct definition
|
||||||
code.append("struct ").append(structName).append(" {");
|
code.append("struct ").append(structName).append(" {");
|
||||||
String descrip = struct.getDescription();
|
String descrip = struct.getDescription();
|
||||||
|
@ -192,65 +200,60 @@ public class DataTypeWriter {
|
||||||
code.append(" ").append(comment(descrip));
|
code.append(" ").append(comment(descrip));
|
||||||
}
|
}
|
||||||
code.append(EOL);
|
code.append(EOL);
|
||||||
|
|
||||||
// Process components
|
// Process components
|
||||||
for (DataTypeComponent component : struct.getComponents()) {
|
for (DataTypeComponent component : struct.getComponents()) {
|
||||||
writeComponentBlock(component, struct, code, dependencies);
|
writeComponentBlock(component, struct, code, dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
code.append(annotator.getSuffix(struct, null));
|
code.append(annotator.getSuffix(struct, null));
|
||||||
code.append("};");
|
code.append("};");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeUnionBlock(Union union, StringBuilder code, Set<String> dependencies) {
|
private void writeUnionBlock(Union union, StringBuilder code, Set<String> dependencies) {
|
||||||
String unionName = union.getDisplayName();
|
String unionName = union.getDisplayName();
|
||||||
|
|
||||||
// Forward declaration
|
// Union definition (no forward declaration needed - let dependency ordering
|
||||||
code.append("typedef union ").append(unionName).append(" ").append(unionName)
|
// handle it)
|
||||||
.append(", *P").append(unionName).append(";").append(EOL);
|
|
||||||
|
|
||||||
// Union definition
|
|
||||||
code.append("union ").append(unionName).append(" {");
|
code.append("union ").append(unionName).append(" {");
|
||||||
String descrip = union.getDescription();
|
String descrip = union.getDescription();
|
||||||
if (descrip != null && descrip.length() > 0) {
|
if (descrip != null && descrip.length() > 0) {
|
||||||
code.append(" ").append(comment(descrip));
|
code.append(" ").append(comment(descrip));
|
||||||
}
|
}
|
||||||
code.append(EOL);
|
code.append(EOL);
|
||||||
|
|
||||||
// Process components
|
// Process components
|
||||||
for (DataTypeComponent component : union.getComponents()) {
|
for (DataTypeComponent component : union.getComponents()) {
|
||||||
writeComponentBlock(component, union, code, dependencies);
|
writeComponentBlock(component, union, code, dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
code.append(annotator.getSuffix(union, null));
|
code.append(annotator.getSuffix(union, null));
|
||||||
code.append("};");
|
code.append("};");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeComponentBlock(DataTypeComponent component, Composite composite, StringBuilder code, Set<String> dependencies) {
|
private void writeComponentBlock(DataTypeComponent component, Composite composite, StringBuilder code,
|
||||||
|
Set<String> dependencies) {
|
||||||
code.append(" ");
|
code.append(" ");
|
||||||
code.append(annotator.getPrefix(composite, component));
|
code.append(annotator.getPrefix(composite, component));
|
||||||
|
|
||||||
String fieldName = component.getFieldName();
|
String fieldName = component.getFieldName();
|
||||||
String originalName = fieldName;
|
String originalName = fieldName;
|
||||||
boolean needsFixing = fieldName != null && fieldName.contains("?");
|
boolean needsFixing = fieldName != null && fieldName.contains("?");
|
||||||
if (fieldName == null || fieldName.length() == 0 || needsFixing) {
|
if (fieldName == null || fieldName.length() == 0 || needsFixing) {
|
||||||
fieldName = component.getDefaultFieldName();
|
fieldName = component.getDefaultFieldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataType componentDataType = component.getDataType();
|
DataType componentDataType = component.getDataType();
|
||||||
|
|
||||||
// Add dependency only if it's not a pointer (pointers can be forward declared)
|
DataType depType = getImmediateDependencyType(componentDataType);
|
||||||
if (!isPointerType(componentDataType)) {
|
if (depType != null) {
|
||||||
DataType depType = getImmediateDependencyType(componentDataType);
|
dependencies.add(depType.getDisplayName());
|
||||||
if (depType != null && !isBuiltInType(depType)) {
|
|
||||||
dependencies.add(depType.getDisplayName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code.append(getTypeDeclaration(fieldName, componentDataType, component.getLength()));
|
code.append(getTypeDeclaration(fieldName, componentDataType, component.getLength()));
|
||||||
code.append(";");
|
code.append(";");
|
||||||
code.append(annotator.getSuffix(composite, component));
|
code.append(annotator.getSuffix(composite, component));
|
||||||
|
|
||||||
String comment = component.getComment();
|
String comment = component.getComment();
|
||||||
String commentText = comment != null && comment.length() > 0 ? comment : "";
|
String commentText = comment != null && comment.length() > 0 ? comment : "";
|
||||||
if (needsFixing) {
|
if (needsFixing) {
|
||||||
|
@ -264,7 +267,7 @@ public class DataTypeWriter {
|
||||||
|
|
||||||
private void writeEnumBlock(Enum enumm, StringBuilder code, Set<String> dependencies) {
|
private void writeEnumBlock(Enum enumm, StringBuilder code, Set<String> dependencies) {
|
||||||
String enumName = enumm.getDisplayName();
|
String enumName = enumm.getDisplayName();
|
||||||
|
|
||||||
if (enumName.startsWith("define_") && enumName.length() > 7 && enumm.getCount() == 1) {
|
if (enumName.startsWith("define_") && enumName.length() > 7 && enumm.getCount() == 1) {
|
||||||
long val = enumm.getValues()[0];
|
long val = enumm.getValues()[0];
|
||||||
code.append("#define ").append(enumName.substring(7)).append(" ").append(Long.toString(val));
|
code.append("#define ").append(enumName.substring(7)).append(" ").append(Long.toString(val));
|
||||||
|
@ -275,7 +278,7 @@ public class DataTypeWriter {
|
||||||
code.append(" ").append(comment(description));
|
code.append(" ").append(comment(description));
|
||||||
}
|
}
|
||||||
code.append(EOL);
|
code.append(EOL);
|
||||||
|
|
||||||
String[] names = enumm.getNames();
|
String[] names = enumm.getNames();
|
||||||
for (int j = 0; j < names.length; ++j) {
|
for (int j = 0; j < names.length; ++j) {
|
||||||
code.append(" ");
|
code.append(" ");
|
||||||
|
@ -297,20 +300,77 @@ public class DataTypeWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeFunctionDefinitionBlock(FunctionDefinition funcDef, String name, StringBuilder code,
|
||||||
|
Set<String> dependencies) {
|
||||||
|
DataType returnType = funcDef.getReturnType();
|
||||||
|
ParameterDefinition[] params = funcDef.getArguments();
|
||||||
|
|
||||||
|
// Add return type dependency if not built-in
|
||||||
|
if (returnType != null && !isBuiltInType(returnType)) {
|
||||||
|
DataType depType = getImmediateDependencyType(returnType);
|
||||||
|
if (depType != null) {
|
||||||
|
dependencies.add(depType.getDisplayName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build function typedef
|
||||||
|
code.append("typedef ");
|
||||||
|
if (returnType != null) {
|
||||||
|
code.append(getTypeDeclaration("", returnType, -1)).append(" ");
|
||||||
|
} else {
|
||||||
|
code.append("void ");
|
||||||
|
}
|
||||||
|
|
||||||
|
code.append("(*").append(name).append(")(");
|
||||||
|
|
||||||
|
if (params != null && params.length > 0) {
|
||||||
|
for (int i = 0; i < params.length; i++) {
|
||||||
|
ParameterDefinition param = params[i];
|
||||||
|
DataType paramType = param.getDataType();
|
||||||
|
|
||||||
|
// Add parameter type dependency if not built-in
|
||||||
|
if (!isBuiltInType(paramType) && !isPointerType(paramType)) {
|
||||||
|
DataType depType = getImmediateDependencyType(paramType);
|
||||||
|
if (depType != null) {
|
||||||
|
dependencies.add(depType.getDisplayName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String paramName = param.getName();
|
||||||
|
if (paramName == null || paramName.isEmpty()) {
|
||||||
|
paramName = "param" + (i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
code.append(getTypeDeclaration(paramName, paramType, -1));
|
||||||
|
if (i < params.length - 1) {
|
||||||
|
code.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
code.append("void");
|
||||||
|
}
|
||||||
|
|
||||||
|
code.append(");");
|
||||||
|
}
|
||||||
|
|
||||||
private void writeTypeDefBlock(TypeDef typeDef, StringBuilder code, Set<String> dependencies) {
|
private void writeTypeDefBlock(TypeDef typeDef, StringBuilder code, Set<String> dependencies) {
|
||||||
String typedefName = typeDef.getDisplayName();
|
String typedefName = typeDef.getDisplayName();
|
||||||
DataType dataType = typeDef.getDataType();
|
DataType dataType = typeDef.getDataType();
|
||||||
String dataTypeName = dataType.getDisplayName();
|
String dataTypeName = dataType.getDisplayName();
|
||||||
|
|
||||||
if (!isIntegral(typedefName, dataTypeName)) {
|
// Handle function definition typedefs
|
||||||
// Add dependency only if it's not a pointer
|
if (dataType instanceof FunctionDefinition) {
|
||||||
if (!isPointerType(dataType)) {
|
writeFunctionDefinitionBlock((FunctionDefinition) dataType, typedefName, code, dependencies);
|
||||||
DataType depType = getImmediateDependencyType(dataType);
|
} // Could be pointer to function
|
||||||
if (depType != null && !isBuiltInType(depType)) {
|
else if (dataType instanceof Pointer && ((Pointer) dataType).getDataType() instanceof FunctionDefinition) {
|
||||||
dependencies.add(depType.getDisplayName());
|
writeFunctionDefinitionBlock((FunctionDefinition) ((Pointer) dataType).getDataType(), typedefName, code,
|
||||||
}
|
dependencies);
|
||||||
|
} else {
|
||||||
|
DataType depType = getImmediateDependencyType(dataType);
|
||||||
|
if (depType != null && !isBuiltInType(depType)) {
|
||||||
|
dependencies.add(depType.getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
String typedefString = getTypeDeclaration(typedefName, dataType, -1);
|
String typedefString = getTypeDeclaration(typedefName, dataType, -1);
|
||||||
code.append("typedef ").append(typedefString).append(";");
|
code.append("typedef ").append(typedefString).append(";");
|
||||||
}
|
}
|
||||||
|
@ -322,7 +382,7 @@ public class DataTypeWriter {
|
||||||
code.append(declaration);
|
code.append(declaration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPointerType(DataType dt) {
|
private boolean isPointerType(DataType dt) {
|
||||||
return dt instanceof Pointer;
|
return dt instanceof Pointer;
|
||||||
}
|
}
|
||||||
|
@ -338,6 +398,8 @@ public class DataTypeWriter {
|
||||||
dt = ((Array) dt).getDataType();
|
dt = ((Array) dt).getDataType();
|
||||||
} else if (dt instanceof BitFieldDataType) {
|
} else if (dt instanceof BitFieldDataType) {
|
||||||
dt = ((BitFieldDataType) dt).getBaseDataType();
|
dt = ((BitFieldDataType) dt).getBaseDataType();
|
||||||
|
} else if (dt instanceof Pointer) {
|
||||||
|
dt = ((Pointer) dt).getDataType();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -349,22 +411,22 @@ public class DataTypeWriter {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = "";
|
name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
if (dataType instanceof BitFieldDataType) {
|
if (dataType instanceof BitFieldDataType) {
|
||||||
BitFieldDataType bfDt = (BitFieldDataType) dataType;
|
BitFieldDataType bfDt = (BitFieldDataType) dataType;
|
||||||
name = name + ":" + bfDt.getDeclaredBitSize();
|
name = name + ":" + bfDt.getDeclaredBitSize();
|
||||||
dataType = bfDt.getBaseDataType();
|
dataType = bfDt.getBaseDataType();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle arrays and pointers
|
// Handle arrays and pointers
|
||||||
while (dataType instanceof Array) {
|
while (dataType instanceof Array) {
|
||||||
Array array = (Array) dataType;
|
Array array = (Array) dataType;
|
||||||
name = name + "[" + array.getNumElements() + "]";
|
name = name + "[" + array.getNumElements() + "]";
|
||||||
dataType = array.getDataType();
|
dataType = array.getDataType();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (dataType instanceof Pointer) {
|
while (dataType instanceof Pointer) {
|
||||||
Pointer pointer = (Pointer) dataType;
|
Pointer pointer = (Pointer) dataType;
|
||||||
DataType elem = pointer.getDataType();
|
DataType elem = pointer.getDataType();
|
||||||
|
@ -377,12 +439,12 @@ public class DataTypeWriter {
|
||||||
name = "(" + name + ")";
|
name = "(" + name + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = getDataTypePrefix(dataType);
|
String prefix = getDataTypePrefix(dataType);
|
||||||
|
|
||||||
String dataTypeString;
|
String dataTypeString;
|
||||||
if (dataType instanceof AbstractIntegerDataType) {
|
if (dataType instanceof AbstractIntegerDataType) {
|
||||||
dataTypeString = ((AbstractIntegerDataType)dataType).getCDeclaration();
|
dataTypeString = ((AbstractIntegerDataType) dataType).getCDeclaration();
|
||||||
} else {
|
} else {
|
||||||
dataTypeString = dataType.getDisplayName();
|
dataTypeString = dataType.getDisplayName();
|
||||||
}
|
}
|
||||||
|
@ -391,7 +453,7 @@ public class DataTypeWriter {
|
||||||
if (name.length() != 0) {
|
if (name.length() != 0) {
|
||||||
componentString = componentString + " " + name;
|
componentString = componentString + " " + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return componentString;
|
return componentString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,8 +462,9 @@ public class DataTypeWriter {
|
||||||
if (dataType instanceof TypeDef) {
|
if (dataType instanceof TypeDef) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only add struct/union prefix for direct struct/union references (not typedefs)
|
// Only add struct/union prefix for direct struct/union references (not
|
||||||
|
// typedefs)
|
||||||
if (dataType instanceof Structure) {
|
if (dataType instanceof Structure) {
|
||||||
return "struct ";
|
return "struct ";
|
||||||
} else if (dataType instanceof Union) {
|
} else if (dataType instanceof Union) {
|
||||||
|
@ -419,7 +482,7 @@ public class DataTypeWriter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean endsWithIntegralType = false;
|
boolean endsWithIntegralType = false;
|
||||||
for (String type : INTEGRAL_TYPES) {
|
for (String type : INTEGRAL_TYPES) {
|
||||||
if (typedefName.endsWith(" " + type)) {
|
if (typedefName.endsWith(" " + type)) {
|
||||||
|
@ -427,13 +490,13 @@ public class DataTypeWriter {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String modifier : INTEGRAL_MODIFIERS) {
|
for (String modifier : INTEGRAL_MODIFIERS) {
|
||||||
if (typedefName.indexOf(modifier + " ") >= 0 || typedefName.indexOf(" " + modifier) >= 0) {
|
if (typedefName.indexOf(modifier + " ") >= 0 || typedefName.indexOf(" " + modifier) >= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endsWithIntegralType) {
|
if (endsWithIntegralType) {
|
||||||
return true;
|
return true;
|
||||||
} else if (typedefName.endsWith(" " + basetypeName)) {
|
} else if (typedefName.endsWith(" " + basetypeName)) {
|
||||||
|
@ -447,31 +510,32 @@ public class DataTypeWriter {
|
||||||
List<Block> result = new ArrayList<>();
|
List<Block> result = new ArrayList<>();
|
||||||
Set<String> visited = new HashSet<>();
|
Set<String> visited = new HashSet<>();
|
||||||
Set<String> visiting = new HashSet<>();
|
Set<String> visiting = new HashSet<>();
|
||||||
|
|
||||||
for (Block block : blocks.values()) {
|
for (Block block : blocks.values()) {
|
||||||
if (!visited.contains(block.dataType.getDisplayName())) {
|
if (!visited.contains(block.dataType.getDisplayName())) {
|
||||||
topologicalSortVisit(block, blocks, visited, visiting, result);
|
topologicalSortVisit(block, blocks, visited, visiting, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void topologicalSortVisit(Block block, Map<String, Block> blocks,
|
private void topologicalSortVisit(Block block, Map<String, Block> blocks,
|
||||||
Set<String> visited, Set<String> visiting, List<Block> result) {
|
Set<String> visited, Set<String> visiting, List<Block> result) {
|
||||||
String blockName = block.dataType.getDisplayName();
|
String blockName = block.dataType.getDisplayName();
|
||||||
|
|
||||||
if (visiting.contains(blockName)) {
|
if (visiting.contains(blockName)) {
|
||||||
// Circular dependency detected, but we'll continue (forward declarations should handle this)
|
// Circular dependency detected, but we'll continue (forward declarations should
|
||||||
|
// handle this)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visited.contains(blockName)) {
|
if (visited.contains(blockName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
visiting.add(blockName);
|
visiting.add(blockName);
|
||||||
|
|
||||||
// Visit dependencies first
|
// Visit dependencies first
|
||||||
for (String dep : block.dependencies) {
|
for (String dep : block.dependencies) {
|
||||||
Block depBlock = blocks.get(dep);
|
Block depBlock = blocks.get(dep);
|
||||||
|
@ -479,7 +543,7 @@ public class DataTypeWriter {
|
||||||
topologicalSortVisit(depBlock, blocks, visited, visiting, result);
|
topologicalSortVisit(depBlock, blocks, visited, visiting, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visiting.remove(blockName);
|
visiting.remove(blockName);
|
||||||
visited.add(blockName);
|
visited.add(blockName);
|
||||||
result.add(block);
|
result.add(block);
|
||||||
|
|
|
@ -11,11 +11,14 @@ import ghidra.app.script.GhidraScript;
|
||||||
import ghidra.program.model.data.CategoryPath;
|
import ghidra.program.model.data.CategoryPath;
|
||||||
import ghidra.program.model.data.Composite;
|
import ghidra.program.model.data.Composite;
|
||||||
import ghidra.program.model.data.DataType;
|
import ghidra.program.model.data.DataType;
|
||||||
|
import ghidra.program.model.data.Enum;
|
||||||
import ghidra.program.model.data.EnumDataType;
|
import ghidra.program.model.data.EnumDataType;
|
||||||
import ghidra.program.model.data.ProgramBasedDataTypeManager;
|
import ghidra.program.model.data.ProgramBasedDataTypeManager;
|
||||||
import ghidra.program.model.data.Structure;
|
import ghidra.program.model.data.Structure;
|
||||||
import ghidra.program.model.data.TypeDef;
|
import ghidra.program.model.data.TypeDef;
|
||||||
import ghidra.program.model.data.TypedefDataType;
|
import ghidra.program.model.data.TypedefDataType;
|
||||||
|
import ghidra.program.model.data.Union;
|
||||||
|
import ghidra.program.model.data.UnionDataType;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
|
|
||||||
public class TypeDumper {
|
public class TypeDumper {
|
||||||
|
@ -74,6 +77,7 @@ public class TypeDumper {
|
||||||
Iterator<DataType> it = dtm.getAllDataTypes();
|
Iterator<DataType> it = dtm.getAllDataTypes();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
DataType dt = it.next();
|
DataType dt = it.next();
|
||||||
|
|
||||||
if (typeBlacklist.contains(dt.getDisplayName()))
|
if (typeBlacklist.contains(dt.getDisplayName()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -81,15 +85,18 @@ public class TypeDumper {
|
||||||
if (catPath.getPathElements().length > 0 && categoryPathBlacklist.contains(catPath.getPathElements()[0]))
|
if (catPath.getPathElements().length > 0 && categoryPathBlacklist.contains(catPath.getPathElements()[0]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// if (dt.getName().equals("ImageBaseOffset32"))
|
if (dt instanceof Structure || dt instanceof TypeDef || dt instanceof EnumDataType
|
||||||
// throw new Exception("Found: " + dt.getDisplayName() + " - " +
|
|| dt instanceof Union || dt instanceof Enum) {
|
||||||
// catPath.getPathElements()[0] + " - " + dt.getClass().getSimpleName());
|
|
||||||
|
|
||||||
if (dt instanceof Structure || dt instanceof TypeDef || dt instanceof EnumDataType) {
|
if (dt.getDisplayName().contains("NormalizeFn"))
|
||||||
// script.println("Adding: " + dt.getDisplayName() + " - " +
|
script.println("DEBUG " + dt.getDisplayName() + " - " + dt.getClass().getSimpleName());
|
||||||
// dt.getClass().getSimpleName());
|
|
||||||
filteredTypes.add(dt);
|
if (dt.getDisplayName().contains("tdstObjectTypeElement_") ||
|
||||||
|
dt.getDisplayName().contains("ObjectTypeElementHandle"))
|
||||||
|
|
||||||
|
filteredTypes.add(dt);
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = "";
|
String s = "";
|
||||||
|
|
Loading…
Reference in New Issue