Warning
The documentation for Elf hasn’t been touched yet! If you want to contribute (or have ideas for better documentation), feel free to send me a pull request or email me.
Kenshoto’s Elf parser
This package will let you use programatic ninja-fu when trying to parse Elf binaries. The API is based around several objects representing constructs in the Elf binary format. The Elf object itself contains parsed metadata and lists of things like section headers and relocation entries. Additionally, most of the objects implement repr() in some form or another which allows you a bunch of readelf-like functionality.
Eventually this API will allow you to modify Elf binaries and spit them back out in working order (not complete, you may notice some of the initial code).
Send bug reports to Invisigoth or Metr0.
Bases: vstruct.defs.elf.Elf32, vstruct.defs.elf.Elf64
For prelinked and main-exe elf binaries, return the value for the loaded base address...
Because relocation type names are decided based on the arch, only the Elf knows for sure...
Returns true if the given Elf binary is a dynamically shared object.
lookup symbols from this elf binary by address. This returns the name for the given symbol or None for not found
An object to represent an Elf dynamic entry. (linker/loader directives)
Elf relocation entries consist mostly of “fixup” address which are taken care of by the loader at runtime. Things like GOT entries, PLT jmp codes etc all have an Elf relocation entry.
Returns a Elf class for a string of bytes. Basically just passes your bytes into a StringIO() and hands that off to Elf.Elf
Parameters: | fbytes (str.) – The bytestring comprising the Elf. |
---|---|
Returns: | Elf.Elf instance of the specified Elf. |
Return type: | Elf.Elf |
Returns an Elf class for a specified file path. Makes sure to open the file in “rb” mode to read binary.
Parameters: | fname (str.) – The filename of our Elf. |
---|---|
Returns: | Elf.Elf instance of the specified Elf. |
Return type: | Elf.Elf |
Returns a Elf class for a string of bytes. Basically just passes your bytes into a StringIO() and hands that off to Elf.Elf
Example:
>>> # Import vtrace and Elf
>>> import vtrace, Elf
>>> # Initilize our vtrace.Trace object
>>> trace = vtrace.getTrace()
>>> trace.execute('/path/to/program')
>>> # Get our library bases
>>> libBase = trace.getMeta("LibraryBases")
>>> # Get the first address of our first entry (not realistic)
>>> base = libBase.items()[0][1]
>>> # Create our Elf.Elf()
>>> p = Elf.peFromMemoryObject(trace, base)
Parameters: |
|
---|---|
Returns: | Elf.Elf instance of the specified Elf (with inmem=True). |
Return type: |
ELF static definitions