aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


client/tests/os_version.c (1725B)


      1 #include <assert.h>
      2 #include <stdint.h>
      3 #include <stdio.h>
      4 #include <string.h>
      5 #ifdef _WIN32
      6 #include <windows.h>
      7 #else
      8 #include "linux_platform.h"
      9 #include "guest_memory.h"
     10 #endif
     11 
     12 int main(void)
     13 {
     14 #ifndef _WIN32
     15     assert(guest_map("OS version test memory", 0x50000000u, 0x10000u));
     16     g_fs_base = 0x50001000u;
     17 #endif
     18     uint32_t digest = 2166136261u;
     19     const uint32_t sizes[] = {0, 147, 148, 149, 155, 156, 157};
     20     for (unsigned i = 0; i < 7; ++i) {
     21         unsigned char bytes[208];
     22         memset(bytes, 0xa5, sizeof(bytes));
     23         memcpy(bytes + 4, &sizes[i], 4);
     24 #ifdef _WIN32
     25         SetLastError(777);
     26 #else
     27         memcpy((void *)ADDR(0x50003000u), bytes, sizeof(bytes));
     28         MEM32(g_fs_base + 0x34) = 777;
     29         g_esp = 0x5000ff00u;
     30         MEM32(g_esp + 4) = 0x50003004u;
     31 #endif
     32 
     33 #ifdef _WIN32
     34         int result = GetVersionExA((OSVERSIONINFOA *)(bytes + 4));
     35         uint32_t error = GetLastError();
     36 #else
     37         linux_platform_lookup("KERNEL32.dll", "GetVersionExA")();
     38         int result = g_eax;
     39         uint32_t error = MEM32(g_fs_base + 0x34);
     40         memcpy(bytes, (void *)ADDR(0x50003000u), sizeof(bytes));
     41         assert(g_esp == 0x5000ff08u);
     42 #endif
     43 
     44         assert(result == (sizes[i] == 148 || sizes[i] == 156));
     45         assert(error == (result ? 777 : 122));
     46         assert(bytes[0] == 0xa5 && bytes[3] == 0xa5 && bytes[160] == 0xa5);
     47         digest = (digest ^ result) * 16777619u;
     48         digest = (digest ^ error) * 16777619u;
     49         for (unsigned j = 0; j < sizeof(bytes); ++j) digest = (digest ^ bytes[j]) * 16777619u;
     50     }
     51     assert(digest == 0x4002a101);
     52     printf("OS version: 7 size/layout/error cases, NT compatibility profile, digest %08x\n", digest);
     53     return 0;
     54 }