Created
February 20, 2018 15:39
-
-
Save Francesco149/80758f651e9106db2afa114592760abf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* some methods in love live school idol festival have obfuscated strings. not | |
* sure if this is a thing built into java or if it's some known obfuscator, | |
* but either way this is a small tool to decipher them | |
* | |
* the pseudocode will usually look something like this | |
* | |
* ```c | |
* v6 = "ke|RarsmsnRapeawi"; | |
* v7 = 2; | |
* do | |
* { | |
* v761[0] = ((*v6 - 1) ^ 1) - 1; | |
* v761[1] = ((v6[1] - 1) ^ 2) - 1; | |
* v761[2] = ((v6[2] - 1) ^ 3) - 1; | |
* v761[3] = ((v6[3] - 1) ^ 4) - 1; | |
* v761[4] = ((v6[4] - 1) ^ 5) - 1; | |
* v761[5] = ((v6[5] - 1) ^ 6) - 1; | |
* v761[6] = ((v6[6] - 1) ^ 7) - 1; | |
* v761[7] = ((v6[7] - 1) ^ 8) - 1; | |
* v761[8] = ((v6[8] - 1) ^ 9) - 1; | |
* v761[9] = ((v6[9] - 1) ^ 0xA) - 1; | |
* v761[10] = ((v6[10] - 1) ^ 0xB) - 1; | |
* v761[11] = ((v6[11] - 1) ^ 0xC) - 1; | |
* v761[12] = ((v6[12] - 1) ^ 0xD) - 1; | |
* v761[13] = ((v6[13] - 1) ^ 0xE) - 1; | |
* v761[14] = ((v6[14] - 1) ^ 0xF) - 1; | |
* v761[15] = ((v6[15] - 1) ^ 0x10) - 1; | |
* LOBYTE(v762) = ((v6[16] - 1) ^ 0x11) - 1; | |
* BYTE1(v762) = ((v6[17] - 1) ^ 0x12) - 1; | |
* --v7; | |
* v6 = v761; | |
* } | |
* while ( v7 ); | |
* ``` | |
* | |
* 2 would be the number of rounds here | |
* | |
* # license | |
* this is free and unencumbered software released into the public domain. | |
* refer to the attached UNLICENSE or http://unlicense.org/ | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#define info(fmt, ...) fprintf(stderr, fmt "\n", __VA_ARGS__); | |
#define inf1(msg) info("%s", msg) | |
int main(int argc, char* argv[]) | |
{ | |
size_t n; | |
char* str; | |
size_t rounds = 2; | |
if (argc < 2) | |
{ | |
info("usage: %s encrypted_string nrounds", argv[0]); | |
inf1("encrypted_string: the encrypted string, or - to read from stdin"); | |
inf1("nrounds: number of rounds, defaults to 2. you get this by " | |
"reading the disassembly or by trial and error"); | |
return 1; | |
} | |
if (!strcmp(argv[1], "-")) | |
{ | |
str = (char*)malloc(0x10000); | |
if (!str) { | |
perror("malloc"); | |
return 1; | |
} | |
if (!(n = fread(str, 1, 0xFFFF, stdin)) && !feof(stdin)) | |
{ | |
perror("fread"); | |
return 1; | |
} | |
str[n] = 0; | |
} | |
else { | |
str = argv[1]; | |
} | |
if (argc >= 3) rounds = strtoul(argv[2], 0, 10); | |
for (n = 0; n < rounds; ++n) | |
{ | |
char* p; | |
for (p = str; *p; ++p) { | |
*p = ((*p - 1) ^ (p - str + 1)) - 1; | |
} | |
} | |
puts(str); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment