K0lb3 / UnityPy

UnityPy is python module that makes it possible to extract/unpack and edit Unity assets
MIT License
771 stars 114 forks source link

Decompression failed: corrupt input or insufficient space #175

Closed StarHeartHunt closed 1 year ago

StarHeartHunt commented 1 year ago

Code

import os
import UnityPy
import json

def unpack_all_assets(source_folder: str, destination_folder: str):
    # iterate over all files in source folder
    for root, dirs, files in os.walk(source_folder):
        for file_name in files:
            # generate file_path
            file_path = os.path.join(root, file_name)
            # load that file via UnityPy.load
            env = UnityPy.load(file_path)

unpack_all_assets("unitycn", "Exported")

Error

> python .\main4.py 
Error loading, reverting to EndianBinaryReader:
 Decompression failed: corrupt input or insufficient space in destination buffer. Error code: 16

Bug Expectation: load normally Actually: Error occurred and exit

To Reproduce

And the Unity version is 2019.4.30f1, the issue could be related to the Unity CN decryption.

K0lb3 commented 1 year ago

The game the file is from definitely uses custom "compression" that replaces lz4. It's one of the features of Unity CN pro.

The devs can freely design this custom compression and can't be detected within the files themselves, well, besides that, they produce this error.

Mind that this feature is not the same as Unity CN's build-in protection feature.

K0lb3 commented 1 year ago

^ I was partially wrong with the previous answer; apparently, Unity also added stream alignment to BundleFiles in some Unity 2019.4 versions. I added a hotfix for this for now.

Laesx commented 11 months ago

The game the file is from definitely uses custom "compression" that replaces lz4. It's one of the features of Unity CN pro.

The devs can freely design this custom compression and can't be detected within the files themselves, well, besides that, they produce this error.

Mind that this feature is not the same as Unity CN's build-in protection feature.

I think I encountered this issue, file doesn't seem to be encrypted but I still get the same error as the OP. Unity Version is 2020.3.42f1 CN and UnityPy version is 1.10.2 File is https://files.catbox.moe/0v79bw.bundle Any way to try different compressions?