ELF binary parser

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

ELF binary parser

Postby snahmad75 » 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

ESP_Sprite
Posts: 9020
Joined: Thu Nov 26, 2015 4:08 am

Re: ELF binary parser

Postby ESP_Sprite » Sat Dec 15, 2018 3:44 am

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?

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: ELF binary parser

Postby loboris » Sat Dec 15, 2018 10:05 am

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 

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: ELF binary parser

Postby Ritesh » 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.
Regards,
Ritesh Prajapati

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: ELF binary parser

Postby snahmad75 » 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.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: ELF binary parser

Postby Ritesh » Mon Dec 17, 2018 10:09 am

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.
Regards,
Ritesh Prajapati

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: ELF binary parser

Postby ESP_Angus » Mon Dec 17, 2018 10:53 pm

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.

Who is online

Users browsing this forum: No registered users and 149 guests