Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
descatal2
Posts: 5
Joined: Fri Oct 29, 2021 7:11 am

Re: Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Post by descatal2 »

MSQ wrote:spiritovod, anakronus

Thank you for the script, this works perfectly on the larger CPK files! I am sorry for the confusion regarding the differences in platforms, I did not realise the files were different in this case.

Edit: The CPK containers are not encrypted, I just messed up my game files (I might have accidentally encrypted them?) not too sure, but I can confirm that after clean reinstalling, the files definitely have the CPK header by default and by no means are fully encrypted. Sorry about this!

To further my knowledge of this topic: would there be a way to create a tool that decrypts the crilayla streams while they are still inside the CPK, or is it a must that each stream must be unpacked then decrypted. Thanks again!


I am not sure if it fits your criteria, but I've made modified the CriPakTools source code to run quickbms to decrypt the blowfish encryption.

Here's the program with source code included:

https://drive.google.com/file/d/1UxyqVh ... sp=sharing

Source:
https://drive.google.com/file/d/1SgG3uv ... sp=sharing

I've added a new -q argument to take in blowfish encryption key while decrypting files. It will automatically decrypts the encrypted data using quickbms before passing it back to the original program to decrypt (thus automatically decompress CRILAYLA compression)

Usage:
CriPakTools -x -i "the_path_to_CPK_you_want_to_decrypt" -d "the_path_to_decrypted_folder" -q "blowfish_encryption_key"

e.g.
If I want to extract psg00.cpk
CriPakTools -x -i "psg00.cpk" -d "unpacked" -q "CryptedByMititei"

If you are interested in repacking the CPK files (to mod), unfortunately I don't have many luck using the original CriPakTools to have good result (the pointers are all over the place).
Due to this, I made a workaround that instead of injecting / replace the files, the program will encrypt the files inside the repacked CPK.
I've added a new argument -p for this

Usage:
CriPakTools -p -i "the_path_to_CPK_you_want_to_encrypt" -o "output_encrypted_CPK_path" -q "blowfish_encryption_key"

e.g.
CriPakTools -p -i "psg00.cpk" -o "psg00-encrypted.cpk" -q "CryptedByMititei"

However, due to the limitation of CriPakTools, there's some CPK that's going to spew out error due to wrong ITOC header reading code.
If that's the case I would suggest to manually extract the encrypted data chunk from CPK, and manually decrypt it using the bms script.
The decrypted data should have a CRILAYLA header, and if it does, copy and replace the data inside the original encrypted CPK with it, and you should be able to decrypt them normally using any cpk decompression tool.
For repack do the same step but in reverse.

Hopefully this helps with the asset extractions.
MSQ
Posts: 20
Joined: Sat Oct 30, 2021 7:59 pm

Re: Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Post by MSQ »

descatal2
Thank you for this tool, it's exactly what I was looking for and most certainly helps me with my work! Being able to have an easier time repacking the CPK is loved. :D
DooshDR
Posts: 7
Joined: Wed Nov 10, 2021 5:49 pm

Re: Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Post by DooshDR »

Hi everyone and thank you so much for your great work. I tried to extract files from .cpk with CriPakGUI and some of them cannot be extracted. For example here: https://m.imgur.com/a/nECg6fC
When you try to extract files from some of the .cpk, you get an error related to “illegal characters”. As you can see on the screenshot, there are a bunch of <NULL> everywhere. I tried with command line and the error is “NullReferenceException”.
None of the extraction tools work with these problematic cpk files.
Thanks

Edit: Here is the cpk: https://mega.nz/file/xYhGRSZT#S_F5VI6oF ... KzvCjoIIxA

Edit2: I managed to extract some files with a HEX editor. First I opened the .cpk with CriPakGUI then I selected the part corresponding to each file (offset + data size) in the HEX editor. Then I decrypted the extracted file. Really tedious! But it's not efficient when there are 1500 files.
descatal2
Posts: 5
Joined: Fri Oct 29, 2021 7:11 am

Re: Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Post by descatal2 »

DooshDR wrote:Hi everyone and thank you so much for your great work. I tried to extract files from .cpk with CriPakGUI and some of them cannot be extracted. For example here: https://m.imgur.com/a/nECg6fC
When you try to extract files from some of the .cpk, you get an error related to “illegal characters”. As you can see on the screenshot, there are a bunch of <NULL> everywhere. I tried with command line and the error is “NullReferenceException”.
None of the extraction tools work with these problematic cpk files.
Thanks

Edit: Here is the cpk: https://mega.nz/file/xYhGRSZT#S_F5VI6oF ... KzvCjoIIxA

Edit2: I managed to extract some files with a HEX editor. First I opened the .cpk with CriPakGUI then I selected the part corresponding to each file (offset + data size) in the HEX editor. Then I decrypted the extracted file. Really tedious! But it's not efficient when there are 1500 files.


Yes, that's the CRIPAKGUI's problem I stated in my post above. Some of the CPK is just not supported by this tool due to ITOC header read error. Since even the CriPakTool cannot read the pointers properly, the code can't progress to the point where it can decrypt anything.

Hence, I don't have any answer to this but to ask anyone who has experience in CPK file extraction to look into this ITOC header problem. For now if you want you can write your own reader or modify the existing code to circumvent the error so that the pointers are correctly read.

Another experimental way is to try and file the file's starting pointer inside the CPK itself. It is quite recognizable since it is just a bunch of gibberish bytes. Once you found that, just copy everything from that point on until the file end, and paste it into a new binary file.
Then, decrypt the extracted byte arrays using the BMS script.
Once that is done, replace the byte you just copied inside the CPK with the newly decrypted byte arrays.
If everything is correct, the decrypted byte will have a CRILAYLA compression header, and replacing this will allow you to read the CPK file properly using official Cri extraction tools since it is not encrypted anymore.
DooshDR
Posts: 7
Joined: Wed Nov 10, 2021 5:49 pm

Re: Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Post by DooshDR »

descatal2 wrote:
DooshDR wrote:Hi everyone and thank you so much for your great work. I tried to extract files from .cpk with CriPakGUI and some of them cannot be extracted. For example here: https://m.imgur.com/a/nECg6fC
When you try to extract files from some of the .cpk, you get an error related to “illegal characters”. As you can see on the screenshot, there are a bunch of <NULL> everywhere. I tried with command line and the error is “NullReferenceException”.
None of the extraction tools work with these problematic cpk files.
Thanks

Edit: Here is the cpk: https://mega.nz/file/xYhGRSZT#S_F5VI6oF ... KzvCjoIIxA

Edit2: I managed to extract some files with a HEX editor. First I opened the .cpk with CriPakGUI then I selected the part corresponding to each file (offset + data size) in the HEX editor. Then I decrypted the extracted file. Really tedious! But it's not efficient when there are 1500 files.


Yes, that's the CRIPAKGUI's problem I stated in my post above. Some of the CPK is just not supported by this tool due to ITOC header read error. Since even the CriPakTool cannot read the pointers properly, the code can't progress to the point where it can decrypt anything.

Hence, I don't have any answer to this but to ask anyone who has experience in CPK file extraction to look into this ITOC header problem. For now if you want you can write your own reader or modify the existing code to circumvent the error so that the pointers are correctly read.

Another experimental way is to try and file the file's starting pointer inside the CPK itself. It is quite recognizable since it is just a bunch of gibberish bytes. Once you found that, just copy everything from that point on until the file end, and paste it into a new binary file.
Then, decrypt the extracted byte arrays using the BMS script.
Once that is done, replace the byte you just copied inside the CPK with the newly decrypted byte arrays.
If everything is correct, the decrypted byte will have a CRILAYLA compression header, and replacing this will allow you to read the CPK file properly using official Cri extraction tools since it is not encrypted anymore.


Thanks. Finally managed to extract them.
I'm looking for the character bios files.
I managed to extract and decrypt every .cpk package. But still, no luck.
With a series of fails and retries, I managed to isolate a file that makes the game crash just when you click on a character bio.
So I unpacked the files from it and decrypted/uncompressed them. Not sure if it is indeed this one but still worth a try. It's unreadable. So maybe someone here can figure out what this is about. The name contains "pt" so maybe it's just "pointers".
Here's the archive.
DooshDR
Posts: 7
Joined: Wed Nov 10, 2021 5:49 pm

Re: Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Post by DooshDR »

Ok, anyone knows how to decypher this? It's the content of one of the files.

 _ R 
±] 
¹] W '13?~17[ '13? v
+.;,~2;=*,13?90;*7=~ 1<1*~13<?**2;,~
R +47~7*-+'?N ?_ U_ R_ T_ N X _ Y 
 U] ~~
6;~2;?:;,~18~*6;~?**2;~
;?3p~;~7-~*6;~.721*~18~*6;~ 07*~or~*6;~?**2;4;*r~T?0:~*6;~3?70~.721*~18~13<?**2;,~p~T~~?(709~21-*~67-~.?,;0*-~?-~?~=672:r~6;~9,;)~+.~?*~*6;~|
+00'~
=6112|~T1,.6?0?9;p~T~~;~7-~?~*?2;0*;:~<75;,~)7*6~?~(;,'~-61,*~8+-;r~<+*~67-~8796*709~-5722-~?,;~T+0:;07?<2;p~T~~7-~31**1~7-~|;2.~*6;~);?5~?0:~=,+-6~*6;~-*,109p|~ 6;0~8?=;:~)7*6~:?09;,r~T6;~)1+2:~,?*6;,~:7;~*6?0~97(;~+.~*6;~8796*p~1);(;,r~6;~6?-~?~3?41,~T-61,*=13709d~6;~7-~70=,;:7<2'~:;0-;~)6;0~7*~=13;-~*1~3?**;,-~18~*6;~6;?,*r~T?0:~870:-~673-;28~+0?<2;~*1~8+22'~+0:;,-*?0:~67-~8;;2709-~81,~67$+,+~+0*72~?8*;,~T*6;~;0:~18~*6;~)?,~?9?70-*~*6;~?3.<;227?0-pT~~7-~?,3-~);,;~-;(;,;2'~704+,;:~70~=13<?*~?9?70-*~67-~?,=6;0;3'~?,+:?r~?0:~T6?:~*1~<;~,;.2?=;:~)7*6~6796s.;,81,3?0=;~?,*787=7?2~273<-p
l~ b-,)s*?9c<;81,;s=2;?,s*;&*s6;,;`L ¶ôó½ßáºåð»ÎÓ¹Úÿ½ßÉ
Gamer101_123
Posts: 5
Joined: Mon Aug 29, 2016 1:09 am

Re: Super Robot Wars 30 (PC) .cpk extracting, decryption & encryption

Post by Gamer101_123 »

Would any kind soul can help me figure out how to convert the status image .bin files into .png files?
I'm in the process of extracting the CPK files and decrypt them, but like always, the end result are usually in .bin or .dat files (from older SRW games).