This software and its source code (if available) are licensed under the Apache-2.0 license (unless otherwise specified) which DOES NOT APPLY to any third-party code (such as zlib for example) and borrowed Assembler code (ripped code from other software executable files).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
/*
2025.09.15 - v1.2
- add support for Ukrainian version
- add "ukr_3_2.txt" for latest Ukrainian version
2024.03.22 - v1.1
- add support for CheMax FC (for consoles)
- updated "eng_19_2.txt" with the latest "eng_20_8.txt"
2024.02.22 - v1.0
- first public release
*/
char *basename(char *s) {
char *r;
if (s) {
for (r = s; *r; r++) {
if ((*r == '/') || (*r == '\\')) {
s = &r[1];
}
}
}
return(s);
}
void newext(char *name, char *ext) {
char *p;
if (name && ext) {
for (; (*name == '.'); name++);
for (p = NULL; *name; name++) {
if (*name == '.') {
p = name;
}
}
strcpy(p ? p : name, ext);
}
}
void dumpdata(char *name, void *data, uint32_t size) {
FILE *f;
if (name) {
f = fopen(name, "wb");
if (f) {
if (data && size) {
fwrite(data, size, 1, f);
}
fclose(f);
}
}
}
uint32_t CheMaxDecrypt(uint8_t *p, uint32_t size, uint32_t type) {
uint8_t key[10];
uint32_t i, k;
i = 0;
/* sanity check */
if (p && size && (type < 3)) {
switch (type) {
case 0:
/* CheMax FC */
memcpy(key, "qs3g#erty0", sizeof(key));
break;
case 1:
/* CheMax old */
memcpy(key, "a@g5eDu(*5", sizeof(key));
break;
case 2:
/* CheMax new */
memcpy(key, "qZ8&5N3eS0", sizeof(key));
break;
}
/* for FC reduce size of data to decrypt */
if (!type) {
k = size - 1;
/* skip tail zero bytes */
while ((k) && (!p[k])) { k--; }
/* find file tail values (if any) */
while ((k) && ((p[k] == ';') || ((p[k] >= '0') && (p[k] <= '9')))) { k--; }
/* must be zero byte */
if ((k) && (!p[k])) {
p[k] = ' ';
k++;
i = 0;
for (; k < size; k++) {
if ((p[k] < '0') || (p[k] > '9')) { break; }
i *= 10;
i += p[k] - '0';
}
/* replace zero bytes with spaces */
for (; k < size; k++) {
p[k] = p[k] ? p[k] : ' ';
}
/* update size to decrypt */
size = i;
}
}
/* decrypt database with key */
for (i = 0; i < size; i++) {
k = i % sizeof(key);
if (!type) {
/* CheMax FC */
p[i] -= key[k];
} else {
/* CheMax */
p[i] += ((p[i] > key[k]) ? 0 : 255) - key[k];
}
}
i = 1;
}
return(i);
}
/* test mask for characters that are used in database texts */
static uint8_t tmsk[32] = {
0x00, 0x64, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
0x04, 0x80, 0x7B, 0x40, 0xEF, 0xB9, 0x38, 0xF1,
0xFF, 0xFF, 0xFF, 0xDF, 0xFF, 0xFF, 0xFF, 0xFF
};
uint32_t CheMaxFindKey(uint8_t *p, uint32_t size) {
uint32_t i, j, key;
uint8_t t[128];
/* invalid key number by default */
key = 100;
/* sanity check */
if (p && (size >= sizeof(t))) {
for (i = 0; i < 3; i++) {
memcpy(t, p, sizeof(t));
CheMaxDecrypt(t, sizeof(t), i);
/* check decrypted buffer */
for (j = 0; j < sizeof(t); j++) {
/* invalid key */
if (!(tmsk[t[j] / 8] & (0x80 >> (t[j] % 8)))) {
break;
}
}
/* key found */
if (j >= sizeof(t)) {
key = i;
break;
}
}
}
return(key);
}
int main(int argc, char *argv[]) {
uint32_t l;
uint8_t *p;
FILE *fl;
char s[260];
printf(
"CheMax Cheats Maximal PC/FC database decrypter v1.2\n"
"(c) CTPAX-X Team 2024,2025\n"
"http://www.CTPAX-X.org/\n\n"
);
if (argc != 2) {
printf("Usage: dechemax <cheats.dat>\n\n");
return(1);
}
fl = fopen(argv[1], "rb");
if (!fl) {
printf("Error: can't open input file.\n\n");
return(2);
}
fseek(fl, 0, SEEK_END);
l = ftell(fl);
p = (uint8_t *) malloc(l);
if (!p) {
fclose(fl);
printf("Error: not enough memory for output file.\n\n");
return(3);
}
fseek(fl, 0, SEEK_SET);
memset(p, 0, l);
fread(p, l, 1, fl);
fclose(fl);
if (!CheMaxDecrypt(p, l, CheMaxFindKey(p, l))) {
free(p);
printf("Error: invalid input file format.\n\n");
return(4);
}
strcpy(s, basename(argv[1]));
printf("%s => ", s);
newext(s, ".txt");
printf("%s\n", s);
dumpdata(s, p, l);
free(p);
printf("\ndone\n\n");
return(0);
}