pl0nk hace 10 meses
commit
f1b7c3805b
  1. 2
      .gitignore
  2. 10
      Makefile
  3. 23
      README.md
  4. 128
      main.c
  5. 176
      xxtea.c
  6. 47
      xxtea.h

2
.gitignore vendido

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
*.o
tjcrypt

10
Makefile

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
CC=gcc
CFLAGS=-I. -llz4
DEPS=xxtea.c
OBJ=xxtea.o main.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
tjcrypt: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS)

23
README.md

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
# TJCRYPT
Decyprt Pocket Incoming lua files tested ver 1.0.5.
## Build
Requirements:
- make `sudo apt install make`
- liblz4-dev `sudo apt install liblz4-dev`
Steps:
- Just run `make` on repo top directory
## Example Usage
Decrypting
```
$ ./tjcrypt d assets/repository/repo.mapping repo.mapping.json
```
Encrypting
```
$ ./tjcrypt e repo.mapping.json assets/repository/repo.mapping
```

128
main.c

@ -0,0 +1,128 @@ @@ -0,0 +1,128 @@
#include <lz4.h>
#include <stdio.h>
#include <stdlib.h>
#include "xxtea.h"
const unsigned char key[16] =
"\xd2\"\x82\x7f\xe9\xd3r\xa5$\x90\x8cm\n\x96\xcb\xa3";
const unsigned char password[16] = "MODDEDBYPL0NK!!!";
const int key_len = 16;
void tj_decrypt(const char *path, const char *out) {
unsigned char tmp = 0, fix_key[16] = {0};
unsigned char *dec = 0, *dst = 0;
xxtea_long ret = 0;
FILE *f = fopen(path, "rb");
fseek(f, 0, SEEK_END);
long size = ftell(f);
fseek(f, 0, SEEK_SET);
char *buffer = malloc(size + 1);
fread(buffer, 1, size, f);
fclose(f);
if (buffer[0] != 't' || buffer[1] != 'j' || buffer[2] != '!') {
fprintf(stderr, "can't decrypt this type of file\n");
goto BAIL_OUT;
}
for (int i = 0; i < 16; i++) {
tmp = key[i % key_len];
fix_key[i] ^= tmp ^ buffer[i + 3];
}
dec = xxtea_decrypt(buffer + 23, size - 23, fix_key, 16, &ret);
if (!ret) goto BAIL_OUT;
unsigned int dstSz = *(unsigned int *)dec;
if (dstSz != *(unsigned int *)(buffer + 19)) goto BAIL_OUT;
dst = malloc(dstSz + 1);
if (!dst) goto BAIL_OUT;
LZ4_decompress_safe(dec + 4, dst, ret - 4, dstSz);
f = fopen(out, "wb");
fwrite(dst, dstSz, 1, f);
fclose(f);
BAIL_OUT:
free(dst);
free(buffer);
return;
}
void tj_encrypt(const char *path, const char *out) {
unsigned char tmp = 0, fix_key[16] = {0};
unsigned char *enc = 0, *dst = 0;
xxtea_long ret = 0;
FILE *f = fopen(path, "rb");
fseek(f, 0, SEEK_END);
long size = ftell(f);
fseek(f, 0, SEEK_SET);
char *buffer = malloc(size + 1);
fread(buffer, 1, size, f);
fclose(f);
dst = malloc(size*2+1);
ret = LZ4_compress_default(buffer, dst + 4, size, size*2);
if (!ret) {
fprintf(stderr, "failed compressing\n");
goto BAIL_OUT;
}
fprintf(stderr, "[ret] %ld %d\n", size*2, ret);
for (int i = 0; i < 16; i++) {
tmp = key[i % key_len];
fix_key[i] ^= tmp ^ password[i];
}
f = fopen(out, "wb");
fwrite("tj!", 3, 1, f);
fwrite(password, 16, 1, f);
fwrite(&size, 4, 1, f);
*(unsigned int*) dst = size;
size = ret;
ret = 0;
enc = xxtea_encrypt(dst, size + 4, fix_key, 16, &ret);
if (!ret) {
fprintf(stderr, "failed encrypting\n");
goto BAIL_OUT;
}
fprintf(stderr, "[ret] %ld %d\n", size, ret);
fwrite(enc, ret, 1, f);
fclose(f);
BAIL_OUT:
free(dst);
free(buffer);
return;
}
int main(int argc, char const *argv[]) {
if (argc < 4) goto HELP;
switch (argv[1][0]) {
case 'e':
/* encrypt */
tj_encrypt(argv[2], argv[3]);
break;
case 'd':
/* decrypt */
tj_decrypt(argv[2], argv[3]);
break;
default:
HELP:
fprintf(stderr, "usage: %s [d|e] in out\n", argv[0]);
break;
}
return 0;
}

176
xxtea.c

@ -0,0 +1,176 @@ @@ -0,0 +1,176 @@
/***********************************************************************
Copyright 2006-2009 Ma Bingyao
Copyright 2013 Gao Chunhui, Liu Tao
These sources is free software. Redistributions of source code must
retain the above copyright notice. Redistributions in binary form
must reproduce the above copyright notice. You can redistribute it
freely. You can use it with any free or commercial software.
These sources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
github: https://github.com/liut/pecl-xxtea
*************************************************************************/
#include "xxtea.h"
#include <memory.h>
#include <stdlib.h>
static void xxtea_long_encrypt(xxtea_long *v, xxtea_long len, xxtea_long *k)
{
xxtea_long n = len - 1;
xxtea_long z = v[n], y = v[0], p, q = 6 + 52 / (n + 1), sum = 0, e;
if (n < 1) {
return;
}
while (0 < q--) {
sum += XXTEA_DELTA;
e = sum >> 2 & 3;
for (p = 0; p < n; p++) {
y = v[p + 1];
z = v[p] += XXTEA_MX;
}
y = v[0];
z = v[n] += XXTEA_MX;
}
}
static void xxtea_long_decrypt(xxtea_long *v, xxtea_long len, xxtea_long *k)
{
xxtea_long n = len - 1;
xxtea_long z = v[n], y = v[0], p, q = 6 + 52 / (n + 1), sum = q * XXTEA_DELTA, e;
if (n < 1) {
return;
}
while (sum != 0) {
e = sum >> 2 & 3;
for (p = n; p > 0; p--) {
z = v[p - 1];
y = v[p] -= XXTEA_MX;
}
z = v[n];
y = v[0] -= XXTEA_MX;
sum -= XXTEA_DELTA;
}
}
static unsigned char *fix_key_length(unsigned char *key, xxtea_long key_len)
{
unsigned char *tmp = (unsigned char *)malloc(16);
memcpy(tmp, key, key_len);
memset(tmp + key_len, '\0', 16 - key_len);
return tmp;
}
static xxtea_long *xxtea_to_long_array(unsigned char *data, xxtea_long len, int include_length, xxtea_long *ret_len) {
xxtea_long i, n, *result;
n = len >> 2;
n = (((len & 3) == 0) ? n : n + 1);
if (include_length) {
result = (xxtea_long *)malloc((n + 1) << 2);
result[n] = len;
*ret_len = n + 1;
} else {
result = (xxtea_long *)malloc(n << 2);
*ret_len = n;
}
memset(result, 0, n << 2);
for (i = 0; i < len; i++) {
result[i >> 2] |= (xxtea_long)data[i] << ((i & 3) << 3);
}
return result;
}
static unsigned char *xxtea_to_byte_array(xxtea_long *data, xxtea_long len, int include_length, xxtea_long *ret_len) {
xxtea_long i, n, m;
unsigned char *result;
n = len << 2;
if (include_length) {
m = data[len - 1];
if ((m < n - 7) || (m > n - 4)) return NULL;
n = m;
}
result = (unsigned char *)malloc(n + 1);
for (i = 0; i < n; i++) {
result[i] = (unsigned char)((data[i >> 2] >> ((i & 3) << 3)) & 0xff);
}
result[n] = '\0';
*ret_len = n;
return result;
}
static unsigned char *do_xxtea_encrypt(unsigned char *data, xxtea_long len, unsigned char *key, xxtea_long *ret_len) {
unsigned char *result;
xxtea_long *v, *k, v_len, k_len;
v = xxtea_to_long_array(data, len, 1, &v_len);
k = xxtea_to_long_array(key, 16, 0, &k_len);
xxtea_long_encrypt(v, v_len, k);
result = xxtea_to_byte_array(v, v_len, 0, ret_len);
free(v);
free(k);
return result;
}
static unsigned char *do_xxtea_decrypt(unsigned char *data, xxtea_long len, unsigned char *key, xxtea_long *ret_len) {
unsigned char *result;
xxtea_long *v, *k, v_len, k_len;
v = xxtea_to_long_array(data, len, 0, &v_len);
k = xxtea_to_long_array(key, 16, 0, &k_len);
xxtea_long_decrypt(v, v_len, k);
result = xxtea_to_byte_array(v, v_len, 1, ret_len);
free(v);
free(k);
return result;
}
unsigned char *xxtea_encrypt(unsigned char *data, xxtea_long data_len, unsigned char *key, xxtea_long key_len, xxtea_long *ret_length)
{
unsigned char *result;
*ret_length = 0;
if (key_len < 16) {
unsigned char *key2 = fix_key_length(key, key_len);
result = do_xxtea_encrypt(data, data_len, key2, ret_length);
free(key2);
}
else
{
result = do_xxtea_encrypt(data, data_len, key, ret_length);
}
return result;
}
unsigned char *xxtea_decrypt(unsigned char *data, xxtea_long data_len, unsigned char *key, xxtea_long key_len, xxtea_long *ret_length)
{
unsigned char *result;
*ret_length = 0;
if (key_len < 16) {
unsigned char *key2 = fix_key_length(key, key_len);
result = do_xxtea_decrypt(data, data_len, key2, ret_length);
free(key2);
}
else
{
result = do_xxtea_decrypt(data, data_len, key, ret_length);
}
return result;
}
/* }}} */

47
xxtea.h

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
/***********************************************************************
Copyright 2006-2009 Ma Bingyao
Copyright 2013 Gao Chunhui, Liu Tao
These sources is free software. Redistributions of source code must
retain the above copyright notice. Redistributions in binary form
must reproduce the above copyright notice. You can redistribute it
freely. You can use it with any free or commercial software.
These sources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
github: https://github.com/liut/pecl-xxtea
*************************************************************************/
#ifndef XXTEA_H
#define XXTEA_H
#include <stddef.h> /* for size_t & NULL declarations */
#if defined(_MSC_VER)
typedef unsigned __int32 xxtea_long;
#else
#if defined(__FreeBSD__) && __FreeBSD__ < 5
/* FreeBSD 4 doesn't have stdint.h file */
#include <inttypes.h>
#else
#include <stdint.h>
#endif
typedef uint32_t xxtea_long;
#endif /* end of if defined(_MSC_VER) */
#define XXTEA_MX (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z)
#define XXTEA_DELTA 0x9e3779b9
unsigned char *xxtea_encrypt(unsigned char *data, xxtea_long data_len, unsigned char *key, xxtea_long key_len, xxtea_long *ret_length);
unsigned char *xxtea_decrypt(unsigned char *data, xxtea_long data_len, unsigned char *key, xxtea_long key_len, xxtea_long *ret_length);
#endif
Cargando…
Cancelar
Guardar