Merge remote-tracking branch 'origin/Ghidra_11.4'

This commit is contained in:
Ryan Kurtz 2025-05-19 09:47:37 -04:00
commit 2e7c5da7b0
2 changed files with 48 additions and 15 deletions

View file

@ -82,7 +82,8 @@ public class DyldCacheExtractLoader extends MachoLoader {
try {
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor);
MachoExtractProgramBuilder.buildProgram(program, provider, fileBytes, log, monitor);
MachoExtractProgramBuilder.buildProgram(program, provider, fileBytes, false, log,
monitor);
addOptionalComponents(program, options, log, monitor);
}
catch (CancelledException e) {
@ -98,9 +99,29 @@ public class DyldCacheExtractLoader extends MachoLoader {
@Override
protected void loadProgramInto(ByteProvider provider, LoadSpec loadSpec,
List<Option> options, MessageLog messageLog, Program program, TaskMonitor monitor)
List<Option> options, MessageLog log, Program program, TaskMonitor monitor)
throws IOException, LoadException, CancelledException {
load(provider, loadSpec, options, program, monitor, messageLog);
FSRL fsrl = provider.getFSRL();
Group[] children = program.getListing().getDefaultRootModule().getChildren();
if (Arrays.stream(children).anyMatch(e -> e.getName().contains(fsrl.getPath()))) {
log.appendMsg("%s has already been added".formatted(fsrl.getPath()));
return;
}
try {
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor);
MachoExtractProgramBuilder.buildProgram(program, provider, fileBytes, true, log,
monitor);
addOptionalComponents(program, options, log, monitor);
}
catch (CancelledException e) {
return;
}
catch (IOException e) {
throw e;
}
catch (Exception e) {
throw new IOException(e);
}
}
@Override
@ -220,11 +241,14 @@ public class DyldCacheExtractLoader extends MachoLoader {
files.addAll(fs.getFiles(flags));
for (GFile file : files) {
Group[] children = program.getListing().getDefaultRootModule().getChildren();
if (Arrays.stream(children).noneMatch(e -> e.getName().contains(file.getPath()))) {
if (Arrays.stream(children).anyMatch(e -> e.getName().contains(file.getPath()))) {
log.appendMsg("%s has already been added".formatted(file.getPath()));
continue;
}
ByteProvider p = fs.getByteProvider(file, monitor);
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, p, monitor);
MachoExtractProgramBuilder.buildProgram(program, p, fileBytes, log, monitor);
}
MachoExtractProgramBuilder.buildProgram(program, p, fileBytes, true, log,
monitor);
}
}
}

View file

@ -31,19 +31,24 @@ import ghidra.util.task.TaskMonitor;
*/
public class MachoExtractProgramBuilder extends MachoProgramBuilder {
private boolean loadInto;
/**
* Creates a new {@link MachoExtractProgramBuilder} based on the given information.
*
* @param program The {@link Program} to build up.
* @param provider The {@link ByteProvider} that contains the Mach-O's bytes.
* @param fileBytes Where the Mach-O's bytes came from.
* @param loadInto True if the Mach-O is being loaded into an existing program; otherwise, false
* @param log The log.
* @param monitor A cancelable task monitor.
* @throws Exception if a problem occurs.
*/
protected MachoExtractProgramBuilder(Program program, ByteProvider provider,
FileBytes fileBytes, MessageLog log, TaskMonitor monitor) throws Exception {
FileBytes fileBytes, boolean loadInto, MessageLog log, TaskMonitor monitor)
throws Exception {
super(program, provider, fileBytes, log, monitor);
this.loadInto = loadInto;
}
/**
@ -52,14 +57,15 @@ public class MachoExtractProgramBuilder extends MachoProgramBuilder {
* @param program The {@link Program} to build up.
* @param provider The {@link ByteProvider} that contains the Mach-O's bytes.
* @param fileBytes Where the Mach-O's bytes came from.
* @param loadInto True if the Mach-O is being loaded into an existing program; otherwise, false
* @param log The log.
* @param monitor A cancelable task monitor.
* @throws Exception if a problem occurs.
*/
public static void buildProgram(Program program, ByteProvider provider, FileBytes fileBytes,
MessageLog log, TaskMonitor monitor) throws Exception {
boolean loadInto, MessageLog log, TaskMonitor monitor) throws Exception {
MachoExtractProgramBuilder programBuilder = new MachoExtractProgramBuilder(program,
provider, fileBytes, log, monitor);
provider, fileBytes, loadInto, log, monitor);
programBuilder.build();
}
@ -93,10 +99,13 @@ public class MachoExtractProgramBuilder extends MachoProgramBuilder {
FunctionManager funcManager = program.getFunctionManager();
ExternalManager extManager = program.getExternalManager();
// Add the new exported symbol like normal
super.processNewExport(baseAddr, export, name);
// Add the new exported symbol, but only make it an entry point if it's from the primary
// thing being loaded
Address exportAddr = baseAddr.add(export.address());
program.getSymbolTable().createLabel(exportAddr, name, SourceType.IMPORTED);
if (!loadInto) {
program.getSymbolTable().addExternalEntryPoint(exportAddr);
}
for (Symbol sym : symbolTable.getGlobalSymbols(name)) {