jsandin / esp-bin2elf

Converts a flash dump from an esp8266 device into an ELF executable file for analysis and reverse engineering.
81 stars 13 forks source link

Codec issue decoding magic by 0xe9 #11

Open kwafula opened 2 weeks ago

kwafula commented 2 weeks ago

Hi Sandin,

Great tool, hoping I can get the fix to finish my RE project.

If my cursory analysis is correct, the code needs to replace StringO with BytesIO to handle bytes stream correctly, but I am not 100% sure. I am working on REing my esp8266, if I get this fixed for python3 I will update the issue. However, I'd be grateful if you have a quick fix ( I am not seasoned at python programming)

##################################################################### 1) StringIO deprecated in Python3 ##################################################################### ┌──(kali㉿kali)-[~/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf] └─$ python3 esp8266-bin-to-elf.py
Traceback (most recent call last): File "/home/kali/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf/esp8266-bin-to-elf.py", line 1, in import esp_bin2elf File "/home/kali/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf/esp_bin2elf.py", line 8, in from esp_rom import EspRom File "/home/kali/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf/esp_rom.py", line 7, in from StringIO import StringIO ModuleNotFoundError: No module named 'StringIO'

##################################################################### 2) After updating the code to import StringIO from io ##################################################################### (kali㉿kali)-[~/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf] └─$ python3 esp8266-bin-to-elf.py
Traceback (most recent call last): File "/home/kali/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf/esp8266-bin-to-elf.py", line 5, in rom = esp_bin2elf.parse_rom('tywe3s-2mb.bin', '../bin/tywe3s-2mb.bin', flash_layout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kali/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf/esp_bin2elf.py", line 14, in parse_rom rom = EspRom(rom_name, f, flash_layout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kali/Desktop/CSC-844/TuyaTYWE3S/esp-bin2elf/esp_rom.py", line 15, in init self.contents = rom_bytes_stream.read() ^^^^^^^^^^^^^^^^^^^^^^^ File "", line 322, in decode UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 0: invalid continuation byte

kwafula commented 2 weeks ago

I want to confirm that the I successfully converted the Espressif Tuya Tywe3s esp8266 firmware flash bin to ELF bin. My confing was as follows

  1. Python2.7 latest
  2. Python2.7 pip setuptools-44.1.1 , upgrade to version 0.7.4 or higher as follows:
    • sudo /usr/bin/python2.7 -m pip install setuptools --upgrade --ignore-installed
  3. Follow this instructions from @Zayfod here to install elffile:
  4. If you have issues with "coding" follow instructions from @CarlosG here:

Hope this help! Again, thanks @jsandlin