View Single Post
  #8  
Old 24-04-2025, 08:29
L33THAK0R's Avatar
L33THAK0R L33THAK0R is offline
Registered User
 
Join Date: Feb 2021
Location: Saudi Arabia
Posts: 406
Thanks: 137
Thanked 117 Times in 70 Posts
L33THAK0R is on a distinguished road
Quote:
Originally Posted by teusma View Post
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.
Attached Files
File Type: zip Solution_Resources.zip (1.13 MB, 6 views)

Last edited by L33THAK0R; 24-04-2025 at 08:34.
Reply With Quote