Created
August 28, 2017 14:47
-
-
Save secrary/d15e06ea3260ba0fcd971503b89851eb 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
#include <Windows.h> | |
#include <algorithm> | |
#include <iostream> | |
#include <ctime> | |
u_char TABLE_[] = { | |
0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, | |
0x20, 0x22, 0x24, 0x26, 0x28, 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, | |
0x40, 0x42, 0x44, 0x46, 0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E, | |
0x60, 0x62, 0x64, 0x66, 0x68, 0x6A, 0x6C, 0x6E, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7A, 0x7C, 0x7E, | |
0x80, 0x82, 0x84, 0x86, 0x88, 0x8A, 0x8C, 0x8E, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9A, 0x9C, 0x9E, | |
0xA0, 0xA2, 0xA4, 0xA6, 0xA8, 0xAA, 0xAC, 0xAE, 0xB0, 0xB2, 0xB4, 0xB6, 0xB8, 0xBA, 0xBC, 0xBE, | |
0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE, 0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE, | |
0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE, 0xF0, 0xF2, 0xF4, 0xF6, 0xF8, 0xFA, 0xFC, 0xFE, | |
0x1B, 0x19, 0x1F, 0x1D, 0x13, 0x11, 0x17, 0x15, 0x0B, 0x09, 0x0F, 0x0D, 0x03, 0x01, 0x07, 0x05, | |
0x3B, 0x39, 0x3F, 0x3D, 0x33, 0x31, 0x37, 0x35, 0x2B, 0x29, 0x2F, 0x2D, 0x23, 0x21, 0x27, 0x25, | |
0x5B, 0x59, 0x5F, 0x5D, 0x53, 0x51, 0x57, 0x55, 0x4B, 0x49, 0x4F, 0x4D, 0x43, 0x41, 0x47, 0x45, | |
0x7B, 0x79, 0x7F, 0x7D, 0x73, 0x71, 0x77, 0x75, 0x6B, 0x69, 0x6F, 0x6D, 0x63, 0x61, 0x67, 0x65, | |
0x9B, 0x99, 0x9F, 0x9D, 0x93, 0x91, 0x97, 0x95, 0x8B, 0x89, 0x8F, 0x8D, 0x83, 0x81, 0x87, 0x85, | |
0xBB, 0xB9, 0xBF, 0xBD, 0xB3, 0xB1, 0xB7, 0xB5, 0xAB, 0xA9, 0xAF, 0xAD, 0xA3, 0xA1, 0xA7, 0xA5, | |
0xDB, 0xD9, 0xDF, 0xDD, 0xD3, 0xD1, 0xD7, 0xD5, 0xCB, 0xC9, 0xCF, 0xCD, 0xC3, 0xC1, 0xC7, 0xC5, | |
0xFB, 0xF9, 0xFF, 0xFD, 0xF3, 0xF1, 0xF7, 0xF5, 0xEB, 0xE9, 0xEF, 0xED, 0xE3, 0xE1, 0xE7, 0xE5, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
}; | |
int main() | |
{ | |
start_: | |
srand(time(0)); | |
u_char key[4]{}; | |
u_char al, cl; | |
do { | |
key[0] = 0x20 + rand() % (0x7F - 0x20); | |
al = key[0]; | |
u_char bl = al; // key[0] | |
cl = bl; // key[0] | |
DWORD ebx = (DWORD)bl << 4; | |
al &= 0xF; | |
DWORD ecx = (DWORD)cl >> 4; | |
cl = ecx & 0xF; | |
} while (al == cl); // e.g "(0x22), 3(0x33), D(0x44), U(0x55), f(0x66), w(0x77) | |
key[1] = (key[0] << 4) | ((key[0] >> 4) & 0xF); // e.g. 0x46 >>> 0x64 | |
key[2] = key[0] + key[1]; | |
key[3] = 0; | |
u_char middle_[17]{}; | |
u_char org_middle_[17]{}; | |
// Generate randomly | |
for (size_t i = 0; i < 17; i++) | |
{ | |
middle_[i] = 0x20 + rand() % (0x7F - 0x20); | |
} | |
std::copy(std::begin(middle_), std::end(middle_), org_middle_); | |
u_char last_[17]{}; | |
// loop_1 | |
__asm { | |
lea esi, middle_; | |
mov ecx, 13; | |
loop_1: | |
lodsd; | |
xor eax, 0x1BADC0DE; | |
bswap eax; | |
not al; | |
rol eax, cl; | |
inc ecx; | |
bswap eax; | |
ror eax, cl; | |
dec ecx; | |
not eax; | |
xor eax, 0x98765432; | |
xchg al, ah; | |
mov [esi - 4], eax; | |
sub esi, 3; | |
loop loop_1; | |
} | |
// loop_2 | |
for (size_t i = 0; i < 16; i++) | |
{ | |
middle_[i] ^= key[2]; | |
} | |
size_t i = 0; | |
BOOL flag = FALSE; | |
for (u_char a = 0; a < 0xFF; a++) | |
{ | |
for (u_char b = 0; b < 0xFF; b++) | |
{ | |
for (u_char c = 0; c < 0xFF; c++) | |
{ | |
for (u_char d = 0; d < 0xFF; d++) | |
{ | |
u_char ah = a ^ b ^ c ^ d; | |
u_char al = a ^ b; | |
al = TABLE_[al]; // xlat | |
al ^= ah; | |
al ^= a; | |
if (al != middle_[i]) | |
continue; | |
last_[i] = a; | |
al = b ^ c; | |
al = TABLE_[al]; | |
al ^= ah; | |
al ^= b; | |
if (al != middle_[i + 0x4]) | |
continue; | |
last_[i + 4] = b; | |
al = c ^ d; | |
al = TABLE_[al]; | |
al ^= ah; | |
al ^= c; | |
if (al != middle_[i + 0x8]) | |
continue; | |
last_[i + 0x8] = c; | |
al = d ^ a; | |
al = TABLE_[al]; | |
al ^= ah; | |
al ^= d; | |
if (al != middle_[i + 0xC]) | |
continue; | |
last_[i + 0xC] = d; | |
i++; | |
a = b = c = d = 0; | |
if (i >= 4) { | |
flag = TRUE; | |
goto NEXT; | |
} | |
} | |
} | |
} | |
} | |
NEXT: | |
if (!flag) { | |
std::cout << "\nCan not generate keyfile\nNext Try..."; | |
goto start_; | |
} | |
HANDLE f = CreateFile(L"\\Path\\to\\keyme.exe\\reginf.k23", GENERIC_WRITE, 0, NULL, | |
CREATE_ALWAYS, 0, NULL); | |
if (!f) { | |
std::cout << "Can not create file...\n"; | |
getchar(); | |
return 1; | |
} | |
u_char buf[] = { key[0], key[1], key[2], key[3] }; | |
for (size_t i = 0; i < 4; i++) | |
{ | |
WriteFile(f, &buf[i], sizeof(u_char), NULL, NULL); | |
} | |
WriteFile(f, org_middle_, 16, NULL, NULL); | |
WriteFile(f, last_, 16, NULL, NULL); | |
CloseHandle(f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment