Class ElfNote

java.lang.Object
ghidra.app.util.bin.format.elf.info.ElfNote
All Implemented Interfaces:
ElfInfoItem
Direct Known Subclasses:
NoteAbiTag, NoteGnuBuildId, NoteGnuProperty, NoteGoBuildId

public class ElfNote extends Object implements ElfInfoItem
ELF note sections have a well-defined format that combines identity information along with a binary blob that is specific to each type of note.

Notes are identified by the combination of a name string and vendorType number, and are usually stored in a ELF section with a specific name.

  • Field Details

    • nameLen

      protected final int nameLen
    • name

      protected final String name
    • vendorType

      protected final int vendorType
    • description

      protected final byte[] description
  • Constructor Details

    • ElfNote

      protected ElfNote(int nameLen, String name, int vendorType, byte[] description)
    • ElfNote

      protected ElfNote(int nameLen, String name, int vendorType)
  • Method Details

    • read

      public static ElfNote read(BinaryReader reader) throws IOException
      Reads a generic ElfNote instance from the supplied BinaryReader.
      Parameters:
      reader - BinaryReader to read from
      Returns:
      new ElfNote instance, never null
      Throws:
      IOException - if bad data or error reading
    • readFromProgramHelper

      protected static <T extends ElfNote> T readFromProgramHelper(Program program, String sectionName, ElfNote.NoteReaderFunc<T> readerFunc)
      A helper method for read() methods defined in specific Note classes to attempt to read a specific Note type from a Program.
      Type Parameters:
      T - Note type
      Parameters:
      program - Program
      sectionName - name of the note section
      readerFunc - ElfNote.NoteReaderFunc that converts a generic note instance into a specialized note.
      Returns:
      new Note instance, or null if not present or error reading
    • isGnu

      public boolean isGnu()
      Shortcut test of name == "GNU"
      Returns:
      true if name is "GNU"
    • getName

      public String getName()
      Returns the name value of this note.
      Returns:
      string name
    • getNameLen

      public int getNameLen()
    • getDescription

      public byte[] getDescription()
      Returns the bytes in the description portion of the note.
      Returns:
      byte array
    • getDescriptionLen

      public int getDescriptionLen()
    • getDescriptionAsHexString

      public String getDescriptionAsHexString()
      Returns a hex string of the description bytes.
      Returns:
      hex string
    • getDescriptionReader

      public BinaryReader getDescriptionReader(boolean isLittleEndian)
      Returns a BinaryReader that reads from this note's description blob.
      Parameters:
      isLittleEndian - flag, see BinaryReader(ByteProvider, boolean)
      Returns:
      new BinaryReader
    • getVendorType

      public int getVendorType()
      Returns the vendor type 'enum' value of this note.
      Returns:
      vendor type 'enum' value
    • getNoteTypeName

      public String getNoteTypeName()
      Returns a string that describes this note's type, used when creating the default getProgramInfoKey() value.

      Specific Note subclasses can override this to return a better string than this default implementation, or can override the getProgramInfoKey() method.

      Returns:
      descriptive string
    • getNoteValueString

      public String getNoteValueString()
      Returns a string representation of this note's 'value', used when creating the PROGRAM_INFO entry.

      Specific Note subclasses should override this to return a better string than this default implementation.

      Returns:
      string describing this note's value
    • getProgramInfoKey

      public String getProgramInfoKey()
      Returns a string that is used to build a PROGRAM_INFO entry's key.

      Specific Note subclasses can override this to return a better key string.

      Returns:
      key string (avoid using '.' characters as they will be converted to '_'s)
    • decorateProgramInfo

      public void decorateProgramInfo(Options programInfoOptions)
      Adds a single entry to the Options, built from the getProgramInfoKey() value and getNoteValueString() value.
      Parameters:
      programInfoOptions - Options to add entry to
    • markupProgram

      public void markupProgram(Program program, Address address)
      Description copied from interface: ElfInfoItem
      Markup a program's info and memory with this item.
      Specified by:
      markupProgram in interface ElfInfoItem
      Parameters:
      program - Program to markup
      address - Address of the item in the program
    • toStructure

      public StructureDataType toStructure(DataTypeManager dtm)
      Returns a Structure datatype that matches the format of this ElfNote, or null if this ElfNote shouldn't be represented/marked up.
      Parameters:
      dtm - DataTypeManager that will receive the structure
      Returns:
      StructureDataType that specifies the layout of the ElfNote, or null
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createNoteStructure

      protected static StructureDataType createNoteStructure(CategoryPath cp, String structName, boolean templatedName, int noteNameLen, int noteDescLen, DataTypeManager dtm)