port: ProcessCRC verbatim (module introspection adapted) + XTrap mapped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6d2d262de8
commit
80c5a1e39f
@@ -1,23 +1,87 @@
|
||||
// Platform skeleton for UserInterface/ProcessCRC.h (40250 UserInterface/ProcessCRC.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 UserInterface/ProcessCRC.cpp, verbatim except the Win32 process introspection (see PORT below).
|
||||
// GetExeCRC is declared in ProcessCRC.h but only __GetExeCRC is defined in 40250.
|
||||
#include "UserInterface/StdAfx.h"
|
||||
#include "UserInterface/ProcessCRC.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
static BYTE abCRCMagicCube[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
static BYTE abCRCXorTable[8] = { 102, 30, 188, 44, 39, 201, 43, 5 };
|
||||
static BYTE bMagicCubeIdx = 0;
|
||||
|
||||
auto GetExeCRC(DWORD &, DWORD &) -> bool
|
||||
const char * stristr(const char * big, const char * little)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
const char * t = big;
|
||||
size_t len = strlen(little) - 1;
|
||||
|
||||
for (t = big; *t; ++t)
|
||||
if (!_strnicmp(t, little, len))
|
||||
return t;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
auto BuildProcessCRC() -> void
|
||||
// PORT: 40250 walks a Toolhelp32 module snapshot for the module whose path contains the executable name and
|
||||
// returns its path and load address. The platform has no module snapshot, so the executable is never found:
|
||||
// the path in which 40250 gives up the same way (then ProcCRC = 0).
|
||||
bool GetProcessInformation(std::string & exeFileName, LPCVOID * ppvAddress)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return false;
|
||||
}
|
||||
|
||||
auto GetProcessCRCMagicCubePiece() -> BYTE
|
||||
// PORT: 40250 ReadProcessMemory's the first 1 MB of the module image and CRCs it (a partial copy counts).
|
||||
// Unreachable here (GetProcessInformation never finds the module); returns 0 as 40250 does on a failed read.
|
||||
DWORD GetProcessMemoryCRC(LPCVOID c_pvBaseAddress)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<BYTE>();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool __GetExeCRC(DWORD & r_dwProcCRC, DWORD & r_dwFileCRC)
|
||||
{
|
||||
std::string exeFileName;
|
||||
LPCVOID c_pvBaseAddress;
|
||||
|
||||
GetExcutedFileName(exeFileName);
|
||||
|
||||
if (GetProcessInformation(exeFileName, &c_pvBaseAddress))
|
||||
r_dwProcCRC = GetProcessMemoryCRC(c_pvBaseAddress);
|
||||
else
|
||||
r_dwProcCRC = 0;
|
||||
|
||||
r_dwFileCRC = GetFileCRC32(exeFileName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void BuildProcessCRC()
|
||||
{
|
||||
if (LocaleService_IsHONGKONG() || LocaleService_IsTAIWAN())
|
||||
{
|
||||
memset(abCRCMagicCube, 0, sizeof(abCRCMagicCube));
|
||||
bMagicCubeIdx = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD dwProcCRC, dwFileCRC;
|
||||
|
||||
if (__GetExeCRC(dwProcCRC, dwFileCRC))
|
||||
{
|
||||
abCRCMagicCube[0] = BYTE(dwProcCRC & 0x000000ff);
|
||||
abCRCMagicCube[1] = BYTE(dwFileCRC & 0x000000ff);
|
||||
abCRCMagicCube[2] = BYTE( (dwProcCRC & 0x0000ff00) >> 8 );
|
||||
abCRCMagicCube[3] = BYTE( (dwFileCRC & 0x0000ff00) >> 8 );
|
||||
abCRCMagicCube[4] = BYTE( (dwProcCRC & 0x00ff0000) >> 16 );
|
||||
abCRCMagicCube[5] = BYTE( (dwFileCRC & 0x00ff0000) >> 16 );
|
||||
abCRCMagicCube[6] = BYTE( (dwProcCRC & 0xff000000) >> 24 );
|
||||
abCRCMagicCube[7] = BYTE( (dwFileCRC & 0xff000000) >> 24 );
|
||||
|
||||
bMagicCubeIdx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
BYTE GetProcessCRCMagicCubePiece()
|
||||
{
|
||||
BYTE bPiece = BYTE(abCRCMagicCube[bMagicCubeIdx] ^ abCRCXorTable[bMagicCubeIdx]);
|
||||
|
||||
if (!(++bMagicCubeIdx & 7))
|
||||
bMagicCubeIdx = 0;
|
||||
|
||||
return bPiece;
|
||||
}
|
||||
|
||||
@@ -199,6 +199,10 @@ if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
|
||||
add_test(NAME port.text_bar COMMAND $<TARGET_FILE:port_text_bar_test>)
|
||||
set_tests_properties(port.text_bar PROPERTIES SKIP_RETURN_CODE 77)
|
||||
|
||||
add_executable(port_process_crc_test ${PROJECT_SOURCE_DIR}/tests/port/port_process_crc_test.cpp)
|
||||
target_link_libraries(port_process_crc_test PRIVATE port_platform)
|
||||
add_test(NAME port.process_crc COMMAND $<TARGET_FILE:port_process_crc_test>)
|
||||
|
||||
# MilesLib: the 40250 sound managers over the Miles emulation (platform/MilesLib/MilesAil.cpp).
|
||||
add_executable(port_miles_test ${PROJECT_SOURCE_DIR}/tests/port/port_miles_test.cpp)
|
||||
target_link_libraries(port_miles_test PRIVATE port_platform)
|
||||
|
||||
Reference in New Issue
Block a user