82 lines
4.7 KiB
C
82 lines
4.7 KiB
C
/* Isolated original-component probe. Compile at a non-game image base and run
|
|
* with reference_capture.py --asset-probe against a COPIED Neutron.exe only.
|
|
* Maps PE sections without running entry points/imports. Executes only proven
|
|
* leaf vector accessors and 43A750 with an already-invalid sound handle.
|
|
* Synthetic vtables use the guarded source targets rebased to the mapped copy;
|
|
* these selected paths use relative calls/fields, never absolute source globals.
|
|
* Does not execute the full loader, controller, physics or original game. */
|
|
#include <windows.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#define TC __attribute__((thiscall))
|
|
typedef struct { float x,y,z,w; } Vec4;
|
|
typedef void *(TC *GetVector)(void *, void *);
|
|
typedef void (TC *SetVector)(void *, Vec4);
|
|
typedef void (TC *Prepare)(void *);
|
|
static unsigned char *mapped;
|
|
static void *at(unsigned va) { return mapped+va-0x400000; }
|
|
static void require(int ok, const char *message) {
|
|
if (!ok) { fprintf(stderr,"FAIL %s\n",message); exit(2); }
|
|
}
|
|
static void map_copy(void) {
|
|
FILE *f=fopen("Neutron.exe","rb"); require(f!=NULL,"copied EXE available");
|
|
fseek(f,0,SEEK_END); long size=ftell(f); rewind(f);
|
|
require(size>0 && size<16000000,"bounded EXE size");
|
|
unsigned char *data=malloc(size); require(data!=NULL,"file allocation");
|
|
require(fread(data,1,size,f)==(size_t)size,"read copied EXE"); fclose(f);
|
|
require(size>64 && *(uint16_t*)data==IMAGE_DOS_SIGNATURE,"DOS header");
|
|
uint32_t nt_offset=*(uint32_t*)(data+0x3c);
|
|
require(nt_offset<(uint32_t)size-sizeof(IMAGE_NT_HEADERS32),"NT header bounds");
|
|
IMAGE_NT_HEADERS32 *nt=(void*)(data+nt_offset);
|
|
require(nt->Signature==IMAGE_NT_SIGNATURE && nt->FileHeader.Machine==IMAGE_FILE_MACHINE_I386
|
|
&& nt->OptionalHeader.ImageBase==0x400000 && nt->OptionalHeader.SizeOfImage<16000000,"expected PE32 layout");
|
|
unsigned char *image=VirtualAlloc(NULL,nt->OptionalHeader.SizeOfImage,
|
|
MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
|
|
require(image!=NULL,"component code map"); mapped=image;
|
|
IMAGE_SECTION_HEADER *sections=IMAGE_FIRST_SECTION(nt);
|
|
require((unsigned char*)(sections+nt->FileHeader.NumberOfSections)<=data+size,"section table bounds");
|
|
for (unsigned i=0;i<nt->FileHeader.NumberOfSections;i++) {
|
|
IMAGE_SECTION_HEADER *s=§ions[i];
|
|
require((uint64_t)s->PointerToRawData+s->SizeOfRawData<=(uint64_t)size
|
|
&& (uint64_t)s->VirtualAddress+s->SizeOfRawData<=nt->OptionalHeader.SizeOfImage,"section bounds");
|
|
memcpy(image+s->VirtualAddress,data+s->PointerToRawData,s->SizeOfRawData);
|
|
}
|
|
free(data);
|
|
}
|
|
int main(void) {
|
|
setbuf(stdout,NULL); map_copy();
|
|
unsigned char complete[0x2100]={0}; unsigned char *object=complete+0xc0;
|
|
uintptr_t complete_table[0x500/4]={0}, interface_table[0x500/4]={0};
|
|
complete_table[0x148/4]=(uintptr_t)at(0x429a00);
|
|
interface_table[0x2c4/4]=(uintptr_t)at(0x471f40);
|
|
*(uintptr_t*)complete=(uintptr_t)complete_table; *(uintptr_t*)object=(uintptr_t)interface_table;
|
|
const unsigned getters[]={0x471290,0x4712e0,0x4713d0};
|
|
const unsigned setters[]={0x471bd0,0x471cc0,0x471f70};
|
|
const unsigned authored[]={0x3c,0x4c,0x7c}, live[]={0x164,0x174,0x1a4};
|
|
for (unsigned i=0;i<3;i++) {
|
|
Vec4 expected={11+i,22+i,33+i,44+i}, result;
|
|
memcpy(object+authored[i],&expected,sizeof(expected));
|
|
memset(object+live[i],0xa5,sizeof(expected));
|
|
((GetVector)at(getters[i]))(object,&result);
|
|
((SetVector)at(setters[i]))(object,result);
|
|
require(memcmp(object+live[i],&expected,sizeof(expected))==0,"authored vector reapplied");
|
|
}
|
|
puts("PASS original leaf accessors reapply authored acceleration/impulse/velocity including fourth component");
|
|
*(int32_t*)(complete+0xa44)=-1; // Avoid external sound-stop branch.
|
|
*(float*)(object+0x608)=345;
|
|
*(int16_t*)(object+0x704)=1; *(int16_t*)(object+0x728)=3;
|
|
*(float*)(object+0x7b4)=.625f;
|
|
unsigned char before[sizeof(complete)]; memcpy(before,complete,sizeof(complete));
|
|
((Prepare)at(0x43a750))(object);
|
|
require(*(float*)(object+0x608)==0,"preparation speed cleared");
|
|
Vec4 *velocity=(void*)(object+0x1a4);
|
|
require(velocity->x==0 && velocity->y==0 && velocity->z==0 && velocity->w==46,"only velocity XYZ cleared");
|
|
memset(before+0xc0+0x608,0,4); memset(before+0xc0+0x1a4,0,12);
|
|
require(memcmp(before,complete,sizeof(complete))==0,"all other sentinel fields preserved");
|
|
puts("PASS original 43A750 clears speed/velocity XYZ; preserves impulse, acceleration, mode, jump and hold sentinels");
|
|
puts("LIMIT isolated original routines with invalid sound handle; no whole-loader/game runtime verification");
|
|
return 0;
|
|
}
|