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

Dissecting fails on latest version of the bk7231tools #4

Closed ihrapsa closed 2 years ago

ihrapsa commented 2 years ago

Hi, I've tried dissecting this bin with the latest commit of the tools but it fails as follows:

% python3 bk7231tools.py dissect_dump -e -O dump_extract_dir dump_calex_rgbcct_bulb.bin
RBL containers:
    0x10f9a: bootloader - [encoding_algorithm=NONE, size=0xe470]
Traceback (most recent call last):
  File "/Users/testuser/Downloads/bk7231tools/bk7231tools.py", line 279, in <module>
    args.handler(args)
  File "/Users/testuser/Downloads/bk7231tools/bk7231tools.py", line 188, in dissect_dump_file
    containers = __carve_and_write_rbl_containers(dumpfile=dumpfile, layout=layout,
  File "/Users/testuser/Downloads/bk7231tools/bk7231tools.py", line 89, in __carve_and_write_rbl_containers
    fsout.write(__decrypt_code_partition(partition, container.payload))
  File "/Users/testuser/Downloads/bk7231tools/bk7231tools.py", line 51, in __decrypt_code_partition
    return cipher.decrypt(payload, partition.mapped_address)
  File "/Users/testuser/Downloads/bk7231tools/bk7231tools/crypto/code.py", line 70, in decrypt
    return self.encrypt(data, stream_start_offset=stream_start_offset)
  File "/Users/testuser/Downloads/bk7231tools/bk7231tools/crypto/code.py", line 59, in encrypt
    raise ValueError(f"Given data length {len(data)} is not a multiple of block length {self.BLOCK_LENGTH_BYTES}")
ValueError: Given data length 58480 is not a multiple of block length 32

With an older version of this tool (before commit 470817c ) everything runs ok

notkmhn commented 2 years ago

Thanks for the report. Commit 90c861785b9b4b880e2a2fd33d816d8c66ffda29 fixes it :)