mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Merge remote-tracking branch 'origin/Ghidra_11.4'
This commit is contained in:
commit
2e7c5da7b0
2 changed files with 48 additions and 15 deletions
|
@ -82,7 +82,8 @@ public class DyldCacheExtractLoader extends MachoLoader {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor);
|
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);
|
addOptionalComponents(program, options, log, monitor);
|
||||||
}
|
}
|
||||||
catch (CancelledException e) {
|
catch (CancelledException e) {
|
||||||
|
@ -98,9 +99,29 @@ public class DyldCacheExtractLoader extends MachoLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadProgramInto(ByteProvider provider, LoadSpec loadSpec,
|
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 {
|
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
|
@Override
|
||||||
|
@ -220,11 +241,14 @@ public class DyldCacheExtractLoader extends MachoLoader {
|
||||||
files.addAll(fs.getFiles(flags));
|
files.addAll(fs.getFiles(flags));
|
||||||
for (GFile file : files) {
|
for (GFile file : files) {
|
||||||
Group[] children = program.getListing().getDefaultRootModule().getChildren();
|
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()))) {
|
||||||
ByteProvider p = fs.getByteProvider(file, monitor);
|
log.appendMsg("%s has already been added".formatted(file.getPath()));
|
||||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, p, monitor);
|
continue;
|
||||||
MachoExtractProgramBuilder.buildProgram(program, p, fileBytes, log, monitor);
|
|
||||||
}
|
}
|
||||||
|
ByteProvider p = fs.getByteProvider(file, monitor);
|
||||||
|
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, p, monitor);
|
||||||
|
MachoExtractProgramBuilder.buildProgram(program, p, fileBytes, true, log,
|
||||||
|
monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,19 +31,24 @@ import ghidra.util.task.TaskMonitor;
|
||||||
*/
|
*/
|
||||||
public class MachoExtractProgramBuilder extends MachoProgramBuilder {
|
public class MachoExtractProgramBuilder extends MachoProgramBuilder {
|
||||||
|
|
||||||
|
private boolean loadInto;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link MachoExtractProgramBuilder} based on the given information.
|
* Creates a new {@link MachoExtractProgramBuilder} based on the given information.
|
||||||
*
|
*
|
||||||
* @param program The {@link Program} to build up.
|
* @param program The {@link Program} to build up.
|
||||||
* @param provider The {@link ByteProvider} that contains the Mach-O's bytes.
|
* @param provider The {@link ByteProvider} that contains the Mach-O's bytes.
|
||||||
* @param fileBytes Where the Mach-O's bytes came from.
|
* @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 log The log.
|
||||||
* @param monitor A cancelable task monitor.
|
* @param monitor A cancelable task monitor.
|
||||||
* @throws Exception if a problem occurs.
|
* @throws Exception if a problem occurs.
|
||||||
*/
|
*/
|
||||||
protected MachoExtractProgramBuilder(Program program, ByteProvider provider,
|
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);
|
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 program The {@link Program} to build up.
|
||||||
* @param provider The {@link ByteProvider} that contains the Mach-O's bytes.
|
* @param provider The {@link ByteProvider} that contains the Mach-O's bytes.
|
||||||
* @param fileBytes Where the Mach-O's bytes came from.
|
* @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 log The log.
|
||||||
* @param monitor A cancelable task monitor.
|
* @param monitor A cancelable task monitor.
|
||||||
* @throws Exception if a problem occurs.
|
* @throws Exception if a problem occurs.
|
||||||
*/
|
*/
|
||||||
public static void buildProgram(Program program, ByteProvider provider, FileBytes fileBytes,
|
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,
|
MachoExtractProgramBuilder programBuilder = new MachoExtractProgramBuilder(program,
|
||||||
provider, fileBytes, log, monitor);
|
provider, fileBytes, loadInto, log, monitor);
|
||||||
programBuilder.build();
|
programBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +99,13 @@ public class MachoExtractProgramBuilder extends MachoProgramBuilder {
|
||||||
FunctionManager funcManager = program.getFunctionManager();
|
FunctionManager funcManager = program.getFunctionManager();
|
||||||
ExternalManager extManager = program.getExternalManager();
|
ExternalManager extManager = program.getExternalManager();
|
||||||
|
|
||||||
// Add the new exported symbol like normal
|
// Add the new exported symbol, but only make it an entry point if it's from the primary
|
||||||
super.processNewExport(baseAddr, export, name);
|
// thing being loaded
|
||||||
|
|
||||||
Address exportAddr = baseAddr.add(export.address());
|
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)) {
|
for (Symbol sym : symbolTable.getGlobalSymbols(name)) {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue