Class ObjcUtils

java.lang.Object
ghidra.app.util.bin.format.objc.ObjcUtils

public final class ObjcUtils extends Object
  • Constructor Details

    • ObjcUtils

      public ObjcUtils()
  • Method Details

    • readNextIndex

      public static long readNextIndex(BinaryReader reader, boolean is32bit) throws IOException
      Returns the next read index value.

      If is32bit is true, then 4 bytes will be read to form the index. Otherwise, 8 bytes will be read to form the index.

      Parameters:
      reader - A BinaryReader positioned at the start of the index to read
      is32bit - 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, or null if the pointer is 0.

      If is32bit is true, then 4 bytes will be read to form the pointer. Otherwise, 8 bytes will be read to form the pointer.

      Parameters:
      reader - A BinaryReader positioned at the start of the string pointer to read
      is32bit - True if the string pointer is 32-bit; false if 64-bit;
      Returns:
      the string referenced at the next read pointer, or null if the pointer is 0
      Throws:
      IOException - if an IO-related error occurred
    • isThumb

      public static boolean isThumb(Program program, Address address)
      Returns whether or not the given address is THUMB code.
      Parameters:
      program - The Program
      address - The Address to check
      Returns:
      whether or not the given address is THUMB code
    • isThumb

      public static boolean isThumb(Program program, long address)
      Returns whether or not the given address is THUMB code.
      Parameters:
      program - The Program
      address - The address to check
      Returns:
      whether or not the given address is THUMB code
    • setThumbBit

      public static void setThumbBit(Program program, ObjcState state, Address address)
      If needed, sets the TMode bit at the specified address
      Parameters:
      program - The Program
      state - The state
      address - The Address to set
    • toAddress

      public static Address toAddress(Program program, long offset)
      Returns an Address that corresponds to the given offset in the default address space.
      Parameters:
      program - The Program
      offset - The offset to convert to an Address
      Returns:
      an Address that 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 - The Program
      dt - The DataType to apply
      address - The Address to apply the data type at
      Returns:
      The Data
      Throws:
      CodeUnitInsertionException - if data creation failed
    • createString

      public static String createString(Program program, Address address)
      Creates a string data type at the given address
      Parameters:
      program - The Program
      address - The Address where to create the string at
      Returns:
      The string, or null if it didn't get created
    • 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 - The Program
      parentNamespace - The parent namespace
      namespaceName - 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 name
      InvalidInputException - 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 primary Symbol.
      Parameters:
      program - The Program
      parentNamespace - The parent namespace
      symbolName - The symbol name
      symbolAddress - The symbol Address
      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 - The Program
      namespacePath - 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 name
      InvalidInputException - if the given name is invalid
    • createMethods

      public static final void createMethods(Program program, ObjcState state, MessageLog log, TaskMonitor monitor)
      Creates methods
      Parameters:
      program - The Program
      state - The state
      log - The log
      monitor - A cancellable monitor
    • 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 fix
      program - The Program
      monitor - A cancellable monitor
    • setBlocksReadOnly

      public static void setBlocksReadOnly(Memory memory, List<String> blockNames)
      Sets the given block names as read-only
      Parameters:
      memory - The Memory
      blockNames - A List of block names to set as read-only
    • getObjcBlocks

      public static List<MemoryBlock> getObjcBlocks(String section, Program program)
      Returns a List of MemoryBlocks that match the given section name.
      Parameters:
      section - The section name
      program - The Program
      Returns:
      a List of MemoryBlocks that match the given section name