| 35 | return Result; |
| 36 | } |
| 37 | BOOL LoadFileW(HANDLE hProcess, LPCWSTR Path, DWORD Flags, WDLL*& wFile) |
| 38 | { |
| 39 | |
| 40 | HANDLE hFile = 0; |
| 41 | BOOL Result = 0; |
| 42 | DWORD NumberOfBytesRead = 0, FileSize = 0; |
| 43 | PIMAGE_SECTION_HEADER SectionHeaders = 0; |
| 44 | LPVOID lpwDll = 0, lpwThread = 0; |
| 45 | HANDLE hThread = 0, FileHandle = 0; |
| 46 | if (!wFile) |
| 47 | { |
| 48 | SetLastError(1990); |
| 49 | return 0; |
| 50 | } |
| 51 | wFile->hProcess = hProcess; |
| 52 | if (!wFile->hProcess) |
| 53 | { |
| 54 | SetLastError(1991); |
| 55 | return 0; |
| 56 | } |
| 57 | hFile = CreateFileW(Path, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); |
| 58 | if (hFile == INVALID_HANDLE_VALUE) |
| 59 | { |
| 60 | SetLastError(1992); |
| 61 | return 0; |
| 62 | } |
| 63 | FileHandle = hFile; |
| 64 | FileSize = GetFileSize(FileHandle, 0); |
| 65 | if (!FileSize) |
| 66 | { |
| 67 | CloseHandle(FileHandle); |
| 68 | SetLastError(1993); |
| 69 | return 0; |
| 70 | } |
| 71 | wFile->Module = reinterpret_cast<HMODULE>(VirtualAlloc(0, FileSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)); |
| 72 | if (!wFile->Module) |
| 73 | { |
| 74 | CloseHandle(FileHandle); |
| 75 | |
| 76 | SetLastError(1994); |
| 77 | return 0; |
| 78 | } |
| 79 | if (!ReadFile(hFile, wFile->Module, static_cast<DWORD>(FileSize), &NumberOfBytesRead, 0)) |
| 80 | { |
| 81 | VirtualFree(wFile->Module, FileSize, MEM_DECOMMIT); |
| 82 | CloseHandle(FileHandle); |
| 83 | SetLastError(1995); |
| 84 | return 0; |
| 85 | } |
| 86 | if (!LoadFileFromMemory(hProcess, wFile->Module, Flags, wFile)) |
| 87 | { |
| 88 | CloseHandle(FileHandle); |
| 89 | return 0; |
| 90 | } |
| 91 | if (!VirtualFree(wFile->Module, FileSize, MEM_DECOMMIT)) |
| 92 | { |
| 93 | CloseHandle(FileHandle); |
| 94 | SetLastError(1996); |
no test coverage detected