tools: function names for the Ghidra project, Hold-Key test helper
- tools/names.txt lists identified sacred.exe functions ("0xADDR
Class::Method"); rename.ps1 / Rename.java apply them to the persistent
Ghidra project, so decompiles read with real names.
- decompile.ps1: parameters other than the addresses are named-only (the
first address was taken as -Out).
- game-input.ps1: Hold-Key for polled keys such as movement.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
09f7dcc0f4
commit
52db0f79f9
6 files changed
+182
-1
No files matched your search
@@ -0,0 +1,74 @@
|
||||
// Apply function names from tools/names.txt to the persistent sacred.exe
|
||||
// Ghidra project.
|
||||
//
|
||||
// Headless usage (see tools/rename.ps1):
|
||||
// analyzeHeadless <projectDir> sacred -process sacred.exe -noanalysis
|
||||
// -scriptPath tools/ghidra -postScript Rename.java <namesFile>
|
||||
//
|
||||
// names.txt: one "0xADDRESS Name" per line, "Class::Method" puts the function
|
||||
// into a class namespace; "#" starts a comment. Functions are created where
|
||||
// none starts at the address yet.
|
||||
// @category sacred_re
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import ghidra.app.cmd.disassemble.DisassembleCommand;
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.program.model.symbol.Namespace;
|
||||
import ghidra.program.model.symbol.SourceType;
|
||||
import ghidra.program.model.symbol.SymbolTable;
|
||||
|
||||
public class Rename extends GhidraScript {
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
String[] args = getScriptArgs();
|
||||
if (args.length != 1) {
|
||||
printerr("usage: Rename.java <namesFile>");
|
||||
return;
|
||||
}
|
||||
SymbolTable symbols = currentProgram.getSymbolTable();
|
||||
int renamed = 0;
|
||||
for (String raw : Files.readAllLines(Paths.get(args[0]), StandardCharsets.UTF_8)) {
|
||||
String line = raw.replaceAll("#.*", "").trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String[] parts = line.split("\\s+");
|
||||
if (parts.length != 2) {
|
||||
printerr("bad line: " + raw);
|
||||
continue;
|
||||
}
|
||||
Address address = toAddr(parts[0]);
|
||||
Function function = getFunctionAt(address);
|
||||
if (function == null) {
|
||||
new DisassembleCommand(address, null, true).applyTo(currentProgram, monitor);
|
||||
function = createFunction(address, null);
|
||||
}
|
||||
if (function == null) {
|
||||
printerr("no function at " + parts[0]);
|
||||
continue;
|
||||
}
|
||||
String name = parts[1];
|
||||
Namespace namespace = currentProgram.getGlobalNamespace();
|
||||
int separator = name.lastIndexOf("::");
|
||||
if (separator >= 0) {
|
||||
String className = name.substring(0, separator);
|
||||
name = name.substring(separator + 2);
|
||||
namespace = symbols.getNamespace(className, currentProgram.getGlobalNamespace());
|
||||
if (namespace == null) {
|
||||
namespace = symbols.createClass(currentProgram.getGlobalNamespace(), className,
|
||||
SourceType.USER_DEFINED);
|
||||
}
|
||||
}
|
||||
function.setParentNamespace(namespace);
|
||||
function.setName(name, SourceType.USER_DEFINED);
|
||||
renamed++;
|
||||
}
|
||||
println("renamed " + renamed + " functions");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user