lib.dwfl
Class Elf

java.lang.Object
  extended by lib.dwfl.Elf

public class Elf
extends Object

This class represents an Elf object.


Field Summary
private  FileDescriptor fd
           
private  long pointer
           
 
Constructor Summary
Elf(FileDescriptor fd, ElfCommand command)
          Creates a new elf object
Elf(File file, ElfCommand command)
          Creates a new elf object
Elf(long ptr)
           
 
Method Summary
 void close()
          Destroy the external elf file object associated with this object.
 ElfEHeader createNewEHeader(int wordSize)
          Creates a new Elf Header if none exists
 int createNewPHeader(long count)
          Creates a new program header table if none exists
 ElfSection createNewSection()
          Creates a new ElfSection at the end of the table and returns it
protected  int elf_cntl(int __cmd)
           
protected  int elf_flagehdr(int __cmd, int __flags)
           
protected  int elf_flagelf(int __cmd, int __flags)
           
protected  int elf_flagphdr(int __cmd, int __flags)
           
private static String elf_get_last_error_msg()
           
private static int elf_get_last_error_no()
           
protected  ElfData elf_get_raw_data(long offset, long size)
           
protected  int elf_get_version()
           
protected  ElfArchiveHeader elf_getarhdr()
           
protected  long elf_getaroff()
           
protected  long elf_getarsym(long __ptr)
           
protected  long elf_getbase()
           
protected  ElfEHeader elf_getehdr()
           
protected  String elf_getident()
           
protected  ElfPHeader elf_getphdr(int index)
           
protected  long elf_getscn(long __index)
           
protected  long elf_getshnum()
           
protected  long elf_getshstrndx()
           
protected  int elf_kind()
           
private  void elf_newehdr(int wordSize)
           
protected  int elf_newphdr(long __cnt)
           
protected  long elf_newscn()
           
protected  int elf_next()
           
protected  long elf_nextscn(long __scn)
           
protected  long elf_offscn(long offset)
           
protected  long elf_rand(int __offset)
           
protected  String elf_rawfile(long __ptr)
           
protected  String elf_strptr(long __index, long __offset)
           
private  void elf_update(int cmd)
           
private  void elf_updatehdr(ElfEHeader header)
           
protected  int elf_updatephdr(int index, ElfPHeader header)
           
private static long elfBegin(FileDescriptor fd, ElfCommand cmd)
           
private static void elfEnd(long elf)
           
protected  void finalize()
           
 ElfFlags flag(ElfCommand command, ElfFlags flags)
          Sets or clears flags in the Elf file
 ElfFlags flagEHeader(ElfCommand command, ElfFlags flags)
          Sets or clears flags in the Elf header
 ElfFlags flagPHeader(ElfCommand command, ElfFlags flags)
          Sets or clears flags in the Elf program header
 long getArchiveElement(int offset)
           
 ElfArchiveHeader getArchiveHeader()
           
 long getArchiveOffset()
           
 ElfArchiveSymbol getArchiveSymbol(long ptr)
           
 long getBase()
           
 int getControlDescriptor(ElfCommand command)
           
private static FileDescriptor getDescriptor(File file, ElfCommand command)
           
 ElfEHeader getEHeader()
           
 int getElfVersion()
           
 String getIdentification()
           
 ElfKind getKind()
           
static String getLastErrorMsg()
           
static int getLastErrorNo()
           
 ElfSection getNextSection(ElfSection previous)
           
 ElfPHeader getPHeader(int index)
           
(package private)  long getPointer()
           
 ElfData getRawData(long offset, long size)
           
 String getRawFileContents(long ptr)
           
 ElfSection getSection(long index)
          Returns the ElfSection at the provided index
 ElfSection getSectionByOffset(int offset)
          Returns the ElfSection at the given offset
 long getSectionCount()
           
 long getSHeaderStringTableIndex()
           
 String getStringAtOffset(long index, long offset)
          Returns the string at the provided offset from the provided index
 ElfCommand next()
           
 void update(ElfCommand command)
          Update the Elf descriptor and write the file to disk
 void updateEHeader(ElfEHeader header)
          Update the ELF header
 int updatePHeader(int index, ElfPHeader header)
          Update the program header
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pointer

private long pointer

fd

private FileDescriptor fd
Constructor Detail

Elf

Elf(long ptr)

Elf

public Elf(File file,
           ElfCommand command)
Creates a new elf object

Parameters:
file - The file to create the object from
command - The appropriate ElfCommand

Elf

public Elf(FileDescriptor fd,
           ElfCommand command)
Creates a new elf object

Parameters:
file - The file to create the object from
command - The appropriate ElfCommand
Method Detail

close

public void close()
Destroy the external elf file object associated with this object.


finalize

protected void finalize()
Overrides:
finalize in class Object

getDescriptor

private static FileDescriptor getDescriptor(File file,
                                            ElfCommand command)

next

public ElfCommand next()
Returns:
The next elf command

getElfVersion

public int getElfVersion()
Returns:
version

update

public void update(ElfCommand command)
Update the Elf descriptor and write the file to disk

Parameters:
command - The ElfCommand

getKind

public ElfKind getKind()
Returns:
The type of file associated with this Elf object.

getBase

public long getBase()
Returns:
The base offset for the Elf object

getIdentification

public String getIdentification()
Parameters:
ptr -
Returns:
The file identification data

getEHeader

public ElfEHeader getEHeader()
Returns:
The object file header

createNewEHeader

public ElfEHeader createNewEHeader(int wordSize)
Creates a new Elf Header if none exists

Returns:
A new ElfHeader

updateEHeader

public void updateEHeader(ElfEHeader header)
Update the ELF header

Parameters:
header -

getPHeader

public ElfPHeader getPHeader(int index)
Returns:
The program header table

updatePHeader

public int updatePHeader(int index,
                         ElfPHeader header)
Update the program header

Parameters:
index -
header -
Returns:
success/fail

createNewPHeader

public int createNewPHeader(long count)
Creates a new program header table if none exists

Parameters:
count -
Returns:
The program header table

getSectionByOffset

public ElfSection getSectionByOffset(int offset)
Returns the ElfSection at the given offset

Parameters:
offset - The offset to get the header at
Returns:
The ElfSection

getSection

public ElfSection getSection(long index)
Returns the ElfSection at the provided index

Parameters:
index - The index
Returns:
The ElfSection at that index

getNextSection

public ElfSection getNextSection(ElfSection previous)
Parameters:
previous - The current ElfSection
Returns:
The ElfSection that immediately follows it

createNewSection

public ElfSection createNewSection()
Creates a new ElfSection at the end of the table and returns it

Returns:
The new ElfSection

getSectionCount

public long getSectionCount()
Parameters:
dst -
Returns:
The number of sections in the Elf file.

getSHeaderStringTableIndex

public long getSHeaderStringTableIndex()
Parameters:
dst -
Returns:
The section index of the section header string table in the Elf file.

flag

public ElfFlags flag(ElfCommand command,
                     ElfFlags flags)
Sets or clears flags in the Elf file

Parameters:
command - An ElfCommand
flags - The flags to set/clear
Returns:
the current flags

flagEHeader

public ElfFlags flagEHeader(ElfCommand command,
                            ElfFlags flags)
Sets or clears flags in the Elf header

Parameters:
command - An ElfCommand
flags - The flags to set/clear
Returns:
the current flags

flagPHeader

public ElfFlags flagPHeader(ElfCommand command,
                            ElfFlags flags)
Sets or clears flags in the Elf program header

Parameters:
command - An ElfCommand
flags - The flags to set/clear
Returns:
the current flags

getStringAtOffset

public String getStringAtOffset(long index,
                                long offset)
Returns the string at the provided offset from the provided index

Parameters:
index - The index
offset - The offset from index e* @return The string at index + offset

getArchiveHeader

public ElfArchiveHeader getArchiveHeader()
Returns:
The Elf archive header

getArchiveOffset

public long getArchiveOffset()
Returns:
The offset in the archive of the current elf file.

getArchiveElement

public long getArchiveElement(int offset)
Parameters:
offset - The offset to get the archive element from
Returns:
The archive element at the provided offset

getArchiveSymbol

public ElfArchiveSymbol getArchiveSymbol(long ptr)
Parameters:
ptr -
Returns:
The symbol table of the archive

getControlDescriptor

public int getControlDescriptor(ElfCommand command)
Parameters:
command - An ElfCommand
Returns:
The control Elf descriptor.

getRawFileContents

public String getRawFileContents(long ptr)
Parameters:
ptr -
Returns:
The uninterpreted file conents

getPointer

long getPointer()

getLastErrorMsg

public static String getLastErrorMsg()
Returns:
The descriptive last error message elf returned.

getLastErrorNo

public static int getLastErrorNo()
Returns:
The descriptive last error message elf returned.

getRawData

public ElfData getRawData(long offset,
                          long size)
Returns:
Elf data packaged in ElfData class from given offset and size.

elfBegin

private static long elfBegin(FileDescriptor fd,
                             ElfCommand cmd)
                      throws ElfException
Throws:
ElfException

elfEnd

private static void elfEnd(long elf)

elf_next

protected int elf_next()

elf_get_version

protected int elf_get_version()

elf_update

private void elf_update(int cmd)

elf_kind

protected int elf_kind()

elf_getbase

protected long elf_getbase()

elf_getident

protected String elf_getident()

elf_getehdr

protected ElfEHeader elf_getehdr()

elf_newehdr

private void elf_newehdr(int wordSize)

elf_updatehdr

private void elf_updatehdr(ElfEHeader header)

elf_getphdr

protected ElfPHeader elf_getphdr(int index)

elf_updatephdr

protected int elf_updatephdr(int index,
                             ElfPHeader header)

elf_newphdr

protected int elf_newphdr(long __cnt)

elf_offscn

protected long elf_offscn(long offset)

elf_getscn

protected long elf_getscn(long __index)

elf_nextscn

protected long elf_nextscn(long __scn)

elf_newscn

protected long elf_newscn()

elf_getshnum

protected long elf_getshnum()

elf_getshstrndx

protected long elf_getshstrndx()

elf_flagelf

protected int elf_flagelf(int __cmd,
                          int __flags)

elf_flagehdr

protected int elf_flagehdr(int __cmd,
                           int __flags)

elf_flagphdr

protected int elf_flagphdr(int __cmd,
                           int __flags)

elf_strptr

protected String elf_strptr(long __index,
                            long __offset)

elf_getarhdr

protected ElfArchiveHeader elf_getarhdr()

elf_getaroff

protected long elf_getaroff()

elf_rand

protected long elf_rand(int __offset)

elf_getarsym

protected long elf_getarsym(long __ptr)

elf_cntl

protected int elf_cntl(int __cmd)

elf_rawfile

protected String elf_rawfile(long __ptr)

elf_get_last_error_msg

private static String elf_get_last_error_msg()

elf_get_last_error_no

private static int elf_get_last_error_no()

elf_get_raw_data

protected ElfData elf_get_raw_data(long offset,
                                   long size)