Page 1 of 1

ELF binary parser

Posted: Thu Dec 13, 2018 11:49 pm
by snahmad75
Hi,

I there any C or C++ ELF binary parser which can parse bin files. either signed or not.

Thanks,
Naeem

Re: ELF binary parser

Posted: Sat Dec 15, 2018 3:44 am
by ESP_Sprite
Erm, a bin-file is not an elf-file, so an elf parser can, by definition, not parse a bin file. What do you need this for?

Re: ELF binary parser

Posted: Sat Dec 15, 2018 10:05 am
by loboris
A standard elf file is also created during the build process and it can be parsed using any elf parser like 'readelf'

Code: Select all

<mydir>$ readelf -h -l MicroPython.elf
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Tensilica Xtensa Processor
  Version:                           0x1
  Entry point address:               0x40081708
  Start of program headers:          52 (bytes into file)
  Start of section headers:          14056380 (bytes into file)
  Flags:                             0x300
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         8
  Size of section headers:           40 (bytes)
  Number of section headers:         55
  Section header string table index: 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x3f3ffee0 0x3f3ffee0 0x62ba8 0x62ba8 RW  0x1
  LOAD           0x062bb0 0x3ffc0000 0x3ffc0000 0x055b4 0x055b4 RW  0x1
  LOAD           0x068168 0x3ffc55b8 0x3ffc55b8 0x00000 0x0c1f8 RW  0x1
  LOAD           0x068164 0x40080000 0x40080000 0x00400 0x00400 R E 0x1
  LOAD           0x068564 0x40080400 0x40080400 0x1f980 0x1f980 RWE 0x1
  LOAD           0x087ee4 0x400c0000 0x400c0000 0x00663 0x00663 R E 0x1
  LOAD           0x088548 0x400d0018 0x400d0018 0x160432 0x160432 R E 0x1
  LOAD           0x1e8980 0x50000000 0x50000000 0x0098a 0x0098c RW  0x1

 Section to Segment mapping:
  Segment Sections...
   00     .flash.rodata 
   01     .dram0.data 
   02     .dram0.bss 
   03     .iram0.vectors 
   04     .iram0.text 
   05     .rtc.text 
   06     .flash.text 
   07     .rtc.data .rtc_noinit 

Re: ELF binary parser

Posted: Sun Dec 16, 2018 4:35 pm
by Ritesh
snahmad75 wrote:
Thu Dec 13, 2018 11:49 pm
Hi,

I there any C or C++ ELF binary parser which can parse bin files. either signed or not.

Thanks,
Naeem
readelf and objdump utilities will be helpful to parse elf and binary files.

Re: ELF binary parser

Posted: Mon Dec 17, 2018 9:48 am
by snahmad75
Ritesh wrote:
Sun Dec 16, 2018 4:35 pm
snahmad75 wrote:
Thu Dec 13, 2018 11:49 pm
Hi,

I there any C or C++ ELF binary parser which can parse bin files. either signed or not.

Thanks,
Naeem
readelf and objdump utilities will be helpful to parse elf and binary files.
OK, Thanks. As I understood readelf and objdump utilities are python scripts.

Re: ELF binary parser

Posted: Mon Dec 17, 2018 10:09 am
by Ritesh
snahmad75 wrote:
Mon Dec 17, 2018 9:48 am
Ritesh wrote:
Sun Dec 16, 2018 4:35 pm
snahmad75 wrote:
Thu Dec 13, 2018 11:49 pm
Hi,

I there any C or C++ ELF binary parser which can parse bin files. either signed or not.

Thanks,
Naeem
readelf and objdump utilities will be helpful to parse elf and binary files.
OK, Thanks. As I understood readelf and objdump utilities are python scripts.
You can use xtensa-esp32-elf-readelf and xtensa-esp32-elf-objdump utilities which are part if ESP32 Toolchain using which you can parse elf file as per your requirement.

Re: ELF binary parser

Posted: Mon Dec 17, 2018 10:53 pm
by ESP_Angus
If you want to parse the .bin file rather than the .elf file (which is the output of "esptool.py elf2image" and the file which is actually flashed to the ESP32), then you can use esptool.py:

Code: Select all

esptool.py --chip esp32 image_info binfile.bin
This doesn't work for the .elf file, you need to use one of the other tools mentioned in the thread.

Note that esptool.py ignores any signature appended to the .bin file.