Package ghidra.app.util.bin.format.objc
Class ObjcUtils
java.lang.Object
ghidra.app.util.bin.format.objc.ObjcUtils
Objective-C utilities
-
Field Summary
FieldsChangeModifier and TypeFieldDescriptionstatic final StringString that prefixes Objective-C class symbolsstatic final StringThe Objective-C compiler name, used byProgram.setCompiler(String)static final StringString that prefixes Objective-C meta-class symbolsstatic final StringThe Objective-C_objc_msgSendstub calling convention name (added with processor extension) -
Constructor Summary
Constructors -
Method Summary
ChangeModifier and TypeMethodDescriptionstatic intaddExtensions(Program program, TaskMonitor monitor) Adds Objective-C processor extensions to theProgram, which include: A special calling convention used by objc_msgSend stubs Call fixups to clear out a lot of Objective-C Automatic Reference Counting (ARC) clutterstatic DatacreateData(Program program, DataType dt, Address address) Applies the data type at the specified addressstatic final voidcreateMethods(Program program, ObjcState state, MessageLog log, TaskMonitor monitor) Creates methodsstatic NamespacecreateNamespace(Program program, String... namespacePath) Returns a newly created namespace hierarchy formed from the list of given strings.static StringcreateString(Program program, Address address) Creates a string data type at the given addressstatic SymbolcreateSymbol(Program program, Namespace parentNamespace, String symbolName, Address symbolAddress) Returns a newly created primarySymbol.static StringdereferenceAsciiString(BinaryReader reader, boolean is32bit) Returns the string referenced at the next read pointer, ornullif the pointer is 0.static final voidfixupReferences(List<String> sectionNames, Program program, TaskMonitor monitor) Removes references to the NULL address and adjusts THUMB references to no longer be offcutstatic NamespacegetClassNamespace(Program program, Namespace parentNamespace, String namespaceName) Returns the class inside the given parent namespace, or a newly created one if it doesn't exist.static List<MemoryBlock> getObjcBlocks(String section, Program program) Returns aListofMemoryBlocks that match the given section name.static booleanReturns true if the givenProgramis an Objective-C program; otherwise, false.static booleanReturns true if the givenListof section names contains an Objective-C section name; otherwise, false.static booleanReturns whether or not the given address is THUMB code.static booleanReturns whether or not the given address is THUMB code.static longreadNextIndex(BinaryReader reader, boolean is32bit) Returns the next read index value.static voidsetBlocksReadOnly(Memory memory, List<String> blockNames) Sets the given block names as read-onlystatic voidsetThumbBit(Program program, ObjcState state, Address address) If needed, sets the TMode bit at the specified addressstatic StringstripClassPrefix(String name) Returns the given name with any Objective-C class prefixes stripped off.static AddressReturns anAddressthat corresponds to the given offset in the default address space.
-
Field Details
-
OBJC_COMPILER
The Objective-C compiler name, used byProgram.setCompiler(String)- See Also:
-
OBJC_MSGSEND_STUBS_CC
The Objective-C_objc_msgSendstub calling convention name (added with processor extension)- See Also:
-
OBJC_CLASS_SYMBOL_PREFIX
String that prefixes Objective-C class symbols- See Also:
-
OBJC_META_CLASS_SYMBOL_PREFIX
String that prefixes Objective-C meta-class symbols- See Also:
-
-
Constructor Details
-
ObjcUtils
public ObjcUtils()
-
-
Method Details
-
readNextIndex
Returns the next read index value.If
is32bitis true, then 4 bytes will be read to form the index. Otherwise, 8 bytes will be read to form the index.- Parameters:
reader- ABinaryReaderpositioned at the start of the index to readis32bit- True if the index is 32-bit; false if 64-bit;- Returns:
- the next read index value
- Throws:
IOException- if an IO-related error occurred
-
dereferenceAsciiString
public static String dereferenceAsciiString(BinaryReader reader, boolean is32bit) throws IOException Returns the string referenced at the next read pointer, ornullif the pointer is 0.If
is32bitis true, then 4 bytes will be read to form the pointer. Otherwise, 8 bytes will be read to form the pointer.- Parameters:
reader- ABinaryReaderpositioned at the start of the string pointer to readis32bit- True if the string pointer is 32-bit; false if 64-bit;- Returns:
- the string referenced at the next read pointer, or
nullif the pointer is 0 - Throws:
IOException- if an IO-related error occurred
-
isThumb
Returns whether or not the given address is THUMB code. -
isThumb
Returns whether or not the given address is THUMB code.- Parameters:
program- TheProgramaddress- The address to check- Returns:
- whether or not the given address is THUMB code
-
setThumbBit
If needed, sets the TMode bit at the specified address -
toAddress
Returns anAddressthat corresponds to the given offset in the default address space. -
createData
public static Data createData(Program program, DataType dt, Address address) throws CodeUnitInsertionException Applies the data type at the specified address- Parameters:
program- TheProgramdt- TheDataTypeto applyaddress- TheAddressto apply the data type at- Returns:
- The
Data - Throws:
CodeUnitInsertionException- if data creation failed
-
createString
Creates a string data type at the given address -
getClassNamespace
public static Namespace getClassNamespace(Program program, Namespace parentNamespace, String namespaceName) throws DuplicateNameException, InvalidInputException Returns the class inside the given parent namespace, or a newly created one if it doesn't exist.- Parameters:
program- TheProgramparentNamespace- The parent namespacenamespaceName- The name of the class namespace to get/create- Returns:
- the class inside the given parent namespace, or a newly created one if it doesn't exist
- Throws:
DuplicateNameException- if another label exists with the given nameInvalidInputException- if the given name is invalid
-
createSymbol
public static Symbol createSymbol(Program program, Namespace parentNamespace, String symbolName, Address symbolAddress) throws InvalidInputException Returns a newly created primarySymbol.- Parameters:
program- TheProgramparentNamespace- The parent namespacesymbolName- The symbol namesymbolAddress- The symbolAddress- Returns:
- a newly created primary
Symbol - Throws:
InvalidInputException- if the given name is invalid
-
createNamespace
public static Namespace createNamespace(Program program, String... namespacePath) throws DuplicateNameException, InvalidInputException Returns a newly created namespace hierarchy formed from the list of given strings.- Parameters:
program- TheProgramnamespacePath- The namespace path- Returns:
- a newly created namespace hierarchy formed from the list of given strings
- Throws:
DuplicateNameException- if another label exists with the given nameInvalidInputException- if the given name is invalid
-
createMethods
public static final void createMethods(Program program, ObjcState state, MessageLog log, TaskMonitor monitor) Creates methods -
fixupReferences
public static final void fixupReferences(List<String> sectionNames, Program program, TaskMonitor monitor) Removes references to the NULL address and adjusts THUMB references to no longer be offcut- Parameters:
sectionNames- The names of the sections to fixprogram- TheProgrammonitor- A cancellable monitor
-
setBlocksReadOnly
Sets the given block names as read-only -
getObjcBlocks
Returns aListofMemoryBlocks that match the given section name.- Parameters:
section- The section nameprogram- TheProgram- Returns:
- a
ListofMemoryBlocks that match the given section name
-
isObjc
Returns true if the givenProgramis an Objective-C program; otherwise, false.NOTE: This method only identifies Mach-O Objective-C programs. ELF Objective-C programs produced with GCC use different section names.
-
isObjc
Returns true if the givenListof section names contains an Objective-C section name; otherwise, false.NOTE: This method only identifies Mach-O Objective-C programs. ELF Objective-C programs produced with GCC use different section names.
-
stripClassPrefix
Returns the given name with any Objective-C class prefixes stripped off.- Parameters:
name- The name to strip- Returns:
- the given name with any Objective-C class prefixes stripped off
- See Also:
-
addExtensions
Adds Objective-C processor extensions to theProgram, which include:- A special calling convention used by objc_msgSend stubs
- Call fixups to clear out a lot of Objective-C Automatic Reference Counting (ARC) clutter
- Parameters:
program- TheProgramto add the extensions tomonitor- A cancelable task monitor- Returns:
- The number of extensions successfully added
- Throws:
IOException- if an IO-related error occurred- See Also:
-