Class ElfFile


  • public final class ElfFile
    extends java.lang.Object
    An ELF (Executable and Linkable Format) file can be a relocatable, executable, shared or core file.
     http://man7.org/linux/man-pages/man5/elf.5.html
     http://en.wikipedia.org/wiki/Executable_and_Linkable_Format
     http://www.ibm.com/developerworks/library/l-dynamic-libraries/
     http://downloads.openwatcom.org/ftp/devel/docs/elf-64-gen.pdf
     
     Elf64_Addr, Elf64_Off, Elf64_Xword, Elf64_Sxword: 8 bytes
     Elf64_Word, Elf64_Sword: 4 bytes
     Elf64_Half: 2 bytes
     
    • Field Detail

      • ARCH_SPARC

        public static final int ARCH_SPARC
        SPARC architecture type.
        See Also:
        Constant Field Values
      • ARCH_i386

        public static final int ARCH_i386
        Intel 386 architecture type.
        See Also:
        Constant Field Values
      • ARCH_68k

        public static final int ARCH_68k
        Motorola 68000 architecture type.
        See Also:
        Constant Field Values
      • ARCH_88k

        public static final int ARCH_88k
        Motorola 88000 architecture type.
        See Also:
        Constant Field Values
      • ARCH_i860

        public static final int ARCH_i860
        Intel 860 architecture type.
        See Also:
        Constant Field Values
      • objectSize

        public final byte objectSize
        Byte identifying the size of objects, either CLASS_32 or {link 2 .
      • encoding

        public final byte encoding
        Returns a byte identifying the data encoding of the processor specific data. This byte will be either DATA_INVALID, DATA_LSB or DATA_MSB.
      • elfVersion

        public final byte elfVersion
      • abi

        public final byte abi
      • abiVersion

        public final byte abiVersion
      • file_type

        public final short file_type
        Identifies the object file type. One of the FT_* constants in the class.
      • arch

        public final short arch
        The required architecture. One of the ARCH_* constants in the class.
      • version

        public final int version
        Version
      • entry_point

        public final long entry_point
        Virtual address to which the system first transfers control. If there is no entry point for the file the value is 0.
      • ph_offset

        public final long ph_offset
        Program header table offset in bytes. If there is no program header table the value is 0.
      • sh_offset

        public final long sh_offset
        Section header table offset in bytes. If there is no section header table the value is 0.
      • flags

        public final int flags
        Processor specific flags.
      • eh_size

        public final short eh_size
        ELF header size in bytes.
      • ph_entry_size

        public final short ph_entry_size
        e_phentsize. Size of one entry in the file's program header table in bytes. All entries are the same size.
      • num_ph

        public final short num_ph
        e_phnum. Number of ElfSegment entries in the program header table, 0 if no entries.
      • sh_entry_size

        public final short sh_entry_size
        Section header entry size in bytes.
      • num_sh

        public final short num_sh
        Number of entries in the section header table, 0 if no entries.
    • Constructor Detail

      • ElfFile

        public ElfFile​(java.nio.MappedByteBuffer buffer,
                       long startPosition)
                throws ElfException,
                       java.io.IOException
        Throws:
        ElfException
        java.io.IOException
      • ElfFile

        public ElfFile​(java.io.ByteArrayInputStream baos)
                throws ElfException,
                       java.io.IOException
        Throws:
        ElfException
        java.io.IOException
    • Method Detail

      • getSection

        public ElfSection getSection​(int index)
                              throws ElfException,
                                     java.io.IOException
        Returns the section header at the specified index. The section header at index 0 is defined as being a undefined section.
        Throws:
        ElfException
        java.io.IOException
      • getSectionNameStringTable

        public ElfStringTable getSectionNameStringTable()
                                                 throws ElfException,
                                                        java.io.IOException
        Returns the section header string table associated with this ELF file.
        Throws:
        ElfException
        java.io.IOException
      • getStringTable

        public ElfStringTable getStringTable()
                                      throws ElfException,
                                             java.io.IOException
        Returns the string table associated with this ELF file.
        Throws:
        ElfException
        java.io.IOException
      • getDynamicStringTable

        public ElfStringTable getDynamicStringTable()
                                             throws ElfException,
                                                    java.io.IOException
        Returns the dynamic symbol table associated with this ELF file, or null if one does not exist.
        Throws:
        ElfException
        java.io.IOException
      • getDynamicLinkSection

        public ElfSection getDynamicLinkSection()
                                         throws java.io.IOException
        The ElfSection.SHT_DYNAMIC section (of which there may be only one). Named ".dynamic".
        Throws:
        java.io.IOException
      • firstSectionByName

        public ElfSection firstSectionByName​(java.lang.String sectionName)
                                      throws ElfException,
                                             java.io.IOException
        Throws:
        ElfException
        java.io.IOException
      • getELFSymbol

        public ElfSymbol getELFSymbol​(java.lang.String symbolName)
                               throws ElfException,
                                      java.io.IOException
        Returns the elf symbol with the specified name or null if one is not found.
        Throws:
        ElfException
        java.io.IOException
      • getELFSymbol

        public ElfSymbol getELFSymbol​(long address)
                               throws ElfException,
                                      java.io.IOException
        Returns the elf symbol with the specified address or null if one is not found. 'address' is relative to base of shared object for .so's.
        Throws:
        ElfException
        java.io.IOException
      • getProgramHeader

        public ElfSegment getProgramHeader​(int index)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • fromStream

        public static ElfFile fromStream​(java.io.InputStream in)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getInterpreter

        public java.lang.String getInterpreter()
                                        throws java.io.IOException
        The interpreter specified by the ElfSegment.PT_INTERP program header, if any.
        Throws:
        java.io.IOException