FileForums

FileForums (https://fileforums.com/index.php)
-   Conversion Tutorials (https://fileforums.com/forumdisplay.php?f=55)
-   -   Help me with encrypted data.pak file (https://fileforums.com/showthread.php?t=106708)

teusma 22-04-2025 17:47

Help me with encrypted data.pak file
 
1 Attachment(s)
I wanted to repack the game Car Jacker Hotwired and Gone but the data.pak file is encrypted - so files like .ogg .wav .dds do not compress efficiently with msc, oggre...

I can extract the files with quickbms but this script cannot reconstruct them back. I wanted someone to help me make a tool that decrypts and encrypts (CLI) this file.

Looking online I found a website (https://habr.com/ru/articles/689354/) where someone explains how to do this but I didn't understand anything:(. If anyone can help me I would really appreciate it. I really want to compress this data.

interesting topic about this file: https://web.archive.org/web/20220309...p=69458#p69458

the AI ​​claude told me that it is possible, using the quickbms script, to create a program in c++ (CLI) that has the function of decrypting and encrypting the data.pak file. but I don't understand anything about programming :(. so please, someone who understands programming do this for me, I beg you. Hahaha it was dramatic. it's serious!!! please!


I will leave the file for analysis:

KaktoR 23-04-2025 08:56

1 Attachment(s)
Use quickbms reimport
Code:

quickbms_4gb_files -w -r "en_gine_pak_CarJacker - Hotwired and Gone.bms" "data.pak" "data.pak_extract"
Edit: Try this. Make backup of game folder somewhere. Copy contents to (backup) game dir and follow instructions (read BAT/TXT file names)

teusma 23-04-2025 19:26

this doesn't help, because I will have to keep the data.pak plus the extracted files.

KaktoR 23-04-2025 22:33

You keep data.pak, but it's empty except for something in the file footer which is required by the script to reimport the files properly so the data.pak file is crc perfect after second reimport.

teusma 24-04-2025 00:52

Are you saying that the data.pak is empty after executing "01_unpack.bat" because if so... I'm running it and it's still not getting empty...

KaktoR 24-04-2025 02:04

  1. Unpack data.pak with "01_unpack.bat"
  2. Compress extracted data ("data.pak_extracted" folder) with your tools
  3. Zero extracted data ("data.pak_extracted" folder) with "03_zeroing_extracted_files.bat"
  4. Reimport zero'd extracted data with "04_reimport_zerod_files.bat"
  5. Compress zero'd data.pak with your compressor (ratio is 1% or less because the data.pak file is empty at this point)
  6. Install the game with your installer (or extract archive files otherwise). After this point the extracted data ("data.pak_extracted" folder) is now like the original files again
  7. Reimport extractred data with "07_reimport_extracted_files.bat"

Look at the data.pak before and after reimport zero'd files.

Original
https://i.imgur.com/zhCl23U.png

Reimported zero'd files
https://i.imgur.com/V77fD0F.png

If you compress the modified data.pak with 7z or any other compressor, ratio is extrem low (compressed data.pak from 91MB to 25KB).

teusma 24-04-2025 02:37

It took me a while but I understood haha, thanks. the only downside is that the quickbms executable is 19.3 MB and compressed 3.79 MB, this will overshadow almost all the gain I will have by decrypting the data.pak. But do what you know...that's life. If someone could create a C++ program from this BMS script, the executable would not exceed 100kb....

L33THAK0R 24-04-2025 08:29

1 Attachment(s)
Quote:

Originally Posted by teusma (Post 507418)
It took me a while but I understood haha, thanks. the only downside is that the quickbms executable is 19.3 MB and compressed 3.79 MB, this will overshadow almost all the gain I will have by decrypting the data.pak. But do what you know...that's life. If someone could create a C++ program from this BMS script, the executable would not exceed 100kb....

I had a read through the article you linked and the concept is a lot simpler than you think. Based off of the authors "java-like pseudocode" I whipped up a couple python scripts that "decrypt" and "encrypt" the data.pak file. What is actually happening is basic obfuscation, for even bytes, the value is divided by 2, for odd bytes, 255 is added, and then the value is divided by 2. Very simple stuff.

Even though I've only ever dabbled in python scripting, writing a C++ application proved to be quite simple, here's the source code:

Code:

#include <fstream>
#include <vector>
#include <cstdint>
#include <iostream>

uint8_t reencrypt_byte(uint8_t d) {
    return (d < 128) ? (d * 2)
                    : static_cast<uint8_t>(2 * d - 255);
}

int main(int argc, char* argv[]) {
    if (argc != 3) {
        std::cerr << "Usage: reenc <infile> <outfile>\n";
        return 1;
    }

    // Read input file
    std::ifstream fin(argv[1], std::ios::binary);
    if (!fin) { perror("Error opening input"); return 1; }
    std::vector<uint8_t> buf((std::istreambuf_iterator<char>(fin)),
                              std::istreambuf_iterator<char>());

    // Transform in place
    for (auto &b : buf) {
        b = reencrypt_byte(b);
    }

    // Write output file
    std::ofstream fout(argv[2], std::ios::binary);
    if (!fout) { perror("Error opening output"); return 1; }
    fout.write(reinterpret_cast<char*>(buf.data()), buf.size());

    return 0;
}

I've saved you the trouble of compiling this, attached in the zip file are both the python scripts as well as the C++ source code and application, as well as a copy of sfk + a batch script for patching all the extracted streams (well 1116/1139 files, but all WAV, OGG were found. 651/663 DDS found.), if you choose to go down that route. Good news is this solution meets your requirements, with just srep+lolz the compiled C++ executable goes from 131KiB to 34.9KiB. Hope this helps, this was a good excuse to keep some technical skills fresh.

teusma 24-04-2025 19:26

Couldn't you (if it's not too much to ask) simply produce a tool that looks like this pak_enc_dec that can be put in a chain like this: -mpak_enc_dec+oggre+srep+msc+lolz.

To be honest, your program I don't understand how it works. and it also has a dependency on dlls - which is not a big problem since when compressed it drops from 1.50mb to 343kb...

Sorry if I'm being noob in any way.

L33THAK0R 25-04-2025 03:09

Quote:

Originally Posted by teusma (Post 507425)
Couldn't you (if it's not too much to ask) simply produce a tool that looks like this pak_enc_dec that can be put in a chain like this: -mpak_enc_dec+oggre+srep+msc+lolz.

To be honest, your program I don't understand how it works. and it also has a dependency on dlls - which is not a big problem since when compressed it drops from 1.50mb to 343kb...

Sorry if I'm being noob in any way.

There shouldn't be a dependency on DLLs for the compiled executable. The usage is also plain to see when you run it from the command line. I'd advise running your own tests but I would think msc+oggre+lolz would be better suited, if you choose to not perform any post-install operations. Given how it would be a single command in a batch script to run the restoration for the data.pak I don't think any further development is warranted.

teusma 08-05-2025 17:02

1 Attachment(s)
forget it, I managed to create myself (with the help of AI) a tool(with only 29kb) that can be used like this: -mpak+oggre+srep+msc+lolz reaching all types
of files inside the data.pak already decrypted. this ambition I had to make this repack was more for sport - because it doesn't save much
space - due to the amount of .ogg and .wav being small, but even so it was a delight to compress after applying the decryption.

I'll leave the tool here for anyone who wants to use it too:


All times are GMT -7. The time now is 14:24.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
FileForums @ https://fileforums.com