Initial commit
This commit is contained in:
30
game_payload/src/utils.c
Normal file
30
game_payload/src/utils.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <crc32.h>
|
||||
#include <err.h>
|
||||
|
||||
#include <utils.h>
|
||||
|
||||
uint32_t utils_file_crc32c(const char *filePath) {
|
||||
HANDLE file = CreateFileA(filePath, FILE_READ_ACCESS, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (!file) {
|
||||
err_mb_a("Could not open file: %s", filePath);
|
||||
}
|
||||
|
||||
LARGE_INTEGER fileSize;
|
||||
GetFileSizeEx(file, &fileSize);
|
||||
|
||||
HANDLE hMap = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
char *map = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
|
||||
if (!map) {
|
||||
err_mb_a("Could not create file mapping for %s", filePath);
|
||||
}
|
||||
|
||||
uint32_t crc = crc32c(0, (unsigned char*)map, fileSize.QuadPart);
|
||||
|
||||
UnmapViewOfFile(map);
|
||||
CloseHandle(hMap);
|
||||
CloseHandle(file);
|
||||
|
||||
return crc;
|
||||
}
|
||||
Reference in New Issue
Block a user