MakeELF
ELF reader-writer library
Public Member Functions | Public Attributes | List of all members
makeelf.elf.ELF Class Reference

Public Member Functions

def __init__ (self, e_class=ELFCLASS.ELFCLASS32, e_data=ELFDATA.ELFDATA2MSB, e_type=ET.ET_EXEC, e_machine=EM.EM_NONE)
 
def __str__ (self)
 
def __repr__ (self)
 
def __bytes__ (self)
 
def from_bytes (b)
 
def from_file (filename)
 
def get_section_by_name (self, sec_name)
 Get section with header based on its name. More...
 
def append_section (self, sec_name, sec_data, sec_addr)
 Add new section to ELF file. More...
 
def append_special_section (self, sec_name)
 Add new special section to ELF file. More...
 
def append_segment (self, sec_id, addr=None, mem_size=-1, flags='rwx')
 Add new program header, describing segment in memory. More...
 
def append_symbol (self, sym_name, sym_section, sym_offset, sym_size, sym_binding=STB.STB_LOCAL, sym_type=STT.STT_NOTYPE, sym_visibility=STV.STV_DEFAULT)
 Append new symbol to symbol table. More...
 

Public Attributes

 little
 Header endianness indicator. More...
 
 Elf
 Instance of elfstruct.Elf32 class. More...
 

Detailed Description

This class is a wrapper on ELF structures provided by elfstruct module

It provides set of functions allowing easy manipulation of ELF as a whole,
without requirement of update of particular fields, especially offsets and
section headers

Member Function Documentation

◆ __bytes__()

def makeelf.elf.ELF.__bytes__ (   self)
Serialize ELF object into block of bytes

Makes some header updates and serializes object to file, so output
should always be valid ELF file

◆ append_section()

def makeelf.elf.ELF.append_section (   self,
  sec_name,
  sec_data,
  sec_addr 
)

Add new section to ELF file.

Name is automatically appended to .shstrtab section (section is created if does not exists)

Parameters
sec_nameName of the section to append
Returns
ID of newly added section

◆ append_segment()

def makeelf.elf.ELF.append_segment (   self,
  sec_id,
  addr = None,
  mem_size = -1,
  flags = 'rwx' 
)

Add new program header, describing segment in memory.

This function is for executable and shared objects only. On other types of ELFs causes exception. Currently appended segment can only be of type PT_LOAD

Parameters
sec_idid of section already describing this segment
addrvirtual address at which segment will be loaded
mem_sizesize of segment after loading into memory
Returns
ID of newly added segment

◆ append_special_section()

def makeelf.elf.ELF.append_special_section (   self,
  sec_name 
)

Add new special section to ELF file.

This function allows to add one of the special, structured sections to ELF file. Name is automatically appended to .shstrtab section

Parameters
sec_nameName of the section to append
Returns
ID of newly added section

◆ append_symbol()

def makeelf.elf.ELF.append_symbol (   self,
  sym_name,
  sym_section,
  sym_offset,
  sym_size,
  sym_binding = STB.STB_LOCAL,
  sym_type = STT.STT_NOTYPE,
  sym_visibility = STV.STV_DEFAULT 
)

Append new symbol to symbol table.

Creates symbol table, if necessary, adds new symbol name to symbol string table and symbol descriptor to symbol table.

Parameters
sym_namename of symbol as str or bytes, or None if unnamed
sym_sectionnumber of section, where symbol is located
sym_offsetlocation of symbol from start of the section
sym_sizesize of the symbol in bytes
Returns
index of symbol in table

◆ from_bytes()

def makeelf.elf.ELF.from_bytes (   b)
Deserializes ELF from block of bytes

◆ from_file()

def makeelf.elf.ELF.from_file (   filename)
Deserializes ELF from filesystem

◆ get_section_by_name()

def makeelf.elf.ELF.get_section_by_name (   self,
  sec_name 
)

Get section with header based on its name.

Parameters
sec_nameName of the section
Returns
Tuple of header and section

Member Data Documentation

◆ Elf

makeelf.elf.ELF.Elf

Instance of elfstruct.Elf32 class.

Provides possibility to make any modification to ELF file, including setting fields to invalid values.

◆ little

makeelf.elf.ELF.little

Header endianness indicator.

Is true, if header values are meant to be stored as little-endian or false otherwise


The documentation for this class was generated from the following file: