Skip to content

Instantly share code, notes, and snippets.

@th0rex
Created February 11, 2018 12:41
Show Gist options
  • Save th0rex/43c0832e3fdb019571b743170afd311c to your computer and use it in GitHub Desktop.
Save th0rex/43c0832e3fdb019571b743170afd311c to your computer and use it in GitHub Desktop.
#include <string.h>
char* some_arr =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
// @0x4012a2
int find_char(char* arr, char to_find) {
int i = 0;
for (; arr[i] != 0; ++i) {
if (arr[i] == to_find) {
return i;
}
}
return -1;
}
// does something to your name
void sub_4012c8(char* name, char* arr) {
char c = 0;
char* name_start = name;
while ((c = *name++)) {
int res = find_char(arr, c);
if (res == -1) { // not found
continue;
}
*name_start++ = (char)res;
}
*name_start = 0; // 0 terminate the string
}
void sub_401273(char* arr, char* tmp_buffer, unsigned name_length) {
char* arr_2 = arr + name_length;
char c = 0;
while ((c = *arr_2++)) {
*tmp_buffer++ = c;
}
for (int i = name_length; i > 0; --i) {
*tmp_buffer++ = *arr++;
}
*tmp_buffer = 0; // zero terminate
}
void sub_4011ff(char* tmp_buffer, unsigned name_length) {
name_length *= 4;
if (name_length > 60) {
name_length = 0x1E;
}
sub_401273(some_arr, tmp_buffer, name_length);
}
void sub_4011c0(char* name, char* result, char* tmp_buffer) {
// i won't spoil everything
// name is the input name
// tmp_buffer the shuffeled buffer
}
// probably checks serial
char sub_401224(char computed, char input, char* tmp_buffer) {
/* computed is the serial compute from your name */
/* input is the serial that you actually input */
char buffer[0x80];
int computed_index = find_char(tmp_buffer, computed);
sub_401273(tmp_buffer, buffer, computed_index);
int input_index = find_char(buffer, input);
return tmp_buffer[input_index];
}
// @0x4010be
void check(void* handle, char* name, char* serial) {
sub_4012c8(name, some_arr);
unsigned name_length = 0;
if ((name_length = strlen(name)) == 0) {
MessageBoxA(handle, "no name entered", /* other params*/);
return;
}
if (strlen(serial) == 0) {
MessageBoxA(handle, "no serial entered", /* other params*/);
return;
}
char tmp_buffer[26 + 26 + 10] = {0};
sub_4011ff(tmp_buffer, name_length); // probably just shuffles the array
char result[0x80] = {0};
sub_4011c0(name, result, tmp_buffer); // figure it out
char* p_result = result;
char* p_serial = serial;
for (int i = name_length; i > 0; --i) {
char r = *p_result;
char n = *p_serial;
char value = sub_401224(r, n, tmp_buffer); // probably checks the serial
if (value == *name++) {
p_result++;
p_serial++;
} else {
MessageBoxA(handle, "wrong serial", /* ... */);
return;
}
}
MessageBoxA(handle, "Serial is OK", /* ... */);
}
void _start() {
char name[0x80] = {0}; // get from window
char serial[0x80] = {0}; // get from window
void* handle = GetModuleHandleA();
// ... variables initialized here and window created
check(handle, name, serial); // @0x4010be
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment