| 623 | } |
| 624 | |
| 625 | LPVOID PeRebuild::createFileMappingViewFull(const WCHAR * filePath) |
| 626 | { |
| 627 | hFileToMap = CreateFile(filePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
| 628 | |
| 629 | if( hFileToMap == INVALID_HANDLE_VALUE ) |
| 630 | { |
| 631 | #ifdef DEBUG_COMMENTS |
| 632 | Scylla::debugLog.log(L"createFileMappingView :: INVALID_HANDLE_VALUE %u", GetLastError()); |
| 633 | #endif |
| 634 | hMappedFile = 0; |
| 635 | hFileToMap = 0; |
| 636 | addrMappedDll = 0; |
| 637 | return NULL; |
| 638 | } |
| 639 | |
| 640 | hMappedFile = CreateFileMapping(hFileToMap, 0, PAGE_READWRITE, 0, 0, NULL); |
| 641 | |
| 642 | if( hMappedFile == NULL ) |
| 643 | { |
| 644 | #ifdef DEBUG_COMMENTS |
| 645 | Scylla::debugLog.log(L"createFileMappingViewFull :: hMappedFile == NULL"); |
| 646 | #endif |
| 647 | CloseHandle(hFileToMap); |
| 648 | hMappedFile = 0; |
| 649 | hFileToMap = 0; |
| 650 | addrMappedDll = 0; |
| 651 | return NULL; |
| 652 | } |
| 653 | |
| 654 | if (GetLastError() == ERROR_ALREADY_EXISTS) |
| 655 | { |
| 656 | #ifdef DEBUG_COMMENTS |
| 657 | Scylla::debugLog.log(L"createFileMappingView :: GetLastError() == ERROR_ALREADY_EXISTS"); |
| 658 | #endif |
| 659 | CloseHandle(hFileToMap); |
| 660 | hMappedFile = 0; |
| 661 | hFileToMap = 0; |
| 662 | addrMappedDll = 0; |
| 663 | return NULL; |
| 664 | } |
| 665 | |
| 666 | addrMappedDll = MapViewOfFile(hMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, 0); |
| 667 | |
| 668 | if(!addrMappedDll) |
| 669 | { |
| 670 | #ifdef DEBUG_COMMENTS |
| 671 | Scylla::debugLog.log(L"createFileMappingView :: addrMappedDll == NULL"); |
| 672 | #endif |
| 673 | CloseHandle(hFileToMap); |
| 674 | CloseHandle(hMappedFile); |
| 675 | hMappedFile = 0; |
| 676 | hFileToMap = 0; |
| 677 | return NULL; |
| 678 | } |
| 679 | |
| 680 | return addrMappedDll; |
| 681 | } |
| 682 | |