Skip to content

Commit 7f22bab

Browse files
authored
v7.10.2: Extracted from https://www.rarlab.com/rar/unrarsrc-7.1.2.tar.gz (sic: version numbers) (#42)
1 parent 12e82f9 commit 7f22bab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+910
-268
lines changed

UnRAR.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@
238238
<ClCompile Include="hash.cpp" />
239239
<ClCompile Include="headers.cpp" />
240240
<ClCompile Include="isnt.cpp" />
241+
<ClCompile Include="largepage.cpp" />
241242
<ClCompile Include="list.cpp" />
242243
<ClCompile Include="match.cpp" />
244+
<ClCompile Include="motw.cpp" />
243245
<ClCompile Include="options.cpp" />
244246
<ClCompile Include="pathfn.cpp" />
245247
<ClCompile Include="qopen.cpp" />

UnRARDll.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@
374374
<ClCompile Include="hash.cpp" />
375375
<ClCompile Include="headers.cpp" />
376376
<ClCompile Include="isnt.cpp" />
377+
<ClCompile Include="largepage.cpp" />
377378
<ClCompile Include="match.cpp" />
379+
<ClCompile Include="motw.cpp" />
378380
<ClCompile Include="options.cpp" />
379381
<ClCompile Include="pathfn.cpp" />
380382
<ClCompile Include="qopen.cpp" />

arccmt.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ bool Archive::DoGetComment(std::wstring &CmtData)
3636
{
3737
// Current (RAR 3.0+) version of archive comment.
3838
Seek(GetStartPos(),SEEK_SET);
39-
return SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData);
39+
if (SearchSubBlock(SUBHEAD_TYPE_CMT)!=0)
40+
if (ReadCommentData(CmtData))
41+
return true;
42+
else
43+
uiMsg(UIERROR_CMTBROKEN,FileName);
44+
return false;
4045
}
4146
#ifndef SFX_MODULE
4247
// Old style (RAR 2.9) comment header embedded into the main

archive.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void Archive::CheckArc(bool EnableBroken)
6767
// password is incorrect.
6868
if (!FailedHeaderDecryption)
6969
uiMsg(UIERROR_BADARCHIVE,FileName);
70-
ErrHandler.Exit(RARX_FATAL);
70+
ErrHandler.Exit(RARX_BADARC);
7171
}
7272
}
7373

@@ -109,9 +109,11 @@ RARFORMAT Archive::IsSignature(const byte *D,size_t Size)
109109
// We check the last signature byte, so we can return a sensible
110110
// warning in case we'll want to change the archive format
111111
// sometimes in the future.
112+
#ifndef SFX_MODULE
112113
if (D[6]==0)
113114
Type=RARFMT15;
114115
else
116+
#endif
115117
if (D[6]==1)
116118
Type=RARFMT50;
117119
else

archive.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Archive:public File
5858
bool ProhibitQOpen;
5959
#endif
6060
public:
61-
Archive(CommandData *InitCmd=NULL);
61+
Archive(CommandData *InitCmd=nullptr);
6262
~Archive();
6363
static RARFORMAT IsSignature(const byte *D,size_t Size);
6464
bool IsArchive(bool EnableBroken);
@@ -147,6 +147,9 @@ class Archive:public File
147147
bool NewArchive;
148148

149149
std::wstring FirstVolumeName;
150+
#ifdef PROPAGATE_MOTW
151+
MarkOfTheWeb Motw;
152+
#endif
150153
};
151154

152155

arcread.cpp

+23-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ size_t Archive::ReadHeader()
2020
case RARFMT14:
2121
ReadSize=ReadHeader14();
2222
break;
23-
#endif
2423
case RARFMT15:
2524
ReadSize=ReadHeader15();
2625
break;
26+
#endif
2727
case RARFMT50:
2828
ReadSize=ReadHeader50();
2929
break;
@@ -106,6 +106,9 @@ void Archive::UnexpEndArcMsg()
106106
if (CurBlockPos!=ArcSize || NextBlockPos!=ArcSize)
107107
{
108108
uiMsg(UIERROR_UNEXPEOF,FileName);
109+
if (CurHeaderType!=HEAD_FILE)
110+
uiMsg(UIERROR_TRUNCSERVICE,FileName,SubHead.FileName);
111+
109112
ErrHandler.SetErrorCode(RARX_WARNING);
110113
}
111114
}
@@ -137,6 +140,7 @@ inline int64 SafeAdd(int64 v1,int64 v2,int64 f)
137140
}
138141

139142

143+
#ifndef SFX_MODULE
140144
size_t Archive::ReadHeader15()
141145
{
142146
RawRead Raw(this);
@@ -145,7 +149,7 @@ size_t Archive::ReadHeader15()
145149

146150
if (Decrypt)
147151
{
148-
#ifdef RAR_NOCRYPT // For rarext.dll and unrar_nocrypt.dll.
152+
#ifdef RAR_NOCRYPT // For rarext.dll, Setup.SFX and unrar_nocrypt.dll.
149153
return 0;
150154
#else
151155
RequestArcPassword(NULL);
@@ -545,6 +549,7 @@ size_t Archive::ReadHeader15()
545549

546550
return Raw.Size();
547551
}
552+
#endif // #ifndef SFX_MODULE
548553

549554

550555
size_t Archive::ReadHeader50()
@@ -740,10 +745,15 @@ size_t Archive::ReadHeader50()
740745
byte csum[SIZE_PSWCHECK_CSUM];
741746
Raw.GetB(csum,SIZE_PSWCHECK_CSUM);
742747

748+
// Exclude this code for rarext.dll, Setup.SFX and unrar_nocrypt.dll linked
749+
// without sha256. But still set Encrypted=true for rarext.dll here,
750+
// so it can recognize encrypted header archives in archive properties.
751+
#ifndef RAR_NOCRYPT
743752
byte Digest[SHA256_DIGEST_SIZE];
744753
sha256_get(CryptHead.PswCheck, SIZE_PSWCHECK, Digest);
745754

746755
CryptHead.UsePswCheck=memcmp(csum,Digest,SIZE_PSWCHECK_CSUM)==0;
756+
#endif
747757
}
748758
Encrypted=true;
749759
}
@@ -1036,22 +1046,30 @@ void Archive::ProcessExtra50(RawRead *Raw,size_t ExtraSize,const BaseBlock *bb)
10361046
FileHeader *hd=(FileHeader *)bb;
10371047
switch(FieldType)
10381048
{
1049+
#ifndef RAR_NOCRYPT // Except rarext.dll, Setup.SFX and unrar_nocrypt.dll.
10391050
case FHEXTRA_CRYPT:
10401051
{
10411052
FileHeader *hd=(FileHeader *)bb;
10421053
uint EncVersion=(uint)Raw->GetV();
10431054
if (EncVersion>CRYPT_VERSION)
1055+
{
10441056
UnkEncVerMsg(hd->FileName,L"x" + std::to_wstring(EncVersion));
1057+
hd->CryptMethod=CRYPT_UNKNOWN;
1058+
}
10451059
else
10461060
{
10471061
uint Flags=(uint)Raw->GetV();
1048-
hd->UsePswCheck=(Flags & FHEXTRA_CRYPT_PSWCHECK)!=0;
1049-
hd->UseHashKey=(Flags & FHEXTRA_CRYPT_HASHMAC)!=0;
10501062
hd->Lg2Count=Raw->Get1();
10511063
if (hd->Lg2Count>CRYPT5_KDF_LG2_COUNT_MAX)
1064+
{
10521065
UnkEncVerMsg(hd->FileName,L"xc" + std::to_wstring(hd->Lg2Count));
1066+
hd->CryptMethod=CRYPT_UNKNOWN;
1067+
}
10531068
else
10541069
{
1070+
hd->UsePswCheck=(Flags & FHEXTRA_CRYPT_PSWCHECK)!=0;
1071+
hd->UseHashKey=(Flags & FHEXTRA_CRYPT_HASHMAC)!=0;
1072+
10551073
Raw->GetB(hd->Salt,SIZE_SALT50);
10561074
Raw->GetB(hd->InitV,SIZE_INITV);
10571075
if (hd->UsePswCheck)
@@ -1085,6 +1103,7 @@ void Archive::ProcessExtra50(RawRead *Raw,size_t ExtraSize,const BaseBlock *bb)
10851103
}
10861104
}
10871105
break;
1106+
#endif
10881107
case FHEXTRA_HASH:
10891108
{
10901109
FileHeader *hd=(FileHeader *)bb;

blake2s.hpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
#define BLAKE2_DIGEST_SIZE 32
66
#define BLAKE2_THREADS_NUMBER 8
77

8-
enum blake2s_constant
9-
{
10-
BLAKE2S_BLOCKBYTES = 64,
11-
BLAKE2S_OUTBYTES = 32
12-
};
13-
8+
// Use constexpr instead of enums for -std=c++20 compatibility.
9+
constexpr size_t BLAKE2S_BLOCKBYTES = 64;
10+
constexpr size_t BLAKE2S_OUTBYTES = 32;
1411

1512
// Alignment to 64 improves performance of both SSE and non-SSE versions.
1613
// Alignment to n*16 is required for SSE version, so we selected 64.

cmddata.cpp

+58-20
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ void CommandData::Init()
3838
InclArgs.Reset();
3939
ArcNames.Reset();
4040
StoreArgs.Reset();
41+
#ifdef PROPAGATE_MOTW
42+
MotwList.Reset();
43+
#endif
4144
Password.Clean();
4245
NextVolSizes.clear();
4346
#ifdef RARDLL
@@ -189,7 +192,7 @@ void CommandData::ParseDone()
189192
#if !defined(SFX_MODULE)
190193
void CommandData::ParseEnvVar()
191194
{
192-
char *EnvVar=getenv("RAR");
195+
char *EnvVar=getenv("RARINISWITCHES");
193196
if (EnvVar!=NULL)
194197
{
195198
std::wstring EnvStr;
@@ -293,6 +296,9 @@ void CommandData::ProcessSwitchesString(const std::wstring &Str)
293296
void CommandData::ProcessSwitch(const wchar *Switch)
294297
{
295298

299+
if (LargePageAlloc::ProcessSwitch(this,Switch))
300+
return;
301+
296302
switch(toupperw(Switch[0]))
297303
{
298304
case '@':
@@ -619,8 +625,6 @@ void CommandData::ProcessSwitch(const wchar *Switch)
619625
}
620626
}
621627
break;
622-
case 'M':
623-
break;
624628
case 'D':
625629
{
626630
bool SetDictLimit=toupperw(Switch[2])=='X';
@@ -665,33 +669,30 @@ void CommandData::ProcessSwitch(const wchar *Switch)
665669
if (toupperw(Switch[2])=='S' && Switch[3]==0)
666670
SkipEncrypted=true;
667671
break;
668-
case 'S':
672+
case 'L':
673+
if (toupperw(Switch[2])=='P')
669674
{
670-
std::wstring StoreNames=(Switch[2]==0 ? DefaultStoreList:Switch+2);
671-
size_t Pos=0;
672-
while (Pos<StoreNames.size())
675+
UseLargePages=true;
676+
if (!LargePageAlloc::IsPrivilegeAssigned() && LargePageAlloc::AssignConfirmation())
673677
{
674-
if (StoreNames[Pos]=='.')
675-
Pos++;
676-
size_t EndPos=StoreNames.find(';',Pos);
677-
std::wstring Mask=StoreNames.substr(Pos,EndPos==std::wstring::npos ? EndPos:EndPos-Pos);
678-
if (Mask.find_first_of(L"*?.")==std::wstring::npos)
679-
Mask.insert(0,L"*.");
680-
StoreArgs.AddString(Mask);
681-
if (EndPos==std::wstring::npos)
682-
break;
683-
Pos=EndPos+1;
678+
LargePageAlloc::AssignPrivilege();
679+
680+
// Quit immediately. We do not want to interrupt the current copy
681+
// archive processing with reboot after assigning privilege.
682+
SetupComplete=true;
684683
}
685684
}
686685
break;
686+
case 'M':
687+
break;
688+
case 'S':
689+
GetBriefMaskList(Switch[2]==0 ? DefaultStoreList:Switch+2,StoreArgs);
690+
break;
687691
#ifdef RAR_SMP
688692
case 'T':
689693
Threads=atoiw(Switch+2);
690694
if (Threads>MaxPoolThreads || Threads<1)
691695
BadSwitch(Switch);
692-
else
693-
{
694-
}
695696
break;
696697
#endif
697698
default:
@@ -752,6 +753,18 @@ void CommandData::ProcessSwitch(const wchar *Switch)
752753
}
753754
break;
754755
#endif
756+
#ifdef PROPAGATE_MOTW
757+
case 'M':
758+
{
759+
MotwAllFields=Switch[2]=='1';
760+
const wchar *Sep=wcschr(Switch+2,'=');
761+
if (Switch[2]=='-')
762+
MotwList.Reset();
763+
else
764+
GetBriefMaskList(Sep==nullptr ? L"*":Sep+1,MotwList);
765+
}
766+
break;
767+
#endif
755768
#ifdef _WIN_ALL
756769
case 'N':
757770
if (toupperw(Switch[2])=='I')
@@ -1033,6 +1046,11 @@ void CommandData::ProcessCommand()
10331046
#ifndef SFX_MODULE
10341047

10351048
const wchar *SingleCharCommands=L"FUADPXETK";
1049+
1050+
// RAR -mlp command is the legitimate way to assign the required privilege.
1051+
if (Command.empty() && UseLargePages || SetupComplete)
1052+
return;
1053+
10361054
if (Command[0]!=0 && Command[1]!=0 && wcschr(SingleCharCommands,Command[0])!=NULL || ArcName.empty())
10371055
OutHelp(Command.empty() ? RARX_SUCCESS:RARX_USERERROR); // Return 'success' for 'rar' without parameters.
10381056

@@ -1231,5 +1249,25 @@ int64 CommandData::GetVolSize(const wchar *S,uint DefMultiplier)
12311249
}
12321250

12331251

1252+
// Treat the list like rar;zip as *.rar;*.zip for -ms and similar switches.
1253+
void CommandData::GetBriefMaskList(const std::wstring &Masks,StringList &Args)
1254+
{
1255+
size_t Pos=0;
1256+
while (Pos<Masks.size())
1257+
{
1258+
if (Masks[Pos]=='.')
1259+
Pos++;
1260+
size_t EndPos=Masks.find(';',Pos);
1261+
std::wstring Mask=Masks.substr(Pos,EndPos==std::wstring::npos ? EndPos:EndPos-Pos);
1262+
if (Mask.find_first_of(L"*?.")==std::wstring::npos)
1263+
Mask.insert(0,L"*.");
1264+
Args.AddString(Mask);
1265+
if (EndPos==std::wstring::npos)
1266+
break;
1267+
Pos=EndPos+1;
1268+
}
1269+
}
1270+
1271+
12341272

12351273

cmddata.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#ifndef _RAR_CMDDATA_
22
#define _RAR_CMDDATA_
33

4+
#if defined(_WIN_ALL) && !defined(SFX_MODULE)
5+
// In Windows we implement our own command line parser to avoid replacing
6+
// \" by " in standard parser. Such replacing corrupts destination paths
7+
// like "dest path\" in extraction commands.
8+
#define CUSTOM_CMDLINE_PARSER
9+
#endif
410

511
#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"
612

@@ -56,6 +62,8 @@ class CommandData:public RAROptions
5662
void ReportWrongSwitches(RARFORMAT Format);
5763
#endif
5864

65+
void GetBriefMaskList(const std::wstring &Masks,StringList &Args);
66+
5967

6068
std::wstring Command;
6169
std::wstring ArcName;
@@ -78,6 +86,9 @@ class CommandData:public RAROptions
7886
StringList InclArgs;
7987
StringList ArcNames;
8088
StringList StoreArgs;
89+
#ifdef PROPAGATE_MOTW
90+
StringList MotwList; // Extensions to assign the mark of the web.
91+
#endif
8192

8293
SecPassword Password;
8394

cmdmix.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ void CommandData::OutHelp(RAR_EXIT ExitCode)
6363
MCHelpSwAT,MCHelpSwAC,MCHelpSwAD,MCHelpSwAG,MCHelpSwAI,MCHelpSwAP,
6464
MCHelpSwCm,MCHelpSwCFGm,MCHelpSwCL,MCHelpSwCU,MCHelpSwDH,MCHelpSwEP,
6565
MCHelpSwEP3,MCHelpSwEP4,MCHelpSwF,MCHelpSwIDP,MCHelpSwIERR,
66-
MCHelpSwINUL,MCHelpSwIOFF,MCHelpSwKB,MCHelpSwME,MCHelpSwN,MCHelpSwNa,
67-
MCHelpSwNal,MCHelpSwO,MCHelpSwOC,MCHelpSwOL,MCHelpSwOP,MCHelpSwOR,
68-
MCHelpSwOW,MCHelpSwP,MCHelpSwR,MCHelpSwRI,MCHelpSwSC,MCHelpSwSI,
69-
MCHelpSwSL,MCHelpSwSM,MCHelpSwTA,MCHelpSwTB,MCHelpSwTN,MCHelpSwTO,
70-
MCHelpSwTS,MCHelpSwU,MCHelpSwVUnr,MCHelpSwVER,MCHelpSwVP,MCHelpSwX,
71-
MCHelpSwXa,MCHelpSwXal,MCHelpSwY
66+
MCHelpSwINUL,MCHelpSwIOFF,MCHelpSwKB,MCHelpSwME,MCHelpSwMLP,
67+
MCHelpSwN,MCHelpSwNa,MCHelpSwNal,MCHelpSwO,MCHelpSwOC,MCHelpSwOL,
68+
MCHelpSwOM,MCHelpSwOP,MCHelpSwOR,MCHelpSwOW,MCHelpSwP,MCHelpSwR,
69+
MCHelpSwRI,MCHelpSwSC,MCHelpSwSI,MCHelpSwSL,MCHelpSwSM,MCHelpSwTA,
70+
MCHelpSwTB,MCHelpSwTN,MCHelpSwTO,MCHelpSwTS,MCHelpSwU,MCHelpSwVUnr,
71+
MCHelpSwVER,MCHelpSwVP,MCHelpSwX,MCHelpSwXa,MCHelpSwXal,MCHelpSwY
7272
#endif
7373
};
7474

@@ -80,7 +80,7 @@ void CommandData::OutHelp(RAR_EXIT ExitCode)
8080
#ifndef _WIN_ALL
8181
static MSGID Win32Only[]={
8282
MCHelpSwIEML,MCHelpSwVD,MCHelpSwAO,MCHelpSwOS,MCHelpSwIOFF,
83-
MCHelpSwEP2,MCHelpSwOC,MCHelpSwONI,MCHelpSwDR,MCHelpSwRI
83+
MCHelpSwEP2,MCHelpSwMLP,MCHelpSwOC,MCHelpSwONI,MCHelpSwDR,MCHelpSwRI
8484
};
8585
bool Found=false;
8686
for (uint J=0;J<ASIZE(Win32Only);J++)

0 commit comments

Comments
 (0)