Part 3: verdict plumbing (stderr is ground truth), elimination matrix, inert-by-construction proof for Route-1, honest ceiling
This commit is contained in:
1 parent
f5225a7fec
commit
cca4ff16cf
8 files changed
+550
No files matched your search
@@ -0,0 +1,35 @@
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <tlhelp32.h>
|
||||
static int queue_all(DWORD pid, void *func, ULONG_PTR param) {
|
||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
||||
if (snap == INVALID_HANDLE_VALUE) return -1;
|
||||
THREADENTRY32 te; te.dwSize = sizeof te;
|
||||
int queued = 0;
|
||||
if (Thread32First(snap, &te)) {
|
||||
do {
|
||||
if (te.th32OwnerProcessID != pid) continue;
|
||||
HANDLE th = OpenThread(THREAD_SET_CONTEXT, FALSE, te.th32ThreadID);
|
||||
if (!th) continue;
|
||||
if (QueueUserAPC((PAPCFUNC)func, th, param)) queued++;
|
||||
CloseHandle(th);
|
||||
} while (Thread32Next(snap, &te));
|
||||
}
|
||||
CloseHandle(snap);
|
||||
return queued;
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
DWORD pid = (DWORD)atoi(argv[1]);
|
||||
ULONG_PTR target = (ULONG_PTR)strtoull(argv[2], NULL, 0);
|
||||
const char *key = argv[3];
|
||||
HANDLE pr = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, FALSE, pid);
|
||||
if (!pr) { printf("OpenProcess fail\n"); return 1; }
|
||||
wchar_t wkey[64];
|
||||
int kl = MultiByteToWideChar(CP_ACP, 0, key, -1, wkey, 64);
|
||||
void *kmem = VirtualAllocEx(pr, NULL, (SIZE_T)kl * 2, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
if (!kmem || !WriteProcessMemory(pr, kmem, wkey, (SIZE_T)kl * 2, NULL)) { printf("key fail\n"); return 1; }
|
||||
int n = queue_all(pid, (void *)target, (ULONG_PTR)kmem);
|
||||
printf("%d APCs to %p\n", n, (void *)target);
|
||||
CloseHandle(pr);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/* apc_injector: queue LoadLibraryW(dll) as a user APC on existing threads of
|
||||
* the target. No remote thread, no loader DLL in the target.
|
||||
* usage: apc_injector.exe <pid> <dll path (ascii)>
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) { printf("usage: apc_injector pid dllpath\n"); return 1; }
|
||||
DWORD pid = (DWORD)atoi(argv[1]);
|
||||
|
||||
wchar_t wpath[512];
|
||||
int wl = MultiByteToWideChar(CP_ACP, 0, argv[2], -1, wpath, 512);
|
||||
if (!wl) { printf("path conv fail\n"); return 1; }
|
||||
|
||||
HANDLE pr = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, FALSE, pid);
|
||||
if (!pr) { printf("OpenProcess fail GLE=%lu\n", GetLastError()); return 1; }
|
||||
|
||||
SIZE_T sz = (SIZE_T)wl * sizeof(wchar_t);
|
||||
void *mem = VirtualAllocEx(pr, NULL, sz, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
if (!mem) { printf("VirtualAllocEx fail GLE=%lu\n", GetLastError()); return 1; }
|
||||
if (!WriteProcessMemory(pr, mem, wpath, sz, NULL)) { printf("WPM fail GLE=%lu\n", GetLastError()); return 1; }
|
||||
|
||||
HMODULE k32 = GetModuleHandleW(L"kernel32.dll");
|
||||
void *lla = (void *)GetProcAddress(k32, "LoadLibraryW");
|
||||
|
||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
||||
if (snap == INVALID_HANDLE_VALUE) { printf("snap fail\n"); return 1; }
|
||||
|
||||
THREADENTRY32 te; te.dwSize = sizeof te;
|
||||
int queued = 0, failed = 0;
|
||||
if (Thread32First(snap, &te)) {
|
||||
do {
|
||||
if (te.th32OwnerProcessID != pid) continue;
|
||||
HANDLE th = OpenThread(THREAD_SET_CONTEXT, FALSE, te.th32ThreadID);
|
||||
if (!th) { failed++; continue; }
|
||||
if (QueueUserAPC((PAPCFUNC)lla, th, (ULONG_PTR)mem)) queued++;
|
||||
else failed++;
|
||||
CloseHandle(th);
|
||||
} while (Thread32Next(snap, &te));
|
||||
}
|
||||
CloseHandle(snap);
|
||||
CloseHandle(pr);
|
||||
printf("APC queued to %d threads (%d failed); mem=%p\n", queued, failed, mem);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/* apc_injector2: two modes.
|
||||
* mode "dll": queue LoadLibraryW(path) APCs (env-driven start)
|
||||
* mode "init": LoadLibraryW via one APC, then queue
|
||||
* slinky_init(keyw) APCs on all threads (loader-style start)
|
||||
* usage: apc_injector2.exe dll <pid> <dll path>
|
||||
* apc_injector2.exe init <pid> <dll path> <32-char key>
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
static int queue_all(DWORD pid, void *func, ULONG_PTR param) {
|
||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
||||
if (snap == INVALID_HANDLE_VALUE) { printf("snap fail\n"); return -1; }
|
||||
THREADENTRY32 te; te.dwSize = sizeof te;
|
||||
int queued = 0;
|
||||
if (Thread32First(snap, &te)) {
|
||||
do {
|
||||
if (te.th32OwnerProcessID != pid) continue;
|
||||
HANDLE th = OpenThread(THREAD_SET_CONTEXT, FALSE, te.th32ThreadID);
|
||||
if (!th) continue;
|
||||
if (QueueUserAPC((PAPCFUNC)func, th, param)) queued++;
|
||||
CloseHandle(th);
|
||||
} while (Thread32Next(snap, &te));
|
||||
}
|
||||
CloseHandle(snap);
|
||||
return queued;
|
||||
}
|
||||
|
||||
static HMODULE find_remote_module(DWORD pid, const char *name) {
|
||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
|
||||
if (snap == INVALID_HANDLE_VALUE) return NULL;
|
||||
MODULEENTRY32W me; me.dwSize = sizeof me;
|
||||
HMODULE base = NULL;
|
||||
wchar_t wname[128]; MultiByteToWideChar(CP_ACP, 0, name, -1, wname, 128);
|
||||
if (Module32FirstW(snap, &me)) {
|
||||
do {
|
||||
if (_wcsicmp(me.szModule, wname) == 0) { base = me.hModule; break; }
|
||||
} while (Module32NextW(snap, &me));
|
||||
}
|
||||
CloseHandle(snap);
|
||||
return base;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 4) { printf("usage: apc2 dll|init pid path [key]\n"); return 1; }
|
||||
const char *mode = argv[1];
|
||||
DWORD pid = (DWORD)atoi(argv[2]);
|
||||
|
||||
HANDLE pr = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, FALSE, pid);
|
||||
if (!pr) { printf("OpenProcess fail GLE=%lu\n", GetLastError()); return 1; }
|
||||
|
||||
if (strcmp(mode, "dll") == 0) {
|
||||
wchar_t wpath[512];
|
||||
int wl = MultiByteToWideChar(CP_ACP, 0, argv[3], -1, wpath, 512);
|
||||
void *mem = VirtualAllocEx(pr, NULL, (SIZE_T)wl * 2, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
if (!mem || !WriteProcessMemory(pr, mem, wpath, (SIZE_T)wl * 2, NULL)) { printf("write fail\n"); return 1; }
|
||||
FARPROC llw = GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "LoadLibraryW");
|
||||
int n = queue_all(pid, (void *)llw, (ULONG_PTR)mem);
|
||||
printf("dll mode: %d APCs\n", n);
|
||||
} else {
|
||||
/* init mode: step 1 load, step 2 call export */
|
||||
wchar_t wpath[512];
|
||||
int wl = MultiByteToWideChar(CP_ACP, 0, argv[3], -1, wpath, 512);
|
||||
void *mem = VirtualAllocEx(pr, NULL, (SIZE_T)wl * 2, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
if (!mem || !WriteProcessMemory(pr, mem, wpath, (SIZE_T)wl * 2, NULL)) { printf("write fail\n"); return 1; }
|
||||
FARPROC llw = GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "LoadLibraryW");
|
||||
int n = queue_all(pid, (void *)llw, (ULONG_PTR)mem);
|
||||
printf("init mode: %d load APCs queued, waiting for module...\n", n);
|
||||
HMODULE base = NULL;
|
||||
for (int i = 0; i < 40 && !base; i++) {
|
||||
Sleep(500);
|
||||
base = find_remote_module(pid, "lib_beta_win.dll");
|
||||
}
|
||||
if (!base) { printf("client never mapped (no alertable thread?)\n"); return 1; }
|
||||
printf("client base = %p\n", (void *)base);
|
||||
void *slinky_init = (void *)((ULONG_PTR)base + 0x1000); /* export RVA */
|
||||
|
||||
const char *key = argv[4];
|
||||
wchar_t wkey[64];
|
||||
int kl = MultiByteToWideChar(CP_ACP, 0, key, -1, wkey, 64);
|
||||
void *kmem = VirtualAllocEx(pr, NULL, (SIZE_T)kl * 2, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
if (!kmem || !WriteProcessMemory(pr, kmem, wkey, (SIZE_T)kl * 2, NULL)) { printf("key write fail\n"); return 1; }
|
||||
int n2 = queue_all(pid, slinky_init, (ULONG_PTR)kmem);
|
||||
printf("init mode: %d slinky_init APCs queued (key=%s)\n", n2, key);
|
||||
}
|
||||
CloseHandle(pr);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/* keytest2: like slinky_key_test but JVM options come from a file
|
||||
* (one option per line, %TEMP%\opencode\jvm_opts.txt), so we can
|
||||
* reproduce Minecraft's exact JVM environment and bisect.
|
||||
* usage: keytest2.exe <32-char key>
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
typedef jint (JNICALL *CreateVM_t)(JavaVM **, void **, void *);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *key = (argc > 1) ? argv[1] : "E984C65498462E0BB9877136F4368535";
|
||||
size_t n = strlen(key);
|
||||
if (n != 32) { printf("[k2] key must be 32 chars\n"); return 1; }
|
||||
wchar_t wkey[64]; for (size_t i = 0; i <= n; i++) wkey[i] = (wchar_t)(unsigned char)key[i];
|
||||
SetEnvironmentVariableW(L"SLINKY_LICENSE", wkey);
|
||||
printf("[k2] key=%s\n", key); fflush(stdout);
|
||||
|
||||
/* load MC's jvm.dll (same VM the game uses) */
|
||||
HMODULE jvm = LoadLibraryW(L"C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.502.7-hotspot\\jre\\bin\\server\\jvm.dll");
|
||||
if (!jvm) { printf("[k2] no jvm.dll\n"); return 1; }
|
||||
CreateVM_t cjv = (CreateVM_t)GetProcAddress(jvm, "JNI_CreateJavaVM");
|
||||
|
||||
/* read options file */
|
||||
JavaVMOption opts[128]; int nopt = 0;
|
||||
static char lines[128][1024];
|
||||
FILE *f = fopen("C:\\Users\\nicot\\AppData\\Local\\Temp\\opencode\\jvm_opts.txt", "r");
|
||||
if (f) {
|
||||
char buf[1024];
|
||||
while (nopt < 128 && fgets(buf, sizeof buf, f)) {
|
||||
size_t L = strlen(buf);
|
||||
while (L && (buf[L-1] == '\n' || buf[L-1] == '\r')) buf[--L] = 0;
|
||||
if (!L) continue;
|
||||
strcpy(lines[nopt], buf);
|
||||
opts[nopt].optionString = lines[nopt];
|
||||
nopt++;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
printf("[k2] %d JVM options\n", nopt); fflush(stdout);
|
||||
|
||||
JavaVMInitArgs va; memset(&va, 0, sizeof va);
|
||||
va.version = JNI_VERSION_1_8; va.ignoreUnrecognized = JNI_TRUE;
|
||||
va.nOptions = nopt; va.options = opts;
|
||||
JavaVM *vm = NULL; void *env = NULL;
|
||||
jint cr = cjv ? cjv(&vm, &env, &va) : -1;
|
||||
printf("[k2] JNI_CreateJavaVM -> %d\n", cr); fflush(stdout);
|
||||
if (cr != 0) return 1;
|
||||
|
||||
/* keep self-unload blocked so we survive a failed validate */
|
||||
HMODULE k32 = GetModuleHandleW(L"kernel32.dll");
|
||||
unsigned char *fle = (unsigned char *)GetProcAddress(k32, "FreeLibraryAndExitThread");
|
||||
unsigned char *et = (unsigned char *)GetProcAddress(k32, "ExitThread");
|
||||
unsigned char stub[7] = { 0x8B, 0xCA, 0xE9, 0, 0, 0, 0 };
|
||||
intptr_t rel = (intptr_t)et - (intptr_t)(fle + 7);
|
||||
memcpy(stub + 3, &rel, 4);
|
||||
DWORD old;
|
||||
VirtualProtect(fle, 7, PAGE_EXECUTE_READWRITE, &old);
|
||||
memcpy(fle, stub, 7);
|
||||
VirtualProtect(fle, 7, old, &old);
|
||||
|
||||
HMODULE h = LoadLibraryW(L"C:\\Users\\nicot\\Downloads\\lib_beta_win_unpacked.devirt.bin~\\lib_beta_win.dll");
|
||||
printf("[k2] client -> %p\n", (void *)h); fflush(stdout);
|
||||
if (!h) return 1;
|
||||
typedef int (WINAPI *init_t)(const wchar_t *);
|
||||
init_t init = (init_t)GetProcAddress(h, "slinky_init");
|
||||
if (!init) return 1;
|
||||
int r = init(wkey);
|
||||
printf("[k2] slinky_init -> %d %s\n", r, r == 0 ? "<== VALID" : "<== rejected");
|
||||
fflush(stdout);
|
||||
Sleep(3000);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* keytest3: JVM + LoadLibrary(client) then a TRACER WINDOW (client mapped,
|
||||
* guard unconsumed), then explicit slinky_init. For MemoryAccessMonitor use.
|
||||
* usage: keytest3.exe <32-char key>
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
typedef jint (JNICALL *CreateVM_t)(JavaVM **, void **, void *);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *key = (argc > 1) ? argv[1] : "E984C65498462E0BB9877136F4368535";
|
||||
size_t n = strlen(key);
|
||||
if (n != 32) { printf("[k3] key must be 32 chars\n"); return 1; }
|
||||
wchar_t wkey[64]; for (size_t i = 0; i <= n; i++) wkey[i] = (wchar_t)(unsigned char)key[i];
|
||||
SetEnvironmentVariableW(L"SLINKY_LICENSE", wkey);
|
||||
printf("[k3] key=%s\n", key); fflush(stdout);
|
||||
|
||||
HMODULE jvm = LoadLibraryW(L"C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.502.7-hotspot\\jre\\bin\\server\\jvm.dll");
|
||||
if (jvm) {
|
||||
CreateVM_t cjv = (CreateVM_t)GetProcAddress(jvm, "JNI_CreateJavaVM");
|
||||
JavaVM *vm = NULL; void *env = NULL;
|
||||
JavaVMInitArgs va; memset(&va, 0, sizeof va);
|
||||
va.version = JNI_VERSION_1_8; va.ignoreUnrecognized = JNI_TRUE;
|
||||
printf("[k3] JNI_CreateJavaVM -> %d\n", cjv ? cjv(&vm, &env, &va) : -1); fflush(stdout);
|
||||
}
|
||||
|
||||
HMODULE k32 = GetModuleHandleW(L"kernel32.dll");
|
||||
unsigned char *fle = (unsigned char *)GetProcAddress(k32, "FreeLibraryAndExitThread");
|
||||
unsigned char *et = (unsigned char *)GetProcAddress(k32, "ExitThread");
|
||||
unsigned char stub[7] = { 0x8B, 0xCA, 0xE9, 0, 0, 0, 0 };
|
||||
intptr_t rel = (intptr_t)et - (intptr_t)(fle + 7);
|
||||
memcpy(stub + 3, &rel, 4);
|
||||
DWORD old;
|
||||
VirtualProtect(fle, 7, PAGE_EXECUTE_READWRITE, &old);
|
||||
memcpy(fle, stub, 7);
|
||||
VirtualProtect(fle, 7, old, &old);
|
||||
|
||||
HMODULE h = LoadLibraryW(L"C:\\Users\\nicot\\Downloads\\lib_beta_win_unpacked.devirt.bin~\\lib_beta_win.dll");
|
||||
printf("[k3] client -> %p\n", (void *)h); fflush(stdout);
|
||||
printf("[k3] TRACER WINDOW open (60s)...\n"); fflush(stdout);
|
||||
Sleep(60000);
|
||||
printf("[k3] calling slinky_init...\n"); fflush(stdout);
|
||||
typedef int (WINAPI *init_t)(const wchar_t *);
|
||||
init_t init = (init_t)GetProcAddress(h, "slinky_init");
|
||||
int r = init ? init(wkey) : -1;
|
||||
printf("[k3] slinky_init -> %d %s\n", r, r == 0 ? "<== VALID" : "<== rejected");
|
||||
fflush(stdout);
|
||||
Sleep(15000);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/* keytest4: keytest3 + N dummy threads before slinky_init.
|
||||
* usage: keytest4.exe <32-char key> <thread-count>
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
typedef jint (JNICALL *CreateVM_t)(JavaVM **, void **, void *);
|
||||
|
||||
static DWORD WINAPI dummy(LPVOID p) { Sleep(INFINITE); return 0; }
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *key = (argc > 1) ? argv[1] : "E984C65498462E0BB9877136F4368535";
|
||||
int nthr = (argc > 2) ? atoi(argv[2]) : 0;
|
||||
size_t n = strlen(key);
|
||||
if (n != 32) { printf("[k4] key must be 32 chars\n"); return 1; }
|
||||
wchar_t wkey[64]; for (size_t i = 0; i <= n; i++) wkey[i] = (wchar_t)(unsigned char)key[i];
|
||||
SetEnvironmentVariableW(L"SLINKY_LICENSE", wkey);
|
||||
printf("[k4] key=%s threads=%d\n", key, nthr); fflush(stdout);
|
||||
|
||||
for (int i = 0; i < nthr; i++) {
|
||||
HANDLE h = CreateThread(NULL, 0, dummy, NULL, 0, NULL);
|
||||
if (h) CloseHandle(h);
|
||||
}
|
||||
printf("[k4] %d dummy threads spawned\n", nthr); fflush(stdout);
|
||||
|
||||
HMODULE jvm = LoadLibraryW(L"C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.502.7-hotspot\\jre\\bin\\server\\jvm.dll");
|
||||
if (jvm) {
|
||||
CreateVM_t cjv = (CreateVM_t)GetProcAddress(jvm, "JNI_CreateJavaVM");
|
||||
JavaVM *vm = NULL; void *env = NULL;
|
||||
JavaVMInitArgs va; memset(&va, 0, sizeof va);
|
||||
va.version = JNI_VERSION_1_8; va.ignoreUnrecognized = JNI_TRUE;
|
||||
printf("[k4] JNI_CreateJavaVM -> %d\n", cjv ? cjv(&vm, &env, &va) : -1); fflush(stdout);
|
||||
}
|
||||
|
||||
HMODULE k32 = GetModuleHandleW(L"kernel32.dll");
|
||||
unsigned char *fle = (unsigned char *)GetProcAddress(k32, "FreeLibraryAndExitThread");
|
||||
unsigned char *et = (unsigned char *)GetProcAddress(k32, "ExitThread");
|
||||
unsigned char stub[7] = { 0x8B, 0xCA, 0xE9, 0, 0, 0, 0 };
|
||||
intptr_t rel = (intptr_t)et - (intptr_t)(fle + 7);
|
||||
memcpy(stub + 3, &rel, 4);
|
||||
DWORD old;
|
||||
VirtualProtect(fle, 7, PAGE_EXECUTE_READWRITE, &old);
|
||||
memcpy(fle, stub, 7);
|
||||
VirtualProtect(fle, 7, old, &old);
|
||||
|
||||
HMODULE h = LoadLibraryW(L"C:\\Users\\nicot\\Downloads\\lib_beta_win_unpacked.devirt.bin~\\lib_beta_win.dll");
|
||||
printf("[k4] client -> %p\n", (void *)h); fflush(stdout);
|
||||
typedef int (WINAPI *init_t)(const wchar_t *);
|
||||
init_t init = (init_t)GetProcAddress(h, "slinky_init");
|
||||
int r = init ? init(wkey) : -1;
|
||||
printf("[k4] slinky_init -> %d %s\n", r, r == 0 ? "<== VALID" : "<== rejected");
|
||||
fflush(stdout);
|
||||
Sleep(3000);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/* keytest6: JVM + RUN a Java main (SleepMain2), then load client + validate.
|
||||
* Discriminates "JVM that has executed application code" from virgin JVM.
|
||||
* usage: keytest6.exe <32-char key>
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
typedef jint (JNICALL *CreateVM_t)(JavaVM **, void **, void *);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const char *key = (argc > 1) ? argv[1] : "E984C65498462E0BB9877136F4368535";
|
||||
size_t n = strlen(key);
|
||||
if (n != 32) { printf("[k6] key must be 32 chars\n"); return 1; }
|
||||
wchar_t wkey[64]; for (size_t i = 0; i <= n; i++) wkey[i] = (wchar_t)(unsigned char)key[i];
|
||||
SetEnvironmentVariableW(L"SLINKY_LICENSE", wkey);
|
||||
printf("[k6] key=%s\n", key); fflush(stdout);
|
||||
|
||||
HMODULE jvm = LoadLibraryW(L"C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.502.7-hotspot\\jre\\bin\\server\\jvm.dll");
|
||||
if (!jvm) { printf("[k6] no jvm.dll\n"); return 1; }
|
||||
CreateVM_t cjv = (CreateVM_t)GetProcAddress(jvm, "JNI_CreateJavaVM");
|
||||
|
||||
static char cp[1024];
|
||||
strcpy(cp, "-Djava.class.path=C:\\Users\\nicot\\AppData\\Local\\Temp\\opencode\\sleepmain");
|
||||
JavaVMOption opts[2]; opts[0].optionString = cp;
|
||||
JavaVMInitArgs va; memset(&va, 0, sizeof va);
|
||||
va.version = JNI_VERSION_1_8; va.ignoreUnrecognized = JNI_TRUE;
|
||||
va.nOptions = 1; va.options = opts;
|
||||
JavaVM *vm = NULL; JNIEnv *env = NULL;
|
||||
jint cr = cjv(&vm, (void **)&env, &va);
|
||||
printf("[k6] JNI_CreateJavaVM -> %d\n", cr); fflush(stdout);
|
||||
if (cr != 0) return 1;
|
||||
|
||||
/* RUN real Java application code: SleepMain2.main() */
|
||||
jclass cls = (*env)->FindClass(env, "SleepMain2");
|
||||
if (!cls) { printf("[k6] FindClass(SleepMain2) FAILED\n"); if ((*env)->ExceptionCheck(env)) (*env)->ExceptionDescribe(env); return 1; }
|
||||
jmethodID mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V");
|
||||
if (!mid) { printf("[k6] GetStaticMethodID(main) FAILED\n"); return 1; }
|
||||
jclass scls = (*env)->FindClass(env, "java/lang/String");
|
||||
jobjectArray jargs = (*env)->NewObjectArray(env, 1, scls, (*env)->NewStringUTF(env, "run"));
|
||||
printf("[k6] invoking SleepMain2.main ...\n"); fflush(stdout);
|
||||
(*env)->CallStaticVoidMethod(env, cls, mid, jargs);
|
||||
if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); return 1; }
|
||||
printf("[k6] main() completed - JVM has now run application code\n"); fflush(stdout);
|
||||
|
||||
/* keep self-unload blocked */
|
||||
HMODULE k32 = GetModuleHandleW(L"kernel32.dll");
|
||||
unsigned char *fle = (unsigned char *)GetProcAddress(k32, "FreeLibraryAndExitThread");
|
||||
unsigned char *et = (unsigned char *)GetProcAddress(k32, "ExitThread");
|
||||
unsigned char stub[7] = { 0x8B, 0xCA, 0xE9, 0, 0, 0, 0 };
|
||||
intptr_t rel = (intptr_t)et - (intptr_t)(fle + 7);
|
||||
memcpy(stub + 3, &rel, 4);
|
||||
DWORD old;
|
||||
VirtualProtect(fle, 7, PAGE_EXECUTE_READWRITE, &old);
|
||||
memcpy(fle, stub, 7);
|
||||
VirtualProtect(fle, 7, old, &old);
|
||||
|
||||
HMODULE h = LoadLibraryW(L"C:\\Users\\nicot\\Downloads\\lib_beta_win_unpacked.devirt.bin~\\lib_beta_win.dll");
|
||||
printf("[k6] client -> %p\n", (void *)h); fflush(stdout);
|
||||
if (!h) return 1;
|
||||
typedef int (WINAPI *init_t)(const wchar_t *);
|
||||
init_t init = (init_t)GetProcAddress(h, "slinky_init");
|
||||
int r = init ? init(wkey) : -1;
|
||||
printf("[k6] slinky_init -> %d %s\n", r, r == 0 ? "<== VALID" : "<== rejected");
|
||||
fflush(stdout);
|
||||
Sleep(3000);
|
||||
if (vm) (*vm)->DestroyJavaVM(vm);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user