Package net.fornwall.jelf
Class ElfFile
java.lang.Object
net.fornwall.jelf.ElfFile
An ELF (Executable and Linkable Format) file that can be a relocatable, executable, shared or core file.
Use one of the following methods to parse input to get an instance of this class:
Resources about ELF files:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteAIX application binary interface.static final byteAROS application binary interface.static final byteCloudABI application binary interface.static final byteFenix OS application binary interface.static final byteFreeBSD application binary interface.static final byteGNU Hurd application binary interface.static final byteHP-UX application binary interface.static final byteIRIX application binary interface.static final byteLinux application binary interface.static final byteNovell Modesto application binary interface.static final byteNetBSD application binary interface.static final byteNonStop Kernel application binary interface.static final byteOpenBSD application binary interface.static final byteOpenVMS application binary interface.static final byteStratus Technologies OpenVOS application binary interface.static final byteSolaris application binary interface.static final byteSystem V application binary interface.static final byteTru64 application binary interface.static final intMotorola 68000 architecture type.static final intMotorola 88000 architecture type.static final intstatic final intstatic final intAT&T architecture type.static final intIntel 386 architecture type.static final intIntel 860 architecture type.static final intMIPS architecture type.static final intNo architecture type.static final intSPARC architecture type.static final intstatic final byte32-bit objects.static final byte64-bit objects.static final byteLSB data encoding.static final byteMSB data encoding.final shorte_ehsize.final longVirtual address to which the system first transfers control.final inte_flags.final shortThe required architecture.final shorte_phentsize.final shorte_phnum.final longe_phoff.final shorte_shentsize.final shorte_shnum.final longe_shoff.final shortElf{32,64}_Ehdr#e_shstrndx.final shortIdentifies the object file type.final intVersionfinal bytefinal byteReturns a byte identifying the data encoding of the processor specific data.final byteIdentifies the target operating system ABI.final byteSet to 1 for the original and current (as of writing) version of ELF.final byteFurther specifies the ABI version.static final intCore file file type.static final intShared object file type.static final intExecutable file type.static final intRelocatable file type. -
Method Summary
Modifier and TypeMethodDescriptionfirstSectionByName(String sectionName) firstSectionByType(int type) <T extends ElfSection>
TfirstSectionByType(Class<T> type) static ElfFilefrom(byte[] buffer) static ElfFilestatic ElfFilefrom(InputStream in) static ElfFilefrom(MappedByteBuffer mappedByteBuffer) static ElfFilefrom(BackingFile backingFile) TheElfSectionHeader.SHT_DYNAMICsection (of which there may be only one).Returns the dynamic symbol table associated with this ELF file, or null if one does not exist.TheElfSectionHeader.SHT_DYNSYMsection (of which there may be only one), if any.getELFSymbol(long address) Returns the elf symbol with the specified address or null if one is not found.getELFSymbol(String symbolName) Returns the elf symbol with the specified name or null if one is not found.The interpreter specified by theElfSegment.PT_INTERPprogram header, if any.getProgramHeader(int index) getSection(int index) Returns the section header at the specified index.Returns the section header string table associated with this ELF file.Returns the string table associated with this ELF file.TheElfSectionHeader.SHT_SYMTABsection (of which there may be only one), if any.booleanis32Bits()sectionsOfType(int sectionType)
-
Field Details
-
ET_REL
public static final int ET_RELRelocatable file type. A possible value ofe_type.- See Also:
-
ET_EXEC
public static final int ET_EXECExecutable file type. A possible value ofe_type.- See Also:
-
ET_DYN
public static final int ET_DYNShared object file type. A possible value ofe_type.- See Also:
-
ET_CORE
public static final int ET_CORECore file file type. A possible value ofe_type.- See Also:
-
CLASS_32
public static final byte CLASS_3232-bit objects. A possible value ofei_class.- See Also:
-
CLASS_64
public static final byte CLASS_6464-bit objects. A possible value ofei_class.- See Also:
-
ABI_SYSTEMV
public static final byte ABI_SYSTEMVSystem V application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_HPUX
public static final byte ABI_HPUXHP-UX application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_NETBSD
public static final byte ABI_NETBSDNetBSD application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_LINUX
public static final byte ABI_LINUXLinux application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_GNUHERD
public static final byte ABI_GNUHERDGNU Hurd application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_SOLARIS
public static final byte ABI_SOLARISSolaris application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_AIX
public static final byte ABI_AIXAIX application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_IRIX
public static final byte ABI_IRIXIRIX application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_FREEBSD
public static final byte ABI_FREEBSDFreeBSD application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_TRU64
public static final byte ABI_TRU64Tru64 application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_MODESTO
public static final byte ABI_MODESTONovell Modesto application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_OPENBSD
public static final byte ABI_OPENBSDOpenBSD application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_OPENVMS
public static final byte ABI_OPENVMSOpenVMS application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_NONSTOP
public static final byte ABI_NONSTOPNonStop Kernel application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_AROS
public static final byte ABI_AROSAROS application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_FENIX
public static final byte ABI_FENIXFenix OS application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_CLOUD
public static final byte ABI_CLOUDCloudABI application binary interface. A possible value ofei_osabi.- See Also:
-
ABI_OPENVOS
public static final byte ABI_OPENVOSStratus Technologies OpenVOS application binary interface. A possible value ofei_osabi.- See Also:
-
DATA_LSB
public static final byte DATA_LSBLSB data encoding. A possible value ofei_data.- See Also:
-
DATA_MSB
public static final byte DATA_MSBMSB data encoding. A possible value ofei_data.- See Also:
-
ARCH_NONE
public static final int ARCH_NONENo architecture type. A possible value ofe_machine.- See Also:
-
ARCH_ATT
public static final int ARCH_ATTAT&T architecture type. A possible value ofe_machine.- See Also:
-
ARCH_SPARC
public static final int ARCH_SPARCSPARC architecture type. A possible value ofe_machine.- See Also:
-
ARCH_i386
public static final int ARCH_i386Intel 386 architecture type. A possible value ofe_machine.- See Also:
-
ARCH_68k
public static final int ARCH_68kMotorola 68000 architecture type. A possible value ofe_machine.- See Also:
-
ARCH_88k
public static final int ARCH_88kMotorola 88000 architecture type. A possible value ofe_machine.- See Also:
-
ARCH_i860
public static final int ARCH_i860Intel 860 architecture type. A possible value ofe_machine.- See Also:
-
ARCH_MIPS
public static final int ARCH_MIPSMIPS architecture type. A possible value ofe_machine.- See Also:
-
ARCH_ARM
public static final int ARCH_ARM- See Also:
-
ARCH_X86_64
public static final int ARCH_X86_64- See Also:
-
ARCH_AARCH64
public static final int ARCH_AARCH64- See Also:
-
ei_class
public final byte ei_class -
ei_data
public final byte ei_dataReturns a byte identifying the data encoding of the processor specific data. This byte will be either DATA_INVALID, DATA_LSB or DATA_MSB. -
ei_version
public final byte ei_versionSet to 1 for the original and current (as of writing) version of ELF. -
ei_osabi
public final byte ei_osabiIdentifies the target operating system ABI. -
es_abiversion
public final byte es_abiversionFurther specifies the ABI version. Its interpretation depends on the target ABI. -
e_type
public final short e_typeIdentifies the object file type. One of the ET_* constants in the class. -
e_machine
public final short e_machineThe required architecture. One of the ARCH_* constants in the class. -
e_version
public final int e_versionVersion -
e_entry
public final long e_entryVirtual address to which the system first transfers control. If there is no entry point for the file the value is 0. -
e_phoff
public final long e_phoffe_phoff. Program header table offset in bytes. If there is no program header table the value is 0. -
e_shoff
public final long e_shoffe_shoff. Section header table offset in bytes. If there is no section header table the value is 0. -
e_flags
public final int e_flagse_flags. Processor specific flags. -
e_ehsize
public final short e_ehsizee_ehsize. ELF header size in bytes. -
e_phentsize
public final short e_phentsizee_phentsize. Size of one entry in the file's program header table in bytes. All entries are the same size. -
e_phnum
public final short e_phnume_phnum. Number ofElfSegmententries in the program header table, 0 if no entries. -
e_shentsize
public final short e_shentsizee_shentsize. Section header entry size in bytes - all entries are the same size. -
e_shnum
public final short e_shnume_shnum. Number of entries in the section header table, 0 if no entries. -
e_shstrndx
public final short e_shstrndxElf{32,64}_Ehdr#e_shstrndx. Index into the section header table associated with the section name string table. SH_UNDEF if there is no section name string table.
-
-
Method Details
-
is32Bits
public boolean is32Bits() -
getSection
Returns the section header at the specified index. The section header at index 0 is defined as being a undefined section.- Parameters:
index- the index of the ELF section to fetch- Returns:
- the ELF section at the specified index
- Throws:
ElfException
-
sectionsOfType
- Throws:
ElfException
-
getSectionNameStringTable
Returns the section header string table associated with this ELF file.- Returns:
- the section header string table for this file
- Throws:
ElfException
-
getStringTable
Returns the string table associated with this ELF file.- Returns:
- the string table for this file
- Throws:
ElfException
-
getDynamicStringTable
Returns the dynamic symbol table associated with this ELF file, or null if one does not exist.- Returns:
- the dynamic symbol table for this file, if any
- Throws:
ElfException
-
getSymbolTableSection
TheElfSectionHeader.SHT_SYMTABsection (of which there may be only one), if any.- Returns:
- the symbol table section for this file, if any
- Throws:
ElfException
-
getDynamicSymbolTableSection
TheElfSectionHeader.SHT_DYNSYMsection (of which there may be only one), if any.- Returns:
- the dynamic symbol table section for this file, if any
- Throws:
ElfException
-
getDynamicSection
TheElfSectionHeader.SHT_DYNAMICsection (of which there may be only one). Named ".dynamic".- Returns:
- the dynamic section for this file, if any
-
firstSectionByType
- Throws:
ElfException
-
firstSectionByType
- Throws:
ElfException
-
firstSectionByName
- Throws:
ElfException
-
getELFSymbol
Returns the elf symbol with the specified name or null if one is not found.- Parameters:
symbolName- the name of the symbol to fetch- Returns:
- information about the specified symbol
- Throws:
ElfException
-
getELFSymbol
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.- Parameters:
address- the address of the symbol to fetch- Returns:
- the symbol at the specified address, if any
- Throws:
ElfException
-
getProgramHeader
-
from
- Throws:
IOException
-
from
- Throws:
ElfExceptionIOException
-
from
- Throws:
ElfException
-
from
- Throws:
ElfException
-
from
- Throws:
ElfException
-
getInterpreter
The interpreter specified by theElfSegment.PT_INTERPprogram header, if any.- Returns:
- the interpreter for this file, if any
-