From: <sv...@op...> - 2024-12-07 18:55:18
|
Author: sagamusix Date: Sat Dec 7 19:55:03 2024 New Revision: 22479 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22479 Log: [Var] Update to unrar 7.1.2. Added: trunk/OpenMPT/include/unrar/largepage.cpp (contents, props changed) trunk/OpenMPT/include/unrar/largepage.hpp (contents, props changed) trunk/OpenMPT/include/unrar/motw.cpp (contents, props changed) trunk/OpenMPT/include/unrar/motw.hpp (contents, props changed) Modified: trunk/OpenMPT/build/premake/ext-UnRAR.lua trunk/OpenMPT/build/vs2017winxp/ext/UnRAR.vcxproj trunk/OpenMPT/build/vs2017winxpansi/ext/UnRAR.vcxproj trunk/OpenMPT/build/vs2019win7/ext/UnRAR.vcxproj trunk/OpenMPT/build/vs2022win10/ext/UnRAR.vcxproj trunk/OpenMPT/build/vs2022win10clang/ext/UnRAR.vcxproj trunk/OpenMPT/build/vs2022win7/ext/UnRAR.vcxproj trunk/OpenMPT/build/vs2022win8/ext/UnRAR.vcxproj trunk/OpenMPT/build/vs2022win81/ext/UnRAR.vcxproj trunk/OpenMPT/include/unrar/OpenMPT.txt trunk/OpenMPT/include/unrar/arccmt.cpp trunk/OpenMPT/include/unrar/archive.cpp trunk/OpenMPT/include/unrar/archive.hpp trunk/OpenMPT/include/unrar/arcread.cpp trunk/OpenMPT/include/unrar/blake2s.hpp trunk/OpenMPT/include/unrar/cmddata.cpp trunk/OpenMPT/include/unrar/cmddata.hpp trunk/OpenMPT/include/unrar/cmdmix.cpp trunk/OpenMPT/include/unrar/consio.cpp trunk/OpenMPT/include/unrar/consio.hpp trunk/OpenMPT/include/unrar/crypt.hpp trunk/OpenMPT/include/unrar/dll.cpp trunk/OpenMPT/include/unrar/dll.hpp trunk/OpenMPT/include/unrar/errhnd.hpp trunk/OpenMPT/include/unrar/extinfo.hpp trunk/OpenMPT/include/unrar/extract.cpp trunk/OpenMPT/include/unrar/extract.hpp trunk/OpenMPT/include/unrar/filefn.cpp trunk/OpenMPT/include/unrar/filefn.hpp trunk/OpenMPT/include/unrar/hash.cpp trunk/OpenMPT/include/unrar/hash.hpp trunk/OpenMPT/include/unrar/list.cpp trunk/OpenMPT/include/unrar/loclang.hpp trunk/OpenMPT/include/unrar/options.hpp trunk/OpenMPT/include/unrar/os.hpp trunk/OpenMPT/include/unrar/rar.hpp trunk/OpenMPT/include/unrar/rardefs.hpp trunk/OpenMPT/include/unrar/smallfn.cpp trunk/OpenMPT/include/unrar/smallfn.hpp trunk/OpenMPT/include/unrar/system.cpp trunk/OpenMPT/include/unrar/system.hpp trunk/OpenMPT/include/unrar/timefn.hpp trunk/OpenMPT/include/unrar/ui.hpp trunk/OpenMPT/include/unrar/uiconsole.cpp trunk/OpenMPT/include/unrar/unicode.cpp trunk/OpenMPT/include/unrar/unpack.cpp trunk/OpenMPT/include/unrar/unpack.hpp trunk/OpenMPT/include/unrar/version.hpp trunk/OpenMPT/include/unrar/volume.cpp trunk/OpenMPT/include/unrar/win32acl.cpp trunk/OpenMPT/include/unrar/win32stm.cpp Modified: trunk/OpenMPT/build/premake/ext-UnRAR.lua ============================================================================== --- trunk/OpenMPT/build/premake/ext-UnRAR.lua Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/premake/ext-UnRAR.lua Sat Dec 7 19:55:03 2024 (r22479) @@ -38,6 +38,7 @@ "../../include/unrar/hash.cpp", "../../include/unrar/headers.cpp", "../../include/unrar/isnt.cpp", + "../../include/unrar/largepage.cpp", "../../include/unrar/list.cpp", "../../include/unrar/match.cpp", "../../include/unrar/options.cpp", @@ -91,6 +92,7 @@ "../../include/unrar/headers.hpp", "../../include/unrar/headers5.hpp", "../../include/unrar/isnt.hpp", + "../../include/unrar/largepage.hpp", "../../include/unrar/list.hpp", "../../include/unrar/loclang.hpp", "../../include/unrar/log.hpp", Modified: trunk/OpenMPT/build/vs2017winxp/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2017winxp/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2017winxp/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -614,6 +614,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -677,6 +678,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/build/vs2017winxpansi/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2017winxpansi/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2017winxpansi/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -614,6 +614,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -677,6 +678,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/build/vs2019win7/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2019win7/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2019win7/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -623,6 +623,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -686,6 +687,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/build/vs2022win10/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2022win10/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2022win10/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -1553,6 +1553,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -1616,6 +1617,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/build/vs2022win10clang/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2022win10clang/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2022win10clang/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -1187,6 +1187,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -1250,6 +1251,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/build/vs2022win7/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2022win7/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2022win7/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -635,6 +635,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -698,6 +699,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/build/vs2022win8/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2022win8/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2022win8/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -935,6 +935,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -998,6 +999,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/build/vs2022win81/ext/UnRAR.vcxproj ============================================================================== --- trunk/OpenMPT/build/vs2022win81/ext/UnRAR.vcxproj Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/build/vs2022win81/ext/UnRAR.vcxproj Sat Dec 7 19:55:03 2024 (r22479) @@ -935,6 +935,7 @@ <ClInclude Include="..\..\..\include\unrar\headers.hpp" /> <ClInclude Include="..\..\..\include\unrar\headers5.hpp" /> <ClInclude Include="..\..\..\include\unrar\isnt.hpp" /> + <ClInclude Include="..\..\..\include\unrar\largepage.hpp" /> <ClInclude Include="..\..\..\include\unrar\list.hpp" /> <ClInclude Include="..\..\..\include\unrar\loclang.hpp" /> <ClInclude Include="..\..\..\include\unrar\log.hpp" /> @@ -998,6 +999,7 @@ <ClCompile Include="..\..\..\include\unrar\hash.cpp" /> <ClCompile Include="..\..\..\include\unrar\headers.cpp" /> <ClCompile Include="..\..\..\include\unrar\isnt.cpp" /> + <ClCompile Include="..\..\..\include\unrar\largepage.cpp" /> <ClCompile Include="..\..\..\include\unrar\list.cpp" /> <ClCompile Include="..\..\..\include\unrar\match.cpp" /> <ClCompile Include="..\..\..\include\unrar\options.cpp" /> Modified: trunk/OpenMPT/include/unrar/OpenMPT.txt ============================================================================== --- trunk/OpenMPT/include/unrar/OpenMPT.txt Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/OpenMPT.txt Sat Dec 7 19:55:03 2024 (r22479) @@ -1,4 +1,4 @@ -This folder is based on https://rarlab.com/rar/unrarsrc-7.0.9.tar.gz +This folder is based on https://rarlab.com/rar/unrarsrc-7.1.2.tar.gz All modifications to existing files have been done in a manner so that no existing lines were edited; only new lines were added. @@ -11,7 +11,7 @@ The following files have been modified: extract.cpp, filcreat.cpp, file.cpp, filefn.cpp, find.cpp, match.cpp, -os.hpp, pathfn.cpp, rdwrfn.cpp, secpassword.cpp, volume.cpp, +os.hpp, pathfn.cpp, rardefs.hpp, rdwrfn.cpp, secpassword.cpp, volume.cpp, win32acl.cpp, win32lnk.cpp For building, premake is used to generate Visual Studio project files. Modified: trunk/OpenMPT/include/unrar/arccmt.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/arccmt.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/arccmt.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -36,7 +36,12 @@ { // Current (RAR 3.0+) version of archive comment. Seek(GetStartPos(),SEEK_SET); - return SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData); + if (SearchSubBlock(SUBHEAD_TYPE_CMT)!=0) + if (ReadCommentData(CmtData)) + return true; + else + uiMsg(UIERROR_CMTBROKEN,FileName); + return false; } #ifndef SFX_MODULE // Old style (RAR 2.9) comment header embedded into the main Modified: trunk/OpenMPT/include/unrar/archive.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/archive.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/archive.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -67,7 +67,7 @@ // password is incorrect. if (!FailedHeaderDecryption) uiMsg(UIERROR_BADARCHIVE,FileName); - ErrHandler.Exit(RARX_FATAL); + ErrHandler.Exit(RARX_BADARC); } } @@ -109,9 +109,11 @@ // We check the last signature byte, so we can return a sensible // warning in case we'll want to change the archive format // sometimes in the future. +#ifndef SFX_MODULE if (D[6]==0) Type=RARFMT15; else +#endif if (D[6]==1) Type=RARFMT50; else Modified: trunk/OpenMPT/include/unrar/archive.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/archive.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/archive.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -58,7 +58,7 @@ bool ProhibitQOpen; #endif public: - Archive(CommandData *InitCmd=NULL); + Archive(CommandData *InitCmd=nullptr); ~Archive(); static RARFORMAT IsSignature(const byte *D,size_t Size); bool IsArchive(bool EnableBroken); @@ -147,6 +147,9 @@ bool NewArchive; std::wstring FirstVolumeName; +#ifdef PROPAGATE_MOTW + MarkOfTheWeb Motw; +#endif }; Modified: trunk/OpenMPT/include/unrar/arcread.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/arcread.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/arcread.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -20,10 +20,10 @@ case RARFMT14: ReadSize=ReadHeader14(); break; -#endif case RARFMT15: ReadSize=ReadHeader15(); break; +#endif case RARFMT50: ReadSize=ReadHeader50(); break; @@ -106,6 +106,9 @@ if (CurBlockPos!=ArcSize || NextBlockPos!=ArcSize) { uiMsg(UIERROR_UNEXPEOF,FileName); + if (CurHeaderType!=HEAD_FILE) + uiMsg(UIERROR_TRUNCSERVICE,FileName,SubHead.FileName); + ErrHandler.SetErrorCode(RARX_WARNING); } } @@ -137,6 +140,7 @@ } +#ifndef SFX_MODULE size_t Archive::ReadHeader15() { RawRead Raw(this); @@ -145,7 +149,7 @@ if (Decrypt) { -#ifdef RAR_NOCRYPT // For rarext.dll and unrar_nocrypt.dll. +#ifdef RAR_NOCRYPT // For rarext.dll, Setup.SFX and unrar_nocrypt.dll. return 0; #else RequestArcPassword(NULL); @@ -545,6 +549,7 @@ return Raw.Size(); } +#endif // #ifndef SFX_MODULE size_t Archive::ReadHeader50() @@ -740,10 +745,15 @@ byte csum[SIZE_PSWCHECK_CSUM]; Raw.GetB(csum,SIZE_PSWCHECK_CSUM); +// Exclude this code for rarext.dll, Setup.SFX and unrar_nocrypt.dll linked +// without sha256. But still set Encrypted=true for rarext.dll here, +// so it can recognize encrypted header archives in archive properties. +#ifndef RAR_NOCRYPT byte Digest[SHA256_DIGEST_SIZE]; sha256_get(CryptHead.PswCheck, SIZE_PSWCHECK, Digest); CryptHead.UsePswCheck=memcmp(csum,Digest,SIZE_PSWCHECK_CSUM)==0; +#endif } Encrypted=true; } @@ -1036,22 +1046,30 @@ FileHeader *hd=(FileHeader *)bb; switch(FieldType) { +#ifndef RAR_NOCRYPT // Except rarext.dll, Setup.SFX and unrar_nocrypt.dll. case FHEXTRA_CRYPT: { FileHeader *hd=(FileHeader *)bb; uint EncVersion=(uint)Raw->GetV(); if (EncVersion>CRYPT_VERSION) + { UnkEncVerMsg(hd->FileName,L"x" + std::to_wstring(EncVersion)); + hd->CryptMethod=CRYPT_UNKNOWN; + } else { uint Flags=(uint)Raw->GetV(); - hd->UsePswCheck=(Flags & FHEXTRA_CRYPT_PSWCHECK)!=0; - hd->UseHashKey=(Flags & FHEXTRA_CRYPT_HASHMAC)!=0; hd->Lg2Count=Raw->Get1(); if (hd->Lg2Count>CRYPT5_KDF_LG2_COUNT_MAX) + { UnkEncVerMsg(hd->FileName,L"xc" + std::to_wstring(hd->Lg2Count)); + hd->CryptMethod=CRYPT_UNKNOWN; + } else { + hd->UsePswCheck=(Flags & FHEXTRA_CRYPT_PSWCHECK)!=0; + hd->UseHashKey=(Flags & FHEXTRA_CRYPT_HASHMAC)!=0; + Raw->GetB(hd->Salt,SIZE_SALT50); Raw->GetB(hd->InitV,SIZE_INITV); if (hd->UsePswCheck) @@ -1085,6 +1103,7 @@ } } break; +#endif case FHEXTRA_HASH: { FileHeader *hd=(FileHeader *)bb; Modified: trunk/OpenMPT/include/unrar/blake2s.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/blake2s.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/blake2s.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -5,12 +5,9 @@ #define BLAKE2_DIGEST_SIZE 32 #define BLAKE2_THREADS_NUMBER 8 -enum blake2s_constant -{ - BLAKE2S_BLOCKBYTES = 64, - BLAKE2S_OUTBYTES = 32 -}; - +// Use constexpr instead of enums for -std=c++20 compatibility. +constexpr size_t BLAKE2S_BLOCKBYTES = 64; +constexpr size_t BLAKE2S_OUTBYTES = 32; // Alignment to 64 improves performance of both SSE and non-SSE versions. // Alignment to n*16 is required for SSE version, so we selected 64. Modified: trunk/OpenMPT/include/unrar/cmddata.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/cmddata.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/cmddata.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -38,6 +38,9 @@ InclArgs.Reset(); ArcNames.Reset(); StoreArgs.Reset(); +#ifdef PROPAGATE_MOTW + MotwList.Reset(); +#endif Password.Clean(); NextVolSizes.clear(); #ifdef RARDLL @@ -189,7 +192,7 @@ #if !defined(SFX_MODULE) void CommandData::ParseEnvVar() { - char *EnvVar=getenv("RAR"); + char *EnvVar=getenv("RARINISWITCHES"); if (EnvVar!=NULL) { std::wstring EnvStr; @@ -293,6 +296,9 @@ void CommandData::ProcessSwitch(const wchar *Switch) { + if (LargePageAlloc::ProcessSwitch(this,Switch)) + return; + switch(toupperw(Switch[0])) { case '@': @@ -619,8 +625,6 @@ } } break; - case 'M': - break; case 'D': { bool SetDictLimit=toupperw(Switch[2])=='X'; @@ -665,33 +669,30 @@ if (toupperw(Switch[2])=='S' && Switch[3]==0) SkipEncrypted=true; break; - case 'S': + case 'L': + if (toupperw(Switch[2])=='P') { - std::wstring StoreNames=(Switch[2]==0 ? DefaultStoreList:Switch+2); - size_t Pos=0; - while (Pos<StoreNames.size()) + UseLargePages=true; + if (!LargePageAlloc::IsPrivilegeAssigned() && LargePageAlloc::AssignConfirmation()) { - if (StoreNames[Pos]=='.') - Pos++; - size_t EndPos=StoreNames.find(';',Pos); - std::wstring Mask=StoreNames.substr(Pos,EndPos==std::wstring::npos ? EndPos:EndPos-Pos); - if (Mask.find_first_of(L"*?.")==std::wstring::npos) - Mask.insert(0,L"*."); - StoreArgs.AddString(Mask); - if (EndPos==std::wstring::npos) - break; - Pos=EndPos+1; + LargePageAlloc::AssignPrivilege(); + + // Quit immediately. We do not want to interrupt the current copy + // archive processing with reboot after assigning privilege. + SetupComplete=true; } } break; + case 'M': + break; + case 'S': + GetBriefMaskList(Switch[2]==0 ? DefaultStoreList:Switch+2,StoreArgs); + break; #ifdef RAR_SMP case 'T': Threads=atoiw(Switch+2); if (Threads>MaxPoolThreads || Threads<1) BadSwitch(Switch); - else - { - } break; #endif default: @@ -752,6 +753,18 @@ } break; #endif +#ifdef PROPAGATE_MOTW + case 'M': + { + MotwAllFields=Switch[2]=='1'; + const wchar *Sep=wcschr(Switch+2,'='); + if (Switch[2]=='-') + MotwList.Reset(); + else + GetBriefMaskList(Sep==nullptr ? L"*":Sep+1,MotwList); + } + break; +#endif #ifdef _WIN_ALL case 'N': if (toupperw(Switch[2])=='I') @@ -1033,6 +1046,11 @@ #ifndef SFX_MODULE const wchar *SingleCharCommands=L"FUADPXETK"; + + // RAR -mlp command is the legitimate way to assign the required privilege. + if (Command.empty() && UseLargePages || SetupComplete) + return; + if (Command[0]!=0 && Command[1]!=0 && wcschr(SingleCharCommands,Command[0])!=NULL || ArcName.empty()) OutHelp(Command.empty() ? RARX_SUCCESS:RARX_USERERROR); // Return 'success' for 'rar' without parameters. @@ -1231,5 +1249,25 @@ } +// Treat the list like rar;zip as *.rar;*.zip for -ms and similar switches. +void CommandData::GetBriefMaskList(const std::wstring &Masks,StringList &Args) +{ + size_t Pos=0; + while (Pos<Masks.size()) + { + if (Masks[Pos]=='.') + Pos++; + size_t EndPos=Masks.find(';',Pos); + std::wstring Mask=Masks.substr(Pos,EndPos==std::wstring::npos ? EndPos:EndPos-Pos); + if (Mask.find_first_of(L"*?.")==std::wstring::npos) + Mask.insert(0,L"*."); + Args.AddString(Mask); + if (EndPos==std::wstring::npos) + break; + Pos=EndPos+1; + } +} + + Modified: trunk/OpenMPT/include/unrar/cmddata.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/cmddata.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/cmddata.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -1,6 +1,12 @@ #ifndef _RAR_CMDDATA_ #define _RAR_CMDDATA_ +#if defined(_WIN_ALL) && !defined(SFX_MODULE) +// In Windows we implement our own command line parser to avoid replacing +// \" by " in standard parser. Such replacing corrupts destination paths +// like "dest path\" in extraction commands. +#define CUSTOM_CMDLINE_PARSER +#endif #define DefaultStoreList L"7z;ace;arj;bz2;cab;gz;jpeg;jpg;lha;lz;lzh;mp3;rar;taz;tbz;tbz2;tgz;txz;xz;z;zip;zipx;zst;tzst" @@ -56,6 +62,8 @@ void ReportWrongSwitches(RARFORMAT Format); #endif + void GetBriefMaskList(const std::wstring &Masks,StringList &Args); + std::wstring Command; std::wstring ArcName; @@ -78,6 +86,9 @@ StringList InclArgs; StringList ArcNames; StringList StoreArgs; +#ifdef PROPAGATE_MOTW + StringList MotwList; // Extensions to assign the mark of the web. +#endif SecPassword Password; Modified: trunk/OpenMPT/include/unrar/cmdmix.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/cmdmix.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/cmdmix.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -63,12 +63,12 @@ MCHelpSwAT,MCHelpSwAC,MCHelpSwAD,MCHelpSwAG,MCHelpSwAI,MCHelpSwAP, MCHelpSwCm,MCHelpSwCFGm,MCHelpSwCL,MCHelpSwCU,MCHelpSwDH,MCHelpSwEP, MCHelpSwEP3,MCHelpSwEP4,MCHelpSwF,MCHelpSwIDP,MCHelpSwIERR, - MCHelpSwINUL,MCHelpSwIOFF,MCHelpSwKB,MCHelpSwME,MCHelpSwN,MCHelpSwNa, - MCHelpSwNal,MCHelpSwO,MCHelpSwOC,MCHelpSwOL,MCHelpSwOP,MCHelpSwOR, - MCHelpSwOW,MCHelpSwP,MCHelpSwR,MCHelpSwRI,MCHelpSwSC,MCHelpSwSI, - MCHelpSwSL,MCHelpSwSM,MCHelpSwTA,MCHelpSwTB,MCHelpSwTN,MCHelpSwTO, - MCHelpSwTS,MCHelpSwU,MCHelpSwVUnr,MCHelpSwVER,MCHelpSwVP,MCHelpSwX, - MCHelpSwXa,MCHelpSwXal,MCHelpSwY + MCHelpSwINUL,MCHelpSwIOFF,MCHelpSwKB,MCHelpSwME,MCHelpSwMLP, + MCHelpSwN,MCHelpSwNa,MCHelpSwNal,MCHelpSwO,MCHelpSwOC,MCHelpSwOL, + MCHelpSwOM,MCHelpSwOP,MCHelpSwOR,MCHelpSwOW,MCHelpSwP,MCHelpSwR, + MCHelpSwRI,MCHelpSwSC,MCHelpSwSI,MCHelpSwSL,MCHelpSwSM,MCHelpSwTA, + MCHelpSwTB,MCHelpSwTN,MCHelpSwTO,MCHelpSwTS,MCHelpSwU,MCHelpSwVUnr, + MCHelpSwVER,MCHelpSwVP,MCHelpSwX,MCHelpSwXa,MCHelpSwXal,MCHelpSwY #endif }; @@ -80,7 +80,7 @@ #ifndef _WIN_ALL static MSGID Win32Only[]={ MCHelpSwIEML,MCHelpSwVD,MCHelpSwAO,MCHelpSwOS,MCHelpSwIOFF, - MCHelpSwEP2,MCHelpSwOC,MCHelpSwONI,MCHelpSwDR,MCHelpSwRI + MCHelpSwEP2,MCHelpSwMLP,MCHelpSwOC,MCHelpSwONI,MCHelpSwDR,MCHelpSwRI }; bool Found=false; for (uint J=0;J<ASIZE(Win32Only);J++) Modified: trunk/OpenMPT/include/unrar/consio.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/consio.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/consio.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -255,7 +255,7 @@ #ifndef SILENT -bool getwstr(std::wstring &str) +void getwstr(std::wstring &str) { // Print buffered prompt title function before waiting for input. fflush(stderr); @@ -281,8 +281,8 @@ if (ReadSize<=0) { // Looks like stdin is a null device. We can enter to infinite loop - // calling Ask(), so let's better exit. - ErrHandler.Exit(RARX_USERBREAK); + // calling Ask() or set an empty password, so let's better exit. + ErrHandler.ReadError(L"stdin"); } StrA[ReadSize]=0; @@ -297,20 +297,26 @@ else { std::vector<wchar> Buf(MaxRead); // Up to 4 UTF-8 characters per wchar_t. + DWORD SizeToRead=(DWORD)Buf.size()-1; + + // ReadConsole fails in Windows 7 for requested input exceeding 30 KB. + // Not certain about Windows 8, so check for Windows 10 here. + if (WinNT()<=WNT_W10) + SizeToRead=Min(SizeToRead,0x4000); + DWORD ReadSize=0; - if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE),&Buf[0],(DWORD)Buf.size()-1,&ReadSize,NULL)==0) - return false; + if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE),&Buf[0],SizeToRead,&ReadSize,NULL)==0) + ErrHandler.ReadError(L"stdin"); // Unknown user input, safer to abort. Buf[ReadSize]=0; str=Buf.data(); } #else std::vector<wchar> Buf(MaxRead); // Up to 4 UTF-8 characters per wchar_t. if (fgetws(&Buf[0],Buf.size(),stdin)==NULL) - ErrHandler.Exit(RARX_USERBREAK); // Avoid infinite Ask() loop. + ErrHandler.ReadError(L"stdin"); // Avoid infinite Ask() loop. str=Buf.data(); #endif RemoveLF(str); - return true; } #endif @@ -324,22 +330,22 @@ { uiAlarm(UIALARM_QUESTION); - const int MaxItems=10; + const uint MaxItems=10; wchar Item[MaxItems][40]; - int ItemKeyPos[MaxItems],NumItems=0; + uint ItemKeyPos[MaxItems],NumItems=0; - for (const wchar *NextItem=AskStr;NextItem!=NULL;NextItem=wcschr(NextItem+1,'_')) + for (const wchar *NextItem=AskStr;NextItem!=nullptr;NextItem=wcschr(NextItem+1,'_')) { wchar *CurItem=Item[NumItems]; wcsncpyz(CurItem,NextItem+1,ASIZE(Item[0])); wchar *EndItem=wcschr(CurItem,'_'); - if (EndItem!=NULL) + if (EndItem!=nullptr) *EndItem=0; - int KeyPos=0,CurKey; + uint KeyPos=0,CurKey; while ((CurKey=CurItem[KeyPos])!=0) { bool Found=false; - for (int I=0;I<NumItems && !Found;I++) + for (uint I=0;I<NumItems && !Found;I++) if (toupperw(Item[I][ItemKeyPos[I]])==toupperw(CurKey)) Found=true; if (!Found && CurKey!=' ') @@ -350,11 +356,11 @@ NumItems++; } - for (int I=0;I<NumItems;I++) + for (uint I=0;I<NumItems;I++) { eprintf(I==0 ? (NumItems>3 ? L"\n":L" "):L", "); - int KeyPos=ItemKeyPos[I]; - for (int J=0;J<KeyPos;J++) + uint KeyPos=ItemKeyPos[I]; + for (uint J=0;J<KeyPos;J++) eprintf(L"%c",Item[I][J]); eprintf(L"[%c]%ls",Item[I][KeyPos],&Item[I][KeyPos+1]); } @@ -362,7 +368,7 @@ std::wstring Str; getwstr(Str); wchar Ch=toupperw(Str[0]); - for (int I=0;I<NumItems;I++) + for (uint I=0;I<NumItems;I++) if (Ch==Item[I][ItemKeyPos[I]]) return I+1; return 0; Modified: trunk/OpenMPT/include/unrar/consio.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/consio.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/consio.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -16,13 +16,13 @@ inline void eprintf(const wchar *fmt,...) {} inline void Alarm() {} inline int Ask(const wchar *AskStr) {return 0;} - inline bool getwstr(std::wstring &str) {return false;} + inline void getwstr(std::wstring &str) {} #else void mprintf(const wchar *fmt,...); void eprintf(const wchar *fmt,...); void Alarm(); int Ask(const wchar *AskStr); - bool getwstr(std::wstring &str); + void getwstr(std::wstring &str); #endif #endif Modified: trunk/OpenMPT/include/unrar/crypt.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/crypt.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/crypt.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -3,7 +3,8 @@ enum CRYPT_METHOD { - CRYPT_NONE,CRYPT_RAR13,CRYPT_RAR15,CRYPT_RAR20,CRYPT_RAR30,CRYPT_RAR50 + CRYPT_NONE,CRYPT_RAR13,CRYPT_RAR15,CRYPT_RAR20,CRYPT_RAR30,CRYPT_RAR50, + CRYPT_UNKNOWN }; #define SIZE_SALT50 16 Modified: trunk/OpenMPT/include/unrar/dll.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/dll.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/dll.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -16,8 +16,7 @@ HANDLE PASCAL RAROpenArchive(struct RAROpenArchiveData *r) { - RAROpenArchiveDataEx rx; - memset(&rx,0,sizeof(rx)); + RAROpenArchiveDataEx rx{}; rx.ArcName=r->ArcName; rx.OpenMode=r->OpenMode; rx.CmtBuf=r->CmtBuf; @@ -32,7 +31,7 @@ HANDLE PASCAL RAROpenArchiveEx(struct RAROpenArchiveDataEx *r) { - DataSet *Data=NULL; + DataSet *Data=nullptr; try { ErrHandler.Clean(); @@ -74,7 +73,7 @@ { r->OpenResult=ERAR_EOPEN; delete Data; - return NULL; + return nullptr; } if (!Data->Arc.IsArchive(true)) { @@ -89,7 +88,7 @@ r->OpenResult=ERAR_BAD_ARCHIVE; } delete Data; - return NULL; + return nullptr; } r->Flags=0; @@ -115,7 +114,7 @@ std::wstring CmtDataW; if (r->CmtBufSize!=0 && Data->Arc.GetComment(CmtDataW)) { - if (r->CmtBufW!=NULL) + if (r->CmtBufW!=nullptr) { // CmtDataW.push_back(0); size_t Size=wcslen(CmtDataW.data())+1; @@ -141,6 +140,18 @@ else r->CmtState=r->CmtSize=0; +#ifdef PROPAGATE_MOTW + if (r->MarkOfTheWeb!=nullptr) + { + Data->Cmd.MotwAllFields=r->MarkOfTheWeb[0]=='1'; + const wchar *Sep=wcschr(r->MarkOfTheWeb,'='); + if (r->MarkOfTheWeb[0]=='-') + Data->Cmd.MotwList.Reset(); + else + Data->Cmd.GetBriefMaskList(Sep==nullptr ? L"*":Sep+1,Data->Cmd.MotwList); + } +#endif + Data->Extract.ExtractArchiveInit(Data->Arc); return (HANDLE)Data; } @@ -494,6 +505,8 @@ return ERAR_BAD_PASSWORD; case RARX_SUCCESS: return ERAR_SUCCESS; // 0. + case RARX_BADARC: + return ERAR_BAD_ARCHIVE; default: return ERAR_UNKNOWN; } Modified: trunk/OpenMPT/include/unrar/dll.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/dll.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/dll.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -157,7 +157,8 @@ LPARAM UserData; unsigned int OpFlags; wchar_t *CmtBufW; - unsigned int Reserved[25]; + wchar_t *MarkOfTheWeb; + unsigned int Reserved[23]; }; enum UNRARCALLBACK_MESSAGES { Modified: trunk/OpenMPT/include/unrar/errhnd.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/errhnd.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/errhnd.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -16,6 +16,7 @@ RARX_NOFILES = 10, RARX_BADPWD = 11, RARX_READ = 12, + RARX_BADARC = 13, RARX_USERBREAK = 255 }; Modified: trunk/OpenMPT/include/unrar/extinfo.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/extinfo.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/extinfo.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -11,10 +11,6 @@ std::wstring GetStreamNameNTFS(Archive &Arc); -#ifdef _WIN_ALL -bool SetPrivilege(LPCTSTR PrivName); -#endif - void SetExtraInfo20(CommandData *Cmd,Archive &Arc,const std::wstring &Name); void SetExtraInfo(CommandData *Cmd,Archive &Arc,const std::wstring &Name); void SetFileHeaderExtra(CommandData *Cmd,Archive &Arc,const std::wstring &Name); Modified: trunk/OpenMPT/include/unrar/extract.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/extract.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/extract.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -25,6 +25,7 @@ #ifdef RAR_SMP Unp->SetThreads(Cmd->Threads); #endif + Unp->AllowLargePages(Cmd->UseLargePages); } @@ -112,6 +113,15 @@ void CmdExtract::ExtractArchiveInit(Archive &Arc) { + if (Cmd->Command[0]=='T' || Cmd->Command[0]=='I') + Cmd->Test=true; + +#ifdef PROPAGATE_MOTW + // Invoke here, so it is also supported by unrar.dll. + if (!Cmd->Test && Cmd->MotwList.ItemsCount()>0) + Arc.Motw.ReadZoneIdStream(Arc.FileName,Cmd->MotwAllFields); +#endif + DataIO.AdjustTotalArcSize(&Arc); FileCount=0; @@ -178,12 +188,18 @@ } #endif - mprintf(St(MNotRAR),ArcName.c_str()); - + bool RarExt=false; #ifndef SFX_MODULE - if (CmpExt(ArcName,L"rar")) + RarExt=CmpExt(ArcName,L"rar"); #endif - ErrHandler.SetErrorCode(RARX_WARNING); + + if (RarExt) + uiMsg(UIERROR_BADARCHIVE,ArcName); // Non-archive .rar file. + else + mprintf(St(MNotRAR),ArcName.c_str()); // Non-archive not .rar file, likely in "rar x *.*". + + if (RarExt) + ErrHandler.SetErrorCode(RARX_BADARC); return EXTRACT_ARC_NEXT; } @@ -254,9 +270,6 @@ ExtractArchiveInit(Arc); - if (Cmd->Command[0]=='T' || Cmd->Command[0]=='I') - Cmd->Test=true; - if (Cmd->Command[0]=='I') { @@ -494,7 +507,7 @@ DestFileName=!Cmd->TempPath.empty() ? Cmd->TempPath:Cmd->ExtrPath; AddEndSlash(DestFileName); DestFileName+=L"__tmp_reference_source_"; - MkTemp(DestFileName); + MkTemp(DestFileName,nullptr); MatchedRef.TmpName=DestFileName; } RefTarget=true; // Need it even for 't' to test the reference source. @@ -555,6 +568,7 @@ return !Arc.Solid; // Can try extracting next file only in non-solid archive. } +#ifndef RAR_NOCRYPT // For rarext.dll, Setup.SFX and unrar_nocrypt.dll. if (Arc.FileHead.Encrypted) { RarCheckPassword CheckPwd; @@ -581,9 +595,9 @@ // Set a password before creating the file, so we can skip creating // in case of wrong password. SecPassword FilePassword=Cmd->Password; - #if defined(_WIN_ALL) && !defined(SFX_MODULE) +#if defined(_WIN_ALL) && !defined(SFX_MODULE) ConvertDosPassword(Arc,FilePassword); - #endif +#endif byte PswCheck[SIZE_PSWCHECK]; bool EncSet=DataIO.SetEncryption(false,Arc.FileHead.CryptMethod, @@ -611,16 +625,16 @@ // Avoid new requests for unrar.dll to prevent the infinite loop // if app always returns the same password. - #ifndef RARDLL +#ifndef RARDLL continue; // Request a password again. - #endif +#endif } - #ifdef RARDLL +#ifdef RARDLL // If we already have ERAR_EOPEN as result of missing volume, // we should not replace it with less precise ERAR_BAD_PASSWORD. if (Cmd->DllError!=ERAR_EOPEN) Cmd->DllError=ERAR_BAD_PASSWORD; - #endif +#endif ErrHandler.SetErrorCode(RARX_BADPWD); ExtrFile=false; } @@ -629,6 +643,7 @@ } else DataIO.SetEncryption(false,CRYPT_NONE,NULL,NULL,NULL,0,NULL,NULL); +#endif // RAR_NOCRYPT // Per file symlink conversion flag. Can be turned off in unrar.dll. bool CurConvertSymlinkPaths=ConvertSymlinkPaths; @@ -690,7 +705,29 @@ // any overwrite prompts. if (!CheckWinLimit(Arc,ArcFileName)) return false; - ExtrFile=ExtrCreateFile(Arc,CurFile); + + // Read+write mode is required to set "Compressed" attribute. + // Other than that prefer the write only mode to avoid + // OpenIndiana NAS problem with SetFileTime and read+write files. +#if defined(_WIN_ALL) && !defined(SFX_MODULE) + bool Compressed=Cmd->SetCompressedAttr && + (Arc.FileHead.FileAttr & FILE_ATTRIBUTE_COMPRESSED)!=0; + bool WriteOnly=!Compressed; +#else + bool WriteOnly=true; +#endif + + ExtrFile=ExtrCreateFile(Arc,CurFile,WriteOnly); + +#if defined(_WIN_ALL) && !defined(SFX_MODULE) + // 2024.03.12: Set early to compress written data immediately. + // For 10 GB text file it was ~1.5x faster than when set after close. + + if (ExtrFile && Compressed) + SetFileCompression(CurFile.GetHandle(),true); + +#endif + } if (!ExtrFile && Arc.Solid) @@ -973,6 +1010,9 @@ if (Preallocated>0 && (BrokenFile || DataIO.CurUnpWrite!=Preallocated)) CurFile.Truncate(); +#ifdef PROPAGATE_MOTW + Arc.Motw.CreateZoneIdStream(DestFileName,Cmd->MotwList); +#endif CurFile.SetOpenFileTime( Cmd->xmtime==EXTTIME_NONE ? NULL:&Arc.FileHead.mtime, @@ -992,9 +1032,6 @@ if (SetAttr) { #if defined(_WIN_ALL) && !defined(SFX_MODULE) - if (Cmd->SetCompressedAttr && - (Arc.FileHead.FileAttr & FILE_ATTRIBUTE_COMPRESSED)!=0) - SetFileCompression(DestFileName,true); if (Cmd->ClearArc) Arc.FileHead.FileAttr&=~FILE_ATTRIBUTE_ARCHIVE; #endif @@ -1416,7 +1453,7 @@ } -bool CmdExtract::ExtrCreateFile(Archive &Arc,File &CurFile) +bool CmdExtract::ExtrCreateFile(Archive &Arc,File &CurFile,bool WriteOnly) { return true; // OPENMPT ADDITION bool Success=true; @@ -1428,9 +1465,7 @@ if ((Command=='E' || Command=='X') && !Cmd->Test) { bool UserReject; - // Specify "write only" mode to avoid OpenIndiana NAS problems - // with SetFileTime and read+write files. - if (!FileCreate(Cmd,&CurFile,DestFileName,&UserReject,Arc.FileHead.UnpSize,&Arc.FileHead.mtime,true)) + if (!FileCreate(Cmd,&CurFile,DestFileName,&UserReject,Arc.FileHead.UnpSize,&Arc.FileHead.mtime,WriteOnly)) { Success=false; if (!UserReject) @@ -1490,10 +1525,16 @@ if (Arc.FileHead.Method==0) WrongVer=false; + // Can't unpack the unknown encryption even for stored files. + if (Arc.FileHead.CryptMethod==CRYPT_UNKNOWN) + WrongVer=true; + if (WrongVer) { ErrHandler.UnknownMethodMsg(Arc.FileName,ArcFileName); - uiMsg(UIERROR_NEWERRAR,Arc.FileName); + // No need to suggest a new version if it is just a broken archive. + if (!Arc.BrokenHeader) + uiMsg(UIERROR_NEWERRAR,Arc.FileName); } return !WrongVer; } Modified: trunk/OpenMPT/include/unrar/extract.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/extract.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/extract.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -37,7 +37,7 @@ void ConvertDosPassword(Archive &Arc,SecPassword &DestPwd); #endif void ExtrCreateDir(Archive &Arc,const std::wstring &ArcFileName); - bool ExtrCreateFile(Archive &Arc,File &CurFile); + bool ExtrCreateFile(Archive &Arc,File &CurFile,bool WriteOnly); bool CheckUnpVer(Archive &Arc,const std::wstring &ArcFileName); #ifndef SFX_MODULE void AnalyzeArchive(const std::wstring &ArcName,bool Volume,bool NewNumbering); Modified: trunk/OpenMPT/include/unrar/filefn.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/filefn.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/filefn.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -132,6 +132,8 @@ } + + bool IsRemovable(const std::wstring &Name) { return false; // OPENMPT ADDITION @@ -330,10 +332,10 @@ } -wchar* MkTemp(wchar *Name,size_t MaxSize) +// Ext is the extension with the leading dot, like L".bat", or nullptr to use +// the default extension. +bool MkTemp(std::wstring &Name,const wchar *Ext) { - size_t Length=wcslen(Name); - RarTime CurTime; CurTime.SetCurrentTime(); @@ -352,47 +354,20 @@ for (uint Attempt=0;;Attempt++) { - uint Ext=Random%50000+Attempt; - wchar RndText[50]; + uint RandomExt=Random%50000+Attempt; + if (Attempt==1000) + return false; + // User asked to specify the single extension for all temporary files, // so it can be added to server ransomware protection exceptions. // He wrote, this protection blocks temporary files when adding - // a file to RAR archive with drag and drop. - swprintf(RndText,ASIZE(RndText),L"%u.%03u.rartemp",PID,Ext); - if (Length+wcslen(RndText)>=MaxSize || Attempt==1000) - return NULL; - wcsncpyz(Name+Length,RndText,MaxSize-Length); - if (!FileExist(Name)) - break; - } - return Name; -} - - -bool MkTemp(std::wstring &Name) -{ - RarTime CurTime; - CurTime.SetCurrentTime(); - - // We cannot use CurTime.GetWin() as is, because its lowest bits can - // have low informational value, like being a zero or few fixed numbers. - uint Random=(uint)(CurTime.GetWin()/100000); - - // Using PID we guarantee that different RAR copies use different temp names - // even if started in exactly the same time. - uint PID=0; -#ifdef _WIN_ALL - PID=(uint)GetCurrentProcessId(); -#elif defined(_UNIX) - PID=(uint)getpid(); -#endif + // a file to RAR archive with drag and drop. So unless a calling code + // requires a specific extension, like .bat file when uninstalling, + // we set the uniform extension here. + if (Ext==nullptr) + Ext=L".rartemp"; - for (uint Attempt=0;;Attempt++) - { - uint Ext=Random%50000+Attempt; - if (Attempt==1000) - return false; - std::wstring NewName=Name + std::to_wstring(PID) + L"." + std::to_wstring(Ext) + L".rartemp"; + std::wstring NewName=Name + std::to_wstring(PID) + L"." + std::to_wstring(RandomExt) + Ext; if (!FileExist(NewName)) { Name=NewName; @@ -559,14 +534,21 @@ hFile=CreateFile(LongName.c_str(),FILE_READ_DATA|FILE_WRITE_DATA, FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN,NULL); + if (hFile==INVALID_HANDLE_VALUE) + return false; } - if (hFile==INVALID_HANDLE_VALUE) - return false; + bool Success=SetFileCompression(hFile,State); + CloseHandle(hFile); + return Success; +} + + +bool SetFileCompression(HANDLE hFile,bool State) +{ SHORT NewState=State ? COMPRESSION_FORMAT_DEFAULT:COMPRESSION_FORMAT_NONE; DWORD Result; int RetCode=DeviceIoControl(hFile,FSCTL_SET_COMPRESSION,&NewState, sizeof(NewState),NULL,0,&Result,NULL); - CloseHandle(hFile); return RetCode!=0; } Modified: trunk/OpenMPT/include/unrar/filefn.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/filefn.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/filefn.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -6,7 +6,10 @@ MKDIR_CODE MakeDir(const std::wstring &Name,bool SetAttr,uint Attr); bool CreateDir(const std::wstring &Name); bool CreatePath(const std::wstring &Path,bool SkipLastName,bool Silent); + void SetDirTime(const std::wstring &Name,RarTime *ftm,RarTime *ftc,RarTime *fta); + + bool IsRemovable(const std::wstring &Name); #ifndef SFX_MODULE @@ -28,8 +31,7 @@ void PrepareToDelete(const std::wstring &Name); uint GetFileAttr(const std::wstring &Name); bool SetFileAttr(const std::wstring &Name,uint Attr); -wchar* MkTemp(wchar *Name,size_t MaxSize); -bool MkTemp(std::wstring &Name); +bool MkTemp(std::wstring &Name,const wchar *Ext); enum CALCFSUM_FLAGS {CALCFSUM_SHOWTEXT=1,CALCFSUM_SHOWPERCENT=2,CALCFSUM_SHOWPROGRESS=4,CALCFSUM_CURPOS=8}; @@ -41,6 +43,7 @@ #if defined(_WIN_ALL) && !defined(SFX_MODULE) bool SetFileCompression(const std::wstring &Name,bool State); +bool SetFileCompression(HANDLE hFile,bool State); void ResetFileCache(const std::wstring &Name); #endif Modified: trunk/OpenMPT/include/unrar/hash.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/hash.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/hash.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -275,7 +275,9 @@ { HashValue Final; Result(&Final); - if (Key!=NULL) +#ifndef RAR_NOCRYPT + if (Key!=nullptr) ConvertHashToMAC(&Final,Key); +#endif return Final==*CmpValue; } Modified: trunk/OpenMPT/include/unrar/hash.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/hash.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/hash.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -13,6 +13,8 @@ bool operator == (const HashValue &cmp) const; // Not actually used now. Const member for same reason as operator == above. + // Can be removed after switching to C++20, which automatically provides "!=" + // if operator == is defined. bool operator != (const HashValue &cmp) const {return !(*this==cmp);} HASH_TYPE Type; Added: trunk/OpenMPT/include/unrar/largepage.cpp ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/OpenMPT/include/unrar/largepage.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -0,0 +1,201 @@ +#include "rar.hpp" + +/* +To enable, disable or check Large Memory pages manually: +- open "Local Security Policy" from "Start Menu"; +- open "Lock Pages in Memory" in "Local Policies\User Rights Assignment"; +- add or remove the user and sign out and sign in or restart Windows. +*/ + +#if defined(_WIN_ALL) && !defined(SFX_MODULE) && !defined(RARDLL) +#define ALLOW_LARGE_PAGES +#endif + +LargePageAlloc::LargePageAlloc() +{ + UseLargePages=false; +#ifdef ALLOW_LARGE_PAGES + PageSize=0; +#endif +} + + +void LargePageAlloc::AllowLargePages(bool Allow) +{ +#ifdef ALLOW_LARGE_PAGES + if (Allow && PageSize==0) + { + HMODULE hKernel=GetModuleHandle(L"kernel32.dll"); + if (hKernel!=nullptr) + { + typedef SIZE_T (*GETLARGEPAGEMINIMUM)(); + GETLARGEPAGEMINIMUM pGetLargePageMinimum=(GETLARGEPAGEMINIMUM)GetProcAddress(hKernel, "GetLargePageMinimum"); + if (pGetLargePageMinimum!=nullptr) + PageSize=pGetLargePageMinimum(); + } + if (PageSize==0 || !SetPrivilege(SE_LOCK_MEMORY_NAME)) + { + UseLargePages=false; + return; + } + } + + UseLargePages=Allow; +#endif +} + + +bool LargePageAlloc::IsPrivilegeAssigned() +{ +#ifdef ALLOW_LARGE_PAGES + return SetPrivilege(SE_LOCK_MEMORY_NAME); +#else + return true; +#endif +} + + +bool LargePageAlloc::AssignPrivilege() +{ +#ifdef ALLOW_LARGE_PAGES + HANDLE hToken = NULL; + + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) + return false; + + // Get the required buffer size. + DWORD BufSize=0; + GetTokenInformation(hToken, TokenUser, NULL, 0, &BufSize); + if (BufSize==0 || BufSize>1000000) // Sanity check for returned value. + { + CloseHandle(hToken); + return false; + } + + TOKEN_USER *TokenInfo = (TOKEN_USER*)malloc(BufSize); + + // Get the current user token information. + if (GetTokenInformation(hToken,TokenUser,TokenInfo,BufSize,&BufSize)==0) + { + CloseHandle(hToken); + return false; + } + + // Get SID string for the current user. + LPWSTR ApiSidStr; + ConvertSidToStringSid(TokenInfo->User.Sid, &ApiSidStr); + + // Convert SID to C++ string and release API based buffer. + std::wstring SidStr=ApiSidStr; + LocalFree(ApiSidStr); + CloseHandle(hToken); + + if (IsUserAdmin()) + AssignPrivilegeBySid(SidStr); + else + { + // Define here, so they survive until ShellExecuteEx call. + std::wstring ExeName=GetModuleFileStr(); + std::wstring Param=std::wstring(L"-") + LOCKMEM_SWITCH + SidStr; + + SHELLEXECUTEINFO shExecInfo{}; + shExecInfo.cbSize = sizeof(shExecInfo); + + shExecInfo.hwnd = NULL; // Specifying WinRAR main window here does not work well in command line mode. + shExecInfo.lpVerb = L"runas"; + shExecInfo.lpFile = ExeName.c_str(); + shExecInfo.lpParameters = Param.c_str(); + shExecInfo.nShow = SW_SHOWNORMAL; + BOOL Result=ShellExecuteEx(&shExecInfo); + } +#endif + + return true; +} + + +bool LargePageAlloc::AssignPrivilegeBySid(const std::wstring &Sid) +{ +#ifdef ALLOW_LARGE_PAGES + LSA_HANDLE PolicyHandle; + LSA_OBJECT_ATTRIBUTES ObjectAttributes{}; // Docs require to zero initalize it. + +#ifndef STATUS_SUCCESS // Can be defined through WIL package in WinRAR. + // We define STATUS_SUCCESS here instead of including ntstatus.h to avoid + // macro redefinition warnings. We tried UMDF_USING_NTSTATUS define + // and other workarounds, but it didn't help. + const uint STATUS_SUCCESS=0; +#endif + + if (LsaOpenPolicy(NULL,&ObjectAttributes,POLICY_CREATE_ACCOUNT| + POLICY_LOOKUP_NAMES,&PolicyHandle)!=STATUS_SUCCESS) + return false; + + PSID UserSid; + ConvertStringSidToSid(Sid.c_str(),&UserSid); + + LSA_UNICODE_STRING LsaString; + LsaString.Buffer=(PWSTR)SE_LOCK_MEMORY_NAME; + // It must be in bytes, so multiple it to sizeof(wchar_t). + LsaString.Length=(USHORT)wcslen(LsaString.Buffer)*sizeof(LsaString.Buffer[0]); + LsaString.MaximumLength=LsaString.Length; + + bool Success=LsaAddAccountRights(PolicyHandle,UserSid,&LsaString,1)==STATUS_SUCCESS; + + LocalFree(UserSid); + LsaClose(PolicyHandle); + + mprintf(St(MPrivilegeAssigned)); + if (Ask(St(MYesNo)) == 1) + Shutdown(POWERMODE_RESTART); + + return Success; +#else + return true; +#endif +} + + +bool LargePageAlloc::AssignConfirmation() +{ +#ifdef ALLOW_LARGE_PAGES + mprintf(St(MLockInMemoryNeeded)); + return Ask(St(MYesNo)) == 1; +#else + return false; +#endif +} + + +void* LargePageAlloc::new_large(size_t Size) +{ + void *Allocated=nullptr; + +#ifdef ALLOW_LARGE_PAGES + if (UseLargePages && Size>=PageSize) + { + // VirtualAlloc fails if allocation size isn't multiple of page size. + SIZE_T AllocSize=Size%PageSize==0 ? Size:(Size/PageSize+1)*PageSize; + Allocated=VirtualAlloc(nullptr,AllocSize,MEM_COMMIT|MEM_RESERVE|MEM_LARGE_PAGES,PAGE_READWRITE); + if (Allocated!=nullptr) + LargeAlloc.push_back(Allocated); + } +#endif + return Allocated; +} + + +bool LargePageAlloc::delete_large(void *Addr) +{ +#ifdef ALLOW_LARGE_PAGES + if (Addr!=nullptr) + for (size_t I=0;I<LargeAlloc.size();I++) + if (LargeAlloc[I]==Addr) + { + LargeAlloc[I]=nullptr; + VirtualFree(Addr,0,MEM_RELEASE); + return true; + } +#endif + return false; +} Added: trunk/OpenMPT/include/unrar/largepage.hpp ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/OpenMPT/include/unrar/largepage.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -0,0 +1,54 @@ +#ifndef _RAR_LARGEPAGE_ +#define _RAR_LARGEPAGE_ + +class LargePageAlloc +{ + private: + static constexpr const wchar *LOCKMEM_SWITCH=L"isetup_privilege_lockmem"; + + void* new_large(size_t Size); + bool delete_large(void *Addr); +#ifdef _WIN_ALL + std::vector<void*> LargeAlloc; + SIZE_T PageSize; +#endif + bool UseLargePages; + public: + LargePageAlloc(); + void AllowLargePages(bool Allow); + static bool IsPrivilegeAssigned(); + static bool AssignPrivilege(); + static bool AssignPrivilegeBySid(const std::wstring &Sid); + static bool AssignConfirmation(); + + static bool ProcessSwitch(CommandData *Cmd,const wchar *Switch) + { + if (Switch[0]==LOCKMEM_SWITCH[0]) + { + size_t Length=wcslen(LOCKMEM_SWITCH); + if (wcsncmp(Switch,LOCKMEM_SWITCH,Length)==0) + { + LargePageAlloc::AssignPrivilegeBySid(Switch+Length); + return true; + } + } + return false; + } + + template <class T> T* new_l(size_t Size,bool Clear=false) + { + T *Allocated=(T*)new_large(Size*sizeof(T)); + if (Allocated==nullptr) + Allocated=Clear ? new T[Size]{} : new T[Size]; + return Allocated; + } + + template <class T> void delete_l(T *Addr) + { + if (!delete_large(Addr)) + delete[] Addr; + } +}; + + +#endif Modified: trunk/OpenMPT/include/unrar/list.cpp ============================================================================== --- trunk/OpenMPT/include/unrar/list.cpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/list.cpp Sat Dec 7 19:55:03 2024 (r22479) @@ -37,7 +37,7 @@ mprintf(L"\n%s: %s",St(MListArchive),Arc.FileName.c_str()); mprintf(L"\n%s: ",St(MListDetails)); - const wchar *Fmt=Arc.Format==RARFMT14 ? L"RAR 1.4":(Arc.Format==RARFMT15 ? L"RAR 4":L"RAR 5"); + const wchar *Fmt=Arc.Format==RARFMT14 ? L"RAR 1.4":(Arc.Format==RARFMT15 ? L"RAR 1.5":L"RAR 5"); mprintf(L"%s", Fmt); if (Arc.Solid) mprintf(L", %s", St(MListSolid)); Modified: trunk/OpenMPT/include/unrar/loclang.hpp ============================================================================== --- trunk/OpenMPT/include/unrar/loclang.hpp Fri Dec 6 19:07:14 2024 (r22478) +++ trunk/OpenMPT/include/unrar/loclang.hpp Sat Dec 7 19:55:03 2024 (r22479) @@ -97,6 +97,7 @@ #define MCHelpSwMC L"\n mc<par> Set advanced compression parameters" #define MCHelpSwMD L"\n md[x]<n>[kmg] Dictionary size in KB, MB or GB" #define MCHelpSwME L"\n me[par] Set encryption parameters" +#define MCHelpSwMLP L"\n mlp Use large memory pages" #define MCHelpSwMS L"\n ms[ext;ext] Specify file types to store" #define MCHelpSwMT L"\n mt<threads> Set the number of threads" #define MCHelpSwN L"\n n<file> Additionally filter included files" @@ -107,6 +108,7 @@ #define MCHelpSwOH L"\n oh Save hard links as the link instead of the file" #define MCHelpSwOI L"\n oi[0-4][:min] Save identical files as references" #define MCHelpSwOL L"\n ol[a,-] Process symbolic links as the link [absolute paths, skip]" +#define MCHelpSwOM L"\n om[-|1][=lst] Propagate Mark of the Web" #define MCHelpSwONI L"\n oni Allow potentially incompatible names" #define MCHelpSwOP L"\n op<path> Set the output path for extracted files" #define MCHelpSwOR L"\n or Rename files automatically" @@ -232,8 +234,8 @@ #define MArcComment L"\nArchive comment" #define MReadStdinCmt L"\nReading comment from stdin\n" #define MReadCommFrom L"\nReading comment from %s" -#define MDelComment L"\nDeleting comment from %s" -#define MAddComment L"\nAdding comment to %s" +#define MDelComment L"\nDeleting a comment from %s" +#define MAddComment L"\nAdding a comment to %s" #define MLogCommBrk L"\nThe archive comment is corrupt" #define MCommAskCont L"\nPress 'Enter' to continue or 'Q' to quit:" #define MWriteCommTo L"\nWrite comment to %s" @@ -302,7 +304,7 @@ #define MRecSecDamage L"\nSector %ld (offsets %lX...%lX) damaged" #define MRecCorrected L" - data recovered" #define MRecFailed L" - cannot recover data" -#define MAddRecRec L"\nAdding data recovery record" +#define MAddRecRec L"\nAdding the data recovery record" #define MEraseForVolume L"\n\nErasing contents of drive %c:\n" #define MGetOwnersError L"\nWARNING: Cannot get %s owner and group\n" #define MErrGetOwnerID L"\nWARNING: Cannot get owner %s ID\n" @@ -329,7 +331,6 @@ #define MSubHeadCorrupt L"\nERROR: Corrupt data header found, ignored" #define MSubHeadUnknown L"\nWARNING: Unknown data header format, ignored" #define MSubHeadDataCRC L"\nERROR: Corrupt %s data block" -#define MSubHeadType L"\nData header type: %s" #define MScanError L"\nCannot read contents of %s" #define MNotVolume L"\n%s is not volume" #define MRecVolDiffSets L"\nERROR: %s and %s belong to different sets" @@ -384,7 +385,7 @@ #define MUseSmalllerDict L"\nPlease use a smaller compression dictionary." #define MExtrDictOutMem ... [truncated message content] |