MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / CalculateExeCRC

Function CalculateExeCRC

engine/Poseidon/Network/IntegrityCheck.cpp:10–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <Poseidon/Foundation/Common/Filenames.hpp>
9
10unsigned int CalculateExeCRC(int offset, int size)
11{
12#ifdef _WIN32
13 HMODULE hMod = GetModuleHandle(nullptr);
14
15 // get exe header from PE
16 PIMAGE_DOS_HEADER pDosHdr = (PIMAGE_DOS_HEADER)hMod;
17
18 // From the DOS header, find the NT (PE) header
19 PIMAGE_NT_HEADERS pNtHdr = (PIMAGE_NT_HEADERS)((char*)hMod + pDosHdr->e_lfanew);
20
21 PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(pNtHdr);
22
23 uintptr_t codeStart = (uintptr_t)hMod + pSection->PointerToRawData;
24 uintptr_t codeSize = pSection->SizeOfRawData;
25 uintptr_t codeEnd = codeStart + codeSize;
26
27 uintptr_t checkStart = offset;
28 uintptr_t checkEnd = offset + size;
29 if (checkStart < codeStart)
30 checkStart = codeStart;
31 if (checkStart > codeEnd)
32 checkStart = codeEnd;
33 if (checkEnd < codeStart)
34 checkEnd = codeStart;
35 if (checkEnd > codeEnd)
36 checkEnd = codeEnd;
37
38 Poseidon::Foundation::CRCCalculator crc;
39 crc.Reset();
40 crc.Add((void*)checkStart, (int)(checkEnd - checkStart));
41 return crc.GetResult();
42#else
43 return 0;
44#endif
45}
46
47unsigned int CalculateDataCRC(const char* path, int offset, int size)
48{

Callers 2

GetReferenceCRCFunction · 0.85
IntegrityCheckAnswerFunction · 0.85

Calls 3

ResetMethod · 0.45
AddMethod · 0.45
GetResultMethod · 0.45

Tested by

no test coverage detected