/* Isolated copied EXE scalar slices. No game entrypoint, ray, body or renderer. Absolute scalar operands are relocated into the private copied image. */ #include #include #include #include #include #define TC __attribute__((thiscall)) static unsigned char*mapped; #define AT(a) (mapped+(a)-0x400000) #define F(a) (*(float*)AT(a)) static unsigned char object[0x1f00],hook[0x600],shape[16]; static uintptr_t shape_table[0x40/4]; static float scale_z;static int scale_calls; static void require(int ok,const char*why){if(!ok){fprintf(stderr,"FAIL %s\n",why);exit(2);}} static void TC scale(void*self,float x,float y,float z){require(self==shape&&x==1&&y==1,"shape scale arguments");scale_z=z;scale_calls++;} static void map_source(void){ FILE*f=fopen("Neutron.exe","rb");require(f!=NULL,"generated EXE copy");fseek(f,0,SEEK_END);long size=ftell(f);rewind(f); require(size==1019904,"EXE size");unsigned char*d=malloc(size);require(d!=NULL,"buffer");require(fread(d,1,size,f)==(size_t)size,"read");fclose(f); require(*(uint16_t*)d==IMAGE_DOS_SIGNATURE,"DOS");uint32_t off=*(uint32_t*)(d+0x3c); require(off<(uint32_t)size-sizeof(IMAGE_NT_HEADERS32),"NT bounds");IMAGE_NT_HEADERS32*nt=(void*)(d+off); require(nt->Signature==IMAGE_NT_SIGNATURE&&nt->FileHeader.Machine==IMAGE_FILE_MACHINE_I386&&nt->OptionalHeader.ImageBase==0x400000&&nt->OptionalHeader.SizeOfImage==0x299000,"PE identity"); unsigned char*m=VirtualAlloc(NULL,0x299000,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);require(m!=NULL,"private source map");mapped=m; IMAGE_SECTION_HEADER*s=IMAGE_FIRST_SECTION(nt);require((unsigned char*)(s+nt->FileHeader.NumberOfSections)<=d+size,"sections"); for(unsigned i=0;iFileHeader.NumberOfSections;i++){ require((uint64_t)s[i].PointerToRawData+s[i].SizeOfRawData<=(uint64_t)size&&(uint64_t)s[i].VirtualAddress+s[i].SizeOfRawData<=0x299000,"section bounds"); memcpy(m+s[i].VirtualAddress,d+s[i].PointerToRawData,s[i].SizeOfRawData); }free(d); shape_table[0x34/4]=(uintptr_t)scale;*(void**)shape=shape_table;*(void**)(hook+0x57c)=shape;*(void**)(object+0xb0c)=hook; } static void relocate(uint32_t start,uint32_t end){ const uint32_t operands[]={0x48d96c,0x48d914,0x4a3e5c,0x4f82b8,0x4f82b4,0x4a3e58,0x4f82c8,0x4a3e88, 0x4f82bc,0x4f82c0,0x4f82c4,0x4a3e80,0x4a2ad0,0x48d400,0x4a3e78,0x49fae4,0x4a3e74,0x4a3e70,0x4a3e6c}; for(uint32_t a=start;a+4<=end;a++){ uint32_t value;memcpy(&value,AT(a),4); for(unsigned i=0;i