db/protos.zhl: own function signatures, applied like REPENTOGON's only where RET n agrees
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eafedb13a3
commit
e285a40016
4 files changed
+13
-7
No files matched your search
@@ -1,6 +1,6 @@
|
||||
// Applies REPENTOGON's function declarations (zhl dir) as prototypes, but only where this exe confirms them: for
|
||||
// __thiscall/__stdcall/__fastcall the callee pops its stack arguments (RET n), so the declared stack parameter sizes must
|
||||
// add up to the purge Ghidra found; __cdecl must purge 0. Overloads pick the declaration that fits. Arg: zhl dir
|
||||
// add up to the purge Ghidra found; __cdecl must purge 0. Overloads pick the declaration that fits. Args: dirs of *.zhl
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.program.model.listing.*;
|
||||
@@ -40,10 +40,12 @@ public class ApplyProtos extends GhidraScript {
|
||||
dtm = currentProgram.getDataTypeManager();
|
||||
Pattern decl = Pattern.compile("^\\s*(?:static\\s+)?(__thiscall|__stdcall|__cdecl|__fastcall)\\s+(.+?)\\s*([\\w:]+::~?\\w+)\\s*\\((.*?)\\)\\s*;");
|
||||
Map<String, List<Matcher>> byName = new HashMap<>();
|
||||
for (Path p : Files.newDirectoryStream(Paths.get(getScriptArgs()[0]), "*.zhl"))
|
||||
Map<Matcher, String> from = new IdentityHashMap<>();
|
||||
for (String dir : getScriptArgs()) // db/ first: its declarations are tried before REPENTOGON's
|
||||
for (Path p : Files.newDirectoryStream(Paths.get(dir), "*.zhl"))
|
||||
for (String l : Files.readAllLines(p, java.nio.charset.StandardCharsets.ISO_8859_1)) {
|
||||
Matcher m = decl.matcher(l);
|
||||
if (m.find()) byName.computeIfAbsent(m.group(3).replace("_", ""), k -> new ArrayList<>()).add(m);
|
||||
if (m.find()) { byName.computeIfAbsent(m.group(3).replace("_", ""), k -> new ArrayList<>()).add(m); from.put(m, dir.contains("repentogon") ? "REPENTOGON" : "db/" + p.getFileName()); }
|
||||
}
|
||||
int applied = 0, rejected = 0, unknown = 0;
|
||||
for (Function f : currentProgram.getListing().getFunctions(true)) {
|
||||
@@ -76,7 +78,7 @@ public class ApplyProtos extends GhidraScript {
|
||||
f.setReturnType(ret, SourceType.USER_DEFINED);
|
||||
f.replaceParameters(Function.FunctionUpdateType.DYNAMIC_STORAGE_FORMAL_PARAMS, true, SourceType.USER_DEFINED, ps.toArray(new ParameterImpl[0]));
|
||||
String cm = f.getComment() == null ? "" : f.getComment() + "\n";
|
||||
if (!cm.contains("prototype:")) f.setComment(cm + "prototype: REPENTOGON, confirmed by RET " + purge);
|
||||
if (!cm.contains("prototype:")) f.setComment(cm + "prototype: " + from.get(m) + ", confirmed by RET " + purge);
|
||||
applied++; done = true; break;
|
||||
}
|
||||
if (!done) rejected++;
|
||||
|
||||
Reference in new issue
Block a user