CensoredUsername/unrpyc

"Did not find a zlib compressed blob where it was expected. Either the header has been modified or the file structure has been changed."

LatLichy opened this issue · 6 comments

Hello, I'm not used to code or github so I hope it's ok to report the issue here with this post, sorry if it's the wrong place or if I sound odd

Ren'Py version of the game: 8.0.3.22090809 (That what's written at the bottom of the traceback text file that I get when I try to start the game but it can't launch because of an error)

Version of unrpyc : v2.0.1 (I also tried v1.3.1 just in case because of despair but both don't work)

Version of python : 3.9.13

Error(s) : "line 112, in read_ast_from_file
raise Exception(
Exception: Did not find a zlib compressed blob where it was expected. Either the header has been modified or the file structure has been changed.

Decompilation of 1 file failed"

This error occurs for every single rpyc file of the same game. I also tried to decompile those with another tool, online (https://grviewer.com), and it also encounter an error, the exact same from what i'm able to understand (which is not much tbh), on this website, the error is : "zlib.error: Error -3 while decompressing data: incorrect header check"
And also occurs for all of the rpyc files of the game.

Note : Both unrpyc and the website I just mentioned worked fine to decompile rpyc from another game I tried, so the issue seems to come from the game and not from me (unless you think I did something wrong?)

What I did on unrpyc : went into the unrpyc-master folder, where the file "unrpyc.py" is located, opened the cmd here (by right clicking in the blank space > then open in the cmd), then typed, in the cmd : "python unrpyc.py", then went into the folder where the rpyc file I wanted to decompile is, right click on the file > copy the path, went back to the cmd, and pasted the path, so the final line I typed in the cmd was "python unrpyc.py (file location)", then enter.
Then the cmd indicates that it's indeeed running and trying to decompile the rpyc file, but can't because "line 112, in read_ast_from_file
raise Exception(
Exception: Did not find a zlib compressed blob where it was expected. Either the header has been modified or the file structure has been changed.

Decompilation of 1 file failed"

I also tried with "python unrpyc.py --try-harder (file location)" which gives the following error : " line 213, in
if not all(ord(i) >= 0x20 and ord(i) < 0x80 for i in count.keys()):
TypeError: ord() expected string of length 1, but int found

Decompilation of 1 file failed"

And the automatic method, by putting either the "un.rpyc" or the "un.rpy" file into the "game" folder of the game, then launching it, but the game is unable to launch, and I get a traceback text file saying "While running game code:
Exception: Could not load (un.rpyc or un.rpy)",
the game can launch properly again if I remove the file from the "game" folder.

I tried to replace the "bytecode" file of the "cache" folder by the one provided on the github as well, then launched the game, and it's able to launch, but no decompilation happens.

Finally, I also tried a massive decompilation by typing "python unrpyc.py (GAME FOLDER location, instead of a specific file location)", and the cmd indicates that the program tries to decompile everything, but fails for all of them (100% unsuccessful rate).
This same attempt for the other game I tried worked well and decompiled everything.

Oh and one last thing, I can launch the game from the .exe, but not from Ren'Py (like if I copy and paste the folder into my projects folder of Ren'Py, then go into Ren'Py and try to launch the game, well it doesn't work, there is a file called "after_load.rpyc" that cannot load apparently).
My version of Ren'Py is v.8.2.3.

I spare you all the details about me uninstalling and reinstalling python, unrpyc, the game (from different sources) and all, the result is always the same.

Thanks if you read all that,
I tried to be as complete as possible in my report.

Heya. Based on your description you've ran into a game which has altered the rpyc file format in some way to not match the normal ren'py file format. The errors are accurate, unrpyc cannot read this file.

Well except for the folloiwng:

I also tried with "python unrpyc.py --try-harder (file location)" which gives the following error : " line 213, in
if not all(ord(i) >= 0x20 and ord(i) < 0x80 for i in count.keys()):
TypeError: ord() expected string of length 1, but int found

This is a deobfuscation bug introduced with the python 3 transition, we can fix that and possibly it'll be able to decode it.

But otherwise, you'll have to figure out what the game is doing that is different from ren'py. We can unfortunately not support whatever file format changes people make to their own games.

They seem to have been thorough though, even blocking normal rpy files (un.rpy) as well as the bytecode injection (just checking, it was called bytecode-3.9.rpyb when you put it in there right?

I've pushed an update (and included in the new release) a fix to the issue you encountered with deobfuscation. You can give that a try, it might work.

Thanks for your response.

I downloaded the update and tried again, and it still doesn't work, but the error messages are a bit more precise this time it seems :

When I use the line "python unrpyc.py (file location)", the error is now : "\unrpyc-master\unrpyc.py", line 138, in read_ast_from_file
raise BadRpycException(
BadRpycException: Did not find a zlib compressed blob where it was expected. Either the header has been modified or the file structure has been changed. File header: b'RENPY RPC2\x01\x00\x00\x00.\x00\x00\x00F9\x00\x00\x02\x00\x00\x00t9\x00\x00\x9bP\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc4G.Q'

Unrpyc v2.0.2 results summary:

Processed 1 file.

0 files were successfully decompiled.
1 file did not have the correct header, these were ignored.

To attempt to bypass modifications to the file header, use the --try-harder flag."

As for when I use the line "python unrpyc.py --try-harder (file location)", the error is now : "\unrpyc-master\deobfuscate.py", line 345, in try_decrypt_section
raise ValueError("\n".join(diagnosis))
ValueError: Did not know how to decrypt data.

During handling of the above exception, another exception occurred:"

and : "\unrpyc-master\deobfuscate.py", line 307, in read_ast
diagnosis.append(e.message)
AttributeError: 'ValueError' object has no attribute 'message'


Unrpyc v2.0.2 results summary:

Processed 1 file.

0 files were successfully decompiled.
1 file failed to decompile due to errors."

I also tried the other method one more time, by replacing the "bytecode" file in the "game\cache" folder of the game (and indeed calling it "bytecode-39.rpyb", like the file is called on the github), and the result is the same as before; the game can launch, but no decompilation occurs.

Putting the "un.rpy" file into the "game" folder, then launching the game, still result in the game not being able to start, giving the following error message in a text traceback file : "File "game/un.rpy", line 1, in
python early hide:
File "game/un.rpy", line 30, in _execute_python_hide
bindata = renpy.game.script.read_rpyc_data(file, 1)
AttributeError: 'Script' object has no attribute 'read_rpyc_data'",

And doing the same with the "un.rpyc" file still prevent the game from running as well, saying that this file apparently could not load.

I understand that the rpyc files from this game can't be opened with unrpyc, and still appreciated your help.

Too bad, but thanks a lot anyway

AttributeError: 'Script' object has no attribute 'read_rpyc_data'",

Hmm, you might have a duplicate of #217 on your hands

Indeed. I looked at your link and read everything. I tried to edit the code of the "un.rpy" file to replace the function name "read_rpyc_data" by "read_lidl_discount_data", like you said on the post, and it worked for me as well. Placing the "un.rpy" file in the "game" folder of the game, then launching the game, now works. The game is able to start, and everything is decompiled.
I'm able to do what I want now.

I want to apologize, I'm unfamiliar with github and did not know that it was possible to look at the closed issues report posts. I should have done more tries and research before complaining.

I'm still grateful that you responded and helped me.

Thanks you!

I want to apologize, I'm unfamiliar with github and did not know that it was possible to look at the closed issues report posts. I should have done more tries and research before complaining.

No problem, you left a very detailed bug report that I could easily work with, that is much more than most people do ;)