Files
praxisandClaude Fable 5.2 8e02dccb86 In-client stack: transport, session lifecycle and engine bridge
175 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

91 lines
3.4 KiB
C

#include <windows.h>
#include <stdint.h>
#include <string.h>
#include "original_c49_capture.h"
enum { GW_C49_FUNCTION_BYTES = 928, GW_C49_MAX_FRAMES = 128 };
static const uintptr_t function_start = (uintptr_t)0x142252ae0ULL;
static volatile LONG attempted_frames, finished;
extern void gw_bridge_nohelper_log(uint32_t event, uint32_t result,
uint32_t error);
static void capture_finish(uint32_t status, uint32_t detail)
{
if (InterlockedCompareExchange(&finished, 1, 0) == 0)
gw_bridge_nohelper_log(43, status, detail);
}
void gw_c49_capture_on_owned_frame(void *owner, DWORD primary_thread)
{
MEMORY_BASIC_INFORMATION page = {0};
SIZE_T read_count = 0;
uint8_t bytes[GW_C49_FUNCTION_BYTES];
uint64_t hash = UINT64_C(0xcbf29ce484222325);
char path[1024];
DWORD path_bytes, written = 0;
HANDLE file;
LONG frame;
size_t i;
if (!owner || !primary_thread || GetCurrentThreadId() != primary_thread ||
*(void *volatile *)(uintptr_t)0x145e7a098ULL != owner ||
InterlockedCompareExchange(&finished, 1, 1) == 1)
return;
frame = InterlockedIncrement(&attempted_frames);
if (frame > GW_C49_MAX_FRAMES) return;
if (GetModuleHandleW(NULL) != (HMODULE)(uintptr_t)0x140000000ULL ||
function_start + GW_C49_FUNCTION_BYTES > (uintptr_t)0x1484b8000ULL) {
capture_finish(2, 1);
return;
}
if (VirtualQuery((const void *)function_start, &page, sizeof(page)) !=
sizeof(page) || page.State != MEM_COMMIT ||
(page.Protect & (PAGE_GUARD | PAGE_NOACCESS)) ||
function_start < (uintptr_t)page.BaseAddress ||
page.RegionSize < GW_C49_FUNCTION_BYTES ||
function_start - (uintptr_t)page.BaseAddress >
page.RegionSize - GW_C49_FUNCTION_BYTES) {
if (frame == GW_C49_MAX_FRAMES) capture_finish(3, frame);
return;
}
if (!ReadProcessMemory(GetCurrentProcess(), (const void *)function_start,
bytes, sizeof(bytes), &read_count) ||
read_count != sizeof(bytes)) {
SecureZeroMemory(bytes, sizeof(bytes));
capture_finish(4, (uint32_t)read_count);
return;
}
for (i = 0; i < sizeof(bytes); ++i) {
hash ^= bytes[i];
hash *= UINT64_C(0x100000001b3);
}
path_bytes = GetEnvironmentVariableA("GW_NATIVE_STARTUP_LOG", path,
sizeof(path));
if (!path_bytes || path_bytes >= sizeof(path) - sizeof(".c49.bin")) {
SecureZeroMemory(bytes, sizeof(bytes));
capture_finish(5, path_bytes);
return;
}
memcpy(path + path_bytes, ".c49.bin", sizeof(".c49.bin"));
file = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ, NULL,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE) {
SecureZeroMemory(bytes, sizeof(bytes));
capture_finish(6, GetLastError());
return;
}
if (!WriteFile(file, bytes, sizeof(bytes), &written, NULL) ||
written != sizeof(bytes)) {
CloseHandle(file);
DeleteFileA(path);
SecureZeroMemory(bytes, sizeof(bytes));
capture_finish(7, written);
return;
}
CloseHandle(file);
SecureZeroMemory(bytes, sizeof(bytes));
gw_bridge_nohelper_log(44, (uint32_t)hash, (uint32_t)(hash >> 32));
capture_finish(1, (uint32_t)written);
}