Package net.fornwall.jelf
Class ElfFile
- java.lang.Object
-
- net.fornwall.jelf.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 Summary
Fields Modifier and Type Field Description byte
abi
byte
abiVersion
short
arch
The required architecture.static int
ARCH_68k
Motorola 68000 architecture type.static int
ARCH_88k
Motorola 88000 architecture type.static int
ARCH_AARCH64
static int
ARCH_ARM
static int
ARCH_ATT
AT&T architecture type.static int
ARCH_i386
Intel 386 architecture type.static int
ARCH_i860
Intel 860 architecture type.static int
ARCH_MIPS
MIPS architecture type.static int
ARCH_NONE
No architecture type.static int
ARCH_SPARC
SPARC architecture type.static int
ARCH_X86_64
static byte
CLASS_32
32-bit objects.static byte
CLASS_64
64-bit objects.static byte
DATA_LSB
LSB data encoding.static byte
DATA_MSB
MSB data encoding.short
eh_size
ELF header size in bytes.byte
elfVersion
byte
encoding
Returns a byte identifying the data encoding of the processor specific data.long
entry_point
Virtual address to which the system first transfers control.short
file_type
Identifies the object file type.int
flags
Processor specific flags.static int
FT_CORE
Core file file type.static int
FT_DYN
Shared object file type.static int
FT_EXEC
Executable file type.static int
FT_REL
Relocatable file type.short
num_ph
e_phnum.short
num_sh
Number of entries in the section header table, 0 if no entries.byte
objectSize
short
ph_entry_size
e_phentsize.long
ph_offset
Program header table offset in bytes.short
sh_entry_size
Section header entry size in bytes.long
sh_offset
Section header table offset in bytes.int
version
Version
-
Method Summary
Modifier and Type Method Description ElfSection
firstSectionByName(java.lang.String sectionName)
ElfSection
firstSectionByType()
TheElfSection.SHT_SYMTAB
section (of which there may be only one), if any.ElfSection
firstSectionByType(int type)
static ElfFile
fromBytes(byte[] buffer)
static ElfFile
fromFile(java.io.File file)
static ElfFile
fromStream(java.io.InputStream in)
ElfSection
getDynamicLinkSection()
TheElfSection.SHT_DYNAMIC
section (of which there may be only one).ElfStringTable
getDynamicStringTable()
Returns the dynamic symbol table associated with this ELF file, or null if one does not exist.ElfSection
getDynamicSymbolTableSection()
TheElfSection.SHT_DYNSYM
section (of which there may be only one), if any.ElfSymbol
getELFSymbol(long address)
Returns the elf symbol with the specified address or null if one is not found.ElfSymbol
getELFSymbol(java.lang.String symbolName)
Returns the elf symbol with the specified name or null if one is not found.java.lang.String
getInterpreter()
The interpreter specified by theElfSegment.PT_INTERP
program header, if any.ElfSegment
getProgramHeader(int index)
ElfSection
getSection(int index)
Returns the section header at the specified index.ElfStringTable
getSectionNameStringTable()
Returns the section header string table associated with this ELF file.ElfStringTable
getStringTable()
Returns the string table associated with this ELF file.
-
-
-
Field Detail
-
FT_REL
public static final int FT_REL
Relocatable file type. A possible value offile_type
.- See Also:
- Constant Field Values
-
FT_EXEC
public static final int FT_EXEC
Executable file type. A possible value offile_type
.- See Also:
- Constant Field Values
-
FT_DYN
public static final int FT_DYN
Shared object file type. A possible value offile_type
.- See Also:
- Constant Field Values
-
FT_CORE
public static final int FT_CORE
Core file file type. A possible value offile_type
.- See Also:
- Constant Field Values
-
CLASS_32
public static final byte CLASS_32
32-bit objects.- See Also:
- Constant Field Values
-
CLASS_64
public static final byte CLASS_64
64-bit objects.- See Also:
- Constant Field Values
-
DATA_LSB
public static final byte DATA_LSB
LSB data encoding.- See Also:
- Constant Field Values
-
DATA_MSB
public static final byte DATA_MSB
MSB data encoding.- See Also:
- Constant Field Values
-
ARCH_NONE
public static final int ARCH_NONE
No architecture type.- See Also:
- Constant Field Values
-
ARCH_ATT
public static final int ARCH_ATT
AT&T architecture type.- See Also:
- Constant Field Values
-
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
-
ARCH_MIPS
public static final int ARCH_MIPS
MIPS architecture type.- See Also:
- Constant Field Values
-
ARCH_ARM
public static final int ARCH_ARM
- See Also:
- Constant Field Values
-
ARCH_X86_64
public static final int ARCH_X86_64
- See Also:
- Constant Field Values
-
ARCH_AARCH64
public static final int ARCH_AARCH64
- See Also:
- Constant Field Values
-
objectSize
public final byte objectSize
-
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 ofElfSegment
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
-
firstSectionByType
public ElfSection firstSectionByType() throws ElfException, java.io.IOException
TheElfSection.SHT_SYMTAB
section (of which there may be only one), if any.- Throws:
ElfException
java.io.IOException
-
getDynamicSymbolTableSection
public ElfSection getDynamicSymbolTableSection() throws ElfException, java.io.IOException
TheElfSection.SHT_DYNSYM
section (of which there may be only one), if any.- Throws:
ElfException
java.io.IOException
-
getDynamicLinkSection
public ElfSection getDynamicLinkSection() throws java.io.IOException
TheElfSection.SHT_DYNAMIC
section (of which there may be only one). Named ".dynamic".- Throws:
java.io.IOException
-
firstSectionByType
public ElfSection firstSectionByType(int type) throws ElfException, java.io.IOException
- Throws:
ElfException
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
-
fromFile
public static ElfFile fromFile(java.io.File file) throws ElfException, java.io.IOException
- Throws:
ElfException
java.io.IOException
-
fromBytes
public static ElfFile fromBytes(byte[] buffer) throws ElfException, java.io.IOException
- Throws:
ElfException
java.io.IOException
-
getInterpreter
public java.lang.String getInterpreter() throws java.io.IOException
The interpreter specified by theElfSegment.PT_INTERP
program header, if any.- Throws:
java.io.IOException
-
-