Ghidra is a software reverse engineering (SRE) framework
GP-0: Fixing split dyld_shared_cache FILE memory block issue
Ryan Kurtz879963b0065f
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldCacheHeader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldCacheHeader.javaindex f751995705..83cc230cd1 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldCacheHeader.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldCacheHeader.java@@ -25,6 +25,7 @@ import ghidra.app.util.importer.MessageLog;import ghidra.program.model.address.*;import ghidra.program.model.data.*;import ghidra.program.model.listing.*;+import ghidra.program.model.mem.MemoryBlock;import ghidra.program.model.util.CodeUnitInsertionException;import ghidra.util.exception.CancelledException;import ghidra.util.exception.DuplicateNameException;@@ -101,6 +102,7 @@ public class DyldCacheHeader implements StructConverter {private List<DyldCacheImageTextInfo> imageTextInfoList;private DyldArchitecture architecture;private List<DyldCacheMappingAndSlideInfo> cacheMappingAndSlideInfoList;+ private MemoryBlock fileBlock;/*** Create a new {@link DyldCacheHeader}.@@ -279,7 +281,7 @@ public class DyldCacheHeader implements StructConverter {parseImageTextInfo(log, monitor);}parseCacheMappingSlideInfo(log, monitor);- if (haSlideInfo()) {+ if (hasSlideInfo()) {parseSlideInfos(log, monitor);}}@@ -902,6 +904,15 @@ public class DyldCacheHeader implements StructConverter {"Failed to markup dyld_cache_image_text_info.");}}++ /**+ * Sets the {@link MemoryBlock} associated with this header's FILE block.+ *+ * @param block The {@link MemoryBlock} associated with this header's FILE block+ */+ public void setFileBlock(MemoryBlock block) {+ fileBlock = block;+ }/*** Gets the given file offset's corresponding memory address.@@ -923,10 +934,10 @@ public class DyldCacheHeader implements StructConverter {}}- // Now check the special memory block that contains bytes that weren't supposed to get+ // Now check the special FILE memory block that contains bytes that weren't supposed to get// mapped in to memory- AddressSpace fileSpace = program.getAddressFactory().getAddressSpace("FILE");- if (fileSpace != null) {+ if (fileBlock != null) {+ AddressSpace fileSpace = fileBlock.getStart().getAddressSpace();try {return fileSpace.getAddress(offset);}@@ -943,7 +954,7 @@ public class DyldCacheHeader implements StructConverter {** @return True if any slide info exists; otherwise, false*/- public boolean haSlideInfo() {+ public boolean hasSlideInfo() {if (slideInfoSize != 0) {// this is no longer used, but if non-zero, is older format and has slide-inforeturn true;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/DyldCacheProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/DyldCacheProgramBuilder.javaindex 11a46ee975..30763770a5 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/DyldCacheProgramBuilder.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/DyldCacheProgramBuilder.java@@ -32,6 +32,7 @@ import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSpace;import ghidra.program.model.listing.*;import ghidra.program.model.mem.MemoryAccessException;+import ghidra.program.model.mem.MemoryBlock;import ghidra.program.model.symbol.SourceType;import ghidra.program.model.symbol.SymbolUtilities;import ghidra.util.exception.CancelledException;@@ -176,10 +177,11 @@ public class DyldCacheProgramBuilder extends MachoProgramBuilder {if (endOfMappedOffset < bp.length()) {monitor.setMessage("Processing DYLD unmapped memory block...");- MemoryBlockUtils.createInitializedBlock(program, true, "FILE",+ MemoryBlock fileBlock = MemoryBlockUtils.createInitializedBlock(program, true, "FILE",AddressSpace.OTHER_SPACE.getAddress(endOfMappedOffset), fb, endOfMappedOffset,bp.length() - endOfMappedOffset, "Useful bytes that don't get mapped into memory","", false, false, false, log);+ dyldCacheHeader.setFileBlock(fileBlock);}}