fix(ghidra): normalize Mach-O imported symbol names

This commit is contained in:
morluto
2026-10-11 09:59:27 +08:00
parent 49e6f00ed0
commit f88c99021b
5 changed files with 55 additions and 18 deletions
+9 -1
View File
@@ -33,7 +33,7 @@ public final class ReaGhidraNoReturnFix extends GhidraScript {
for (Function f : fm.getExternalFunctions()) {
monitor.checkCancelled();
// Do not apply import-name assumptions to local functions or to arbitrary externals.
if (!f.hasNoReturn() || !RETURNING_IMPORTS.contains(f.getName())) continue;
if (!f.hasNoReturn() || !RETURNING_IMPORTS.contains(externalAbiName(f))) continue;
f.setNoReturn(false);
enqueueReturning(f, cleared, pending);
}
@@ -98,6 +98,14 @@ public final class ReaGhidraNoReturnFix extends GhidraScript {
}
}
private String externalAbiName(Function function) {
String name = function.getName();
// Mach-O stores C-linkage symbols with one object-format underscore prefix.
if (currentProgram.getExecutableFormat().contains("Mach-O") && name.startsWith("_"))
return name.substring(1);
return name;
}
private boolean clearDecodedReturn(Function function, Listing listing) throws Exception {
if (!function.hasNoReturn() || function.isThunk()) return false;
for (Instruction instruction : listing.getInstructions(function.getBody(), true)) {