Package ghidra.app.util.bin.format.macho
Class MachHeader
- java.lang.Object
-
- ghidra.app.util.bin.format.macho.MachHeader
-
- All Implemented Interfaces:
StructConverter
public class MachHeader extends java.lang.Object implements StructConverter
Represents a mach_header structure.- See Also:
- mach-o/loader.h
-
-
Constructor Summary
Constructors Constructor Description MachHeader()
DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MachHeader
createMachHeader(GenericFactory factory, ByteProvider provider)
Assumes the MachHeader starts at index 0 in the ByteProvider.static MachHeader
createMachHeader(GenericFactory factory, ByteProvider provider, long machHeaderStartIndexInProvider)
Assumes the MachHeader starts at index machHeaderStartIndexInProvider in the ByteProvider.static MachHeader
createMachHeader(GenericFactory factory, ByteProvider provider, long machHeaderStartIndexInProvider, boolean isRemainingMachoRelativeToStartIndex)
Assumes the MachHeader starts at index machHeaderStartIndexInProvider in the ByteProvider.int
getAddressSize()
java.util.List<Section>
getAllSections()
java.util.List<SegmentCommand>
getAllSegments()
int
getCpuSubType()
int
getCpuType()
java.io.InputStream
getDataStream()
java.lang.String
getDescription()
int
getFileType()
<T> T
getFirstLoadCommand(java.lang.Class<T> classType)
int
getFlags()
long
getImageBase()
java.util.List<LoadCommand>
getLoadCommands()
<T> java.util.List<T>
getLoadCommands(java.lang.Class<T> classType)
int
getMagic()
int
getNumberOfCommands()
int
getReserved()
Section
getSection(java.lang.String segmentName, java.lang.String sectionName)
SegmentCommand
getSegment(java.lang.String segmentName)
int
getSizeOfCommands()
long
getStartIndexInProvider()
boolean
is32bit()
boolean
isLittleEndian()
void
parse()
DataType
toDataType()
Returns a structure datatype representing the contents of the implementor of this interface.java.lang.String
toString()
-
-
-
Method Detail
-
createMachHeader
public static MachHeader createMachHeader(GenericFactory factory, ByteProvider provider) throws java.io.IOException, MachException
Assumes the MachHeader starts at index 0 in the ByteProvider.- Parameters:
provider
- the ByteProvider- Throws:
java.io.IOException
- if an I/O error occurs while reading from the ByteProviderMachException
- if an invalid MachHeader is detected
-
createMachHeader
public static MachHeader createMachHeader(GenericFactory factory, ByteProvider provider, long machHeaderStartIndexInProvider) throws java.io.IOException, MachException
Assumes the MachHeader starts at index machHeaderStartIndexInProvider in the ByteProvider.- Parameters:
provider
- the ByteProvidermachHeaderStartIndexInProvider
- the index into the ByteProvider where the MachHeader begins.- Throws:
java.io.IOException
- if an I/O error occurs while reading from the ByteProviderMachException
- if an invalid MachHeader is detected
-
createMachHeader
public static MachHeader createMachHeader(GenericFactory factory, ByteProvider provider, long machHeaderStartIndexInProvider, boolean isRemainingMachoRelativeToStartIndex) throws java.io.IOException, MachException
Assumes the MachHeader starts at index machHeaderStartIndexInProvider in the ByteProvider.- Parameters:
provider
- the ByteProvidermachHeaderStartIndexInProvider
- the index into the ByteProvider where the MachHeader begins.isRemainingMachoRelativeToStartIndex
- TRUE if the rest of the macho uses relative indexing. This is common in UBI and kernel cache files. FALSE if the rest of the file uses absolute indexing from 0. This is common in DYLD cache files.- Throws:
java.io.IOException
- if an I/O error occurs while reading from the ByteProviderMachException
- if an invalid MachHeader is detected
-
parse
public void parse() throws java.io.IOException, MachException
- Throws:
java.io.IOException
MachException
-
getMagic
public int getMagic()
-
getCpuType
public int getCpuType()
-
getImageBase
public long getImageBase()
-
getCpuSubType
public int getCpuSubType()
-
getFileType
public int getFileType()
-
getNumberOfCommands
public int getNumberOfCommands()
-
getSizeOfCommands
public int getSizeOfCommands()
-
getFlags
public int getFlags()
-
getReserved
public int getReserved() throws MachException
- Throws:
MachException
-
toDataType
public DataType toDataType() throws DuplicateNameException, java.io.IOException
Description copied from interface:StructConverter
Returns a structure datatype representing the contents of the implementor of this interface.For example, given:
class A { int foo; double bar; }
The return value should be a structure data type with two data type components; an INT and a DOUBLE. The structure should contain field names and, if possible, field comments.
- Specified by:
toDataType
in interfaceStructConverter
- Returns:
- returns a structure datatype representing the implementor of this interface
- Throws:
DuplicateNameException
- when a datatype of the same name already existsjava.io.IOException
- See Also:
StructureDataType
-
getStartIndexInProvider
public long getStartIndexInProvider()
-
is32bit
public boolean is32bit()
-
getAddressSize
public int getAddressSize()
-
getAllSegments
public java.util.List<SegmentCommand> getAllSegments()
-
getSegment
public SegmentCommand getSegment(java.lang.String segmentName)
-
getSection
public Section getSection(java.lang.String segmentName, java.lang.String sectionName)
-
getAllSections
public java.util.List<Section> getAllSections()
-
getLoadCommands
public java.util.List<LoadCommand> getLoadCommands()
-
getLoadCommands
public <T> java.util.List<T> getLoadCommands(java.lang.Class<T> classType)
-
getFirstLoadCommand
public <T> T getFirstLoadCommand(java.lang.Class<T> classType)
-
isLittleEndian
public boolean isLittleEndian()
-
getDescription
public java.lang.String getDescription()
-
getDataStream
public java.io.InputStream getDataStream() throws java.io.IOException
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-