883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
233 lines
18 KiB
C
233 lines
18 KiB
C
/* Independent PE/WinSock fixture. Not a Forever engine/client replacement. */
|
|
#include <winsock2.h>
|
|
#include <windows.h>
|
|
#include <shellapi.h>
|
|
#include "wine_wire_abi.h"
|
|
#include "wine_wire_host.h"
|
|
_Static_assert(sizeof(struct gw_wire_call)==640,"Wire POD layout mismatch");
|
|
typedef LONG (WINAPI *Initialize)(const WCHAR*);
|
|
typedef LONG (WINAPI *Dispatch)(struct gw_wire_call*);
|
|
typedef LONG (WINAPI *Shutdown)(void);
|
|
static Dispatch dispatch;
|
|
static Shutdown wire_shutdown;
|
|
static HMODULE dll;
|
|
static SOCKET network=INVALID_SOCKET;
|
|
static int sockets_ready;
|
|
static struct gw_wire_call call;
|
|
static char arguments[8][1024];
|
|
static unsigned char incoming[7],payload[65533],outgoing[65535];
|
|
static unsigned char hotfix_reply[1048576];
|
|
#ifdef GW_TEST_AUTH_HOST
|
|
static Dispatch owned_channel;
|
|
static volatile LONG reader_stop,reader_calls,reader_error;
|
|
static DWORD WINAPI channel_reader(void* unused){
|
|
unsigned int i;(void)unused;
|
|
for(i=0;i<10000&&!reader_stop;++i){
|
|
struct gw_wire_call borrowed={0};LONG status;
|
|
borrowed.abi=GW_WINE_WIRE_ABI;borrowed.size=sizeof(borrowed);borrowed.operation=GW_WIRE_PORT;
|
|
status=owned_channel(&borrowed);
|
|
if(status==(LONG)0xc0000184)break; /* Cancellation owns channel teardown. */
|
|
if(status||borrowed.result||!borrowed.value||borrowed.login||borrowed.transport){InterlockedExchange(&reader_error,1);break;}
|
|
InterlockedIncrement(&reader_calls);
|
|
}
|
|
return 0;
|
|
}
|
|
#endif
|
|
static void cleanup(void){
|
|
if(network!=INVALID_SOCKET)closesocket(network);
|
|
if(dispatch){
|
|
if(call.transport){call.operation=GW_WIRE_TRANSPORT_CLOSE;dispatch(&call);}
|
|
if(call.login){call.operation=GW_WIRE_LOGIN_CLOSE;dispatch(&call);}
|
|
}
|
|
if(wire_shutdown){ULONGLONG began=GetTickCount64();while(wire_shutdown()!=0&&GetTickCount64()-began<4000)Sleep(1);}
|
|
if(dll)FreeLibrary(dll);
|
|
if(sockets_ready)WSACleanup();
|
|
}
|
|
static void fail(void){cleanup();ExitProcess(1);}
|
|
/* Fixed line numbers only: no arguments, packets, credentials or pointers. */
|
|
static void require_at(int okay,unsigned int line){
|
|
if(!okay){
|
|
static const char prefix[]="socket-free transport regression at fixture-line=";
|
|
char reverse[12],digits[12];unsigned int n=0,i;DWORD written;
|
|
do{reverse[n++]=(char)('0'+line%10);line/=10;}while(line&&n<sizeof(reverse));
|
|
for(i=0;i<n;++i)digits[i]=reverse[n-i-1];
|
|
WriteFile(GetStdHandle(STD_ERROR_HANDLE),prefix,sizeof(prefix)-1,&written,0);
|
|
WriteFile(GetStdHandle(STD_ERROR_HANDLE),digits,n,&written,0);
|
|
WriteFile(GetStdHandle(STD_ERROR_HANDLE),"\n",1,&written,0);
|
|
fail();
|
|
}
|
|
}
|
|
#define require(okay) require_at((okay),__LINE__)
|
|
static void operation(unsigned int code){call.operation=code;require(!dispatch(&call));}
|
|
static void text(const char* value){DWORD count=0;unsigned int length=0;while(value[length])++length;require(WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),value,length,&count,0)&&count==length);}
|
|
static void number(unsigned long long value){char reverse[24],buffer[24];unsigned int size=0,i;do{reverse[size++]=(char)('0'+value%10);value/=10;}while(value);for(i=0;i<size;++i)buffer[i]=reverse[size-i-1];buffer[size]=0;text(buffer);}
|
|
static unsigned int port(const char* value){unsigned int n=0,i=0;while(value[i]){require(value[i]>='0'&&value[i]<='9');n=n*10+(unsigned int)(value[i++]-'0');require(n<=65535);}require(i&&n);return n;}
|
|
static unsigned int le32(const unsigned char* p){return (unsigned int)p[0]|((unsigned int)p[1]<<8)|((unsigned int)p[2]<<16)|((unsigned int)p[3]<<24);}
|
|
static int equals(const char* a,const char* b){while(*a&&*a==*b){++a;++b;}return *a==*b;}
|
|
static void read_exact(unsigned char* data,unsigned int size){unsigned int at=0;while(at<size){int n=recv(network,(char*)data+at,(int)(size-at),0);require(n>0);at+=(unsigned int)n;}}
|
|
static void write_all(const unsigned char* data,unsigned int size){unsigned int at=0;while(at<size){int n=send(network,(const char*)data+at,(int)(size-at),0);require(n>0);at+=(unsigned int)n;}}
|
|
static void send_enum(void){
|
|
call.opcode=0x37;call.input=0;call.input_bytes=0;call.output=0;call.capacity=0;
|
|
operation(GW_WIRE_SEND);require(call.result==-3&&call.required==6);
|
|
call.output=outgoing;call.capacity=sizeof(outgoing);operation(GW_WIRE_SEND);require(!call.result&&call.required==6);write_all(outgoing,call.required);
|
|
}
|
|
void fixture_start(void){
|
|
int argc=0,i;LPWSTR* argv=CommandLineToArgvW(GetCommandLineW(),&argc);
|
|
Initialize initialize;WSADATA data;struct sockaddr_in endpoint={0};DWORD timeout=3000;
|
|
unsigned int count,which,budget=0,population;
|
|
require(argv&&argc==8);
|
|
for(i=0;i<8;++i){unsigned int n=0;while(argv[i][n]){require(n<1023&&argv[i][n]>=32&&argv[i][n]<=126);arguments[i][n]=(char)argv[i][n];++n;}arguments[i][n]=0;}
|
|
LocalFree(argv);require(equals(arguments[1],"127.0.0.1"));
|
|
dll=LoadLibraryA(GW_WIRE_DLL);require(dll!=0);
|
|
initialize=(Initialize)GetProcAddress(dll,"gw_wire_initialize");
|
|
dispatch=(Dispatch)GetProcAddress(dll,"gw_wire_dispatch");
|
|
wire_shutdown=(Shutdown)GetProcAddress(dll,"gw_wire_shutdown");require(initialize&&dispatch&&wire_shutdown);
|
|
require(!initialize(GW_WIRE_UNIX));call.abi=GW_WINE_WIRE_ABI;call.size=sizeof(call);
|
|
#ifdef GW_TEST_AUTH_HOST
|
|
{
|
|
struct gw_wire_auth_control* control=(struct gw_wire_auth_control*)GetProcAddress(dll,"gw_wire_auth_data");
|
|
struct gw_native_realm* realms=(struct gw_native_realm*)GetProcAddress(dll,"gw_wire_auth_realms");
|
|
LONG (WINAPI *start)(void)=(LONG (WINAPI *)(void))GetProcAddress(dll,"gw_wire_account_start");
|
|
Dispatch owned_transport=(Dispatch)GetProcAddress(dll,"gw_wire_account_transport");
|
|
ULONGLONG began=GetTickCount64();
|
|
HANDLE reader;
|
|
require(control&&realms&&start&&owned_transport&&control->abi==1&&control->size==sizeof(*control));
|
|
call.operation=GW_WIRE_PORT;require(owned_transport(&call)!=0&&call.result==-1&&!call.value);
|
|
control->auth_port=port(arguments[2]);control->retention_ms=3000;control->selected_index=-1;
|
|
__builtin_memcpy(control->username,arguments[4],sizeof(control->username));
|
|
__builtin_memcpy(control->password_path,arguments[5],sizeof(control->password_path));
|
|
__builtin_memcpy(control->version_hash_path,arguments[6],sizeof(control->version_hash_path));
|
|
__builtin_memcpy(control->addon_path,arguments[7],sizeof(control->addon_path));
|
|
require(!start()&&start()!=0&&wire_shutdown()!=0);
|
|
while(control->state==1&&GetTickCount64()-began<4000)Sleep(5);
|
|
if(control->state==5){
|
|
require(control->selected_index==-1&&!control->transport_prepared&&realms[1].flags==0);
|
|
InterlockedExchange((LONG*)&control->selected_index,1);
|
|
while(control->state==5&&GetTickCount64()-began<4000)Sleep(5);
|
|
}
|
|
require(control->state==2&&control->server_proof_verified==1&&control->transport_prepared==1&&control->realm_count==3&&control->selected_index==(realms[1].flags==0?1:0)&&control->thread!=(LONG)GetCurrentThreadId());
|
|
require(realms[0].type==6&&equals(realms[2].address,"192.0.2.1:8090"));
|
|
call.operation=GW_WIRE_PORT;require(!owned_transport(&call)&&!call.result&&call.value==port(arguments[3])&&!call.login&&!call.transport);
|
|
call.operation=GW_WIRE_AUTHENTICATE;require(owned_transport(&call)!=0&&call.result==-1&&!call.login&&!call.transport);
|
|
call.operation=GW_WIRE_AUTHENTICATED;require(!owned_transport(&call)&&!call.result&&!call.value);
|
|
/* Typed gameplay reaches the registry but remains rejected before a
|
|
* real world session/self-create. Account auth alone grants no mover. */
|
|
call.operation=GW_WIRE_ACTIVE_MOVER;require(!owned_transport(&call)&&call.result==-1&&!call.transport&&!call.required);
|
|
call.operation=GW_WIRE_MOVEMENT;require(!owned_transport(&call)&&call.result==-1&&!call.transport&&!call.required);
|
|
call.operation=GW_WIRE_SAY;require(!owned_transport(&call)&&call.result==-1&&!call.transport&&!call.required);
|
|
call.operation=GW_WIRE_WORLD_REQUEST;require(!owned_transport(&call)&&call.result==-1&&!call.transport&&!call.required);
|
|
call.operation=GW_WIRE_ENTITY_STATE;require(!owned_transport(&call)&&call.result==-1&&!call.transport&&!call.required);
|
|
call.operation=GW_WIRE_MOTION_STATE;require(!owned_transport(&call)&&call.result==-1&&!call.transport&&!call.required);
|
|
call.operation=GW_WIRE_GAMEPLAY;require(!owned_transport(&call)&&call.result==-1&&!call.transport&&!call.required);
|
|
{
|
|
LONG (WINAPI *attach)(void)=(LONG (WINAPI *)(void))GetProcAddress(dll,"gw_wire_account_attach_engine_session");
|
|
LONG (WINAPI *beat)(void)=(LONG (WINAPI *)(void))GetProcAddress(dll,"gw_wire_account_engine_heartbeat");
|
|
require(attach&&beat&&attach()!=0&&beat()!=0); /* M2 alone is NOT world authentication. */
|
|
}
|
|
owned_channel=owned_transport;reader=CreateThread(0,0,channel_reader,0,0,0);require(reader!=0);
|
|
while(!reader_calls&&!reader_error&&GetTickCount64()-began<4000)Sleep(1);
|
|
require(reader_calls>0&&!reader_error);
|
|
InterlockedExchange((LONG*)&control->cancel,1);
|
|
while(control->state==2&&GetTickCount64()-began<4000)Sleep(5);
|
|
require(control->state==4&&!control->error&&!control->username[0]&&!control->password_path[0]);
|
|
InterlockedExchange(&reader_stop,1);require(WaitForSingleObject(reader,1000)==WAIT_OBJECT_0&&!reader_error);CloseHandle(reader);
|
|
call.operation=GW_WIRE_PORT;require(owned_transport(&call)!=0&&call.result==-1&&!call.value);
|
|
call.operation=GW_WIRE_COUNTS;require(!dispatch(&call)&&!call.result&&!call.value&&!call.consumed);
|
|
while(wire_shutdown()!=0&&GetTickCount64()-began<4000)Sleep(1);
|
|
wire_shutdown=0;text("realms=3; genuine Windows-thread account, proof validation, advertised realm and socket-free preparation verified\n");cleanup();ExitProcess(0);
|
|
}
|
|
#endif
|
|
call.auth.abi=GW_NATIVE_ABI;call.auth.auth_port=(unsigned short)port(arguments[2]);call.auth.username=arguments[4];call.auth.password_path=arguments[5];call.auth.version_hash_path=arguments[6];
|
|
operation(GW_WIRE_AUTHENTICATE);require(!call.result&&call.login);
|
|
require(wire_shutdown()!=0); /* Live authenticated handle must prevent unload. */
|
|
operation(GW_WIRE_DISCOVER);require(!call.result);
|
|
operation(GW_WIRE_REALM_COUNT);require(!call.result&&call.value==3);
|
|
call.index=0;operation(GW_WIRE_REALM_AT);require(!call.result&&call.realm.type==6);
|
|
__builtin_memcpy(&population,&call.realm.population,sizeof(population));require(population==0x3f000000);
|
|
call.addon_path=arguments[7];call.build=5875;
|
|
for(which=1;which<=2;++which){call.index=which;operation(GW_WIRE_TRANSPORT_OPEN);require(call.result==-1&&!call.transport);}
|
|
call.index=0;operation(GW_WIRE_TRANSPORT_OPEN);require(!call.result&&call.transport);
|
|
{
|
|
unsigned long long clock=12345;
|
|
call.virtual_address=0x46010046;call.input=(const unsigned char*)&clock;call.input_bytes=8;
|
|
operation(GW_WIRE_AUTH_INITIALIZATION);require(call.result==-1&&!call.required);
|
|
operation(GW_WIRE_CLIENT_INITIALIZATION);require(call.result==-1&&!call.required);
|
|
operation(GW_WIRE_DB_REPLY_MISSING);require(call.result==-1&&!call.required);
|
|
operation(GW_WIRE_HOTFIX_REPLY);require(call.result==-1&&!call.required);
|
|
operation(GW_WIRE_AURA_STATE);require(call.result==-1&&!call.required);
|
|
call.index=10;operation(GW_WIRE_GLUE_FEATURES);require(call.result==-1&&!call.required);
|
|
}
|
|
operation(GW_WIRE_LOGIN_CLOSE);require(!call.result&&!call.login);
|
|
operation(GW_WIRE_PORT);require(!call.result&&call.value==port(arguments[3]));
|
|
endpoint.sin_family=AF_INET;endpoint.sin_addr.s_addr=htonl(INADDR_LOOPBACK);endpoint.sin_port=htons((unsigned short)call.value);
|
|
require(!WSAStartup(MAKEWORD(2,2),&data));sockets_ready=1;
|
|
network=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);require(network!=INVALID_SOCKET);
|
|
require(!setsockopt(network,SOL_SOCKET,SO_RCVTIMEO,(const char*)&timeout,sizeof(timeout)));
|
|
require(!setsockopt(network,SOL_SOCKET,SO_SNDTIMEO,(const char*)&timeout,sizeof(timeout)));
|
|
require(!connect(network,(const struct sockaddr*)&endpoint,sizeof(endpoint)));
|
|
read_exact(incoming,4);count=((unsigned int)incoming[0]<<8)|incoming[1];require(count==6);
|
|
call.opcode=(unsigned int)incoming[2]|((unsigned int)incoming[3]<<8);
|
|
read_exact(incoming,4);call.input=incoming;call.input_bytes=4;operation(GW_WIRE_CHALLENGE);require(!call.result);
|
|
call.output=0;call.capacity=0;operation(GW_WIRE_AUTH_REQUEST);require(call.result==-3&&call.required<=sizeof(outgoing));
|
|
call.output=outgoing;call.capacity=sizeof(outgoing);operation(GW_WIRE_AUTH_REQUEST);require(!call.result);write_all(outgoing,call.required);
|
|
while(++budget<16384){
|
|
int n=recv(network,(char*)incoming,sizeof(incoming),0);unsigned int at=0;require(n>0);
|
|
while(at<(unsigned int)n){
|
|
unsigned int consumed;
|
|
call.input=incoming+at;call.input_bytes=(unsigned int)n-at;operation(GW_WIRE_FEED);require(!call.result);consumed=call.consumed;at+=consumed;
|
|
call.output=payload;call.capacity=sizeof(payload);operation(GW_WIRE_PACKET);
|
|
if(call.result==1){require(consumed>0);continue;}
|
|
require(!call.result);
|
|
if(call.packet.opcode==0x1ee){
|
|
unsigned long long clock=12345;
|
|
operation(GW_WIRE_AUTHENTICATED);require(!call.result&&call.value==1);
|
|
call.virtual_address=0x46010046;call.input=(const unsigned char*)&clock;call.input_bytes=8;call.output=0;call.capacity=0;
|
|
operation(GW_WIRE_AUTH_INITIALIZATION);require(call.result==-3&&call.required>60);
|
|
call.output=outgoing;call.capacity=sizeof(outgoing);operation(GW_WIRE_AUTH_INITIALIZATION);require(!call.result&&outgoing[0]==0&&outgoing[4]==0x80);
|
|
call.index=10;operation(GW_WIRE_GLUE_FEATURES);require(!call.result&&call.required==106);
|
|
call.index=0;operation(GW_WIRE_CLIENT_INITIALIZATION);
|
|
/* AvailableHotfixes has one entry per bounded content page,
|
|
* rather than a permanent single-page206-byte fixture. Parse
|
|
* both native packets independently, including cache timing. */
|
|
require(!call.result&&call.required>=206&&call.required<=sizeof(outgoing)&&le32(outgoing)==2&&le32(outgoing+4)==0x4b0001);
|
|
{
|
|
unsigned int available=le32(outgoing+8),pages=le32(outgoing+16),at,j,previous=0;
|
|
require(pages>=1&&pages<=4096&&available==8+8*pages&&call.required==198+8*pages&&le32(outgoing+12)==0x46010046);
|
|
for(j=0;j<pages;++j){unsigned int push=le32(outgoing+20+8*j);require(push>previous&&le32(outgoing+24+8*j)==1);previous=push;}
|
|
at=12+available;
|
|
require(le32(outgoing+at)==0x4701b6&&le32(outgoing+at+4)==170&&outgoing[at+8]==0&&outgoing[at+9]==0);
|
|
for(j=0;j<8;++j)require(outgoing[at+10+j]==((const unsigned char*)&clock)[j]);
|
|
for(j=at+18;j<call.required;++j)require(outgoing[j]==0);
|
|
}
|
|
{
|
|
unsigned int request[4]={70334,70334,1,0},records;
|
|
request[3]=(unsigned int)outgoing[20]|((unsigned int)outgoing[21]<<8)|((unsigned int)outgoing[22]<<16)|((unsigned int)outgoing[23]<<24);
|
|
call.input=(const unsigned char*)request;call.input_bytes=16;call.output=0;call.capacity=0;
|
|
operation(GW_WIRE_HOTFIX_REPLY);require(call.result==-3&&call.required>24&&call.required<=sizeof(hotfix_reply));
|
|
call.output=hotfix_reply;call.capacity=sizeof(hotfix_reply);
|
|
operation(GW_WIRE_HOTFIX_REPLY);require(!call.result&&call.required>24&&call.required<=sizeof(hotfix_reply));
|
|
records=(unsigned int)hotfix_reply[0]|((unsigned int)hotfix_reply[1]<<8)|((unsigned int)hotfix_reply[2]<<16)|((unsigned int)hotfix_reply[3]<<24);
|
|
require(records>=1&&records<=4096&&hotfix_reply[24]==0x20);
|
|
call.output=outgoing;call.capacity=sizeof(outgoing);
|
|
}
|
|
call.input=(const unsigned char*)&clock;call.input_bytes=8;
|
|
call.index=1;operation(GW_WIRE_CLIENT_INITIALIZATION);require(!call.result&&call.required==22&&outgoing[0]==1&&outgoing[4]==0x63&&outgoing[5]==3&&outgoing[6]==0x47&&outgoing[16]==7);
|
|
{
|
|
const unsigned int query[3]={0xdf2f53cf,7421,12345};
|
|
call.input=(const unsigned char*)query;call.input_bytes=12;
|
|
operation(GW_WIRE_DB_REPLY_MISSING);require(!call.result&&call.required==17&&outgoing[12]==0x60&&outgoing[13]==0);
|
|
}
|
|
send_enum();
|
|
}
|
|
else if(call.packet.opcode==0x3b){
|
|
operation(GW_WIRE_CHARACTER_COUNT);require(!call.result);count=call.value;text("characters=");number(count);text("\n");
|
|
for(which=0;which<count;++which){call.index=which;operation(GW_WIRE_CHARACTER_AT);require(!call.result);number(call.character.guid);text(" ");text(call.character.name);text(" level=");number(call.character.level);text(" race=");number(call.character.race);text(" class=");number(call.character.class_id);text("\n");}
|
|
call.realm_id=70;call.virtual_address=0x46010046;call.super_district=2;call.output=outgoing;call.capacity=sizeof(outgoing);operation(GW_WIRE_ENCODE_ROSTER);require(!call.result&&call.required>=34);
|
|
operation(GW_WIRE_RESTRICTIONS);require(!call.result&&call.required>=4&&outgoing[0]==count);
|
|
text("Windows-owned socket and socket-free SRP world channel verified; no Forever engine adoption.\n");cleanup();ExitProcess(0);
|
|
}
|
|
}
|
|
}
|
|
fail();
|
|
}
|