2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps_new/integrity.cpp
5 * PURPOSE: Various integrity check mechanisms
6 * PROGRAMMERS: Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
14 BOOL
VerifyInteg(LPCWSTR lpSHA1Hash
, LPCWSTR lpFileName
)
18 /* first off, does it exist at all? */
19 HANDLE file
= CreateFileW(lpFileName
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
21 if (file
== INVALID_HANDLE_VALUE
)
24 /* let's grab the actual file size to organize the mmap'ing rounds */
26 GetFileSizeEx(file
, &size
);
28 /* retrieve a handle to map the file contents to memory */
29 HANDLE map
= CreateFileMappingW(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
32 /* map that thing in address space */
33 const unsigned char *file_map
= static_cast<const unsigned char *>(MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0));
37 /* initialize the SHA-1 context */
40 /* feed the data to the cookie monster */
41 A_SHAUpdate(&ctx
, file_map
, size
.LowPart
);
43 /* cool, we don't need this anymore */
44 UnmapViewOfFile(file_map
);
46 /* we're done, compute the final hash */
48 A_SHAFinal(&ctx
, sha
);
50 WCHAR buf
[(sizeof(sha
) * 2) + 1];
51 for (UINT i
= 0; i
< sizeof(sha
); i
++)
52 swprintf(buf
+ 2 * i
, L
"%02x", ((unsigned char *)sha
)[i
]);
53 /* does the resulting SHA1 match with the provided one? */
54 if (!_wcsicmp(buf
, lpSHA1Hash
))