Compare commits

..

No commits in common. "master" and "2020-5-5" have entirely different histories.

4 changed files with 35 additions and 46 deletions

View File

@ -8,7 +8,8 @@ constexpr int CHUNK = 16384;
constexpr int WINDOW_BITS = 15; constexpr int WINDOW_BITS = 15;
//Returns true if it was able to open the given file for reading //Returns true if it was able to open the given file for reading
bool IsFile(const std::string& filename) { bool IsFile(const std::string& filename)
{
std::ifstream file(filename); std::ifstream file(filename);
const bool ret = file.good(); const bool ret = file.good();
file.close(); file.close();
@ -43,7 +44,8 @@ void Xor_Str(std::string& str, unsigned char key) {
} }
} }
std::string GZipDecompress(const std::string& in) { std::string GZipDecompress(const std::string& in)
{
//Initialize all members of strm to be 0 //Initialize all members of strm to be 0
z_stream strm = {}; z_stream strm = {};
//Output buffer //Output buffer
@ -80,7 +82,8 @@ std::string GZipDecompress(const std::string& in) {
return final_output; return final_output;
} }
std::string GZipCompress(const std::string& in) { std::string GZipCompress(const std::string& in)
{
//Initialize all members of strm to be 0 //Initialize all members of strm to be 0
z_stream strm = {}; z_stream strm = {};
//Output buffer //Output buffer
@ -111,16 +114,10 @@ std::string GZipCompress(const std::string& in) {
return final_output; return final_output;
} }
/** @brief Decrypt GD save files or level data * std::string Decrypt(const std::string& filename) {
* @param in_data encrypted input data * //load file
* @param xor11 whether or not the data should be xored with 11; * std::string ret = FileToStr(filename);
* select true for gamesave or false for level data * //Xor with value 11
* @retval decrypted data **/
std::string Decrypt(const std::string& in_data, bool xor11) {
//Retun value
std::string ret = in_data;
//Xor with value 11 if nescessary
if(xor11)
Xor_Str(ret, 11); Xor_Str(ret, 11);
//replace - with + and _ with / //replace - with + and _ with /
for (auto& i : ret) { for (auto& i : ret) {
@ -137,18 +134,15 @@ std::string Decrypt(const std::string& in_data, bool xor11) {
return ret; return ret;
} }
/** @brief Encrypt GD save files or level data * std::string Encrypt(const std::string& filename) {
* @param in_data decrypted input data * //load file
* @param xor11 whether or not the data should be xored with 11; * std::string data = FileToStr(filename);
* select true for gamesave or false for level data * //Calculate crc32 checksum
* @retval encrypted data **/ uLong crc = crc32(0L, Z_NULL, 0);
std::string Encrypt(const std::string& in_data, bool xor11) { uint32_t crc32_sum = crc32(crc, (Bytef*)data.data(), data.size());
//Calculate crc32 checksum and size uint32_t dataSize = data.size();
const uLong crc = crc32(0L, Z_NULL, 0);
const uint32_t crc32_sum = crc32(crc, (Bytef*)in_data.data(), in_data.size());
const uint32_t dataSize = in_data.size();
//Compress with GZip //Compress with GZip
std::string ret = GZipCompress(in_data); std::string ret = GZipCompress(data);
//Remove first 2 and last 4 chars of string //Remove first 2 and last 4 chars of string
ret = ret.substr(2, ret.size() - 4 - 2); ret = ret.substr(2, ret.size() - 4 - 2);
//Add header, checksum and size //Add header, checksum and size
@ -166,8 +160,7 @@ std::string Encrypt(const std::string& in_data, bool xor11) {
if (i == '/') if (i == '/')
i = '_'; i = '_';
} }
//Xor with value 11 if nescessary //Xor with value 11
if(xor11)
Xor_Str(ret, 11); Xor_Str(ret, 11);
//Return //Return
return ret; return ret;

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2020 r4 Copyright (c) 2020 xypwn
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -20,27 +20,24 @@ const std::string commands = R"(Commands:
3: Encrypt and save to GD folder 3: Encrypt and save to GD folder
0: Quit)"; 0: Quit)";
enum class Command { enum class Command
{
Decrypt, Decrypt,
Encrypt Encrypt
}; };
bool ExecCommand(Command cmd, const std::string& in_filename, const std::string& out_filename) { bool ExecCommand(Command cmd, const std::string& in_filename, const std::string& out_filename)
//Check if input file is valid {
if(!IsFile(in_filename)) if(!IsFile(in_filename))
{ {
std::cerr << "ERROR: Could not open file " << in_filename << " for reading" << std::endl; std::cerr << "ERROR: Could not open file " << in_filename << " for reading" << std::endl;
return false; return false;
} }
//Read file data into a string
std::string data = FileToStr(in_filename);
switch(cmd) switch(cmd)
{ {
case Command::Decrypt: case Command::Decrypt:
std::cout << "Decrypting " << in_filename << "..." << std::endl; std::cout << "Decrypting " << in_filename << "..." << std::endl;
// Attempt to decrypt data and save it in the given output file if(!StrToFile(out_filename, Decrypt(in_filename)))
if(!StrToFile(out_filename, Decrypt(data, true)))
{ {
std::cerr << "ERROR: Could not open file " << out_filename << " for writing" << std::endl; std::cerr << "ERROR: Could not open file " << out_filename << " for writing" << std::endl;
return false; return false;
@ -48,8 +45,7 @@ bool ExecCommand(Command cmd, const std::string& in_filename, const std::string&
break; break;
case Command::Encrypt: case Command::Encrypt:
std::cout << "Encrypting " << in_filename << "..." << std::endl; std::cout << "Encrypting " << in_filename << "..." << std::endl;
// Attempt to encrypt data and save it in the given output file if(!StrToFile(out_filename, Encrypt(in_filename)))
if(!StrToFile(out_filename, Encrypt(data, true)))
{ {
std::cerr << "ERROR: Could not open file " << out_filename << " for writing" << std::endl; std::cerr << "ERROR: Could not open file " << out_filename << " for writing" << std::endl;
return false; return false;

View File

@ -1,18 +1,18 @@
# Geometry Dash Gamesave Cryptor # Geometry Dash Gamesave Cryptor
## Download ## Download
- The latest Windows binary (.exe) can be downloaded [here](https://git.nobrain.org/r4/gd-gamesave-cryptor/releases) - The latest Windows binary (.exe) can be downloaded [here](https://github.com/xypwn/gd-gamesave-cryptor/releases)
## Usage ## Usage
- `Double click` to open `gd_crypt.exe` - `Double click` to open `gd_crypt.exe`
- It will show a cmd window with multiple options each labeled with a number - It will show a cmd window with multiple options each labeled with a number
- Type in one of the numbers and press `Enter` to execute the command - Type in one of the numbers and press `Enter` to execute the command
## Building from source on GNU/Linux ## Building from source on Linux
#### Building for GNU/Linux #### Building for Linux
- If you are using Proton to play GD, do not use Wine for the Windows version. Use this version instead as it automatically uses the correct path for Proton. - If you are using Proton to play GD, do not use Wine for the Windows version. Use this version instead as it automatically uses the correct path for Proton.
- Clone the repository and cd into it - Clone the repository and cd into it
`$ git clone https://git.nobrain.org/r4/gd-gamesave-cryptor.git` `$ git clone https://github.com/xypwn/gd-gamesave-cryptor.git`
`$ cd gd-gamesave-cryptor` `$ cd gd-gamesave-cryptor`
- Build the binary: - Build the binary:
@ -22,10 +22,10 @@
#### Building for Windows #### Building for Windows
- You will need to install your distro's version of `mingw-w64` - You will need to install your distro's version of `mingw-w64`
- `sudo apt install mingw-w64` on Ubuntu - `sudo apt install mingw-w64` on Ubuntu
- Install the AUR package `mingw-w64-gcc` on Arch GNU/Linux - Install the AUR package `mingw-w64-gcc` on Arch Linux
- Clone the repository and cd into it - Clone the repository and cd into it
`$ git clone https://git.nobrain.org/r4/gd-gamesave-cryptor.git` `$ git clone https://github.com/xypwn/gd-gamesave-cryptor.git`
`$ cd gd-gamesave-cryptor` `$ cd gd-gamesave-cryptor`
- Build the Windows binary: - Build the Windows binary: