jadeite/game_payload/src/utils.c

31 lines
791 B
C
Raw Normal View History

2023-06-05 21:23:08 +00:00
#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;
}