• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision27867 (tree)
Zeit2017-07-02 01:36:09
Autorstefankueng

Log Message

Merged revision(s) r27866 from trunk:
* * remove all signatures from to-be-translated files * adjust the file checksum after modifying it

Ändern Zusammenfassung

Diff

--- branches/1.9.x/src/ResText/ResModule.cpp (revision 27866)
+++ branches/1.9.x/src/ResText/ResModule.cpp (revision 27867)
@@ -1,6 +1,7 @@
11 // TortoiseSVN - a Windows shell extension for easy version control
22
3-// Copyright (C) 2003-2008, 2010-2015 - TortoiseSVN
3+// Copyright (C) 2015-2016 - TortoiseGit
4+// Copyright (C) 2003-2008, 2010-2017 - TortoiseSVN
45
56 // This program is free software; you can redistribute it and/or
67 // modify it under the terms of the GNU General Public License
@@ -21,6 +22,14 @@
2122 #include <regex>
2223 #include <memory>
2324
25+#pragma warning(push)
26+#pragma warning(disable: 4091) // 'typedef ': ignored on left of '' when no variable is declared
27+#include <Imagehlp.h>
28+#pragma warning(pop)
29+
30+
31+#pragma comment(lib, "Imagehlp.lib")
32+
2433 #ifndef RT_RIBBON
2534 #define RT_RIBBON MAKEINTRESOURCE(28)
2635 #endif
@@ -174,6 +183,8 @@
174183 if (!CopyFile(lpszSrcLangDllPath, lpszDestLangDllPath, FALSE))
175184 MYERROR;
176185
186+ RemoveSignatures(lpszDestLangDllPath);
187+
177188 int count = 0;
178189 do
179190 {
@@ -248,6 +259,9 @@
248259 MYERROR;
249260
250261 FreeLibrary(m_hResDll);
262+
263+ AdjustCheckSum(sDestFile);
264+
251265 return TRUE;
252266 DONE_ERROR:
253267 if (m_hResDll)
@@ -255,6 +269,23 @@
255269 return FALSE;
256270 }
257271
272+void CResModule::RemoveSignatures(LPCTSTR lpszDestLangDllPath)
273+{
274+ // Remove any signatures in the file:
275+ // if we don't remove it here, the signature will be invalid after
276+ // we modify this file, and the signtool.exe will throw an error and refuse to sign it again.
277+ auto hFile = CreateFile(lpszDestLangDllPath, FILE_READ_DATA | FILE_WRITE_DATA, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
278+
279+ DWORD certcount = 0;
280+ DWORD indices[100];
281+ ImageEnumerateCertificates(hFile, CERT_SECTION_TYPE_ANY, &certcount, indices, _countof(indices));
282+
283+ for (DWORD i = 0; i < certcount; ++i)
284+ ImageRemoveCertificate(hFile, i);
285+
286+ CloseHandle(hFile);
287+}
288+
258289 BOOL CResModule::ExtractString(LPCTSTR lpszType)
259290 {
260291 HRSRC hrsrc = FindResource(m_hResDll, lpszType, RT_STRING);
@@ -2123,3 +2154,82 @@
21232154 }
21242155 delete [] pBuf;
21252156 }
2157+
2158+bool CResModule::AdjustCheckSum(const std::wstring& resFile)
2159+{
2160+ HANDLE hFile = INVALID_HANDLE_VALUE;
2161+ HANDLE hFileMapping = NULL;
2162+ PVOID pBaseAddress = NULL;
2163+
2164+ try
2165+ {
2166+
2167+ /////////////////////////////////////////////////////////////
2168+ hFile = CreateFile(resFile.c_str(), FILE_READ_DATA | FILE_WRITE_DATA,
2169+ 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
2170+ if (INVALID_HANDLE_VALUE == hFile ||
2171+ NULL == hFile)
2172+ {
2173+ throw GetLastError();
2174+ }
2175+
2176+ /////////////////////////////////////////////////////////////
2177+ hFileMapping = CreateFileMapping(hFile, NULL,
2178+ PAGE_READWRITE, 0, 0, NULL);
2179+ if (NULL == hFileMapping)
2180+ {
2181+ throw GetLastError();
2182+ }
2183+
2184+ /////////////////////////////////////////////////////////////
2185+ pBaseAddress = MapViewOfFile(hFileMapping,
2186+ FILE_MAP_ALL_ACCESS, 0, 0, 0);
2187+ if (NULL == pBaseAddress)
2188+ {
2189+ throw GetLastError();
2190+ }
2191+ auto fileSize = GetFileSize(hFile, nullptr);
2192+ DWORD dwChecksum = 0;
2193+ DWORD dwHeaderSum = 0;
2194+ CheckSumMappedFile(pBaseAddress, fileSize, &dwHeaderSum, &dwChecksum);
2195+
2196+ /////////////////////////////////////////////////////////////
2197+ PIMAGE_DOS_HEADER pDOSHeader = NULL;
2198+ pDOSHeader = static_cast<PIMAGE_DOS_HEADER>(pBaseAddress);
2199+ if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE)
2200+ {
2201+ throw GetLastError();
2202+ }
2203+
2204+ /////////////////////////////////////////////////////////////
2205+ PIMAGE_NT_HEADERS pNTHeader = NULL;
2206+ pNTHeader = reinterpret_cast<PIMAGE_NT_HEADERS>(
2207+ (PBYTE)pBaseAddress + pDOSHeader->e_lfanew);
2208+
2209+ if (pNTHeader->Signature != IMAGE_NT_SIGNATURE)
2210+ {
2211+ throw GetLastError();
2212+ }
2213+
2214+ /////////////////////////////////////////////////////////////
2215+ SetLastError(ERROR_SUCCESS);
2216+
2217+ /////////////////////////////////////////////////////////////
2218+ DWORD* pChecksum = &(pNTHeader->OptionalHeader.CheckSum);
2219+ *pChecksum = dwChecksum;
2220+ }
2221+
2222+ catch (...)
2223+ {
2224+ UnmapViewOfFile(hFileMapping);
2225+ CloseHandle(hFile);
2226+
2227+ return false;
2228+ }
2229+
2230+ UnmapViewOfFile(hFileMapping);
2231+
2232+ CloseHandle(hFile);
2233+
2234+ return true;
2235+}
--- branches/1.9.x/src/ResText/ResModule.h (revision 27866)
+++ branches/1.9.x/src/ResText/ResModule.h (revision 27867)
@@ -1,6 +1,6 @@
11 // TortoiseSVN - a Windows shell extension for easy version control
22
3-// Copyright (C) 2003-2007, 2011-2012, 2014 - TortoiseSVN
3+// Copyright (C) 2003-2007, 2011-2012, 2014-2017 - TortoiseSVN
44
55 // This program is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU General Public License
@@ -117,6 +117,10 @@
117117
118118 void ReplaceStr(LPCWSTR src, WORD * dest, size_t * count, int * translated, int * def);
119119
120+ bool AdjustCheckSum(const std::wstring& resFile);
121+ void RemoveSignatures(LPCTSTR lpszDestLangDllPath);
122+
123+
120124 HMODULE m_hResDll;
121125 HANDLE m_hUpdateRes;
122126 CPOFile m_StringEntries;
Show on old repository browser