tuya-cloudcutter / bk7231tools

This is a collection of tools to interact with and analyze artifacts for BK7231 MCUs
MIT License
38 stars 6 forks source link

sf_find_index broken on Python 3.11 due to funny goto thing #20

Closed jackrosenthal closed 9 months ago

jackrosenthal commented 1 year ago

The goto.py module appears to be completely broken in Python 3.11, likely due to bytecode format changes.

Here is an example traceback (from cloudcutter profile builder, but originates from this library):

% python ~/tuya-cloudcutter/profile-building/build_profile.py Milfra_KS---604S-Wall-Outlet.bin
[+] Processing file='Milfra_KS---604S-Wall-Outlet.bin' as Milfra_KS---604S-Wall-Outlet
RBL containers:
    0x10f9a: bootloader - [encoding_algorithm=NONE, size=0xea20]
        extracted to /home/jrosenth/Milfra_KS---604S-Wall-Outlet
    0x129f0a: app - [encoding_algorithm=NONE, size=0xefd60]
        extracted to /home/jrosenth/Milfra_KS---604S-Wall-Outlet
Storage partition:
Traceback (most recent call last):
  File "/home/jrosenth/tuya-cloudcutter/profile-building/build_profile.py", line 44, in <module>
    extract.run(file)
  File "/home/jrosenth/tuya-cloudcutter/profile-building/extract.py", line 50, in run
    bk7231tools.__main__.dissect_dump_file(input)
  File "/home/jrosenth/libretiny-venv/lib/python3.11/site-packages/bk7231tools/__main__.py", line 240, in dissect_dump_file
    keys = storage.find_all_keys()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jrosenth/libretiny-venv/lib/python3.11/site-packages/bk7231tools/analysis/storage.py", line 207, in find_all_keys
    self.sf_find_index("abcdef")
  File "/home/jrosenth/libretiny-venv/lib/python3.11/site-packages/bk7231tools/analysis/storage.py", line 278, in sf_find_index
    label.label_12
AttributeError: 'NoneType' object has no attribute 'label_12'

The function likely needs re-written to not use this funny goto code, or the goto logic needs updated for the new bytecode formats.

paravoid commented 11 months ago

Thanks @jackrosenthal for reporting this - I originally thought my image was corrupted! This is the same issue as #15 I think.

I bumped into this as well, with Python 3.11, on Debian bookworm, when trying to use upk2esphome.

I spun up a container with Debian buster (oldstable), which shipped with Python 3.9. However, I then bumped into another problem: LibreTiny's upk2esphome needs Python >= 3.10 :( I can of course use a Python container with 3.10, but It'd be nice to get this fixed. Thanks for all of your work!

kuba2k2 commented 9 months ago

@jackrosenthal @paravoid v1.5.0 of bk7231tools doesn't use goto anymore. Futhermore, the storage decryption class is rewritten from ground up, and is more reliable.