1diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
2--- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
3+++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp
4@@ -49,17 +49,17 @@ RSC=rc.exe
5 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
6 # ADD BASE RSC /l 0x419 /d "NDEBUG"
7 # ADD RSC /l 0x419 /d "NDEBUG"
8 BSC32=bscmake.exe
9 # ADD BASE BSC32 /nologo
10 # ADD BSC32 /nologo
11 LINK32=link.exe
12 # 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
13-# 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
14+# 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
15 # SUBTRACT LINK32 /pdb:none
16
17 !ELSEIF  "$(CFG)" == "SFXSetup - Win32 Debug"
18
19 # PROP BASE Use_MFC 0
20 # PROP BASE Use_Debug_Libraries 1
21 # PROP BASE Output_Dir "Debug"
22 # PROP BASE Intermediate_Dir "Debug"
23@@ -76,17 +76,17 @@ LINK32=link.exe
24 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
25 # ADD BASE RSC /l 0x419 /d "_DEBUG"
26 # ADD RSC /l 0x419 /d "_DEBUG"
27 BSC32=bscmake.exe
28 # ADD BASE BSC32 /nologo
29 # ADD BSC32 /nologo
30 LINK32=link.exe
31 # 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
32-# 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
33+# 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
34
35 !ELSEIF  "$(CFG)" == "SFXSetup - Win32 ReleaseD"
36
37 # PROP BASE Use_MFC 0
38 # PROP BASE Use_Debug_Libraries 0
39 # PROP BASE Output_Dir "ReleaseD"
40 # PROP BASE Intermediate_Dir "ReleaseD"
41 # PROP BASE Ignore_Export_Lib 0
42@@ -102,19 +102,19 @@ LINK32=link.exe
43 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
44 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
45 # ADD BASE RSC /l 0x419 /d "NDEBUG"
46 # ADD RSC /l 0x419 /d "NDEBUG"
47 BSC32=bscmake.exe
48 # ADD BASE BSC32 /nologo
49 # ADD BSC32 /nologo
50 LINK32=link.exe
51-# 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"
52+# 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"
53 # SUBTRACT BASE LINK32 /debug /nodefaultlib
54-# 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
55+# 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
56 # SUBTRACT LINK32 /pdb:none
57
58 !ENDIF
59
60 # Begin Target
61
62 # Name "SFXSetup - Win32 Release"
63 # Name "SFXSetup - Win32 Debug"
64diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
65--- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
66+++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
67@@ -120,31 +120,226 @@ static void ShowErrorMessageSpec(const U
68   if (pos >= 0)
69   {
70     message.Delete(pos, 2);
71     message.Insert(pos, name);
72   }
73   ShowErrorMessage(NULL, message);
74 }
75
76+/* BEGIN Mozilla customizations */
77+
78+static char const *
79+FindStrInBuf(char const * buf, size_t bufLen, char const * str)
80+{
81+  size_t index = 0;
82+  while (index < bufLen) {
83+    char const * result = strstr(buf + index, str);
84+    if (result) {
85+      return result;
86+    }
87+    while ((buf[index] != '\0') && (index < bufLen)) {
88+      index++;
89+    }
90+    index++;
91+  }
92+  return NULL;
93+}
94+
95+static bool
96+ReadPostSigningDataFromView(char const * view, DWORD size, AString& data)
97+{
98+  // Find the offset and length of the certificate table,
99+  // so we know the valid range to look for the token.
100+  if (size < (0x3c + sizeof(UInt32))) {
101+    return false;
102+  }
103+  UInt32 PEHeaderOffset = *(UInt32*)(view + 0x3c);
104+  UInt32 optionalHeaderOffset = PEHeaderOffset + 24;
105+  UInt32 certDirEntryOffset = 0;
106+  if (size < (optionalHeaderOffset + sizeof(UInt16))) {
107+    return false;
108+  }
109+  UInt16 magic = *(UInt16*)(view + optionalHeaderOffset);
110+  if (magic == 0x010b) {
111+    // 32-bit executable
112+    certDirEntryOffset = optionalHeaderOffset + 128;
113+  } else if (magic == 0x020b) {
114+    // 64-bit executable; certain header fields are wider
115+    certDirEntryOffset = optionalHeaderOffset + 144;
116+  } else {
117+    // Unknown executable
118+    return false;
119+  }
120+  if (size < certDirEntryOffset + 8) {
121+    return false;
122+  }
123+  UInt32 certTableOffset = *(UInt32*)(view + certDirEntryOffset);
124+  UInt32 certTableLen = *(UInt32*)(view + certDirEntryOffset + sizeof(UInt32));
125+  if (certTableOffset == 0 || certTableLen == 0 ||
126+      size < (certTableOffset + certTableLen)) {
127+    return false;
128+  }
129+
130+  char const token[] = "__MOZCUSTOM__:";
131+  // We're searching for a string inside a binary blob,
132+  // so a normal strstr that bails on the first NUL won't work.
133+  char const * tokenPos = FindStrInBuf(view + certTableOffset,
134+                                       certTableLen, token);
135+  if (tokenPos) {
136+    size_t tokenLen = (sizeof(token) / sizeof(token[0])) - 1;
137+    data = AString(tokenPos + tokenLen);
138+    return true;
139+  }
140+  return false;
141+}
142+
143+static bool
144+ReadPostSigningData(UString exePath, AString& data)
145+{
146+  bool retval = false;
147+  HANDLE exeFile = CreateFileW(exePath, GENERIC_READ, FILE_SHARE_READ, NULL,
148+                               OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
149+  if (exeFile != INVALID_HANDLE_VALUE) {
150+    HANDLE mapping = CreateFileMapping(exeFile, NULL, PAGE_READONLY, 0, 0, NULL);
151+    if (mapping != INVALID_HANDLE_VALUE) {
152+      // MSDN claims the return value on failure is NULL,
153+      // but I've also seen it returned on success, so double-check.
154+      if (mapping || GetLastError() == ERROR_SUCCESS) {
155+        char * view = (char*)MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
156+        if (view) {
157+          DWORD fileSize = GetFileSize(exeFile, NULL);
158+          retval = ReadPostSigningDataFromView(view, fileSize, data);
159+        }
160+        CloseHandle(mapping);
161+      }
162+    }
163+    CloseHandle(exeFile);
164+  }
165+  return retval;
166+}
167+
168+// Delayed load libraries are loaded when the first symbol is used.
169+// The following ensures that we load the delayed loaded libraries from the
170+// system directory.
171+struct AutoLoadSystemDependencies
172+{
173+  AutoLoadSystemDependencies()
174+  {
175+    HMODULE module = ::GetModuleHandleW(L"kernel32.dll");
176+    if (module) {
177+      // SetDefaultDllDirectories is always available on Windows 8 and above. It
178+      // is also available on Windows Vista, Windows Server 2008, and
179+      // Windows 7 when MS KB2533623 has been applied.
180+      typedef BOOL (WINAPI *SetDefaultDllDirectoriesType)(DWORD);
181+      SetDefaultDllDirectoriesType setDefaultDllDirectories =
182+        (SetDefaultDllDirectoriesType) GetProcAddress(module, "SetDefaultDllDirectories");
183+      if (setDefaultDllDirectories) {
184+        setDefaultDllDirectories(0x0800 /* LOAD_LIBRARY_SEARCH_SYSTEM32 */ );
185+        return;
186+      }
187+    }
188+
189+    static LPCWSTR delayDLLs[] = { L"uxtheme.dll", L"userenv.dll",
190+                                   L"setupapi.dll", L"apphelp.dll",
191+                                   L"propsys.dll", L"dwmapi.dll",
192+                                   L"cryptbase.dll", L"oleacc.dll",
193+                                   L"clbcatq.dll" };
194+    WCHAR systemDirectory[MAX_PATH + 1] = { L'\0' };
195+    // If GetSystemDirectory fails we accept that we'll load the DLLs from the
196+    // normal search path.
197+    GetSystemDirectoryW(systemDirectory, MAX_PATH + 1);
198+    size_t systemDirLen = wcslen(systemDirectory);
199+
200+    // Make the system directory path terminate with a slash
201+    if (systemDirectory[systemDirLen - 1] != L'\\' && systemDirLen) {
202+      systemDirectory[systemDirLen] = L'\\';
203+      ++systemDirLen;
204+      // No need to re-NULL terminate
205+    }
206+
207+    // For each known DLL ensure it is loaded from the system32 directory
208+    for (size_t i = 0; i < sizeof(delayDLLs) / sizeof(delayDLLs[0]); ++i) {
209+      size_t fileLen = wcslen(delayDLLs[i]);
210+      wcsncpy(systemDirectory + systemDirLen, delayDLLs[i],
211+      MAX_PATH - systemDirLen);
212+      if (systemDirLen + fileLen <= MAX_PATH) {
213+        systemDirectory[systemDirLen + fileLen] = L'\0';
214+      } else {
215+        systemDirectory[MAX_PATH] = L'\0';
216+      }
217+      LPCWSTR fullModulePath = systemDirectory; // just for code readability
218+      LoadLibraryW(fullModulePath);
219+    }
220+  }
221+} loadDLLs;
222+
223+BOOL
224+RemoveCurrentDirFromSearchPath()
225+{
226+  // kernel32.dll is in the knownDLL list so it is safe to load without a full path
227+  HMODULE kernel32 = LoadLibraryW(L"kernel32.dll");
228+  if (!kernel32) {
229+    return FALSE;
230+  }
231+
232+  typedef BOOL (WINAPI *SetDllDirectoryType)(LPCWSTR);
233+  SetDllDirectoryType SetDllDirectoryFn =
234+    (SetDllDirectoryType)GetProcAddress(kernel32, "SetDllDirectoryW");
235+  if (!SetDllDirectoryFn) {
236+    FreeLibrary(kernel32);
237+    return FALSE;
238+  }
239+
240+  // If this call fails we can't do much about it, so ignore it.
241+  // It is unlikely to fail and this is just a precaution anyway.
242+  SetDllDirectoryFn(L"");
243+  FreeLibrary(kernel32);
244+  return TRUE;
245+}
246+
247+/* END Mozilla customizations */
248+
249 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
250     #ifdef UNDER_CE
251     LPWSTR
252     #else
253     LPSTR
254     #endif
255     /* lpCmdLine */,int /* nCmdShow */)
256 {
257+  /* BEGIN Mozilla customizations */
258+  // Disable current directory from being in the search path.
259+  // This call does not help with implicitly loaded DLLs.
260+  if (!RemoveCurrentDirFromSearchPath()) {
261+    WCHAR minOSTitle[512] = { '\0' };
262+    WCHAR minOSText[512] = { '\0' };
263+    LoadStringW(NULL, IDS_MIN_OS_TITLE, minOSTitle,
264+                sizeof(minOSTitle) / sizeof(minOSTitle[0]));
265+    LoadStringW(NULL, IDS_MIN_OS_TEXT, minOSText,
266+                sizeof(minOSText) / sizeof(minOSText[0]));
267+    MessageBoxW(NULL, minOSText, minOSTitle, MB_OK | MB_ICONERROR);
268+    return 1;
269+  }
270+  /* END Mozilla customizations */
271+
272   g_hInstance = (HINSTANCE)hInstance;
273
274   NT_CHECK
275
276-  #ifdef _WIN32
277-  LoadSecurityDlls();
278-  #endif
279+  // BEGIN Mozilla customizations
280+  // Our AutoLoadSystemDependencies (see above) does the same job as the
281+  // LoadSecurityDlls function, but slightly better because it runs as a static
282+  // initializer, and it doesn't include LOAD_LIBRARY_SEARCH_USER_DIRS in
283+  // the search path, which partially defeats the purpose of calling
284+  // SetDefaultDllDirectories at all.
285+  //#ifdef _WIN32
286+  //LoadSecurityDlls();
287+  //#endif
288+  // END Mozilla customizations
289
290   // InitCommonControls();
291
292   UString archiveName, switches;
293   #ifdef _SHELL_EXECUTE
294   UString executeFile, executeParameters;
295   #endif
296   NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches);
297@@ -167,16 +362,30 @@ int APIENTRY WinMain(HINSTANCE hInstance
298     if (!assumeYes)
299       ShowErrorMessage(L"Can't load config info");
300     return 1;
301   }
302
303   UString dirPrefix ("." STRING_PATH_SEPARATOR);
304   UString appLaunched;
305   bool showProgress = true;
306+
307+  /* BEGIN Mozilla customizations */
308+  bool extractOnly = false;
309+  if (switches.IsPrefixedBy_NoCase(L"-ms") ||
310+      switches.IsPrefixedBy_NoCase(L"/ini") ||
311+      switches.IsPrefixedBy_NoCase(L"/s")) {
312+    showProgress = false;
313+  } else if (switches.IsPrefixedBy_NoCase(L"/extractdir=")) {
314+    assumeYes = true;
315+    showProgress = false;
316+    extractOnly = true;
317+  }
318+  /* END Mozilla customizations */
319+
320   if (!config.IsEmpty())
321   {
322     CObjectVector<CTextConfigPair> pairs;
323     if (!GetTextConfig(config, pairs))
324     {
325       if (!assumeYes)
326         ShowErrorMessage(L"Config failed");
327       return 1;
328@@ -199,17 +408,18 @@ int APIENTRY WinMain(HINSTANCE hInstance
329
330     #ifdef _SHELL_EXECUTE
331     executeFile = GetTextConfigValue(pairs, "ExecuteFile");
332     executeParameters = GetTextConfigValue(pairs, "ExecuteParameters");
333     #endif
334   }
335
336   CTempDir tempDir;
337-  if (!tempDir.Create(kTempDirPrefix))
338+  /* Mozilla customizations - Added !extractOnly */
339+  if (!extractOnly && !tempDir.Create(kTempDirPrefix))
340   {
341     if (!assumeYes)
342       ShowErrorMessage(L"Can not create temp folder archive");
343     return 1;
344   }
345
346   CCodecs *codecs = new CCodecs;
347   CMyComPtr<IUnknown> compressCodecsInfo = codecs;
348@@ -217,17 +427,19 @@ int APIENTRY WinMain(HINSTANCE hInstance
349     HRESULT result = codecs->Load();
350     if (result != S_OK)
351     {
352       ShowErrorMessage(L"Can not load codecs");
353       return 1;
354     }
355   }
356
357-  const FString tempDirPath = tempDir.GetPath();
358+  /* BEGIN Mozilla customizations - added extractOnly  parameter support */
359+  const FString tempDirPath = extractOnly ? switches.Ptr(12) : GetUnicodeString(tempDir.GetPath());
360+  /* END Mozilla customizations */
361   // tempDirPath = L"M:\\1\\"; // to test low disk space
362   {
363     bool isCorrupt = false;
364     UString errorMessage;
365     HRESULT result = ExtractArchive(codecs, fullPath, tempDirPath, showProgress,
366       isCorrupt, errorMessage);
367
368     if (result != S_OK)
369@@ -245,16 +457,38 @@ int APIENTRY WinMain(HINSTANCE hInstance
370             errorMessage = NError::MyFormatMessage(result);
371           ::MessageBoxW(0, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR);
372         }
373       }
374       return 1;
375     }
376   }
377
378+  /* BEGIN Mozilla customizations */
379+  // Retrieve and store any data added to this file after signing.
380+  {
381+    AString postSigningData;
382+    if (ReadPostSigningData(fullPath, postSigningData)) {
383+      FString postSigningDataFilePath(tempDirPath);
384+      NFile::NName::NormalizeDirPathPrefix(postSigningDataFilePath);
385+      postSigningDataFilePath += L"postSigningData";
386+
387+      NFile::NIO::COutFile postSigningDataFile;
388+      postSigningDataFile.Create(postSigningDataFilePath, true);
389+
390+      UInt32 written = 0;
391+      postSigningDataFile.Write(postSigningData, postSigningData.Len(), written);
392+    }
393+  }
394+
395+  if (extractOnly) {
396+    return 0;
397+  }
398+  /* END Mozilla customizations */
399+
400   #ifndef UNDER_CE
401   CCurrentDirRestorer currentDirRestorer;
402   if (!SetCurrentDir(tempDirPath))
403     return 1;
404   #endif
405
406   HANDLE hProcess = 0;
407 #ifdef _SHELL_EXECUTE
408diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h
409--- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h
410+++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.h
411@@ -1,6 +1,8 @@
412 #define IDI_ICON  1
413
414 #define IDS_EXTRACTION_ERROR_TITLE       7
415 #define IDS_EXTRACTION_ERROR_MESSAGE     8
416 #define IDS_CANNOT_CREATE_FOLDER      3003
417 #define IDS_PROGRESS_EXTRACTING       3300
418+#define IDS_MIN_OS_TITLE                70
419+#define IDS_MIN_OS_TEXT                 71
420diff --git a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc
421--- a/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc
422+++ b/other-licenses/7zstub/src/CPP/7zip/Bundles/SFXSetup/resource.rc
423@@ -6,11 +6,13 @@ MY_VERSION_INFO_APP("7z Setup SFX", "7zS
424 IDI_ICON  ICON "setup.ico"
425
426 STRINGTABLE
427 BEGIN
428   IDS_EXTRACTION_ERROR_TITLE  "Extraction Failed"
429   IDS_EXTRACTION_ERROR_MESSAGE  "File is corrupt"
430   IDS_CANNOT_CREATE_FOLDER  "Cannot create folder '{0}'"
431   IDS_PROGRESS_EXTRACTING  "Extracting"
432+  IDS_MIN_OS_TITLE  "Setup Error"
433+  IDS_MIN_OS_TEXT  "Microsoft Windows 7 or newer is required."
434 END
435
436 #include "../../UI/FileManager/ProgressDialog.rc"
437diff --git a/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp b/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp
438--- a/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp
439+++ b/other-licenses/7zstub/src/CPP/7zip/UI/FileManager/ProgressDialog.cpp
440@@ -160,17 +160,18 @@ bool CProgressDialog::OnButtonClicked(in
441 {
442   switch (buttonID)
443   {
444     case IDCANCEL:
445     {
446       bool paused = Sync.GetPaused();
447       Sync.SetPaused(true);
448       _inCancelMessageBox = true;
449-      int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL);
450+      // Mozilla Customization - Removed redundant cancel button from dialog.
451+      int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNO);
452       _inCancelMessageBox = false;
453       Sync.SetPaused(paused);
454       if (res == IDCANCEL || res == IDNO)
455       {
456         if (_externalCloseMessageWasReceived)
457           OnExternalCloseMessage();
458         return true;
459       }
460