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