Die ELF -Datei ist nicht nur eine ausführbare Datei, sondern auch eine sehr bequeme Möglichkeit, das Layout eines Programms im Speicher zu beschreiben. Die ursprüngliche Absicht dieses Projekts besteht darin, einer Person eine ELF -Datei zu erstellen, die die für ein eingebettete Programm verwendete Speicherzuordnung beschreibt. Besonders nützlich für die Verwendung mit anderen Analysetools, wie z. B. IDA/Ghidra/etc ... alle gewünschten Informationen haben, ohne dass nur eine gewöhnliche .bin -Datei geöffnet werden muss und mehrere Idapython -Skripte ausgeführt werden müssen (ich habe es satt, Load additional binary file... Option).
Pull -Anfragen sind natürlich mehr als willkommen?
pip verwenden:
python3 -m pip install simpleelfOder klonen Sie sich und bauen Sie:
git clone [email protected]:doronz88/simpleelf.git
cd simpleelf
python -m pip install -e . -UJetzt können Sie einfach Simpleelf importieren und damit beginnen, damit zu spielen.
Das Parsen ist die Verwendung von ElfStruct einfach. Probieren Sie es aus:
from simpleelf . elf_structs import ElfStructs
ElfStructs ( '<' ). Elf32 . parse ( elf32_buffer ) # outputs a constucts' container
ElfStructs ( '<' ). Elf64 . parse ( elf64_buffer ) # outputs a constucts' container Das Gebäude ist einfach mit ElfBuilder . Probieren Sie es aus:
from simpleelf . elf_builder import ElfBuilder
from simpleelf import elf_consts
# can also be used with ELFCLASS64 to create 64bit layouts
e = ElfBuilder ( elf_consts . ELFCLASS32 )
e . set_endianity ( '<' )
e . set_machine ( elf_consts . EM_ARM )
code = b'CODECODE'
# add a segment
text_address = 0x1234
text_buffer = b'cybercyberbitimbitim' + code
e . add_segment ( text_address , text_buffer ,
elf_consts . PF_R | elf_consts . PF_W | elf_consts . PF_X )
# add a second segment
e . add_segment ( 0x88771122 , b'data in 0x88771122' ,
elf_consts . PF_R | elf_consts . PF_W | elf_consts . PF_X )
# add a code section inside the first segment
code_address = text_address + text_buffer . find ( code ) # point at CODECODE
code_size = len ( code )
e . add_code_section ( code_address , code_size , name = '.text' )
# set entry point
e . set_entry ( code_address )
# add .bss section. not requiring a loaded segment from
# file
bss_address = 0x5678
bss_size = 0x200
e . add_empty_data_section ( bss_address , bss_size , name = '.bss' )
# get raw elf
e . build ()