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