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;
|
||||||
|
@ -147,14 +149,18 @@ public class DataTypeWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
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,6 +181,8 @@ 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()));
|
||||||
}
|
}
|
||||||
|
@ -205,11 +213,8 @@ public class DataTypeWriter {
|
||||||
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) {
|
||||||
|
@ -226,7 +231,8 @@ public class DataTypeWriter {
|
||||||
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));
|
||||||
|
|
||||||
|
@ -239,12 +245,9 @@ public class DataTypeWriter {
|
||||||
|
|
||||||
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()));
|
||||||
|
@ -297,18 +300,75 @@ 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);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -382,7 +444,7 @@ public class DataTypeWriter {
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
@ -401,7 +463,8 @@ public class DataTypeWriter {
|
||||||
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) {
|
||||||
|
@ -458,11 +521,12 @@ public class DataTypeWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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