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
|
||||
#include <Windows.h>
|
||||
#include <d3d8.h>
|
||||
#include <dinput.h>
|
||||
#else
|
||||
#include "win32_shim.h"
|
||||
#endif
|
||||
|
@ -21,6 +22,7 @@ typedef uint16_t word;
|
|||
typedef uint32_t dword;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned long uint;
|
||||
|
||||
struct undefined3 {
|
||||
uint8_t _0;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,7 @@ dlgs.h
|
|||
excpt.h
|
||||
float.h
|
||||
guiddef.h
|
||||
Guiddef.h
|
||||
imm.h
|
||||
io.h
|
||||
jmorecfg.h
|
||||
|
@ -48,7 +49,6 @@ rpcnsip.h
|
|||
rpcnterr.h
|
||||
servprov.h
|
||||
shellapi.h
|
||||
snddef.h
|
||||
stdarg.h
|
||||
stdint.h
|
||||
stdio.h
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// Source code is decompiled from a .class file using FernFlower decompiler.
|
||||
package re3lib;
|
||||
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.app.script.ScriptMessage;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.program.model.data.Enum;
|
||||
import ghidra.util.Msg;
|
||||
|
@ -147,14 +149,18 @@ public class DataTypeWriter {
|
|||
}
|
||||
|
||||
private Block createBlock(DataType dt) throws IOException {
|
||||
if (dt instanceof FunctionDefinition || dt instanceof FactoryDataType) {
|
||||
return null; // Skip these types
|
||||
if (dt instanceof FactoryDataType) {
|
||||
return null; // Skip only factory types
|
||||
}
|
||||
|
||||
dt = dt.clone(this.dtm);
|
||||
Set<String> dependencies = new HashSet<>();
|
||||
StringBuilder code = new StringBuilder();
|
||||
|
||||
if (dt.getDisplayName().contains("HIE_tduLinkedObject")) {
|
||||
System.out.println("DEBUG " + dt.getDisplayName());
|
||||
}
|
||||
|
||||
if (dt.equals(DataType.DEFAULT)) {
|
||||
code.append("typedef unsigned char ").append(DataType.DEFAULT.getName()).append(";");
|
||||
} else if (dt instanceof Dynamic) {
|
||||
|
@ -175,6 +181,8 @@ public class DataTypeWriter {
|
|||
writeTypeDefBlock((TypeDef) dt, code, dependencies);
|
||||
} else if (dt instanceof BuiltInDataType) {
|
||||
writeBuiltInBlock((BuiltInDataType) dt, code, dependencies);
|
||||
} else if (dt instanceof FunctionDefinition) {
|
||||
return null;
|
||||
} else {
|
||||
code.append(comment("Unable to write datatype. Type unrecognized: " + dt.getClass()));
|
||||
}
|
||||
|
@ -205,11 +213,8 @@ public class DataTypeWriter {
|
|||
private void writeUnionBlock(Union union, StringBuilder code, Set<String> dependencies) {
|
||||
String unionName = union.getDisplayName();
|
||||
|
||||
// Forward declaration
|
||||
code.append("typedef union ").append(unionName).append(" ").append(unionName)
|
||||
.append(", *P").append(unionName).append(";").append(EOL);
|
||||
|
||||
// Union definition
|
||||
// Union definition (no forward declaration needed - let dependency ordering
|
||||
// handle it)
|
||||
code.append("union ").append(unionName).append(" {");
|
||||
String descrip = union.getDescription();
|
||||
if (descrip != null && descrip.length() > 0) {
|
||||
|
@ -226,7 +231,8 @@ public class DataTypeWriter {
|
|||
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(annotator.getPrefix(composite, component));
|
||||
|
||||
|
@ -239,13 +245,10 @@ public class DataTypeWriter {
|
|||
|
||||
DataType componentDataType = component.getDataType();
|
||||
|
||||
// Add dependency only if it's not a pointer (pointers can be forward declared)
|
||||
if (!isPointerType(componentDataType)) {
|
||||
DataType depType = getImmediateDependencyType(componentDataType);
|
||||
if (depType != null && !isBuiltInType(depType)) {
|
||||
if (depType != null) {
|
||||
dependencies.add(depType.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
code.append(getTypeDeclaration(fieldName, componentDataType, component.getLength()));
|
||||
code.append(";");
|
||||
|
@ -297,19 +300,76 @@ 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) {
|
||||
String typedefName = typeDef.getDisplayName();
|
||||
DataType dataType = typeDef.getDataType();
|
||||
String dataTypeName = dataType.getDisplayName();
|
||||
|
||||
if (!isIntegral(typedefName, dataTypeName)) {
|
||||
// Add dependency only if it's not a pointer
|
||||
if (!isPointerType(dataType)) {
|
||||
// Handle function definition typedefs
|
||||
if (dataType instanceof FunctionDefinition) {
|
||||
writeFunctionDefinitionBlock((FunctionDefinition) dataType, typedefName, code, dependencies);
|
||||
} // Could be pointer to function
|
||||
else if (dataType instanceof Pointer && ((Pointer) dataType).getDataType() instanceof FunctionDefinition) {
|
||||
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);
|
||||
code.append("typedef ").append(typedefString).append(";");
|
||||
|
@ -338,6 +398,8 @@ public class DataTypeWriter {
|
|||
dt = ((Array) dt).getDataType();
|
||||
} else if (dt instanceof BitFieldDataType) {
|
||||
dt = ((BitFieldDataType) dt).getBaseDataType();
|
||||
} else if (dt instanceof Pointer) {
|
||||
dt = ((Pointer) dt).getDataType();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -382,7 +444,7 @@ public class DataTypeWriter {
|
|||
|
||||
String dataTypeString;
|
||||
if (dataType instanceof AbstractIntegerDataType) {
|
||||
dataTypeString = ((AbstractIntegerDataType)dataType).getCDeclaration();
|
||||
dataTypeString = ((AbstractIntegerDataType) dataType).getCDeclaration();
|
||||
} else {
|
||||
dataTypeString = dataType.getDisplayName();
|
||||
}
|
||||
|
@ -401,7 +463,8 @@ public class DataTypeWriter {
|
|||
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) {
|
||||
return "struct ";
|
||||
} else if (dataType instanceof Union) {
|
||||
|
@ -462,7 +525,8 @@ public class DataTypeWriter {
|
|||
String blockName = block.dataType.getDisplayName();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,14 @@ import ghidra.app.script.GhidraScript;
|
|||
import ghidra.program.model.data.CategoryPath;
|
||||
import ghidra.program.model.data.Composite;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.data.Enum;
|
||||
import ghidra.program.model.data.EnumDataType;
|
||||
import ghidra.program.model.data.ProgramBasedDataTypeManager;
|
||||
import ghidra.program.model.data.Structure;
|
||||
import ghidra.program.model.data.TypeDef;
|
||||
import ghidra.program.model.data.TypedefDataType;
|
||||
import ghidra.program.model.data.Union;
|
||||
import ghidra.program.model.data.UnionDataType;
|
||||
import ghidra.program.model.listing.Program;
|
||||
|
||||
public class TypeDumper {
|
||||
|
@ -74,6 +77,7 @@ public class TypeDumper {
|
|||
Iterator<DataType> it = dtm.getAllDataTypes();
|
||||
while (it.hasNext()) {
|
||||
DataType dt = it.next();
|
||||
|
||||
if (typeBlacklist.contains(dt.getDisplayName()))
|
||||
continue;
|
||||
|
||||
|
@ -81,15 +85,18 @@ public class TypeDumper {
|
|||
if (catPath.getPathElements().length > 0 && categoryPathBlacklist.contains(catPath.getPathElements()[0]))
|
||||
continue;
|
||||
|
||||
// if (dt.getName().equals("ImageBaseOffset32"))
|
||||
// throw new Exception("Found: " + dt.getDisplayName() + " - " +
|
||||
// catPath.getPathElements()[0] + " - " + dt.getClass().getSimpleName());
|
||||
if (dt instanceof Structure || dt instanceof TypeDef || dt instanceof EnumDataType
|
||||
|| dt instanceof Union || dt instanceof Enum) {
|
||||
|
||||
if (dt.getDisplayName().contains("NormalizeFn"))
|
||||
script.println("DEBUG " + dt.getDisplayName() + " - " + dt.getClass().getSimpleName());
|
||||
|
||||
if (dt.getDisplayName().contains("tdstObjectTypeElement_") ||
|
||||
dt.getDisplayName().contains("ObjectTypeElementHandle"))
|
||||
|
||||
if (dt instanceof Structure || dt instanceof TypeDef || dt instanceof EnumDataType) {
|
||||
// script.println("Adding: " + dt.getDisplayName() + " - " +
|
||||
// dt.getClass().getSimpleName());
|
||||
filteredTypes.add(dt);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
String s = "";
|
||||
|
|
Loading…
Reference in New Issue