customizations.diff 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
  2. index b1d740e..61cb260 100644
  3. --- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
  4. +++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
  5. @@ -54,7 +54,7 @@ BSC32=bscmake.exe
  6. # ADD BSC32 /nologo
  7. LINK32=link.exe
  8. # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
  9. -# ADD LINK32 comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"C:\Util\7zS.sfx" /opt:NOWIN98
  10. +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib delayimp.lib /nologo /subsystem:windows /machine:I386 /out:"Release\7zS.sfx" /opt:NOWIN98 /delayload:user32.dll /delayload:shell32.dll /delayload:oleaut32.dll
  11. # SUBTRACT LINK32 /pdb:none
  12. !ELSEIF "$(CFG)" == "SFXSetup - Win32 Debug"
  13. @@ -81,7 +81,7 @@ BSC32=bscmake.exe
  14. # ADD BSC32 /nologo
  15. LINK32=link.exe
  16. # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
  17. -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib /nologo /subsystem:windows /debug /machine:I386 /out:"C:\UTIL\7zSfxS.exe" /pdbtype:sept
  18. +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib delayimp.lib /nologo /subsystem:windows /debug /machine:I386 /out:"Debug\7zSfxS.exe" /pdbtype:sept /delayload:user32.dll /delayload:shell32.dll /delayload:oleaut32.dll
  19. !ELSEIF "$(CFG)" == "SFXSetup - Win32 ReleaseD"
  20. @@ -107,9 +107,9 @@ BSC32=bscmake.exe
  21. # ADD BASE BSC32 /nologo
  22. # ADD BSC32 /nologo
  23. LINK32=link.exe
  24. -# ADD BASE LINK32 comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"C:\UTIL\7zWinSR.exe"
  25. +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"C:\UTIL\7zWinSR.exe"
  26. # SUBTRACT BASE LINK32 /debug /nodefaultlib
  27. -# ADD LINK32 comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"C:\Util\7zSD.sfx" /opt:NOWIN98
  28. +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib delayimp.lib /nologo /subsystem:windows /machine:I386 /out:"ReleaseD\7zSD.sfx" /opt:NOWIN98 /delayload:user32.dll /delayload:shell32.dll /delayload:oleaut32.dll
  29. # SUBTRACT LINK32 /pdb:none
  30. !ENDIF
  31. diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
  32. index 1705a8d..e3a3bb2 100644
  33. --- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
  34. +++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
  35. @@ -125,6 +125,179 @@ static void ShowErrorMessageSpec(const UString &name)
  36. ShowErrorMessage(NULL, message);
  37. }
  38. +/* BEGIN Mozilla customizations */
  39. +
  40. +static char const *
  41. +FindStrInBuf(char const * buf, size_t bufLen, char const * str)
  42. +{
  43. + size_t index = 0;
  44. + while (index < bufLen) {
  45. + char const * result = strstr(buf + index, str);
  46. + if (result) {
  47. + return result;
  48. + }
  49. + while ((buf[index] != '\0') && (index < bufLen)) {
  50. + index++;
  51. + }
  52. + index++;
  53. + }
  54. + return NULL;
  55. +}
  56. +
  57. +static bool
  58. +ReadPostSigningDataFromView(char const * view, DWORD size, AString& data)
  59. +{
  60. + // Find the offset and length of the certificate table,
  61. + // so we know the valid range to look for the token.
  62. + if (size < (0x3c + sizeof(UInt32))) {
  63. + return false;
  64. + }
  65. + UInt32 PEHeaderOffset = *(UInt32*)(view + 0x3c);
  66. + UInt32 optionalHeaderOffset = PEHeaderOffset + 24;
  67. + UInt32 certDirEntryOffset = 0;
  68. + if (size < (optionalHeaderOffset + sizeof(UInt16))) {
  69. + return false;
  70. + }
  71. + UInt16 magic = *(UInt16*)(view + optionalHeaderOffset);
  72. + if (magic == 0x010b) {
  73. + // 32-bit executable
  74. + certDirEntryOffset = optionalHeaderOffset + 128;
  75. + } else if (magic == 0x020b) {
  76. + // 64-bit executable; certain header fields are wider
  77. + certDirEntryOffset = optionalHeaderOffset + 144;
  78. + } else {
  79. + // Unknown executable
  80. + return false;
  81. + }
  82. + if (size < certDirEntryOffset + 8) {
  83. + return false;
  84. + }
  85. + UInt32 certTableOffset = *(UInt32*)(view + certDirEntryOffset);
  86. + UInt32 certTableLen = *(UInt32*)(view + certDirEntryOffset + sizeof(UInt32));
  87. + if (certTableOffset == 0 || certTableLen == 0 ||
  88. + size < (certTableOffset + certTableLen)) {
  89. + return false;
  90. + }
  91. +
  92. + char const token[] = "__MOZCUSTOM__:";
  93. + // We're searching for a string inside a binary blob,
  94. + // so a normal strstr that bails on the first NUL won't work.
  95. + char const * tokenPos = FindStrInBuf(view + certTableOffset,
  96. + certTableLen, token);
  97. + if (tokenPos) {
  98. + size_t tokenLen = (sizeof(token) / sizeof(token[0])) - 1;
  99. + data = AString(tokenPos + tokenLen);
  100. + return true;
  101. + }
  102. + return false;
  103. +}
  104. +
  105. +static bool
  106. +ReadPostSigningData(UString exePath, AString& data)
  107. +{
  108. + bool retval = false;
  109. + HANDLE exeFile = CreateFileW(exePath, GENERIC_READ, FILE_SHARE_READ, NULL,
  110. + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  111. + if (exeFile != INVALID_HANDLE_VALUE) {
  112. + HANDLE mapping = CreateFileMapping(exeFile, NULL, PAGE_READONLY, 0, 0, NULL);
  113. + if (mapping != INVALID_HANDLE_VALUE) {
  114. + // MSDN claims the return value on failure is NULL,
  115. + // but I've also seen it returned on success, so double-check.
  116. + if (mapping || GetLastError() == ERROR_SUCCESS) {
  117. + char * view = (char*)MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
  118. + if (view) {
  119. + DWORD fileSize = GetFileSize(exeFile, NULL);
  120. + retval = ReadPostSigningDataFromView(view, fileSize, data);
  121. + }
  122. + CloseHandle(mapping);
  123. + }
  124. + }
  125. + CloseHandle(exeFile);
  126. + }
  127. + return retval;
  128. +}
  129. +
  130. +// Delayed load libraries are loaded when the first symbol is used.
  131. +// The following ensures that we load the delayed loaded libraries from the
  132. +// system directory.
  133. +struct AutoLoadSystemDependencies
  134. +{
  135. + AutoLoadSystemDependencies()
  136. + {
  137. + HMODULE module = ::GetModuleHandleW(L"kernel32.dll");
  138. + if (module) {
  139. + // SetDefaultDllDirectories is always available on Windows 8 and above. It
  140. + // is also available on Windows Vista, Windows Server 2008, and
  141. + // Windows 7 when MS KB2533623 has been applied.
  142. + typedef BOOL (WINAPI *SetDefaultDllDirectoriesType)(DWORD);
  143. + SetDefaultDllDirectoriesType setDefaultDllDirectories =
  144. + (SetDefaultDllDirectoriesType) GetProcAddress(module, "SetDefaultDllDirectories");
  145. + if (setDefaultDllDirectories) {
  146. + setDefaultDllDirectories(0x0800 /* LOAD_LIBRARY_SEARCH_SYSTEM32 */ );
  147. + return;
  148. + }
  149. + }
  150. +
  151. + static LPCWSTR delayDLLs[] = { L"uxtheme.dll", L"userenv.dll",
  152. + L"setupapi.dll", L"apphelp.dll",
  153. + L"propsys.dll", L"dwmapi.dll",
  154. + L"cryptbase.dll", L"oleacc.dll",
  155. + L"clbcatq.dll" };
  156. + WCHAR systemDirectory[MAX_PATH + 1] = { L'\0' };
  157. + // If GetSystemDirectory fails we accept that we'll load the DLLs from the
  158. + // normal search path.
  159. + GetSystemDirectoryW(systemDirectory, MAX_PATH + 1);
  160. + size_t systemDirLen = wcslen(systemDirectory);
  161. +
  162. + // Make the system directory path terminate with a slash
  163. + if (systemDirectory[systemDirLen - 1] != L'\\' && systemDirLen) {
  164. + systemDirectory[systemDirLen] = L'\\';
  165. + ++systemDirLen;
  166. + // No need to re-NULL terminate
  167. + }
  168. +
  169. + // For each known DLL ensure it is loaded from the system32 directory
  170. + for (size_t i = 0; i < sizeof(delayDLLs) / sizeof(delayDLLs[0]); ++i) {
  171. + size_t fileLen = wcslen(delayDLLs[i]);
  172. + wcsncpy(systemDirectory + systemDirLen, delayDLLs[i],
  173. + MAX_PATH - systemDirLen);
  174. + if (systemDirLen + fileLen <= MAX_PATH) {
  175. + systemDirectory[systemDirLen + fileLen] = L'\0';
  176. + } else {
  177. + systemDirectory[MAX_PATH] = L'\0';
  178. + }
  179. + LPCWSTR fullModulePath = systemDirectory; // just for code readability
  180. + LoadLibraryW(fullModulePath);
  181. + }
  182. + }
  183. +} loadDLLs;
  184. +
  185. +BOOL
  186. +RemoveCurrentDirFromSearchPath()
  187. +{
  188. + // kernel32.dll is in the knownDLL list so it is safe to load without a full path
  189. + HMODULE kernel32 = LoadLibraryW(L"kernel32.dll");
  190. + if (!kernel32) {
  191. + return FALSE;
  192. + }
  193. +
  194. + typedef BOOL (WINAPI *SetDllDirectoryType)(LPCWSTR);
  195. + SetDllDirectoryType SetDllDirectoryFn =
  196. + (SetDllDirectoryType)GetProcAddress(kernel32, "SetDllDirectoryW");
  197. + if (!SetDllDirectoryFn) {
  198. + FreeLibrary(kernel32);
  199. + return FALSE;
  200. + }
  201. +
  202. + // If this call fails we can't do much about it, so ignore it.
  203. + // It is unlikely to fail and this is just a precaution anyway.
  204. + SetDllDirectoryFn(L"");
  205. + FreeLibrary(kernel32);
  206. + return TRUE;
  207. +}
  208. +
  209. +/* END Mozilla customizations */
  210. +
  211. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
  212. #ifdef UNDER_CE
  213. LPWSTR
  214. @@ -133,13 +306,35 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
  215. #endif
  216. /* lpCmdLine */,int /* nCmdShow */)
  217. {
  218. + /* BEGIN Mozilla customizations */
  219. + // Disable current directory from being in the search path.
  220. + // This call does not help with implicitly loaded DLLs.
  221. + if (!RemoveCurrentDirFromSearchPath()) {
  222. + WCHAR minOSTitle[512] = { '\0' };
  223. + WCHAR minOSText[512] = { '\0' };
  224. + LoadStringW(NULL, IDS_MIN_OS_TITLE, minOSTitle,
  225. + sizeof(minOSTitle) / sizeof(minOSTitle[0]));
  226. + LoadStringW(NULL, IDS_MIN_OS_TEXT, minOSText,
  227. + sizeof(minOSText) / sizeof(minOSText[0]));
  228. + MessageBoxW(NULL, minOSText, minOSTitle, MB_OK | MB_ICONERROR);
  229. + return 1;
  230. + }
  231. + /* END Mozilla customizations */
  232. +
  233. g_hInstance = (HINSTANCE)hInstance;
  234. NT_CHECK
  235. - #ifdef _WIN32
  236. - LoadSecurityDlls();
  237. - #endif
  238. + // BEGIN Mozilla customizations
  239. + // Our AutoLoadSystemDependencies (see above) does the same job as the
  240. + // LoadSecurityDlls function, but slightly better because it runs as a static
  241. + // initializer, and it doesn't include LOAD_LIBRARY_SEARCH_USER_DIRS in
  242. + // the search path, which partially defeats the purpose of calling
  243. + // SetDefaultDllDirectories at all.
  244. + //#ifdef _WIN32
  245. + //LoadSecurityDlls();
  246. + //#endif
  247. + // END Mozilla customizations
  248. // InitCommonControls();
  249. @@ -172,6 +367,18 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
  250. UString dirPrefix ("." STRING_PATH_SEPARATOR);
  251. UString appLaunched;
  252. bool showProgress = true;
  253. +
  254. + /* BEGIN Mozilla customizations */
  255. + bool extractOnly = false;
  256. + if (switches.IsPrefixedBy_NoCase(L"/extractdir=")) {
  257. + assumeYes = true;
  258. + showProgress = false;
  259. + extractOnly = true;
  260. + } else if (!switches.IsEmpty()) {
  261. + showProgress = false;
  262. + }
  263. + /* END Mozilla customizations */
  264. +
  265. if (!config.IsEmpty())
  266. {
  267. CObjectVector<CTextConfigPair> pairs;
  268. @@ -204,7 +411,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
  269. }
  270. CTempDir tempDir;
  271. - if (!tempDir.Create(kTempDirPrefix))
  272. + /* Mozilla customizations - Added !extractOnly */
  273. + if (!extractOnly && !tempDir.Create(kTempDirPrefix))
  274. {
  275. if (!assumeYes)
  276. ShowErrorMessage(L"Can not create temp folder archive");
  277. @@ -222,7 +430,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
  278. }
  279. }
  280. - const FString tempDirPath = tempDir.GetPath();
  281. + /* BEGIN Mozilla customizations - added extractOnly parameter support */
  282. + const FString tempDirPath = extractOnly ? switches.Ptr(12) : GetUnicodeString(tempDir.GetPath());
  283. + /* END Mozilla customizations */
  284. // tempDirPath = L"M:\\1\\"; // to test low disk space
  285. {
  286. bool isCorrupt = false;
  287. @@ -250,6 +460,28 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
  288. }
  289. }
  290. + /* BEGIN Mozilla customizations */
  291. + // Retrieve and store any data added to this file after signing.
  292. + {
  293. + AString postSigningData;
  294. + if (ReadPostSigningData(fullPath, postSigningData)) {
  295. + FString postSigningDataFilePath(tempDirPath);
  296. + NFile::NName::NormalizeDirPathPrefix(postSigningDataFilePath);
  297. + postSigningDataFilePath += L"postSigningData";
  298. +
  299. + NFile::NIO::COutFile postSigningDataFile;
  300. + postSigningDataFile.Create(postSigningDataFilePath, true);
  301. +
  302. + UInt32 written = 0;
  303. + postSigningDataFile.Write(postSigningData, postSigningData.Len(), written);
  304. + }
  305. + }
  306. +
  307. + if (extractOnly) {
  308. + return 0;
  309. + }
  310. + /* END Mozilla customizations */
  311. +
  312. #ifndef UNDER_CE
  313. CCurrentDirRestorer currentDirRestorer;
  314. if (!SetCurrentDir(tempDirPath))
  315. diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h
  316. index 533197e..975d779 100644
  317. --- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h
  318. +++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h
  319. @@ -4,3 +4,5 @@
  320. #define IDS_EXTRACTION_ERROR_MESSAGE 8
  321. #define IDS_CANNOT_CREATE_FOLDER 3003
  322. #define IDS_PROGRESS_EXTRACTING 3300
  323. +#define IDS_MIN_OS_TITLE 70
  324. +#define IDS_MIN_OS_TEXT 71
  325. diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc
  326. index 9e88fd4..9fda0d0 100644
  327. --- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc
  328. +++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc
  329. @@ -11,6 +11,8 @@ BEGIN
  330. IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt"
  331. IDS_CANNOT_CREATE_FOLDER "Cannot create folder '{0}'"
  332. IDS_PROGRESS_EXTRACTING "Extracting"
  333. + IDS_MIN_OS_TITLE "Setup Error"
  334. + IDS_MIN_OS_TEXT "Microsoft Windows 7 or newer is required."
  335. END
  336. #include "../../UI/FileManager/ProgressDialog.rc"
  337. diff --git a/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp b/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp
  338. index 27d42b2..9b61369 100644
  339. --- a/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp
  340. +++ b/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp
  341. @@ -165,7 +165,8 @@ bool CProgressDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
  342. bool paused = Sync.GetPaused();
  343. Sync.SetPaused(true);
  344. _inCancelMessageBox = true;
  345. - int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL);
  346. + // Mozilla Customization - Removed redundant cancel button from dialog.
  347. + int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNO);
  348. _inCancelMessageBox = false;
  349. Sync.SetPaused(paused);
  350. if (res == IDCANCEL || res == IDNO)