From c7fb09d2e8b91f74052f51e442cc8921ed8b3ec6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 21 May 2013 17:47:19 +0000 Subject: PluginUpdater now updates also language packs git-svn-id: http://svn.miranda-ng.org/main/trunk@4783 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PluginUpdater/src/Scanner.cpp | 16 +- plugins/PluginUpdater/src/checksum.cpp | 447 +++++++++++++++------------------ 2 files changed, 212 insertions(+), 251 deletions(-) (limited to 'plugins/PluginUpdater/src') diff --git a/plugins/PluginUpdater/src/Scanner.cpp b/plugins/PluginUpdater/src/Scanner.cpp index f013d0dfe4..eebd69cd62 100644 --- a/plugins/PluginUpdater/src/Scanner.cpp +++ b/plugins/PluginUpdater/src/Scanner.cpp @@ -145,6 +145,18 @@ static bool CheckFileRename(const TCHAR *ptszOldName, TCHAR *pNewName) typedef OBJLIST SERVLIST; +static bool isValidExtension(const TCHAR *ptszFileName) +{ + const TCHAR *pExt = _tcsrchr(ptszFileName, '.'); + if (pExt == NULL) + return false; + + if ( !_tcsicmp(pExt, _T(".dll"))) return true; + if ( !_tcsicmp(pExt, _T(".exe"))) return true; + if ( !_tcsicmp(pExt, _T(".txt"))) return true; + return false; +} + static void ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const TCHAR *tszBaseUrl, SERVLIST& hashes, OBJLIST *UpdateFiles) { // skip updater's own folder @@ -174,9 +186,7 @@ static void ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, cons continue; } - TCHAR *pExt = _tcsrchr(ffd.cFileName, '.'); - if (pExt == NULL) continue; - if ( _tcsicmp(pExt, _T(".dll")) && _tcsicmp(pExt, _T(".exe"))) + if ( !isValidExtension(ffd.cFileName)) continue; // calculate the current file's relative name and store it into tszNewName diff --git a/plugins/PluginUpdater/src/checksum.cpp b/plugins/PluginUpdater/src/checksum.cpp index e60970781f..045ea3884b 100644 --- a/plugins/PluginUpdater/src/checksum.cpp +++ b/plugins/PluginUpdater/src/checksum.cpp @@ -18,11 +18,41 @@ int debug = 0; +struct MFileMapping +{ + PBYTE ptr; + HANDLE hMap, hFile; + + MFileMapping(const TCHAR* ptszFileName) + { + ptr = NULL; + hMap = NULL; + + hFile = CreateFile(ptszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (hFile != INVALID_HANDLE_VALUE) + hMap = CreateFileMapping( hFile, NULL, PAGE_WRITECOPY, 0, 0, NULL); + if (hMap) + ptr = (PBYTE)MapViewOfFile(hMap, FILE_MAP_COPY, 0, 0, 0); + } + + ~MFileMapping() + { + if (ptr) + UnmapViewOfFile(ptr); + + if (hMap) + CloseHandle(hMap); + + if (hFile != INVALID_HANDLE_VALUE) + CloseHandle(hFile); + } +}; + static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, BYTE *pBase); static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, BYTE *pBase) { - if ( pIRDE->DataIsDirectory ) + if (pIRDE->DataIsDirectory) PatchResourcesDirectory( PIMAGE_RESOURCE_DIRECTORY(pBase + pIRDE->OffsetToDirectory), pBase); } @@ -41,286 +71,207 @@ static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase) int CalculateModuleHash(const TCHAR *filename, char *szDest) { - HANDLE hFile = INVALID_HANDLE_VALUE; - HANDLE hMap; - PBYTE ptr = 0; - int res = RESULT_OK; - DWORD filesize; - DWORD hsize = 0; - - WORD machine = 0; - DWORD sections = 0; - - hFile = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); - - if ( hFile == INVALID_HANDLE_VALUE ) + MFileMapping map(filename); + if (map.hFile == INVALID_HANDLE_VALUE) return RESULT_NOTFOUND; + if (map.ptr == NULL) + return RESULT_READERROR; + // check minimum and maximum size - filesize = GetFileSize( hFile, &hsize ); + DWORD hsize = 0, filesize = GetFileSize(map.hFile, &hsize ); - if ( !filesize || filesize == INVALID_FILE_SIZE || hsize ) - { - CloseHandle( hFile ); + if ( !filesize || filesize == INVALID_FILE_SIZE || hsize) return RESULT_INVALID; - } - if ( filesize < sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS)) - { - CloseHandle( hFile ); + if (filesize < sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS)) return RESULT_NOTPE; - } - - hMap = CreateFileMapping( hFile, NULL, PAGE_WRITECOPY, 0, 0, NULL ); - if ( hMap ) - ptr = (PBYTE)MapViewOfFile( hMap, FILE_MAP_COPY, 0, 0 ,0 ); + mir_md5_state_t pms; + mir_md5_init(&pms); - if ( ptr ) - { - PIMAGE_DOS_HEADER pIDH = 0; - PIMAGE_NT_HEADERS pINTH = 0; - - pIDH = (PIMAGE_DOS_HEADER)ptr; - - if ( pIDH->e_magic == IMAGE_DOS_SIGNATURE ) - pINTH = (PIMAGE_NT_HEADERS)( ptr + pIDH->e_lfanew ); - - if ( !pINTH) - res = RESULT_NOTPE; - else - if ((PBYTE)pINTH + sizeof(IMAGE_NT_HEADERS) >= ptr + filesize ) - res = RESULT_CORRUPTED; - else - if ( pINTH->Signature != IMAGE_NT_SIGNATURE ) - res = RESULT_NOTPE; - else + PIMAGE_DOS_HEADER pIDH = (PIMAGE_DOS_HEADER)map.ptr; + if (pIDH->e_magic != IMAGE_DOS_SIGNATURE) { +LBL_NotPE: + mir_md5_append(&pms, map.ptr, filesize); + } + else { + PIMAGE_NT_HEADERS pINTH = (PIMAGE_NT_HEADERS)(map.ptr + pIDH->e_lfanew); + if ((PBYTE)pINTH + sizeof(IMAGE_NT_HEADERS) >= map.ptr + filesize ) + return RESULT_CORRUPTED; + if (pINTH->Signature != IMAGE_NT_SIGNATURE) + goto LBL_NotPE; + + WORD machine = pINTH->FileHeader.Machine; + DWORD sections = pINTH->FileHeader.NumberOfSections; + if (!sections) + return RESULT_INVALID; + + // try to found correct offset independent of architectures + DWORD offset = pIDH->e_lfanew + pINTH->FileHeader.SizeOfOptionalHeader + sizeof(IMAGE_NT_HEADERS) - sizeof(IMAGE_OPTIONAL_HEADER); + + PBYTE pRealloc = 0; + PIMAGE_DEBUG_DIRECTORY pDBG = 0; + PIMAGE_DATA_DIRECTORY pIDD; + ULONGLONG base; + if ((machine == IMAGE_FILE_MACHINE_I386) && + (pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER32)) && + (pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)) { - machine = pINTH->FileHeader.Machine; - sections = pINTH->FileHeader.NumberOfSections; - - if ( !sections ) - res = RESULT_INVALID; - else + pIDD = (PIMAGE_DATA_DIRECTORY)((PBYTE)pINTH + offsetof(IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory)); + base = *(DWORD*)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.ImageBase )); + } + else if ((machine == IMAGE_FILE_MACHINE_AMD64) && + (pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER64)) && + (pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)) + { + pIDD = (PIMAGE_DATA_DIRECTORY)((PBYTE)pINTH + offsetof(IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory)); + base = *(ULONGLONG*)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.ImageBase )); + } + else return RESULT_CORRUPTED; + + // Debugging information entry + DWORD dbgAddr = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress; + DWORD dbgSize = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].Size; + + // Export information entry + DWORD expAddr = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; + DWORD expSize = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; + + // Resource directory + DWORD resAddr = pIDD[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress; + DWORD resSize = pIDD[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size; + + // Reallocation information entry + DWORD relocAddr = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress; + DWORD relocSize = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size; + + // verify image integrity + for (DWORD idx=0; idx < sections; idx++) { + PIMAGE_SECTION_HEADER pISH = (PIMAGE_SECTION_HEADER)(map.ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER)); + if (((PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > map.ptr + filesize) || (pISH->PointerToRawData + pISH->SizeOfRawData > filesize)) + return RESULT_CORRUPTED; + + // erase timestamp + if (( dbgSize >= sizeof(IMAGE_DEBUG_DIRECTORY)) && + (dbgAddr >= pISH->VirtualAddress) && + (dbgAddr + dbgSize <= pISH->VirtualAddress + pISH->SizeOfRawData)) { - PIMAGE_DATA_DIRECTORY pIDD = 0; - PIMAGE_DEBUG_DIRECTORY pDBG = 0; - DWORD dbgSize = 0, dbgAddr = 0; // debug information - DWORD expSize = 0, expAddr = 0; // export table - DWORD resSize = 0, resAddr = 0; // resource directory - DWORD relocSize = 0, relocAddr = 0; // relocation table - PBYTE pRealloc = 0; - DWORD offset; - ULONGLONG base = 0; - - // try to found correct offset independent of architectures - offset = pIDH->e_lfanew + pINTH->FileHeader.SizeOfOptionalHeader + sizeof(IMAGE_NT_HEADERS) - sizeof(IMAGE_OPTIONAL_HEADER); - - if (( machine == IMAGE_FILE_MACHINE_I386 ) && - ( pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER32)) && - ( pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC )) - { - pIDD = (PIMAGE_DATA_DIRECTORY)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory )); - base = *(DWORD*)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.ImageBase )); - } - else if (( machine == IMAGE_FILE_MACHINE_AMD64 ) && - ( pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER64)) && - ( pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC )) - { - pIDD = (PIMAGE_DATA_DIRECTORY)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory )); - base = *(ULONGLONG*)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.ImageBase )); - } - else res = RESULT_CORRUPTED; - - if ( pIDD ) { - // Debugging information entry - dbgAddr = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress; - dbgSize = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].Size; - - // Export information entry - expAddr = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; - expSize = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; - - // Resource directory - resAddr = pIDD[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress; - resSize = pIDD[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size; - - // Reallocation information entry - relocAddr = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress; - relocSize = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size; - } + DWORD shift = dbgAddr - pISH->VirtualAddress; + pDBG = (PIMAGE_DEBUG_DIRECTORY)(map.ptr + shift + pISH->PointerToRawData); + pDBG->TimeDateStamp = 0; + } - // verify image integrity - for (DWORD idx=0; idx < sections; idx++) - { - PIMAGE_SECTION_HEADER pISH = (PIMAGE_SECTION_HEADER)( ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER)); + // erase export timestamp + if ((expSize >= sizeof(IMAGE_EXPORT_DIRECTORY)) && + (expAddr >= pISH->VirtualAddress) && + (expAddr + expSize <= pISH->VirtualAddress + pISH->SizeOfRawData)) + { + DWORD shift = expAddr - pISH->VirtualAddress; + PIMAGE_EXPORT_DIRECTORY pEXP = (PIMAGE_EXPORT_DIRECTORY)(map.ptr + shift + pISH->PointerToRawData); + pEXP->TimeDateStamp = 0; + } - if (((PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > ptr + filesize ) || ( pISH->PointerToRawData + pISH->SizeOfRawData > filesize )) - { - res = RESULT_CORRUPTED; - break; - } + // find realocation table + if ((relocSize >= sizeof(IMAGE_BASE_RELOCATION)) && + (relocAddr >= pISH->VirtualAddress) && + (relocAddr + relocSize <= pISH->VirtualAddress + pISH->SizeOfRawData)) + { + DWORD shift = relocAddr - pISH->VirtualAddress; + pRealloc = map.ptr + shift + pISH->PointerToRawData; + } + } - // erase timestamp - if (( dbgSize >= sizeof( IMAGE_DEBUG_DIRECTORY )) && - ( dbgAddr >= pISH->VirtualAddress ) && - ( dbgAddr + dbgSize <= pISH->VirtualAddress + pISH->SizeOfRawData )) - { - DWORD shift = dbgAddr - pISH->VirtualAddress; - pDBG = (PIMAGE_DEBUG_DIRECTORY)( ptr + shift + pISH->PointerToRawData ); - pDBG->TimeDateStamp = 0; - } + for (size_t idx=0; idx < sections; idx++) { + PIMAGE_SECTION_HEADER pISH = (PIMAGE_SECTION_HEADER)(map.ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER)); - // erase export timestamp - if (( expSize >= sizeof( IMAGE_EXPORT_DIRECTORY )) && - ( expAddr >= pISH->VirtualAddress ) && - ( expAddr + expSize <= pISH->VirtualAddress + pISH->SizeOfRawData )) - { - DWORD shift = expAddr - pISH->VirtualAddress; - PIMAGE_EXPORT_DIRECTORY pEXP = (PIMAGE_EXPORT_DIRECTORY)( ptr + shift + pISH->PointerToRawData ); + if (((PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > map.ptr + filesize) || ( pISH->PointerToRawData + pISH->SizeOfRawData > filesize)) + return RESULT_CORRUPTED; - pEXP->TimeDateStamp = 0; - } + // erase debug information + if (pDBG && pDBG->SizeOfData > 0 && + pDBG->PointerToRawData >= pISH->PointerToRawData && + pDBG->PointerToRawData + pDBG->SizeOfData <= pISH->PointerToRawData + pISH->SizeOfRawData) + { + ZeroMemory(map.ptr + pDBG->PointerToRawData, pDBG->SizeOfData); + } - // find realocation table - if (( relocSize >= sizeof( IMAGE_BASE_RELOCATION )) && - ( relocAddr >= pISH->VirtualAddress ) && - ( relocAddr + relocSize <= pISH->VirtualAddress + pISH->SizeOfRawData )) - { - DWORD shift = relocAddr - pISH->VirtualAddress; - pRealloc = ptr + shift + pISH->PointerToRawData; - } - } + // patch resources + if (resSize > 0 && resAddr >= pISH->VirtualAddress && resAddr + resSize <= pISH->VirtualAddress + pISH->SizeOfRawData) { + DWORD shift = resAddr - pISH->VirtualAddress + pISH->PointerToRawData; + IMAGE_RESOURCE_DIRECTORY *pIRD = (IMAGE_RESOURCE_DIRECTORY*)(map.ptr + shift); + PatchResourcesDirectory(pIRD, map.ptr + shift); + } - if ( res == RESULT_OK ) - { - mir_md5_state_t pms; - mir_md5_init( &pms ); + // rebase to zero address + if (pRealloc) { + DWORD blocklen = relocSize; + PIMAGE_BASE_RELOCATION pIBR = (PIMAGE_BASE_RELOCATION)pRealloc; - for (size_t idx=0; idx < sections; idx++) + while(pIBR) { + if ((pIBR->VirtualAddress >= pISH->VirtualAddress) && + (pIBR->VirtualAddress < pISH->VirtualAddress + pISH->SizeOfRawData) && + (pIBR->SizeOfBlock <= blocklen)) { - PIMAGE_SECTION_HEADER pISH = (PIMAGE_SECTION_HEADER)( ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER)); - - if (((PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > ptr + filesize ) || ( pISH->PointerToRawData + pISH->SizeOfRawData > filesize )) - { - res = RESULT_CORRUPTED; - break; - } - - // erase debug information - if ( pDBG && pDBG->SizeOfData > 0 && - pDBG->PointerToRawData >= pISH->PointerToRawData && - pDBG->PointerToRawData + pDBG->SizeOfData <= pISH->PointerToRawData + pISH->SizeOfRawData ) - { - ZeroMemory( ptr + pDBG->PointerToRawData, pDBG->SizeOfData ); - } - - // patch resources - if ( resSize > 0 && resAddr >= pISH->VirtualAddress && resAddr + resSize <= pISH->VirtualAddress + pISH->SizeOfRawData ) - { - DWORD shift = resAddr - pISH->VirtualAddress + pISH->PointerToRawData; - IMAGE_RESOURCE_DIRECTORY *pIRD = (IMAGE_RESOURCE_DIRECTORY*)( ptr + shift ); - PatchResourcesDirectory(pIRD, ptr + shift); - } - - // rebase to zero address - if ( pRealloc ) - { - DWORD blocklen = relocSize; - PWORD pw; - DWORD type; - int len; - PBYTE pAddr; - DWORD shift; - DWORD addr; - - PIMAGE_BASE_RELOCATION pIBR = (PIMAGE_BASE_RELOCATION)pRealloc; - while( pIBR ) - { - if (( pIBR->VirtualAddress >= pISH->VirtualAddress ) && - ( pIBR->VirtualAddress < pISH->VirtualAddress + pISH->SizeOfRawData ) && - ( pIBR->SizeOfBlock <= blocklen )) - { - shift = pIBR->VirtualAddress - pISH->VirtualAddress + pISH->PointerToRawData; - - len = pIBR->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION); - - pw = (PWORD)((PBYTE)pIBR + sizeof(IMAGE_BASE_RELOCATION)); - - while( len > 0 ) - { - type = *pw >> 12; - - addr = ( *pw & 0x0FFF ); - - pAddr = ptr + shift + addr; - - switch( type ) { - case IMAGE_REL_BASED_HIGHLOW: - if ( addr + pIBR->VirtualAddress + sizeof(DWORD) >= pISH->VirtualAddress + pISH->SizeOfRawData ) - { - len = 0; - break; - } - *(PDWORD)pAddr = (DWORD)((*(PDWORD)pAddr) - (DWORD)base ); - break; - - case IMAGE_REL_BASED_DIR64: - if ( addr + pIBR->VirtualAddress + sizeof(ULONGLONG) >= pISH->VirtualAddress + pISH->SizeOfRawData ) - { - len = 0; - break; - } - *(ULONGLONG*)pAddr = (ULONGLONG)((*(ULONGLONG*)pAddr) - base ); - break; - - case IMAGE_REL_BASED_ABSOLUTE: - // stop processing - len = 0; - break; - - case IMAGE_REL_BASED_HIGH: - case IMAGE_REL_BASED_LOW: - case IMAGE_REL_BASED_HIGHADJ: - break; - } - - len -= sizeof(WORD); - pw++; - } + DWORD shift = pIBR->VirtualAddress - pISH->VirtualAddress + pISH->PointerToRawData; + int len = pIBR->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION); + PWORD pw = (PWORD)((PBYTE)pIBR + sizeof(IMAGE_BASE_RELOCATION)); + + while(len > 0) { + DWORD type = *pw >> 12; + DWORD addr = (*pw & 0x0FFF); + PBYTE pAddr = map.ptr + shift + addr; + + switch(type) { + case IMAGE_REL_BASED_HIGHLOW: + if (addr + pIBR->VirtualAddress + sizeof(DWORD) >= pISH->VirtualAddress + pISH->SizeOfRawData) { + len = 0; + break; } + *(PDWORD)pAddr = (DWORD)((*(PDWORD)pAddr) - (DWORD)base ); + break; - blocklen -= pIBR->SizeOfBlock; - if ( blocklen > sizeof(IMAGE_BASE_RELOCATION)) - pIBR = (PIMAGE_BASE_RELOCATION)((PBYTE)pIBR + pIBR->SizeOfBlock ); - else + case IMAGE_REL_BASED_DIR64: + if (addr + pIBR->VirtualAddress + sizeof(ULONGLONG) >= pISH->VirtualAddress + pISH->SizeOfRawData) { + len = 0; break; + } + *(ULONGLONG*)pAddr = (ULONGLONG)((*(ULONGLONG*)pAddr) - base ); + break; + + case IMAGE_REL_BASED_ABSOLUTE: + // stop processing + len = 0; + break; + + case IMAGE_REL_BASED_HIGH: + case IMAGE_REL_BASED_LOW: + case IMAGE_REL_BASED_HIGHADJ: + break; } - } - mir_md5_append( &pms, ptr + pISH->PointerToRawData, pISH->SizeOfRawData ); + len -= sizeof(WORD); + pw++; + } } - if ( res == RESULT_OK ) { - BYTE digest[16]; - mir_md5_finish(&pms, digest); + blocklen -= pIBR->SizeOfBlock; + if (blocklen <= sizeof(IMAGE_BASE_RELOCATION)) + break; - for (int i=0; i < sizeof(digest); i++) - sprintf(szDest + i*2, "%02x", digest[i]); - } + pIBR = (PIMAGE_BASE_RELOCATION)((PBYTE)pIBR + pIBR->SizeOfBlock); } } + + mir_md5_append(&pms, map.ptr + pISH->PointerToRawData, pISH->SizeOfRawData); } } - else res = RESULT_READERROR; - - if ( ptr ) - UnmapViewOfFile( ptr ); - if ( hMap ) - CloseHandle( hMap ); + BYTE digest[16]; + mir_md5_finish(&pms, digest); - CloseHandle( hFile ); + for (int i=0; i < sizeof(digest); i++) + sprintf(szDest + i*2, "%02x", digest[i]); - return res; + return RESULT_OK; } -- cgit v1.2.3