Include headless demangling in delink.sh

This means we get delinked objects with proper mangled names matching
our recompiled files.
This commit is contained in:
KeybadeBlox 2026-02-11 20:23:26 -05:00
parent 55046bf009
commit 53b0e82417
2 changed files with 32 additions and 4 deletions

View file

@ -65,8 +65,11 @@ delink() {
export MSYS_NO_PATHCONV=1 export MSYS_NO_PATHCONV=1
"$1/support/analyzeHeadless$suffix" "$2" "$3"\ "$1/support/analyzeHeadless$suffix" "$2" "$3"\
-readOnly\
-process default.xbe\ -process default.xbe\
-noanalysis\ -noanalysis\
-scriptPath ghidra_scripts\
-preScript MSVC7Mangle.java $4\
-postScript DelinkProgram.java\ -postScript DelinkProgram.java\
/exporter 'COFF relocatable object'\ /exporter 'COFF relocatable object'\
$(printf "/include-range %s " $4)\ $(printf "/include-range %s " $4)\

View file

@ -7,17 +7,20 @@
// permissive form (public, non-const, etc.). // permissive form (public, non-const, etc.).
// //
// Special symbol names like "operator new" or "scalar deleting destructor" // Special symbol names like "operator new" or "scalar deleting destructor"
// are given unique mangling. To properly demangle these, name them as they // are given unique mangling. To properly mangle these, name them as they
// appear in objdiff, replacing spaces with underscores, e.g. "operator_new" // appear in objdiff, replacing spaces with underscores, e.g. "operator_new"
// and "`scalar_deleting_destructor'" (notice the ` and '). // and "`scalar_deleting_destructor'" (notice the ` and ').
// //
// This script can be called in headless mode with the address ranges to mangle
// as arguments, e.g. 0x1234-0x5678. Any symbols referenced by functions being
// mangled will also be mangled in this mode (so that the references are
// correct if the mangling is done in preparation for exporting functions).
//
// @category Symbol // @category Symbol
import ghidra.app.script.GhidraScript; import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Data; import ghidra.program.model.address.AddressSet;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionSignature;
import ghidra.program.model.data.Array; import ghidra.program.model.data.Array;
import ghidra.program.model.data.BooleanDataType; import ghidra.program.model.data.BooleanDataType;
import ghidra.program.model.data.CharDataType; import ghidra.program.model.data.CharDataType;
@ -47,6 +50,9 @@ import ghidra.program.model.data.UnsignedLongLongDataType;
import ghidra.program.model.data.UnsignedShortDataType; import ghidra.program.model.data.UnsignedShortDataType;
import ghidra.program.model.data.VoidDataType; import ghidra.program.model.data.VoidDataType;
import ghidra.program.model.data.WideCharDataType; import ghidra.program.model.data.WideCharDataType;
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionSignature;
import ghidra.program.model.symbol.Namespace; import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.Reference; import ghidra.program.model.symbol.Reference;
import ghidra.program.model.symbol.SourceType; import ghidra.program.model.symbol.SourceType;
@ -66,6 +72,22 @@ import java.util.zip.CRC32;
public class MSVC7Mangle extends GhidraScript{ public class MSVC7Mangle extends GhidraScript{
@Override @Override
public void run() throws Exception { public void run() throws Exception {
// Get selected ranges from arguments if invoked headless
if (isRunningHeadless()) {
final String[] args = getScriptArgs();
final AddressSet addr = new AddressSet();
for (int i = 0; i < args.length; i++) {
final String[] range = args[i].split("-");
addr.add(
currentAddress.getAddress(range[0]),
currentAddress.getAddress(range[1])
);
}
setCurrentSelection(addr);
}
final SymbolIterator iter = currentProgram.getSymbolTable() final SymbolIterator iter = currentProgram.getSymbolTable()
.getPrimarySymbolIterator(currentSelection, true); .getPrimarySymbolIterator(currentSelection, true);
@ -87,6 +109,9 @@ public class MSVC7Mangle extends GhidraScript{
s.setName(mangled, SourceType.USER_DEFINED); s.setName(mangled, SourceType.USER_DEFINED);
makeGlobal(s); makeGlobal(s);
} }
// TODO: in headless mode, also mangle everything
// referenced by functions
} }
} }