Merge remote-tracking branch 'origin/Ghidra_12.0'

This commit is contained in:
Ryan Kurtz
2025-11-24 05:45:29 -05:00
2 changed files with 24 additions and 13 deletions
@@ -25,6 +25,7 @@ import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryBlock; import ghidra.program.model.mem.MemoryBlock;
import ghidra.program.model.symbol.*; import ghidra.program.model.symbol.*;
import ghidra.program.model.util.CodeUnitInsertionException; import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.program.util.DiffUtility;
import ghidra.util.Msg; import ghidra.util.Msg;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.exception.InvalidInputException; import ghidra.util.exception.InvalidInputException;
@@ -47,6 +48,7 @@ public class ExternalDebugFileSymbolImporter {
private int funcSymbolsCopied; private int funcSymbolsCopied;
private int dataSymbolsCopied; private int dataSymbolsCopied;
private int symbolsSkipped; private int symbolsSkipped;
private int symbolCopyFailCount;
private int totalSymbolCount; private int totalSymbolCount;
public ExternalDebugFileSymbolImporter(Program program, Program externalDebugProgram, public ExternalDebugFileSymbolImporter(Program program, Program externalDebugProgram,
@@ -85,37 +87,48 @@ public class ExternalDebugFileSymbolImporter {
log.appendException(e); log.appendException(e);
} }
finally { finally {
Msg.info(this,
Msg.info(this, "Copied %d/%d of %d func/data/total symbols from external debug file" "Copied %d/%d/%d/%d func/data/fail/total symbols from external debug file"
.formatted(funcSymbolsCopied, dataSymbolsCopied, totalSymbolCount)); .formatted(funcSymbolsCopied, dataSymbolsCopied, symbolCopyFailCount,
totalSymbolCount));
} }
} }
private void copyExtSymbol(Symbol extSym) private void copyExtSymbol(Symbol extSym)
throws InvalidInputException, OverlappingFunctionException, CodeUnitInsertionException { throws InvalidInputException, OverlappingFunctionException, CodeUnitInsertionException {
Address extAddr = extSym.getAddress();
Address localAddr = DiffUtility.getCompatibleMemoryAddress(extAddr, program);
if (localAddr == null) {
Msg.info(this, "Unable to copy external debug file symbol %s@%s"
.formatted(extSym.getName(), extAddr));
symbolCopyFailCount++;
return;
}
SymbolType symType = extSym.getSymbolType(); SymbolType symType = extSym.getSymbolType();
String name = extSym.getName(); String name = extSym.getName();
Address addr = extSym.getAddress();
if (symType == SymbolType.FUNCTION && extSym.getObject() instanceof Function extFunc && if (symType == SymbolType.FUNCTION && extSym.getObject() instanceof Function extFunc &&
!extFunc.isThunk()) { !extFunc.isThunk()) {
Function existingFunction = funcMgr.getFunctionAt(addr); Function existingFunction = funcMgr.getFunctionAt(localAddr);
if (existingFunction == null) { if (existingFunction == null) {
existingFunction = existingFunction =
funcMgr.createFunction(name, addr, new AddressSet(addr), SourceType.IMPORTED); funcMgr.createFunction(name, localAddr, new AddressSet(localAddr),
SourceType.IMPORTED);
} }
else if (!name.equals(existingFunction.getName())) { else if (!name.equals(existingFunction.getName())) {
addLabelIfNeeded(name, addr); addLabelIfNeeded(name, localAddr);
} }
funcSymbolsCopied++; funcSymbolsCopied++;
} }
else if (symType == SymbolType.LABEL && extSym.getObject() instanceof Data extData) { else if (symType == SymbolType.LABEL && extSym.getObject() instanceof Data extData) {
if (Undefined.isUndefined(extData.getDataType()) && if (Undefined.isUndefined(extData.getDataType()) &&
DataUtilities.isUndefinedRange(program, addr, addr.add(extData.getLength()))) { DataUtilities.isUndefinedRange(program, localAddr,
localAddr.add(extData.getLength()))) {
DataType undefined = Undefined.getUndefinedDataType(extData.getLength()); DataType undefined = Undefined.getUndefinedDataType(extData.getLength());
DataUtilities.createData(program, addr, undefined, -1, DataUtilities.createData(program, localAddr, undefined, -1,
ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA); ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA);
} }
addLabelIfNeeded(name, addr); addLabelIfNeeded(name, localAddr);
dataSymbolsCopied++; dataSymbolsCopied++;
} }
else { else {
@@ -224,9 +224,7 @@ def main() -> None:
dist_dir: Path = pyghidra_dir / 'pypkg' / 'dist' dist_dir: Path = pyghidra_dir / 'pypkg' / 'dist'
venv_dir = get_ghidra_venv(install_dir, args.dev) venv_dir = get_ghidra_venv(install_dir, args.dev)
python_cmd: List[str] = find_supported_python_exe(install_dir, args.dev) python_cmd: List[str] = find_supported_python_exe(install_dir, args.dev)
print(install_dir)
if python_cmd is not None: if python_cmd is not None:
print(f'Using Python command: "{" ".join(python_cmd)}"') print(f'Using Python command: "{" ".join(python_cmd)}"')
else: else: