diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java index c5f0a4498e..7ba8eee3e7 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/chained/DyldChainedFixups.java @@ -110,7 +110,7 @@ public class DyldChainedFixups { } fixups.add(new DyldFixup(chainLoc, newChainValue, DyldChainedPtr.getSize(pointerFormat), - symbol, libOrdinal)); + symbol.getName(), libOrdinal)); next = DyldChainedPtr.getNext(pointerFormat, chainValue); nextOff += next * DyldChainedPtr.getStride(pointerFormat); @@ -161,7 +161,7 @@ public class DyldChainedFixups { finally { program.getRelocationTable() .add(addr, status, 0, new long[] { fixup.value() }, fixup.size(), - fixup.symbol() != null ? fixup.symbol().getName() : null); + fixup.symbol() != null ? fixup.symbol() : null); } if (fixup.symbol() != null && fixup.libOrdinal() != null) { try { @@ -170,7 +170,7 @@ public class DyldChainedFixups { } catch (Exception e) { log.appendMsg("WARNING: Problem fixing up symbol '%s' - %s" - .formatted(fixup.symbol().getName(), e.getMessage())); + .formatted(fixup.symbol(), e.getMessage())); } } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldFixup.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldFixup.java index a40399da62..30543d40e6 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldFixup.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldFixup.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,15 +15,13 @@ */ package ghidra.app.util.bin.format.macho.dyld; -import ghidra.program.model.symbol.Symbol; - /** * Stores information needed to perform a dyld pointer fixup * * @param offset The offset of where to perform the fixup (from some base address/index) * @param value The fixed up value * @param size The size of the fixup in bytes - * @param symbol The {@link Symbol} associated with the fixup (could be null) + * @param symbol The symbol associated with the fixup (could be null) * @param libOrdinal The library ordinal associated with the fixup (could be null) */ -public record DyldFixup(long offset, long value, int size, Symbol symbol, Integer libOrdinal) {} +public record DyldFixup(long offset, long value, int size, String symbol, Integer libOrdinal) {} 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.java index 0299424ac2..7e28ca6a7d 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 @@ -135,7 +135,7 @@ public class MachoProgramBuilder { processMemoryBlocks(machoHeader, provider.getName(), true, true); // Process load commands - processEntryPoint(); + processEntryPoint(provider.getName()); boolean exportsFound = processExports(machoHeader); processSymbolTables(machoHeader, !exportsFound); processStubs(); @@ -470,9 +470,10 @@ public class MachoProgramBuilder { * We will sort the discovered entry points by priorities assigned to each type of load * command, and only use the one with the highest priority. * + * @param source A name that represents where the memory blocks came from. * @throws Exception If there was a problem discovering or setting the entry point. */ - protected void processEntryPoint() throws Exception { + protected void processEntryPoint(String source) throws Exception { monitor.setMessage("Processing entry point..."); final int LC_MAIN_PRIORITY = 1; @@ -513,14 +514,11 @@ public class MachoProgramBuilder { realEntryFound = true; } else { - log.appendMsg("Ignoring entry point at: " + addr); + log.appendMsg("Ignoring entry point at " + addr + " in " + source); } } } } - else { - log.appendMsg("Unable to determine entry point."); - } } protected boolean processExports(MachHeader header) throws Exception { @@ -965,7 +963,7 @@ public class MachoProgramBuilder { try { fixupExternalLibrary(program, libraryPaths, binding.getLibraryOrdinal(), - symbol); + symbol.getName()); } catch (Exception e) { log.appendMsg("WARNING: Problem fixing up symbol '%s' - %s" @@ -1897,11 +1895,11 @@ public class MachoProgramBuilder { * @param program The {@link Program} * @param libraryPaths A {@link List} of library paths * @param libraryOrdinal The library ordinal - * @param symbol The {@link Symbol} + * @param symbol The symbol * @throws Exception if an unexpected problem occurs */ public static void fixupExternalLibrary(Program program, List libraryPaths, - int libraryOrdinal, Symbol symbol) throws Exception { + int libraryOrdinal, String symbol) throws Exception { ExternalManager extManager = program.getExternalManager(); int libraryIndex = libraryOrdinal - 1; if (libraryIndex < 0 || libraryIndex >= libraryPaths.size()) { @@ -1915,10 +1913,10 @@ public class MachoProgramBuilder { "Library '%s' not found in external program list".formatted(libraryName)); } ExternalLocation loc = - extManager.getUniqueExternalLocation(Library.UNKNOWN, symbol.getName()); + extManager.getUniqueExternalLocation(Library.UNKNOWN, symbol); if (loc != null) { try { - loc.setName(library, symbol.getName(), SourceType.IMPORTED); + loc.setName(library, symbol, SourceType.IMPORTED); } catch (InvalidInputException e) { throw new Exception("Symbol name contains illegal characters"); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/AbstractFileSystem.java b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/AbstractFileSystem.java index f7d7d39f3e..9d970d42dc 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/AbstractFileSystem.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/AbstractFileSystem.java @@ -91,4 +91,8 @@ public abstract class AbstractFileSystem implements GFileSystem { return fsIndex.resolveSymlinks(file); } + @Override + public String toString() { + return getName(); + } } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DyldCacheExtractLoader.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DyldCacheExtractLoader.java index dd341db5f9..ced7559518 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DyldCacheExtractLoader.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/DyldCacheExtractLoader.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,14 +18,17 @@ package ghidra.app.util.opinion; import java.io.IOException; import java.util.*; -import ghidra.app.util.MemoryBlockUtils; -import ghidra.app.util.Option; +import ghidra.app.util.*; import ghidra.app.util.bin.ByteProvider; +import ghidra.app.util.bin.format.macho.dyld.DyldCacheMappingAndSlideInfo; import ghidra.app.util.importer.MessageLog; import ghidra.file.formats.ios.dyldcache.DyldCacheExtractor; +import ghidra.file.formats.ios.dyldcache.DyldCacheFileSystem; +import ghidra.formats.gfilesystem.*; import ghidra.framework.model.DomainObject; import ghidra.framework.model.Project; import ghidra.program.database.mem.FileBytes; +import ghidra.program.model.listing.Group; import ghidra.program.model.listing.Program; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; @@ -37,6 +40,30 @@ public class DyldCacheExtractLoader extends MachoLoader { public final static String DYLD_CACHE_EXTRACT_NAME = "Extracted DYLD Component"; + static final String LIBOBJC_OPTION_NAME = "Add libobjc.dylib"; + static final boolean LIBOBJC_OPTION_DEFAULT = true; + + static final String AUTH_DATA_OPTION_NAME = "Add AUTH_DATA"; + static final boolean AUTH_DATA_OPTION_DEFAULT = false; + + static final String DIRTY_DATA_OPTION_NAME = "Add DIRTY_DATA"; + static final boolean DIRTY_DATA_OPTION_DEFAULT = false; + + static final String CONST_DATA_OPTION_NAME = "Add CONST_DATA"; + static final boolean CONST_DATA_OPTION_DEFAULT = true; + + static final String TEXT_STUBS_OPTION_NAME = "Add TEXT_STUBS"; + static final boolean TEXT_STUBS_OPTION_DEFAULT = true; + + static final String CONFIG_DATA_OPTION_NAME = "Add CONFIG_DATA"; + static final boolean CONFIG_DATA_OPTION_DEFAULT = false; + + static final String READ_ONLY_DATA_OPTION_NAME = "Add READ_ONLY_DATA"; + static final boolean READ_ONLY_DATA_OPTION_DEFAULT = true; + + static final String CONST_TPRO_DATA_OPTION_NAME = "Add CONST_TPRO_DATA"; + static final boolean CONST_TPRO_DATA_OPTION_DEFAULT = false; + @Override public Collection findSupportedLoadSpecs(ByteProvider provider) throws IOException { if (provider.length() >= DyldCacheExtractor.FOOTER_V1.length) { @@ -56,6 +83,7 @@ public class DyldCacheExtractLoader extends MachoLoader { try { FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor); MachoExtractProgramBuilder.buildProgram(program, provider, fileBytes, log, monitor); + addOptionalComponents(program, options, log, monitor); } catch (CancelledException e) { return; @@ -93,7 +121,46 @@ public class DyldCacheExtractLoader extends MachoLoader { @Override public List