GP-4699: Fixed a regression in the MachoLoader that prevented some KDK

binaries from being loaded
This commit is contained in:
Ryan Kurtz 2024-06-20 06:05:30 -04:00
parent b43c58f07b
commit 42710d014d
2 changed files with 22 additions and 15 deletions

View file

@ -244,22 +244,25 @@ public class MachoPrelinkUtils {
* @param offset The offset within the provider to check. * @param offset The offset within the provider to check.
* @return True A valid {@link LoadSpec} for the Mach-O at the given provider's offset, or null * @return True A valid {@link LoadSpec} for the Mach-O at the given provider's offset, or null
* if it is not a Mach-O or a valid {@link LoadSpec} could not be found. * if it is not a Mach-O or a valid {@link LoadSpec} could not be found.
* @throws IOException if there was an IO-related problem.
*/ */
private static LoadSpec getMachoLoadSpec(ByteProvider provider, long offset) private static LoadSpec getMachoLoadSpec(ByteProvider provider, long offset) {
throws IOException { try {
Collection<LoadSpec> loadSpecs = new MachoLoader().findSupportedLoadSpecs( Collection<LoadSpec> loadSpecs = new MachoLoader().findSupportedLoadSpecs(
new ByteProviderWrapper(provider, offset, provider.length() - offset)); new ByteProviderWrapper(provider, offset, provider.length() - offset));
// Getting a LoadSpec back means it's a Mach-O we can load. We also need to make sure // Getting a LoadSpec back means it's a Mach-O we can load. We also need to make sure
// the LoadSpec has a language/compiler spec defined to know we support the processor the // the LoadSpec has a language/compiler spec defined to know we support the processor the
// loader detected. // loader detected.
if (!loadSpecs.isEmpty()) { if (!loadSpecs.isEmpty()) {
LoadSpec loadSpec = loadSpecs.iterator().next(); LoadSpec loadSpec = loadSpecs.iterator().next();
if (loadSpec.getLanguageCompilerSpec() != null) { if (loadSpec.getLanguageCompilerSpec() != null) {
return loadSpec; return loadSpec;
}
} }
return null;
}
catch (IOException e) {
return null;
} }
return null;
} }
} }

View file

@ -412,7 +412,9 @@ public class MachoProgramBuilder {
} }
} }
if (segmentFragment == null) { if (segmentFragment == null) {
log.appendMsg("Could not find/fixup segment in Program Tree: " + segmentName); if (segment.getVMsize() != 0 || segment.getFileSize() != 0) {
log.appendMsg("Could not find/fixup segment in Program Tree: " + segmentName);
}
continue; continue;
} }
ProgramModule segmentModule = rootModule.createModule(segmentName + suffix); ProgramModule segmentModule = rootModule.createModule(segmentName + suffix);
@ -830,8 +832,10 @@ public class MachoProgramBuilder {
List<DyldChainedFixupsCommand> loadCommands = List<DyldChainedFixupsCommand> loadCommands =
machoHeader.getLoadCommands(DyldChainedFixupsCommand.class); machoHeader.getLoadCommands(DyldChainedFixupsCommand.class);
if (!loadCommands.isEmpty()) { if (!loadCommands.isEmpty()) {
BinaryReader memReader = new BinaryReader(new MemoryByteProvider(memory, imagebase),
!memory.isBigEndian());
for (DyldChainedFixupsCommand loadCommand : loadCommands) { for (DyldChainedFixupsCommand loadCommand : loadCommands) {
fixups.addAll(loadCommand.getChainedFixups(reader, imagebase.getOffset(), fixups.addAll(loadCommand.getChainedFixups(memReader, imagebase.getOffset(),
symbolTable, log, monitor)); symbolTable, log, monitor));
} }
} }