/* Patched-loader: maps the devirt DLL, patches validate() to return 0 * unconditionally (bypassing the un-runnable VM stubs), then spawns the * license thread via the clean init at base+0x1220. * * Patch at 0x1800012ae (7 bytes, replacing the lea of the VM blob): * 31 c0 xor eax, eax * e9 24 00 00 00 jmp 0x1800012d7 (validate epilogue, past mov eax,r14d) * => validate() always returns 0 (STATUS_SUCCESS). */ #include #include #include #include #include static int map_pe(const char *path, uint8_t **out_base) { FILE *f = fopen(path, "rb"); if (!f) return 0; fseek(f, 0, SEEK_END); long fsz = ftell(f); fseek(f, 0, SEEK_SET); uint8_t *raw = (uint8_t *)malloc(fsz); if (fread(raw, 1, fsz, f) != (size_t)fsz) return 0; fclose(f); IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *)raw; IMAGE_NT_HEADERS *nt = (IMAGE_NT_HEADERS *)(raw + dos->e_lfanew); uint8_t *base = (uint8_t *)VirtualAlloc((LPVOID)(uintptr_t)nt->OptionalHeader.ImageBase, (SIZE_T)nt->OptionalHeader.SizeOfImage, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (!base) { printf("[mm] preferred base taken\n"); return 0; } memcpy(base, raw, nt->OptionalHeader.SizeOfHeaders); IMAGE_SECTION_HEADER *sec = IMAGE_FIRST_SECTION(nt); for (int i = 0; i < nt->FileHeader.NumberOfSections; i++) if (sec[i].SizeOfRawData) memcpy(base + sec[i].VirtualAddress, raw + sec[i].PointerToRawData, sec[i].SizeOfRawData); IMAGE_DATA_DIRECTORY *idd = &nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; IMAGE_IMPORT_DESCRIPTOR *d = (IMAGE_IMPORT_DESCRIPTOR *)(base + idd->VirtualAddress); for (; d->Name; d++) { HMODULE h = LoadLibraryA((char *)(base + d->Name)); if (!h) return 0; uintptr_t *thunk = (uintptr_t *)(base + (d->OriginalFirstThunk ? d->OriginalFirstThunk : d->FirstThunk)); uintptr_t *iat = (uintptr_t *)(base + d->FirstThunk); for (int i = 0; thunk[i]; i++) { FARPROC p = (thunk[i] & 0x8000000000000000ULL) ? GetProcAddress(h, (LPCSTR)(thunk[i] & 0xFFFF)) : GetProcAddress(h, (char *)(base + thunk[i] + 2)); if (!p) return 0; iat[i] = (uintptr_t)p; } } *out_base = base; return 1; } int main(int argc, char **argv) { const char *defkey = "AAAA-BBBB-CCCC-DDDD-EEEE-FFFF-0"; const char *ck = (argc > 1) ? argv[1] : defkey; wchar_t wkey[256]; size_t n = strlen(ck); for (size_t i = 0; i < n; i++) wkey[i] = (wchar_t)ck[i]; wkey[n] = 0; SetEnvironmentVariableW(L"SLINKY_LICENSE", wkey); printf("[host] key=%s (len %zu)\n", ck, n); fflush(stdout); uint8_t *base = NULL; const char *dllpath = getenv("SLINKY_DLL"); if (!dllpath) dllpath = "lib_beta_win_unpacked.devirt.CRACKED.bin"; /* default: cracked file next to this exe */ if (!map_pe(dllpath, &base)) { printf("[host] map failed\n"); return 1; } printf("[mm] mapped %s at 0x%p\n", dllpath, (void *)base); if (getenv("SLINKY_NOPATCH") == NULL) { static const unsigned char p[] = { 0x31, 0xC0, 0xE9, 0x22, 0x00, 0x00, 0x00 }; DWORD old; VirtualProtect(base + 0x12ae, sizeof(p), PAGE_EXECUTE_READWRITE, &old); memcpy(base + 0x12ae, p, sizeof(p)); VirtualProtect(base + 0x12ae, sizeof(p), old, &old); printf("[patch] validate() -> always returns 0 (SUCCESS)\n"); fflush(stdout); } typedef int (*init_t)(void *, unsigned); int r = ((init_t)(base + 0x1220))(base, 1); printf("[host] init -> %d; validation thread spawned; waiting...\n", r); fflush(stdout); for (int i = 0; i < 12; i++) { Sleep(1000); fflush(stdout); } printf("[host] survived 12s - DLL still mapped\n"); fflush(stdout); return 0; }