Skip to content

Commit

Permalink
refactor program
Browse files Browse the repository at this point in the history
  • Loading branch information
israpps authored Aug 30, 2024
1 parent 0cdd18b commit 7509c25
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 175 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/repack-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ jobs:
clean_release:
runs-on: ubuntu-latest
steps:
- name: delete previous tag/release
- name: rebuild release body
if: github.ref == 'refs/heads/main'
uses: dev-drprasad/delete-tag-and-release@v0.2.0
uses: marvinpinto/action-automatic-releases@latest
with:
delete_release: true
tag_name: "latest"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "Latest"
title: "Latest development build"

build:
needs: [clean_release]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
**.o
**.obj
**.res
*.depend
*.layout
/build
52 changes: 52 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"files.associations": {
"*.make": "makefile",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ cmake_minimum_required(VERSION 3.10)
# set the project name
project(Sheltered-save-converter)

add_executable(Sheltered-save-converter main.cpp)
add_executable(Sheltered-save-converter
main.cpp
)
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
![GitHub all releases](https://img.shields.io/github/downloads/israpps/Sheltered-save-converter/total?style=for-the-badge)
![License](https://img.shields.io/github/license/israpps/Sheltered-save-converter?style=for-the-badge)

Sheltered-save-converter is an open-source command-line utility written in C++ specifically designed to encrypt/decrypt [Sheltered](https://en.wikipedia.org/wiki/Sheltered_(video_game)) save files
Sheltered-save-converter is an open-source command-line utility written in C++ specifically designed to encrypt/decrypt [Sheltered](https://store.steampowered.com/app/356040/Sheltered) and [Sheltered 2](https://store.steampowered.com/app/1289380/Sheltered_2) save files

## How to use
the usage is simple (and program will remind you if you don't enter enough argumments)
```bash
Sheltered_save_file_converter.exe <SAVE_FILE> <CONVERTED_SAVE_FILE_NAME>
```
> also, a batch file was provided for those that don't like/know how to use command line, just drag and drop your save file into the .BAT file located along the program.

## The "Encryption" of the file
the file is just xor'ed with a 17 bytes vector back and forth
```c
0xAC, 0x73, 0xFE, 0xF2, 0xAA, 0xBA, 0x6D, 0xAB, 0x30, 0x3A, 0x8B, 0xA7, 0xDE, 0x0D, 0x15, 0x21, 0x4A
```
wich of these `17` bytes is used to xor one byte of the file? it's decided purely by it's possition on the file itself, The remainder of the division between the current file offset and the ammount of bytes in the "encryption" vector.
literally just this:
```c
uint8_t enc = vec[i % 17];
```

> [!WARNING]
> the file is using CRLF line returns (windows).
> dont change the file to LF line returns (linux)
> since that halves the ammount of bytes consumed by each newline, resulting in erroneous encryption of the file
### Why you made this?
this tool was created as a workaround to the issues regarding the [original javascrypt file](https://jsfiddle.net/mjnpr2ac/18/) used by the sheltered comunity to do this conversion.
this tool was created as a workaround to the issues regarding the [original javascrypt file](https://jsfiddle.net/mjnpr2ac/18/) used by the sheltered comunity years ago to do this conversion.

As you may know, some sort of JavaScript issue is conflicting on save encryption and download



I'm clearly aware of the existense of superior tools that even have UIs for doing this. however, some people might still like the idea of touching the XML file with their own hands

## what can i use this tool for?
to decrypt your game save file into xml format, allowing you to edit/see the save
Expand All @@ -34,6 +47,10 @@ _Or maybe to fix some mistakes you made:_
- change family surname
- change character name

_Or maybe to use this rudimentary xor'ing to hide information from someone???_

it's up to you

### encrypt save file again

After you're done manipulating your XML save file, you can go ahead and encrypt it again.
Expand Down
Binary file removed __binaries/Debug/Sheltered_save_file_converter.exe
Binary file not shown.
7 changes: 0 additions & 7 deletions __binaries/Debug/drag and drop 2 convert.BAT

This file was deleted.

25 changes: 0 additions & 25 deletions exename.h

This file was deleted.

159 changes: 83 additions & 76 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,107 +12,114 @@
#include <vector>

#include <string>
#include <stdint.h>
#include <sys/stat.h>
#include <stdio.h>
#include <cstring>

#ifndef NO_COLOR
#else
#endif // NO_COLOR
#include "version.h"

#if defined(_WIN32) || defined(WIN32)
#include <windows.h>
#define COLOR(args) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),stoi(#args,0,16)); //pass a hex value between 00 and ff (or integer equivalent)
#define PATHCOMP strcasecmp //windows is case insensitive!
#define COLOR(args) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), std::stoi(#args,0,16)) //pass a hex value between 00 and ff (or integer equivalent)
#else
#define COLOR(args)
#define PATHCOMP strcmp
void COLOR(int arg);
#endif

#include "exename.h"
#include "version.h"
#define DAT 0
#define XML 1
#define INV 99

using namespace std;

unsigned char magic[2] = {0x90, 0x3c};
unsigned char *buffer;
std::string encrypt(unsigned char *buf,int size);
std::string arv_fnames[2];
int sf_is;
bool must_pause;
uint8_t *buffer;
std::string xor_data(uint8_t *buf, int size);
int main(int argc, char* argv[])
{
string exename = EXE_NAME(argv[0]);
COLOR(0f)
std::cout;
COLOR(0x0f);
printf("Sheltered SaveFile Converter - By matias Israelson (AKA:El_isra)\n");
printf("Version [%s] - 32bits \n",AutoVersion::FULLVERSION_STRING);
COLOR(07)
if(argc < 3) {
COLOR(0d)
printf("\tUsage: %s infile outfile\n\n",exename.c_str());
COLOR(07)
cin.ignore();
printf("Version [%s]\n",AutoVersion::FULLVERSION_STRING);
COLOR(0x07);
if (argc < 3) {
COLOR(0x0d);
fprintf(stderr, "Sintax errror.\n\tUsage: %s infile outfile\n",argv[0]);
COLOR(0x07);
return 1;
} else {
arv_fnames[0] = EXE_NAME(argv[1]);
arv_fnames[1] = EXE_NAME(argv[2]);
if ( (argc > 3) && (strcmp(argv[3],"--nopause")==0) )
{
must_pause = false;
} else {
must_pause = true;
}
}

vector<unsigned char> bytes;

ifstream file1(argv[1], ios_base::in | ios_base::binary);

unsigned char ch = file1.get();
COLOR(0e)
if (ch==magic[DAT]) {sf_is = DAT; printf("\tDecrypting save file...\n");}///if file begins with encrypted '<'
else if (ch==magic[XML]) {sf_is = XML; printf("\tEncrypting save file...\n");}///if files begins with '<'
else///if none of the conditions before passed...
{
sf_is = INV;
COLOR(0c)
printf("WARNING! [%s] can't be recognized as encrypted or decrypted save file...\n\tpress any key to continue with conversion anyway (or close window)",arv_fnames[0].c_str());
if (must_pause) cin.ignore();
if (!PATHCOMP(argv[1], argv[2])) {
COLOR(0x0C);
fprintf(stderr, "error: input and output are the same!\n");
COLOR(0x07);
return -1;
}
std::vector<uint8_t> bytes;

std::ifstream file1(argv[1], std::ios_base::in | std::ios_base::binary);
if (!file1.is_open()) {
COLOR(0x0C);
fprintf(stderr, "Could not open %s for input\n", argv[1]);
COLOR(0x07);
return 1;
}
COLOR(07)
COLOR(0x07);
uint8_t ch = file1.get();
while (file1.good())
{
bytes.push_back(ch);
ch = file1.get();
}
size_t n = bytes.size();

unsigned char* buff = bytes.data();


std::ofstream out(argv[2], ios_base::binary);
out << encrypt(buff,n);
uint8_t *buff = bytes.data();
printf("input file size: 0x%02lx\n", n);
std::ofstream out(argv[2], std::ios_base::binary);
if (!out.is_open()) {
COLOR(0x0C);
fprintf(stderr, "Could not open %s for output\n", argv[2]);
COLOR(0x07);
return 1;
}
out << xor_data(buff, n);
out.close();
return 0;
}


if (must_pause){
printf("Process completed, press any key to close program\n");
cin.ignore();
std::string xor_data(uint8_t *buf, int size)
{
int a = 0xAC;
uint8_t encrypters[17] = {
0xAC, 0x73, 0xFE, 0xF2, 0xAA, 0xBA, 0x6D, 0xAB,
0x30, 0x3A, 0x8B, 0xA7, 0xDE, 0x0D, 0x15, 0x21,
0x4A
};
std::string output;
for(int i = 0; i < size; i++)
{
uint8_t oldValue = buf[i];
uint8_t encrypter = encrypters[i % 17];
buf[i] = oldValue ^ encrypter;
output += (uint8_t)buf[i];
}
return sf_is;
return output;
}


std::string encrypt(unsigned char *buf,int size)
{
unsigned char encrypters[17] = {172, 115, 254, 242, 170, 186, 109, 171, 48, 58, 139, 167, 222, 13, 21, 33, 74};
std::string output;
for( int i = 0; i < size; i++)
{
unsigned char oldValue = buf[i];
unsigned char encrypter = encrypters[i % 17];
buf[i] = oldValue ^ encrypter;
output += (char)buf[i];
}
return output;
#if defined(_WIN32) || defined(WIN32)
#else
void COLOR(int arg) {
switch (arg)
{
case 0x0F:
puts("\e[0;97m"); //strong white
break;
case 0x0D:
puts("\e[0;95m"); //strong magenta
break;
case 0x0C:
puts("\e[0;91m"); //strong red
break;

case 0x07:
default:
puts("\e[0m");
break;
}
}
#endif
Loading

0 comments on commit 7509c25

Please sign in to comment.