--- src/rescle_1.cc Mon Jul 17 13:55:11 2017 +++ src/rescle.cc Mon Jul 17 13:51:14 2017 @@ -77,6 +77,25 @@ return value + ((value % modula > 0) ? (modula - value % modula) : 0); } +// https://msdn.microsoft.com/en-us/library/ms809762.aspx +int isdll = 0; +void DumpFile(const WCHAR* path) +{ + if (isdll == 0) { + HANDLE hFile = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE hFileMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL); + LPVOID lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0); + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)lpFileBase; + PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS)((DWORD)pDosHeader + (DWORD)pDosHeader->e_lfanew); + if ((pNTHeader->FileHeader.Characteristics & IMAGE_FILE_DLL)) + isdll = 2; + else + isdll = 1; + UnmapViewOfFile(lpFileBase); + CloseHandle(hFileMapping); + CloseHandle(hFile); + } +} class ScopedFile { public: ScopedFile(const WCHAR* path) @@ -656,7 +675,7 @@ } FreeLibrary(hModule); hModule = NULL; - + DumpFile(filename.c_str()); ScopedResourceUpdater ru(filename.c_str(), false); if (ru.Get() == NULL) { return false; @@ -715,7 +734,7 @@ if (!UpdateResourceW (ru.Get() , RT_MANIFEST - , MAKEINTRESOURCEW(1) + , MAKEINTRESOURCEW(isdll) , 1033 // this is hardcoded at 1033, ie, en-us, as that is what RT_MANIFEST default uses , &stringSection.at(0), sizeof(char) * stringSection.size())) { @@ -754,7 +773,7 @@ if (!UpdateResourceW (ru.Get() , RT_MANIFEST - , MAKEINTRESOURCEW(1) + , MAKEINTRESOURCEW(isdll) , 1033 // this is hardcoded at 1033, ie, en-us, as that is what RT_MANIFEST default uses , &stringSection.at(0), sizeof(char) * stringSection.size())) {