Skip to content

Conversation

AniccaY
Copy link

@AniccaY AniccaY commented Sep 14, 2025

Fix CN bundle decrypt :
The wrong block was decrypted
only LZ4HC need decrypt

Fix CN bundle decrypt :
The wrong block was decrypted
only LZ4HC need decrypt
@isHarryh
Copy link
Contributor

Do you have enough evidence to prove this? @AniccaY

Although LZ4HC compression flag is widely used in many UnityCN-encrypted games, we cannot draw a conclusion that LZ4HC flag is used in ALL the UnityCN-encrypted games.

@AniccaY
Copy link
Author

AniccaY commented Sep 16, 2025

old version will decrypt type: None Block, cause read bundle error

@isHarryh
Copy link
Contributor

I'm interested in the asset file you try to decrypt. Could you please provide a sample file and its key to let me investigate deeper?

@AniccaY
Copy link
Author

AniccaY commented Sep 16, 2025

sample.zip
@isHarryh
2 samples
One will parse error, and raise error info.
Two will parse with no error, but when you extract the only one file in bundle, this file is damaged.
This is a relatively hidden problem.

@isHarryh
Copy link
Contributor

Thanks.

In your sample files, the blocks with compression flag NONE need no decryption. In another word, for NONE compression, UnityPy should return the data as-is without decryption.

I think you can use:

        if self.decryptor is not None and comp_flag != CompressionFlags.NONE and flags & 0x100:
            ...

instead of simply limiting the decryption to LZ4HC only. As you can see in Studio's implementation, such decryption is applied to all the LZ4-series compression. Here's the reference.

if self.decryptor is not None and comp_flag != CompressionFlags.NONE and flags & 0x100:
try:
compressed_data = self.decryptor.decrypt_block(compressed_data, index)
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such try-except bypass strategy may conceal potential problems. I think we can remove it.

Btw, it's suggested to rename your PR's title to let it reflect actual works.

Copy link
Contributor

@isHarryh isHarryh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the significance of your new changes.

Please edit the if-statement of L505 only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants