Files
WoW-Hybrid-gateway/tests/engine_packet_win_fixture.c
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

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

71 lines
4.5 KiB
C

/* Own Windows-process ABI/gate fixture; never calls a real game function. */
#include <windows.h>
typedef unsigned int u32;
typedef unsigned long long u64;
struct Host {u32 abi,size,stage,calls,thread,error;u64 owner,table,poll;u64 methods[129];};
struct Packet {u32 abi,size,ready,ack,proof,bytes,submitted,received,opcode,state,error,reserved;u64 receive;unsigned char data[16384];};
struct History {u32 abi,size,capacity,reserved;u64 total,roster_dispatches,headers[128];};
static unsigned char owner[0x1c0];
static void *queue_owner;
static u32 forwarded;
static struct Packet *loaded_packet;
static u32 submitted,submit_match;
static void submit(void *queue,u32 type,void *unused,void *object,const void *data,u32 bytes){
++submitted;submit_match=queue==&queue_owner && type==0x12 && !unused && object==owner && data==loaded_packet->data && bytes==4;
}
static void poll(void *object){if(object==owner)++forwarded;}
static int receive(void *object,u32 queued,u32 processing,const unsigned char *data,u32 bytes){
return object==owner && queued==11 && processing==22 && data && bytes==4?99:-1;
}
void fixture_start(void){
HMODULE dll=LoadLibraryA(GW_DLL_PATH);
struct Host *h;struct Packet *p;struct History *history;
void (*marker)(void *);void (*packet_poll)(void *);
int (*packet_receive)(void *,u32,u32,const unsigned char *,u32);
unsigned char *stub;DWORD previous;
if(!dll)ExitProcess(1);
h=(struct Host *)GetProcAddress(dll,"gw_poll_host_data");p=(struct Packet *)GetProcAddress(dll,"gw_packet_host_data");
history=(struct History *)GetProcAddress(dll,"gw_packet_header_history");
marker=(void (*)(void *))GetProcAddress(dll,"gw_poll_host_callback");
packet_poll=(void (*)(void *))GetProcAddress(dll,"gw_packet_poll_callback");
packet_receive=(int (*)(void *,u32,u32,const unsigned char *,u32))GetProcAddress(dll,"gw_packet_receive_callback");
if(!h || !p || !history || !marker || !packet_poll || !packet_receive || h->size!=1080 || p->size!=16440 || history->abi!=1 || history->size!=sizeof(*history) || history->capacity!=128)ExitProcess(2);
loaded_packet=p;
h->owner=(u64)owner;h->poll=(u64)poll;p->receive=(u64)receive;
*(u32 *)(owner+0x98)=2;queue_owner=owner;*(void **)(owner+0xa0)=&queue_owner;
marker(owner);
if(h->calls!=1 || forwarded!=1 || h->thread!=GetCurrentThreadId() || h->error)ExitProcess(3);
p->data[0]=0x18;p->data[2]=0x47;p->bytes=4;p->ready=1;
packet_poll(owner); /* Missing proof must prevent the pinned engine call. */
if(p->ack!=1 || p->submitted || p->error!=1 || forwarded!=2)ExitProcess(4);
p->proof=1;p->bytes=16385;p->ready=2;
packet_poll(owner);
if(p->ack!=2 || p->submitted || p->error!=1 || forwarded!=3)ExitProcess(5);
p->bytes=4;p->ready=3;queue_owner=0;
packet_poll(owner);
if(p->ack!=3 || p->submitted || p->error!=2 || forwarded!=4)ExitProcess(6);
/* Test the six-argument call only in this owned fixture address space. */
if(VirtualAlloc((void *)0x141e50000ULL,65536,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE)!=(void *)0x141e50000ULL)ExitProcess(9);
stub=(unsigned char *)0x141e54190ULL;stub[0]=0x48;stub[1]=0xb8;*(u64 *)(stub+2)=(u64)submit;stub[10]=0xff;stub[11]=0xe0;
if(!VirtualProtect((void *)0x141e50000ULL,65536,PAGE_EXECUTE_READ,&previous))ExitProcess(10);
FlushInstructionCache(GetCurrentProcess(),stub,12);
queue_owner=owner;p->ready=4;p->error=0;
packet_poll(owner);
if(p->ack!=4 || p->submitted!=1 || submitted!=1 || !submit_match || forwarded!=5 || p->error)ExitProcess(11);
if(packet_receive(owner,11,22,p->data,4)!=99 || p->received!=1 || p->opcode!=0x470018 || p->state!=2)ExitProcess(7);
*(u32 *)p->data=0x5e0000;
if(packet_receive(owner,11,22,p->data,4)!=99 || !(p->reserved&2))ExitProcess(12);
*(u32 *)p->data=0x5e0003;
if(packet_receive(owner,11,22,p->data,4)!=99 || !(p->reserved&1) || p->received!=3)ExitProcess(13);
*(u32 *)p->data=0x470363;
if(packet_receive(owner,11,22,p->data,4)!=99 || history->total!=4 || history->roster_dispatches!=1 || history->headers[3]!=((u64)4<<32|0x470363))ExitProcess(14);
*(u32 *)p->data=0x123456;
for(u32 i=0;i<128;++i)if(packet_receive(owner,11,22,p->data,4)!=99)ExitProcess(15);
if(history->total!=132 || history->roster_dispatches!=1 || history->headers[3]!=((u64)4<<32|0x123456))ExitProcess(16);
h->thread=0xffffffff;p->ready=5;
packet_poll(owner);
if(h->error!=2 || p->ack!=4 || forwarded!=6)ExitProcess(8);
VirtualFree((void *)0x141e50000ULL,0,MEM_RELEASE);
ExitProcess(0);
}