Better type blacklisting

This commit is contained in:
Guus Waals 2024-09-30 23:28:57 +08:00
parent 49ef8d7148
commit 70c2881dbe
5 changed files with 133 additions and 8 deletions

View File

@ -0,0 +1,88 @@
basetsd.h
bink.h
cderr.h
commdlg.h
crtdefs.h
ctype.h
d3d8.h
d3d8caps.h
d3d8types.h
dde.h
ddeml.h
dlgs.h
excpt.h
file.h
float.h
guiddef.h
imm.h
io.h
jmorecfg.h
jpeglib.h
LstDef2.h
Izexpand.h
malloc.h
math.h
mbstring.h
mcx.h
mmsystem.h
mswsock.h
msxml.h
nb30.h
oleidl.h
oaidl.h
objbase.h
oleauto.h
ole2.h
objidl.h
process.h
propidl.h
prsht.h
qos.h
rad.h
rpc.h
rpcasync.h
rpcdce.h
rpcdcep.h
rpcndr.h
rpcnsi.h
rpcnsip.h
rpcnterr.h
servprov.h
shellapi.h
snddef.h
sound.h
stdarg.h
stdint.h
stdio.h
stdlib.h
string.h
time.h
timer.h
tvout.h
unknwn.h
urlmon.h
vadefs.h
verrsrc.h
winbase.h
wincon.h
wincrypt.h
windef.h
WinDef.h
winefs.h
winerror.h
wingdi.h
winioctl.h
winnetwk.h
winnls.h
winnt.h
winperf.h
winreg.h
winscard.h
winsmcrd.h
winsock.h
winsock2.h
winspool.h
winsvc.h
winuser.h
winver.h
wtypes.h

View File

@ -517,7 +517,7 @@ public class DataTypeWriter {
this.writer.write(EOL);
this.writer.write(EOL);
} else {
this.writer.write("typedef enum " + enumName + " {");
this.writer.write("typedef enum " + enumName + "_ {");
String description = enumm.getDescription();
if (description != null && description.length() != 0) {
var10000 = this.writer;

View File

@ -18,6 +18,7 @@ public class RecompileConfig {
// The output directory for the recompiled game
public final String outputDir;
public final String typeBlacklistPath;
public final String categoryPathBlacklistPath;
public final String functionBlacklistPath;
// The static memory block
public final Address staticMemoryBlockStart;
@ -60,6 +61,7 @@ public class RecompileConfig {
script.println("Output path: " + outputDir);
typeBlacklistPath = new File(outputDir, "type_blacklist.txt").toString();
categoryPathBlacklistPath = new File(outputDir, "type_path_blacklist.txt").toString();
functionBlacklistPath = new File(outputDir, "function_blacklist.txt").toString();
dirDecompAuto = new File(outputDir, "gh_auto");

View File

@ -8,10 +8,13 @@ import java.util.Iterator;
import java.util.List;
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.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.listing.Program;
@ -28,7 +31,9 @@ public class TypeDumper {
public void run() throws Exception {
ProgramBasedDataTypeManager dtm = currentProgram.getDataTypeManager();
HashSet<String> typeBlacklist = Utils.loadStructBlacklist(RecompileConfig.INSTANCE.typeBlacklistPath);
HashSet<String> typeBlacklist = Utils.loadSimpleBlacklist(RecompileConfig.INSTANCE.typeBlacklistPath);
HashSet<String> categoryPathBlacklist = Utils
.loadSimpleBlacklist(RecompileConfig.INSTANCE.categoryPathBlacklistPath);
if (typeBlacklist == null) {
script.println("Building struct blacklist from existing data types");
@ -44,15 +49,45 @@ public class TypeDumper {
}
List<DataType> filteredTypes = new ArrayList<>();
// Iterator<DataType> compIt = dtm.getAllDataTypes();
// while (compIt.hasNext()) {
// DataType comp = compIt.next();
// // script.println("Found: " + comp.getDisplayName() + " - " +
// // comp.getClass().getSimpleName());
// if (comp instanceof TypeDef) {
// if (comp.getDisplayName().startsWith("FIL_")) {
// script.println("Found: " + comp.getDisplayName() + " - " + comp.getName() + "
// - " + comp.getClass().getSimpleName());
// }
// }
// // if (comp.getName() == "FIL_tdstConcatFile") {
// // // script.println("Found: " + dt.getDisplayName() + " - " +
// // // dt.getClass().getSimpleName());
// // throw new Exception("Found: " + comp.getDisplayName() + " - " +
// comp.getClass().getSimpleName());
// // }
// }
Iterator<DataType> it = dtm.getAllDataTypes();
while (it.hasNext()) {
DataType dt = it.next();
if (dt instanceof Structure || dt instanceof TypedefDataType || dt instanceof EnumDataType) {
if (typeBlacklist.contains(dt.getDisplayName()))
continue;
script.println("Adding: " + dt.getDisplayName() + " - " +
dt.getClass().getSimpleName());
if (typeBlacklist.contains(dt.getDisplayName()))
continue;
CategoryPath catPath = dt.getCategoryPath();
if (catPath.getPathElements().length > 0 && categoryPathBlacklist.contains(catPath.getPathElements()[0]))
continue;
script.println("Type: " + dt.getDisplayName() + " - CatPath: " + dt.getCategoryPath());
// 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) {
// script.println("Adding: " + dt.getDisplayName() + " - " +
// dt.getClass().getSimpleName());
filteredTypes.add(dt);
}
}

View File

@ -25,7 +25,7 @@ public class Utils {
return name.replaceAll("[^a-zA-Z0-9_]", "_");
}
public static HashSet<String> loadStructBlacklist(String path) {
public static HashSet<String> loadSimpleBlacklist(String path) {
File file = new File(path);
HashSet<String> structBlacklist = new HashSet<>();
try (Scanner scanner = new Scanner(file)) {