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
FieldsModifier and TypeFieldDescriptionprotected FileBytesstatic final Stringprotected Listingprotected MessageLogprotected MachHeaderprotected Memoryprotected TaskMonitorprotected Programprotected ByteProviderprotected BinaryReaderprotected AddressSpace -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMachoProgramBuilder(Program program, ByteProvider provider, FileBytes fileBytes, MessageLog log, TaskMonitor monitor) Creates a newMachoProgramBuilderbased on the given information. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuild()static voidbuildProgram(Program program, ByteProvider provider, FileBytes fileBytes, MessageLog log, TaskMonitor monitor) Builds up a Mach-OProgram.protected NamespacecreateNamespace(String namespaceName) static FunctioncreateOneByteFunction(Program program, String name, Address address) create a one-byte function, so that when the code is analyzed, it will be disassembled, and the function created with the correct body.static voidfixupExternalLibrary(Program program, List<String> libraryPaths, int libraryOrdinal, String symbol) protected voidfixupProgramTree(String suffix) Fixes up the Program Tree to better visualize the memory blocks that were split into sectionsprotected AddressGets the base address of this Mach-O.protected voidprotected voidmarkupChainedFixups(MachHeader header, List<Address> chainedFixups) Markup the givenListof chained fixups by creating pointers at their locations, if possibleprotected voidmarkupHeaders(MachHeader header, Address headerAddr) protected voidmarkupLoadCommandData(MachHeader header, String source) Marks upLoadCommanddadtaprotected voidprotected voidprotected voidprocessChainedFixups(List<String> libraryPaths) protected voidProcessesLoadCommands that appear to be corrupt.protected voidprocessDyldInfo(boolean doClassic, List<String> libraryPaths) protected voidLogs encrypted block rangesprotected voidprocessEntryPoint(String source) Attempts to discover and set the entry point.protected booleanprocessExports(MachHeader header) protected voidProcesses the external relocations from allDynamicSymbolTableCommands.protected voidProcesses the local relocations from allDynamicSymbolTableCommands.protected voidprocessMemoryBlocks(MachHeader header, String source, boolean processSections, boolean allowZeroAddr) Creates memory blocks for the given header.protected voidprocessNewExport(Address baseAddr, ExportTrie.ExportEntry export, String name) protected voidProcesses the section relocations from allSections.protected voidprotected voidprocessSymbolTables(MachHeader header, boolean processExports) protected voidprotected voidProcessesLoadCommands that we haven't implemented yet.protected voidprotected voidprotected voidprotected voidSets theProgramimage baseprotected voidprotected AddresssetupHeaderAddr(Collection<SegmentCommand> segments) Sets up theMachHeaderin memory and returns its address.
-
Field Details
-
HEADER_SYMBOL
- See Also:
-
machoHeader
-
program
-
provider
-
fileBytes
-
log
-
monitor
-
memory
-
listing
-
space
-
reader
-
-
Constructor Details
-
MachoProgramBuilder
protected MachoProgramBuilder(Program program, ByteProvider provider, FileBytes fileBytes, 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.log- The log.monitor- A cancelable task monitor.
-
-
Method Details
-
buildProgram
public static void buildProgram(Program program, ByteProvider provider, FileBytes fileBytes, 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.log- The log.monitor- A cancelable task monitor.- Throws:
Exception- if a problem occurs.
-
build
- Throws:
Exception
-
setProgramImageBase
Sets theProgramimage base -
getMachoBaseAddress
Gets the base address of this Mach-O. This is the address of the start of the Mach-O, not necessary theProgramimage base.- Returns:
- The base address of this Mach-O
-
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
Fixes up the Program Tree to better visualize the memory blocks that were split into sections- Parameters:
suffix- An optional suffix that will get appended to tree segment and segment nodes- Throws:
Exception- if there was a problem fixing up the Program Tree
-
processEntryPoint
Attempts to discover and set the entry point.A program may declare multiple entry points to, for example, confuse static analysis tools. 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.
- Parameters:
source- A name that represents where the memory blocks came from.- Throws:
Exception- If there was a problem discovering or setting the entry point.
-
processExports
- Throws:
Exception
-
processNewExport
protected void processNewExport(Address baseAddr, ExportTrie.ExportEntry export, String name) throws AddressOutOfBoundsException, Exception - Throws:
AddressOutOfBoundsExceptionException
-
processSymbolTables
- Throws:
Exception
-
processStubs
- Throws:
Exception
-
processUndefinedSymbols
- Throws:
Exception
-
processAbsoluteSymbols
- Throws:
Exception
-
processChainedFixups
- Throws:
Exception
-
processDyldInfo
- Throws:
Exception
-
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
-
processSectionRelocations
Processes the section relocations from allSections.- Throws:
CancelledException- if the operation was cancelled.
-
processExternalRelocations
Processes the external relocations from allDynamicSymbolTableCommands.- Throws:
CancelledException- if the operation was cancelled.
-
processLocalRelocations
Processes the local relocations from allDynamicSymbolTableCommands.- Throws:
CancelledException- if the operation was cancelled.
-
processLibraries
- Throws:
Exception
-
processEncryption
Logs encrypted block ranges- Throws:
Exception- if there was a problem detecting the encrypted block ranges
-
processUnsupportedLoadCommands
ProcessesLoadCommands that we haven't implemented yet.- Throws:
CancelledException- if the operation was cancelled.
-
processCorruptLoadCommands
ProcessesLoadCommands that appear to be corrupt.- Throws:
CancelledException- if the operation was cancelled.
-
markupLoadCommandData
Marks upLoadCommanddadta- Parameters:
header- The Mach-O headersource- A name that represents where the header came from (could be null)- Throws:
Exception- If there was a problem performing the markup
-
createNamespace
-
createOneByteFunction
create a one-byte function, so that when the code is analyzed, it will be disassembled, and the function created with the correct body.- Parameters:
program- TheProgramname- the name of the functionaddress- location to create the function- Returns:
- If a function already existed at the given address, that function will be returned. Otherwise, the newly created function will be returned. If there was a problem creating the function, null will be returned.
-
markupChainedFixups
protected void markupChainedFixups(MachHeader header, List<Address> chainedFixups) throws CancelledException Markup the givenListof chained fixups by creating pointers at their locations, if possible- Parameters:
header- The Mach-O headerchainedFixups- TheListof chained fixups to markup- Throws:
CancelledException- if the operation was cancelled
-
markupProgramVars
- Throws:
Exception
-
setRelocatableProperty
protected void setRelocatableProperty() -
setProgramDescription
protected void setProgramDescription() -
markupAndSetGolangInitialProgramProperties
protected void markupAndSetGolangInitialProgramProperties() -
setCompiler
- Throws:
CancelledException
-
renameObjMsgSendRtpSymbol
-
fixupExternalLibrary
-