WIP
This commit is contained in:
@@ -15,6 +15,8 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RebuildFunctionDatabase extends GhidraScript {
|
||||
// Will rebuild all functions
|
||||
public boolean rebuildAllGlobals = true;
|
||||
FunctionDatabase functionDB;
|
||||
|
||||
@Override
|
||||
@@ -28,7 +30,7 @@ public class RebuildFunctionDatabase extends GhidraScript {
|
||||
scanDirectory(RecompileConfig.INSTANCE.dirDecompStub);
|
||||
|
||||
println("Applying default filters...");
|
||||
functionDB.applyDefaultFilters();
|
||||
functionDB.applyDefaultFilters(rebuildAllGlobals);
|
||||
|
||||
println("Saving function database...");
|
||||
functionDB.save();
|
||||
@@ -107,7 +109,8 @@ public class RebuildFunctionDatabase extends GhidraScript {
|
||||
entry.dependencies = dependencies;
|
||||
functionDB.entries.add(entry);
|
||||
} else {
|
||||
throw new Exception("Failed to parse function at " + file.getName());
|
||||
// throw new Exception("Failed to parse function at " + file.getName());
|
||||
println("Failed to parse function at " + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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("enum " + enumName + " {");
|
||||
String description = enumm.getDescription();
|
||||
if (description != null && description.length() != 0) {
|
||||
var10000 = this.writer;
|
||||
@@ -549,7 +549,7 @@ public class DataTypeWriter {
|
||||
this.writer.write(EOL);
|
||||
}
|
||||
|
||||
this.writer.write("} " + enumName + ";");
|
||||
this.writer.write("};");
|
||||
this.writer.write(EOL);
|
||||
this.writer.write(EOL);
|
||||
}
|
||||
|
@@ -100,10 +100,14 @@ public class FunctionDatabase {
|
||||
entries.add(entry);
|
||||
}
|
||||
|
||||
public void applyDefaultFilters() throws Exception {
|
||||
public void applyDefaultFilters(boolean rebuildAllGlobals) throws Exception {
|
||||
GlobalDumper globalDumper = new GlobalDumper(script);
|
||||
FunctionDumper dumper = new FunctionDumper(script, globalDumper);
|
||||
|
||||
if (rebuildAllGlobals) {
|
||||
globalDumper.removeGlobalManifest();
|
||||
}
|
||||
|
||||
boolean madeAnyChanges = false;
|
||||
|
||||
// Create a hash map to store symbol names
|
||||
@@ -142,6 +146,10 @@ public class FunctionDatabase {
|
||||
boolean pendingDelete = false;
|
||||
boolean pendingRegenerate = false;
|
||||
|
||||
if (rebuildAllGlobals) {
|
||||
pendingRegenerate = true;
|
||||
}
|
||||
|
||||
// Remove CRT and other blacklisted functions
|
||||
if (function == null || !dumper.isValidFunction(function)) {
|
||||
// Remove the file
|
||||
@@ -183,11 +191,13 @@ public class FunctionDatabase {
|
||||
for (Dependency dependency : entry.dependencies) {
|
||||
Function depFunction = script.getFunctionAt(dependency.address);
|
||||
if (depFunction == null) {
|
||||
script.println("Dependency not found: " + dependency.name + " at " + dependency.address + " in " + entry.file);
|
||||
script.println(
|
||||
"Dependency not found: " + dependency.name + " at " + dependency.address + " in " + entry.file);
|
||||
pendingRegenerate = true;
|
||||
} else if (!dumper.isValidFunction(depFunction) || !depFunction.getName().equals(dependency.name)) {
|
||||
script
|
||||
.println("Invalid dependency: " + dependency.name + " at " + dependency.address + " in " + entry.file + " should be " + dependency.name);
|
||||
.println("Invalid dependency: " + dependency.name + " at " + dependency.address + " in " + entry.file
|
||||
+ " should be " + dependency.name);
|
||||
pendingRegenerate = true;
|
||||
}
|
||||
}
|
||||
|
@@ -56,6 +56,12 @@ public class GlobalDumper {
|
||||
manifestFile = new File(RecompileConfig.INSTANCE.outputDir, "globals.txt");
|
||||
}
|
||||
|
||||
public void removeGlobalManifest() {
|
||||
if (manifestFile.exists()) {
|
||||
manifestFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean loadGlobalManifest() throws Exception {
|
||||
// Globals are stored in the format of
|
||||
// <address> || <name> || <type>
|
||||
@@ -117,7 +123,8 @@ public class GlobalDumper {
|
||||
script.println("WARNING: Missing type for global: " + sym.getName() + " at " + addr);
|
||||
return;
|
||||
}
|
||||
// script.println("Global: " + addr + " - " + sym.getName() + " - " + dt.getDisplayName());
|
||||
// script.println("Global: " + addr + " - " + sym.getName() + " - " +
|
||||
// dt.getDisplayName());
|
||||
globalAddrs.put(addr, new GlobalRec(addr, sym.getName(), dt));
|
||||
}
|
||||
|
||||
@@ -238,8 +245,11 @@ public class GlobalDumper {
|
||||
throw new Exception("Failed to delete backup file: " + backupFile + ", globals will not be saved!");
|
||||
}
|
||||
}
|
||||
if (!manifestFile.renameTo(backupFile))
|
||||
throw new Exception("Failed to rename manifest file: " + manifestFile + ", globals will not be saved!");
|
||||
|
||||
if (manifestFile.exists()) {
|
||||
if (!manifestFile.renameTo(backupFile))
|
||||
throw new Exception("Failed to rename manifest file: " + manifestFile + ", globals will not be saved!");
|
||||
}
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(manifestFile)) {
|
||||
script.println("Saving global manifest to " + manifestFile);
|
||||
|
@@ -80,7 +80,7 @@ public class TypeDumper {
|
||||
if (catPath.getPathElements().length > 0 && categoryPathBlacklist.contains(catPath.getPathElements()[0]))
|
||||
continue;
|
||||
|
||||
script.println("Type: " + dt.getDisplayName() + " - CatPath: " + dt.getCategoryPath());
|
||||
// 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());
|
||||
|
Reference in New Issue
Block a user