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.
* @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.
* @throws IOException if there was an IO-related problem.
*/
private static LoadSpec getMachoLoadSpec(ByteProvider provider, long offset)
throws IOException {
Collection<LoadSpec> loadSpecs = new MachoLoader().findSupportedLoadSpecs(
new ByteProviderWrapper(provider, offset, provider.length() - offset));
private static LoadSpec getMachoLoadSpec(ByteProvider provider, long offset) {
try {
Collection<LoadSpec> loadSpecs = new MachoLoader().findSupportedLoadSpecs(
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
// the LoadSpec has a language/compiler spec defined to know we support the processor the
// loader detected.
if (!loadSpecs.isEmpty()) {
LoadSpec loadSpec = loadSpecs.iterator().next();
if (loadSpec.getLanguageCompilerSpec() != null) {
return loadSpec;
// 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
// loader detected.
if (!loadSpecs.isEmpty()) {
LoadSpec loadSpec = loadSpecs.iterator().next();
if (loadSpec.getLanguageCompilerSpec() != null) {
return loadSpec;
}
}
return null;
}
catch (IOException e) {
return null;
}
return null;
}
}

View file

@ -412,7 +412,9 @@ public class MachoProgramBuilder {
}
}
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;
}
ProgramModule segmentModule = rootModule.createModule(segmentName + suffix);
@ -830,8 +832,10 @@ public class MachoProgramBuilder {
List<DyldChainedFixupsCommand> loadCommands =
machoHeader.getLoadCommands(DyldChainedFixupsCommand.class);
if (!loadCommands.isEmpty()) {
BinaryReader memReader = new BinaryReader(new MemoryByteProvider(memory, imagebase),
!memory.isBigEndian());
for (DyldChainedFixupsCommand loadCommand : loadCommands) {
fixups.addAll(loadCommand.getChainedFixups(reader, imagebase.getOffset(),
fixups.addAll(loadCommand.getChainedFixups(memReader, imagebase.getOffset(),
symbolTable, log, monitor));
}
}