Ghidra is a software reverse engineering (SRE) framework
GP-4699: Fixed a regression in the MachoLoader that prevented some KDK binaries from being loaded
Ryan Kurtz42710d014d76
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkUtils.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkUtils.javaindex 9053927eb7..391b18759b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkUtils.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoPrelinkUtils.java@@ -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;}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.javaindex deab619cf5..4f53b6c195 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java@@ -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));}}