Redo some autos

This commit is contained in:
2024-10-01 02:36:30 +08:00
parent 46d9e3fda0
commit 3e469475c9
469 changed files with 2148 additions and 7431 deletions

View File

@@ -25,9 +25,9 @@ public class RebuildFunctionDatabase extends GhidraScript {
functionDB = new FunctionDatabase(this);
scanDirectory(RecompileConfig.INSTANCE.dirDecompAuto);
scanDirectory(RecompileConfig.INSTANCE.dirDecompFix);
scanDirectory(RecompileConfig.INSTANCE.dirDecompStub);
scanDirectory(RecompileConfig.INSTANCE.dirDecompAuto, FunctionDatabase.Type.Auto);
scanDirectory(RecompileConfig.INSTANCE.dirDecompFix, FunctionDatabase.Type.Fix);
scanDirectory(RecompileConfig.INSTANCE.dirDecompStub, FunctionDatabase.Type.Stub);
println("Applying default filters...");
functionDB.applyDefaultFilters(rebuildAllGlobals);
@@ -45,17 +45,17 @@ public class RebuildFunctionDatabase extends GhidraScript {
// }
}
private void scanDirectory(File directory) throws Exception {
private void scanDirectory(File directory, FunctionDatabase.Type type) throws Exception {
File[] files = directory.listFiles((dir, name) -> name.endsWith(".cxx"));
if (files == null)
return;
for (File file : files) {
scanFile(file);
scanFile(file, type);
}
}
private void scanFile(File file) throws Exception {
private void scanFile(File file, FunctionDatabase.Type type) throws Exception {
println("Scanning " + file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
@@ -106,6 +106,7 @@ public class RebuildFunctionDatabase extends GhidraScript {
entry.address = functionAddress;
entry.name = functionName;
entry.file = file;
entry.type = type;
entry.dependencies = dependencies;
functionDB.entries.add(entry);
} else {

View File

@@ -13,6 +13,12 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
public class FunctionDatabase {
public enum Type {
Auto,
Fix,
Stub
}
public class Dependency implements java.io.Serializable {
private static final long serialVersionUID = 1L;
public Address address;
@@ -42,12 +48,14 @@ public class FunctionDatabase {
public Address address;
public String name;
public File file;
public Type type;
public List<Dependency> dependencies = new ArrayList<>();
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
out.writeObject(address != null ? address.toString() : null);
out.writeObject(name);
out.writeObject(file != null ? file.toString() : null);
out.writeObject(type);
out.writeObject(dependencies);
}
@@ -61,6 +69,7 @@ public class FunctionDatabase {
if (fileString != null) {
file = new File(fileString);
}
type = (Type) in.readObject();
dependencies = (List<Dependency>) in.readObject();
}
}
@@ -117,8 +126,8 @@ public class FunctionDatabase {
Function function = script.getFunctionAt(entry.address);
if (function != null) {
String dirComponent = entry.file.getParent().toString();
boolean isAuto = dirComponent.startsWith(RecompileConfig.INSTANCE.dirDecompAuto.toString());
boolean isFix = dirComponent.startsWith(RecompileConfig.INSTANCE.dirDecompFix.toString());
boolean isAuto = entry.type == Type.Auto;
boolean isFix = entry.type == Type.Fix;
// Get the actual symbol name and store it in the hash map
String symbolName = function.getName();
symbolNames.put(entry.address, symbolName);
@@ -212,7 +221,7 @@ public class FunctionDatabase {
entry.file.delete();
madeAnyChanges = true;
}
} else if (pendingRegenerate) {
} else if (pendingRegenerate && entry.type != Type.Stub) {
if (!dryMode) {
functionsToRegenerate.add(function);
madeAnyChanges = true;

View File

@@ -107,7 +107,12 @@ public class GlobalDumper {
return true;
}
public void addGlobal(Address addr, HighSymbol sym) {
public void addGlobal(Address addr, HighSymbol sym) throws Exception {
if (addr.compareTo(RecompileConfig.INSTANCE.staticMemoryBlockStart) < 0
|| addr.compareTo(RecompileConfig.INSTANCE.staticMemoryBlockEnd) > 0) {
throw new Exception("Global address out of range: " + addr);
}
DataType dt = sym.getDataType();
// if(symb.get
if (sym.getDataType().getName() == "undefined") {