301 lines
17 KiB
C
301 lines
17 KiB
C
/* Pinned70334 provider registered by the engine's genuine namespace helper.
|
|
* Fresh provider return tables use original qualified Lua helpers; no manual
|
|
* VM allocation, WinAPI imports, thread creation or synthetic auth state.
|
|
* The debugger supplies public rows once at initialization, then detaches.
|
|
* C-function pointers use in-image tail adapters: the genuine VM checks their
|
|
* image bounds before calling, and that validation remains intact.
|
|
*/
|
|
typedef unsigned int u32;
|
|
typedef unsigned long long u64;
|
|
typedef int (*LuaFunction)(void *);
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include "session.h"
|
|
#include "wine_wire_host.h"
|
|
|
|
#ifdef _WIN32
|
|
/* MSVC-target floating comparisons reference this CRT data marker. This
|
|
* freestanding provider owns it locally; no CRT import or initializer runs. */
|
|
int _fltused=0x9875;
|
|
#endif
|
|
_Static_assert(sizeof(int)==4,"Original numeric helper requires signed32 int");
|
|
struct LuaRow { const char *name; LuaFunction callback; };
|
|
struct Registration {
|
|
u32 abi, size;
|
|
volatile u32 stage, error, namespaces_seen, callbacks_seen;
|
|
u32 windows_thread, original_count, registered_count, reserved;
|
|
u64 lua_state, helper_return;
|
|
};
|
|
__declspec(dllexport) struct Registration gw_registration_data={1,sizeof(struct Registration)};
|
|
__declspec(dllexport) struct LuaRow gw_registration_rows[32];
|
|
__declspec(dllexport) const char gw_registration_name[]="GetTurtleRegistrationState";
|
|
__declspec(dllexport) int gw_registration_get_state(void *L) {
|
|
/* Live code verified: (LuaState*, signed32) -> numeric TValue, ordinary ret.
|
|
* The authentic helper creates/binds this closure on its own call path. */
|
|
void (*push_integer)(void *,int)=(void (*)(void *,int))0x144598b00ULL;
|
|
if(!L || L!=(void *)gw_registration_data.lua_state)return 0;
|
|
++gw_registration_data.callbacks_seen;
|
|
push_integer(L,(int)gw_registration_data.stage);return 1;
|
|
}
|
|
|
|
/* Published by the existing owned-module observer, never from Lua. The owner
|
|
* resolves the already loaded, SHA-qualified GWNativeWire.dll export and writes
|
|
* ready LAST. A missing binding is held; it never enables backend UI waiting.
|
|
* Keep the established56-byte registration prefix and the account ABIs intact.
|
|
*/
|
|
struct RegistrationRealmBinding {
|
|
u32 abi,size;
|
|
volatile u32 ready,error;
|
|
u64 module,snapshot,select;
|
|
};
|
|
_Static_assert(sizeof(struct RegistrationRealmBinding)==40,"Realm binding ABI2 changed");
|
|
__declspec(dllexport) struct RegistrationRealmBinding gw_registration_realm_binding={2,sizeof(struct RegistrationRealmBinding)};
|
|
__declspec(dllexport) const char gw_registration_realm_snapshot_name[]="GetTurtleRealmSnapshot";
|
|
__declspec(dllexport) const char gw_registration_realm_request_name[]="RequestTurtleRealm";
|
|
|
|
enum {REALM_SELECT_HELD=-4001,REALM_BINDING_HELD=-4002,REALM_SNAPSHOT_HELD=-4003,REALM_SNAPSHOT_BUSY=-4004};
|
|
typedef int32_t (*SourceRealmSnapshot)(struct gw_wire_account_ui_state*,struct gw_native_realm*,uint32_t);
|
|
typedef int32_t (*SourceRealmSelect)(uint32_t,uint32_t);
|
|
_Static_assert(offsetof(struct RegistrationRealmBinding,select)==32,"Source realm select pointer offset changed");
|
|
/* Keep the bounded 64-row workspace in owned data, rather than a >4KiB
|
|
* automatic Windows frame requiring an unavailable compiler-runtime import.
|
|
* Never disable stack probing. Reentry is held for the complete capture and
|
|
* Lua-marshalling lifetime, so no nested callback can overwrite these rows.
|
|
* A nonlocal Lua/OOM exit that bypasses C cleanup leaves the guard held until
|
|
* a fresh provider lifetime; it cannot expose a partly marshalled snapshot.
|
|
*/
|
|
#if defined(_WIN32) && defined(_MSC_VER)
|
|
/* Keep the large private workspace out of the small, guarded registration
|
|
* data region. Its address is never an observer write/export interface. */
|
|
#pragma section(".gwrealm",read,write)
|
|
__declspec(allocate(".gwrealm"))
|
|
static struct gw_native_realm realm_snapshot_rows[64];
|
|
#elif defined(_WIN32) && (defined(__GNUC__) || defined(__clang__))
|
|
/* Clang/GNU Windows targets use the same named writable data section. */
|
|
static struct gw_native_realm realm_snapshot_rows[64]
|
|
__attribute__((section(".gwrealm"),aligned(_Alignof(struct gw_native_realm))));
|
|
#else
|
|
static struct gw_native_realm realm_snapshot_rows[64];
|
|
#endif
|
|
static uint32_t realm_snapshot_busy;
|
|
|
|
/* Exact cached original registration callsites qualify these domains. They do
|
|
* not qualify numeric argument reading, native floating pushes or table array
|
|
* keys. Root's Lua adapter constructs an array from the string keys r0..r63.
|
|
* Test hooks model the existing primitives, not a replacement Lua VM ABI.
|
|
*/
|
|
#ifdef GW_REGISTRATION_TEST
|
|
void gw_registration_test_create(void*,int,int);
|
|
void gw_registration_test_integer(void*,int);
|
|
void gw_registration_test_string(void*,const char*,size_t);
|
|
void gw_registration_test_set(void*,int);
|
|
int gw_registration_test_top(void*);
|
|
void* gw_registration_test_slot(void*,int);
|
|
void gw_registration_test_read_gate(void*,void*,const void*);
|
|
#define realm_create gw_registration_test_create
|
|
#define realm_integer gw_registration_test_integer
|
|
#define realm_string gw_registration_test_string
|
|
#define realm_set gw_registration_test_set
|
|
#define realm_top gw_registration_test_top
|
|
#define realm_slot gw_registration_test_slot
|
|
#define realm_read_gate gw_registration_test_read_gate
|
|
#else
|
|
static void realm_create(void*L,int array,int hash){
|
|
((void (*)(void*,int,int))0x144596af0ULL)(L,array,hash);
|
|
}
|
|
static void realm_integer(void*L,int value){
|
|
((void (*)(void*,int))0x144598b00ULL)(L,value);
|
|
}
|
|
static void realm_string(void*L,const char*bytes,size_t length){
|
|
((void (*)(void*,const char*,size_t))0x144598c40ULL)(L,bytes,length);
|
|
}
|
|
static void realm_set(void*L,int index){
|
|
((void (*)(void*,int))0x1445995e0ULL)(L,index);
|
|
}
|
|
static int realm_top(void*L){return ((int(*)(void*))(uintptr_t)0x144597980)(L);}
|
|
static void* realm_slot(void*L,int index){return ((void*(*)(void*,int))(uintptr_t)0x144596160)(L,index);}
|
|
static void realm_read_gate(void*L,void*slot,const void*context){((void(*)(void*,void*,const void*))(uintptr_t)0x144596520)(L,slot,context);}
|
|
#endif
|
|
|
|
static size_t realm_length(const char*text,size_t capacity){
|
|
size_t length=0;while(length<capacity && text[length])++length;return length;
|
|
}
|
|
static void realm_key(void*L,const char*key){realm_string(L,key,realm_length(key,64));}
|
|
static void realm_field_integer(void*L,const char*key,int32_t value){
|
|
realm_key(L,key);realm_integer(L,value);realm_set(L,-3);
|
|
}
|
|
static void realm_field_string(void*L,const char*key,const char*value,size_t length){
|
|
realm_key(L,key);realm_string(L,value,length);realm_set(L,-3);
|
|
}
|
|
static int realm_held(void*L,int32_t result){realm_integer(L,result?result:REALM_SNAPSHOT_HELD);return 1;}
|
|
static int realm_u32_supported(uint32_t value){return value<=0x7fffffffU;}
|
|
|
|
#if defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 4 || GW_SOURCE_ONLY_PROFILE == 5)
|
|
extern int gw_source_login_readiness_value(uint64_t module);
|
|
#endif
|
|
static int realm_snapshot_to_lua(void*L,struct gw_native_realm*rows){
|
|
struct gw_wire_account_ui_state header={0};
|
|
uint32_t i;int32_t result;
|
|
if(gw_registration_realm_binding.abi!=2 || gw_registration_realm_binding.size!=sizeof(struct RegistrationRealmBinding) ||
|
|
gw_registration_realm_binding.ready!=1 || gw_registration_realm_binding.error ||
|
|
!gw_registration_realm_binding.module || !gw_registration_realm_binding.snapshot)
|
|
return realm_held(L,REALM_BINDING_HELD);
|
|
result=((SourceRealmSnapshot)(uintptr_t)gw_registration_realm_binding.snapshot)(&header,rows,64);
|
|
if(result)return realm_held(L,result);
|
|
if(header.abi!=1 || header.size!=sizeof(header) || header.copied_realms>64 ||
|
|
!realm_u32_supported(header.generation) || !realm_u32_supported(header.endpoint_kind) ||
|
|
!realm_u32_supported(header.auth_port))return realm_held(L,REALM_SNAPSHOT_HELD);
|
|
for(i=0;i<header.copied_realms;++i){
|
|
if(realm_length(rows[i].name,sizeof(rows[i].name))==sizeof(rows[i].name) ||
|
|
realm_length(rows[i].address,sizeof(rows[i].address))==sizeof(rows[i].address) ||
|
|
!realm_u32_supported(rows[i].type) || !realm_u32_supported(rows[i].flags) ||
|
|
!realm_u32_supported(rows[i].characters) || !realm_u32_supported(rows[i].category) ||
|
|
!realm_u32_supported(rows[i].wire_id))return realm_held(L,REALM_SNAPSHOT_HELD);
|
|
}
|
|
#if defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3 || GW_SOURCE_ONLY_PROFILE == 4 || GW_SOURCE_ONLY_PROFILE == 5)
|
|
realm_create(L,0,(int)(17+header.copied_realms));
|
|
realm_field_integer(L,"source_login_readiness",gw_source_login_readiness_value(gw_registration_realm_binding.module));
|
|
#else
|
|
realm_create(L,0,(int)(16+header.copied_realms));
|
|
#endif
|
|
#define HEADER_UNSIGNED(name) realm_field_integer(L,#name,(int32_t)header.name)
|
|
#define HEADER_SIGNED(name) realm_field_integer(L,#name,header.name)
|
|
HEADER_UNSIGNED(abi);HEADER_UNSIGNED(size);HEADER_UNSIGNED(generation);HEADER_UNSIGNED(endpoint_kind);
|
|
HEADER_SIGNED(state);HEADER_SIGNED(error);HEADER_SIGNED(auth_result);HEADER_SIGNED(discovery_result);
|
|
HEADER_SIGNED(server_proof_verified);HEADER_SIGNED(realm_count);HEADER_SIGNED(selected_index);
|
|
HEADER_SIGNED(transport_prepared);HEADER_SIGNED(cancel);HEADER_UNSIGNED(auth_port);
|
|
HEADER_UNSIGNED(copied_realms);HEADER_SIGNED(genuine_discovery);
|
|
#if defined(GW_SOURCE_ONLY_PROFILE) && GW_SOURCE_ONLY_PROFILE == 5
|
|
/* Only the bound profile-5 snapshot may authorize a nonstandard auth port. */
|
|
realm_field_integer(L,"source_bound_profile",5);
|
|
realm_field_integer(L,"source_bound_auth_port",header.genuine_discovery==1 ? (int32_t)header.auth_port : 0);
|
|
realm_field_integer(L,"source_bound_generation",header.genuine_discovery==1 ? (int32_t)header.generation : 0);
|
|
#endif
|
|
#undef HEADER_UNSIGNED
|
|
#undef HEADER_SIGNED
|
|
for(i=0;i<header.copied_realms;++i){
|
|
char key[4];size_t n=0;uint32_t bits;
|
|
key[n++]='r';if(i>=10)key[n++]=(char)('0'+i/10);key[n++]=(char)('0'+i%10);
|
|
realm_string(L,key,n);realm_create(L,0,8);
|
|
realm_field_integer(L,"type",(int32_t)rows[i].type);
|
|
realm_field_integer(L,"flags",(int32_t)rows[i].flags);
|
|
realm_field_integer(L,"characters",(int32_t)rows[i].characters);
|
|
realm_field_integer(L,"category",(int32_t)rows[i].category);
|
|
realm_field_integer(L,"wire_id",(int32_t)rows[i].wire_id);
|
|
__builtin_memcpy(&bits,&rows[i].population,sizeof(bits));
|
|
/* This is an exact signed bit representation, not a native Lua float.
|
|
* The owned Lua factory normalizes it to unsigned and decodes IEEE754. */
|
|
realm_field_integer(L,"population_bits",(int32_t)bits);
|
|
realm_field_string(L,"name",rows[i].name,realm_length(rows[i].name,sizeof(rows[i].name)));
|
|
realm_field_string(L,"address",rows[i].address,realm_length(rows[i].address,sizeof(rows[i].address)));
|
|
realm_set(L,-3);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
__declspec(dllexport) int gw_registration_get_realm_snapshot(void*L){
|
|
uint32_t idle=0;int result;
|
|
if(!L || L!=(void*)gw_registration_data.lua_state)return 0;
|
|
++gw_registration_data.callbacks_seen;
|
|
if(!__atomic_compare_exchange_n(&realm_snapshot_busy,&idle,1,0,__ATOMIC_ACQUIRE,__ATOMIC_RELAXED))
|
|
return realm_held(L,REALM_SNAPSHOT_BUSY);
|
|
result=realm_snapshot_to_lua(L,realm_snapshot_rows);
|
|
__atomic_store_n(&realm_snapshot_busy,0,__ATOMIC_RELEASE);
|
|
return result;
|
|
}
|
|
|
|
/* Exact original index and read-metadata primitives are delegated, including
|
|
* their restrictions and error behavior. The opaque context token is the one
|
|
* observed at the original checked-reader callsite; no coercion is performed. */
|
|
static int realm_numeric_u32(void*L,int argument,u32 minimum,u32 maximum,u32*out){
|
|
void*slot=realm_slot(L,argument);
|
|
union {u64 bits;double value;} number;
|
|
u32 result;
|
|
if(!slot)return 0;
|
|
realm_read_gate(L,slot,(const void*)(uintptr_t)0x1447ec640);
|
|
if(((const unsigned char*)slot)[8]!=3)return 0;
|
|
number.bits=*(const u64*)slot;
|
|
if((number.bits&0x7ff0000000000000ULL)==0x7ff0000000000000ULL ||
|
|
number.value<(double)minimum || number.value>(double)maximum)return 0;
|
|
result=(u32)number.value;
|
|
if((double)result!=number.value)return 0;
|
|
*out=result;
|
|
return 1;
|
|
}
|
|
|
|
__declspec(dllexport) int gw_registration_request_realm(void*L){
|
|
if(!L || L!=(void*)gw_registration_data.lua_state)return 0;
|
|
++gw_registration_data.callbacks_seen;
|
|
u32 index,generation;
|
|
int32_t result;
|
|
if(gw_registration_realm_binding.abi!=2 || gw_registration_realm_binding.size!=sizeof(struct RegistrationRealmBinding) ||
|
|
gw_registration_realm_binding.ready!=1 || gw_registration_realm_binding.error ||
|
|
!gw_registration_realm_binding.module || !gw_registration_realm_binding.snapshot ||
|
|
!gw_registration_realm_binding.select)return realm_held(L,REALM_SELECT_HELD);
|
|
if(realm_top(L)!=2 || !realm_numeric_u32(L,1,0,63,&index) ||
|
|
!realm_numeric_u32(L,2,1,0x7fffffff,&generation))return realm_held(L,-4005);
|
|
/* The existing Source backend owns generation/CAS, availability and UI
|
|
* activation admission. A zero return means proposal only, not connected. */
|
|
result=((SourceRealmSelect)(uintptr_t)gw_registration_realm_binding.select)(index,generation);
|
|
realm_integer(L,result);
|
|
return 1;
|
|
}
|
|
|
|
/* Owned account sign-in row. Two Lua string arguments are handed to the
|
|
* host's submit function for this call only (contract of
|
|
* native/ui/account_login_binding.h: borrowed bytes and lengths, positive
|
|
* attempt or negative code). The binding is published by the owned-module
|
|
* observer like the realm binding; a missing binding is held. */
|
|
struct RegistrationSignInBinding {
|
|
u32 abi,size;
|
|
volatile u32 ready,error;
|
|
u64 module,submit,context;
|
|
};
|
|
_Static_assert(sizeof(struct RegistrationSignInBinding)==40,"Sign-in binding ABI1 changed");
|
|
__declspec(dllexport) struct RegistrationSignInBinding gw_registration_signin_binding={1,sizeof(struct RegistrationSignInBinding)};
|
|
__declspec(dllexport) const char gw_registration_signin_name[]="SignInTurtleAccount";
|
|
typedef int (*SourceAccountSubmit)(void*,const char*,size_t,const char*,size_t);
|
|
enum {SIGNIN_BINDING_HELD=-4001,SIGNIN_ARGUMENTS_HELD=-4002};
|
|
#ifdef GW_REGISTRATION_TEST
|
|
const char* gw_registration_test_text(void*,int,size_t*);
|
|
#define realm_text gw_registration_test_text
|
|
#else
|
|
/* Original string text primitive (lua_tolstring): slot by 0x144596160, then
|
|
* the same checked read gate 0x144596520 with context 0x1447ec640 as the
|
|
* numeric reader, then TString length (+0x18) and data (+0x20). The stock
|
|
* Login handler reads the account name with exactly this call (0x14242e17f);
|
|
* SelectGameAccount likewise (0x14242f348). REA receipt:
|
|
* claude-lane/exports/string-reader-rea-20261119/receipt.json. */
|
|
static const char* realm_text(void*L,int index,size_t*length){
|
|
return ((const char*(*)(void*,int,size_t*))(uintptr_t)0x14459aee0)(L,index,length);
|
|
}
|
|
#endif
|
|
static int realm_string_argument(void*L,int argument,size_t minimum,size_t maximum,const char**out,size_t*length){
|
|
void*slot=realm_slot(L,argument);size_t n=0;const char*text;
|
|
if(!slot)return 0;
|
|
/* Tag 4 only. Through the original primitive a number would be converted
|
|
* to a string (allocation and a possible collector step inside our
|
|
* callback); the stock handlers accept that, this row does not. */
|
|
if(((const unsigned char*)slot)[8]!=4)return 0;
|
|
text=realm_text(L,argument,&n);
|
|
if(!text || n<minimum || n>maximum)return 0;
|
|
for(size_t i=0;i<n;++i)if(!text[i])return 0;
|
|
*out=text;*length=n;
|
|
return 1;
|
|
}
|
|
__declspec(dllexport) int gw_registration_sign_in_account(void*L){
|
|
const char*account,*password;size_t account_size,password_size;int result;
|
|
if(!L || L!=(void*)gw_registration_data.lua_state)return 0;
|
|
++gw_registration_data.callbacks_seen;
|
|
if(gw_registration_signin_binding.abi!=1 || gw_registration_signin_binding.size!=sizeof(struct RegistrationSignInBinding) ||
|
|
gw_registration_signin_binding.ready!=1 || gw_registration_signin_binding.error ||
|
|
!gw_registration_signin_binding.module || !gw_registration_signin_binding.submit)return realm_held(L,SIGNIN_BINDING_HELD);
|
|
if(realm_top(L)!=2 || !realm_string_argument(L,1,1,32,&account,&account_size) ||
|
|
!realm_string_argument(L,2,1,64,&password,&password_size))return realm_held(L,SIGNIN_ARGUMENTS_HELD);
|
|
/* The host copies what it needs during this call; nothing is retained here. */
|
|
result=((SourceAccountSubmit)(uintptr_t)gw_registration_signin_binding.submit)(
|
|
(void*)(uintptr_t)gw_registration_signin_binding.context,account,account_size,password,password_size);
|
|
realm_integer(L,result?result:SIGNIN_ARGUMENTS_HELD);
|
|
return 1;
|
|
}
|