Package ghidra.app.util.opinion
Class MachoProgramBuilder
java.lang.Object
ghidra.app.util.opinion.MachoProgramBuilder
- Direct Known Subclasses:
DyldCacheProgramBuilder,MachoPrelinkProgramBuilder
Builds up a Mach-O
Program by parsing the Mach-O headers.-
Field Summary
FieldsChangeModifier and TypeFieldDescriptionstatic final Stringprotected FileBytesprotected Listingprotected MessageLogprotected MachHeaderprotected Memoryprotected TaskMonitorprotected Programprotected ByteProviderNEWprotected booleanprotected AddressSpace -
Constructor Summary
ConstructorsChangeModifierConstructorDescriptionprotectedMachoProgramBuilder(Program program, ByteProvider provider, FileBytes fileBytes, boolean shouldAddChainedFixupsRelocations, MessageLog log, TaskMonitor monitor) Creates a newMachoProgramBuilderbased on the given information. -
Method Summary
ChangeModifier and TypeMethodDescriptionprotected voidbuild()NEWstatic voidbuildProgram(Program program, ByteProvider provider, FileBytes fileBytes, boolean addChainedFixupsRelocations, MessageLog log, TaskMonitor monitor) Builds up a Mach-OProgram.NEWprotected voidFixes up the Program Tree to better visualize the memory blocks that were split into sectionsprotected voidmarkupChainedFixups(List<Address> chainedFixups) Markup the givenListof chained fixups by creating pointers at their locations, if possibleprotected voidmarkupHeaders(MachHeader header, Address headerAddr) protected voidprotected voidNEWFixes up any chained fixups.protected voidprocessDyldInfo(boolean doClassic) protected voidLogs encrypted block rangesprotected voidAttempts to discover and set the entry point.NEWprotected booleanprocessExports(MachHeader header) NEWprotected voidProcesses the external relocations from allDynamicSymbolTableCommands.protected voidThe indirect symbols need to be applied across the IMPORT segment.protected voidNEWprotected voidProcesses the local relocations from allDynamicSymbolTableCommands.protected voidprocessMemoryBlocks(MachHeader header, String source, boolean processSections, boolean allowZeroAddr) Creates memory blocks for the given header.protected voidprotected voidSee crt.c from opensource.apple.comNEWprotected voidProcesses the section relocations from allSections.NEWprotected voidprocessSymbolTables(MachHeader header, boolean processExports) protected voidMODIFIEDprotected voidProcessesLoadCommands that we haven't implemented yet.protected voidprotected voidSets the image baseprotected voidprotected AddresssetupHeaderAddr(Collection<SegmentCommand> segments) Sets up theMachHeaderin memory and returns its address.REMOVEDvoidbuildProgram(Program program, ByteProvider provider, FileBytes fileBytes, MessageLog log, TaskMonitor monitor) RemovedREMOVEDvoidRemovedREMOVEDvoidRemovedREMOVEDvoidRemovedREMOVEDvoidRemoved
-
Field Details
-
BLOCK_SOURCE_NAME
- See Also:
-
machoHeader
-
program
-
provider
-
fileBytes
-
shouldAddChainedFixupsRelocations NEW
protected boolean shouldAddChainedFixupsRelocations -
log
-
monitor
-
memory
-
listing
-
space
-
-
Constructor Details
-
MachoProgramBuilder
protected MachoProgramBuilder(Program program, ByteProvider provider, FileBytes fileBytes, boolean shouldAddChainedFixupsRelocations, MessageLog log, TaskMonitor monitor) Creates a newMachoProgramBuilderbased on the given information.- Parameters:
program- TheProgramto build up.provider- TheByteProviderthat contains the Mach-O's bytes.fileBytes- Where the Mach-O's bytes came from.shouldAddChainedFixupsRelocations- True if relocations should be added for chained fixups; otherwise, false.log- The log.monitor- A cancelable task monitor.
-
-
Method Details
-
buildProgram NEW
public static void buildProgram(Program program, ByteProvider provider, FileBytes fileBytes, boolean addChainedFixupsRelocations, MessageLog log, TaskMonitor monitor) throws Exception Builds up a Mach-OProgram.- Parameters:
program- TheProgramto build up.provider- TheByteProviderthat contains the Mach-O's bytes.fileBytes- Where the Mach-O's bytes came from.addChainedFixupsRelocations- True if relocations should be added for chained fixups; otherwise, false.log- The log.monitor- A cancelable task monitor.- Throws:
Exception- if a problem occurs.
-
build
- Throws:
Exception
-
setImageBase
Sets the image base- Throws:
Exception- if there was a problem setting the image base
-
processEncryption
Logs encrypted block ranges- Throws:
Exception- if there was a problem detecting the encrypted block ranges
-
processEntryPoint
Attempts to discover and set the entry point.- Throws:
Exception- If there was a problem discovering or setting the entry point.
-
processMemoryBlocks
protected void processMemoryBlocks(MachHeader header, String source, boolean processSections, boolean allowZeroAddr) throws Exception Creates memory blocks for the given header.- Parameters:
header- The Mach-O header to process for memory block creation.source- A name that represents where the memory blocks came from.processSections- True to split segments into their sections.allowZeroAddr- True if memory blocks at address 0 should be processed; otherwise, false.- Throws:
Exception- If there was a problem processing the memory blocks.
-
fixupProgramTree NEW
Fixes up the Program Tree to better visualize the memory blocks that were split into sections- Throws:
Exception- if there was a problem fixing up the Program Tree
-
processUnsupportedLoadCommands MODIFIED
added throws CancelledException; removed throws Exception-void processUnsupportedLoadCommands() throws Exception+void processUnsupportedLoadCommands() throws CancelledExceptionProcessesLoadCommands that we haven't implemented yet.- Throws:
CancelledException- if the operation was cancelled.Exception(removed)
-
processExports NEW
- Throws:
Exception
-
processSymbolTables NEW
- Throws:
Exception
-
processIndirectSymbols
The indirect symbols need to be applied across the IMPORT segment. The individual section do not really matter except the number of bytes between each symbol varies based on section.- Throws:
Exception- if there is a problem
-
setRelocatableProperty
protected void setRelocatableProperty() -
processLibraries
protected void processLibraries() -
processProgramDescription
protected void processProgramDescription() -
renameObjMsgSendRtpSymbol
-
processUndefinedSymbols
- Throws:
Exception
-
processAbsoluteSymbols
- Throws:
Exception
-
processDyldInfo
protected void processDyldInfo(boolean doClassic) -
markupHeaders
- Throws:
Exception
-
setupHeaderAddr
protected Address setupHeaderAddr(Collection<SegmentCommand> segments) throws AddressOverflowException Sets up theMachHeaderin memory and returns its address. If the header was not intended to reside in memory (like for Mach-O object files}, then this method will create an area in the "OTHER" address space for the header to live in.- Parameters:
segments- ACollectionofMach-O segments- Returns:
- The
AddressofMachHeaderin memory - Throws:
AddressOverflowException- if the address lies outside the address space
-
markupSections
- Throws:
Exception
-
processProgramVars
protected void processProgramVars()See crt.c from opensource.apple.com -
processSectionRelocations NEW
Processes the section relocations from allSections.- Throws:
CancelledException- if the operation was cancelled.
-
processExternalRelocations NEW
Processes the external relocations from allDynamicSymbolTableCommands.- Throws:
CancelledException- if the operation was cancelled.
-
processLocalRelocations NEW
Processes the local relocations from allDynamicSymbolTableCommands.- Throws:
CancelledException- if the operation was cancelled.
-
processChainedFixups NEW
Fixes up any chained fixups. Relies on the __thread_starts section being present.- Returns:
- A list of addresses where chained fixups were performed.
- Throws:
Exception- if there was a problem reading/writing memory.
-
markupChainedFixups
Markup the givenListof chained fixups by creating pointers at their locations, if possible- Parameters:
chainedFixups- TheListof chained fixups to markup- Throws:
CancelledException- if the operation was cancelled
-