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

47 lines
1.9 KiB
C

#include "constructor_seam_plan.h"
#include <limits.h>
#include <string.h>
static const uintptr_t site = (uintptr_t)0x141e448adULL;
static const uint8_t original[GW_CONSTRUCTOR_SEAM_PREFIX_SIZE] = {
0x48,0x83,0xc4,0x40,0x5f,0xc3,0xcc,0xcc,
0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc
};
int gw_constructor_seam_plan(const struct GwConstructorSeamPage *page,
const uint8_t *live_prefix, size_t live_size,
uintptr_t relay, struct GwStartupPatch *patch,
uintptr_t *resume)
{
const uintptr_t next = site + 5;
int64_t displacement;
uint32_t encoded;
/* Win32 MEM_COMMIT, PAGE_EXECUTE_READ and MEM_MAPPED. PAGE_EXECUTE_READWRITE
* is deliberately excluded: an already modified image is not admitted. */
if (!page || !live_prefix || !patch || !resume ||
page->base > site || page->region_size < 16 ||
site - page->base > page->region_size - 16 ||
page->allocation_base != (uintptr_t)0x140000000ULL ||
page->state != 0x1000 || page->protect != 0x20 ||
page->type != 0x40000 || live_size < sizeof(original) ||
memcmp(live_prefix, original, sizeof(original)) != 0)
return -1;
if (!relay || relay > INT64_MAX || next > INT64_MAX) return -2;
displacement = (int64_t)relay - (int64_t)next;
if (displacement < INT32_MIN || displacement > INT32_MAX) return -2;
memset(patch, 0, sizeof(*patch));
patch->address = site;
patch->size = 5;
memcpy(patch->before, original, 5);
patch->after[0] = 0xe9;
encoded = (uint32_t)(int32_t)displacement;
patch->after[1] = (uint8_t)encoded;
patch->after[2] = (uint8_t)(encoded >> 8);
patch->after[3] = (uint8_t)(encoded >> 16);
patch->after[4] = (uint8_t)(encoded >> 24);
*resume = next; /* relay replays add rsp,0x40; pop rdi; then jumps to ret */
return 0;
}