Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
45 lines (41 loc) · 1.08 KB

File metadata and controls

45 lines (41 loc) · 1.08 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
BOOL ReadFileData(WCHAR *filename, BYTE **buff, DWORD *size)
{
if (filename == NULL || buff == NULL || size == NULL)
return FALSE;
HANDLE hFile = CreateFileW(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
// get size of file
LARGE_INTEGER liSize;
if (!GetFileSizeEx(hFile, &liSize)) {
CloseHandle(hFile);
return FALSE;
}
if (liSize.HighPart > 0) {
CloseHandle(hFile);
return FALSE;
}
// read entire file into memory
*buff = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, liSize.LowPart);
if (*buff == NULL) {
CloseHandle(hFile);
return FALSE;
}
BYTE *buffPtr = *buff;
DWORD numLeft = liSize.LowPart;
DWORD numRead = 0;
while (numLeft > 0) {
if (!ReadFile(hFile, buffPtr, numLeft, &numRead, NULL)) {
CloseHandle(hFile);
HeapFree(GetProcessHeap(), 0, *buff);
return FALSE;
}
numLeft -= numRead;
buffPtr += numRead;
}
*size = liSize.LowPart;
CloseHandle(hFile);
return TRUE;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.