Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 (sic: version numbers) (#42)
  • Loading branch information
chlily1 authored Dec 5, 2024
1 parent 12e82f9 commit 7f22bab
Show file tree
Hide file tree
Showing 49 changed files with 910 additions and 268 deletions.
2 changes: 2 additions & 0 deletions UnRAR.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@
<ClCompile Include="hash.cpp" />
<ClCompile Include="headers.cpp" />
<ClCompile Include="isnt.cpp" />
<ClCompile Include="largepage.cpp" />
<ClCompile Include="list.cpp" />
<ClCompile Include="match.cpp" />
<ClCompile Include="motw.cpp" />
<ClCompile Include="options.cpp" />
<ClCompile Include="pathfn.cpp" />
<ClCompile Include="qopen.cpp" />
Expand Down
2 changes: 2 additions & 0 deletions UnRARDll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@
<ClCompile Include="hash.cpp" />
<ClCompile Include="headers.cpp" />
<ClCompile Include="isnt.cpp" />
<ClCompile Include="largepage.cpp" />
<ClCompile Include="match.cpp" />
<ClCompile Include="motw.cpp" />
<ClCompile Include="options.cpp" />
<ClCompile Include="pathfn.cpp" />
<ClCompile Include="qopen.cpp" />
Expand Down
7 changes: 6 additions & 1 deletion arccmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ bool Archive::DoGetComment(std::wstring &CmtData)
{
// 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
Expand Down
4 changes: 3 additions & 1 deletion archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void Archive::CheckArc(bool EnableBroken)
// password is incorrect.
if (!FailedHeaderDecryption)
uiMsg(UIERROR_BADARCHIVE,FileName);
ErrHandler.Exit(RARX_FATAL);
ErrHandler.Exit(RARX_BADARC);
}
}

Expand Down Expand Up @@ -109,9 +109,11 @@ RARFORMAT Archive::IsSignature(const byte *D,size_t Size)
// 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
Expand Down
5 changes: 4 additions & 1 deletion archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Archive:public File
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);
Expand Down Expand Up @@ -147,6 +147,9 @@ class Archive:public File
bool NewArchive;

std::wstring FirstVolumeName;
#ifdef PROPAGATE_MOTW
MarkOfTheWeb Motw;
#endif
};


Expand Down
27 changes: 23 additions & 4 deletions arcread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ size_t Archive::ReadHeader()
case RARFMT14:
ReadSize=ReadHeader14();
break;
#endif
case RARFMT15:
ReadSize=ReadHeader15();
break;
#endif
case RARFMT50:
ReadSize=ReadHeader50();
break;
Expand Down Expand Up @@ -106,6 +106,9 @@ void Archive::UnexpEndArcMsg()
if (CurBlockPos!=ArcSize || NextBlockPos!=ArcSize)
{
uiMsg(UIERROR_UNEXPEOF,FileName);
if (CurHeaderType!=HEAD_FILE)
uiMsg(UIERROR_TRUNCSERVICE,FileName,SubHead.FileName);

ErrHandler.SetErrorCode(RARX_WARNING);
}
}
Expand Down Expand Up @@ -137,6 +140,7 @@ inline int64 SafeAdd(int64 v1,int64 v2,int64 f)
}


#ifndef SFX_MODULE
size_t Archive::ReadHeader15()
{
RawRead Raw(this);
Expand All @@ -145,7 +149,7 @@ size_t Archive::ReadHeader15()

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);
Expand Down Expand Up @@ -545,6 +549,7 @@ size_t Archive::ReadHeader15()

return Raw.Size();
}
#endif // #ifndef SFX_MODULE


size_t Archive::ReadHeader50()
Expand Down Expand Up @@ -740,10 +745,15 @@ size_t Archive::ReadHeader50()
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;
}
Expand Down Expand Up @@ -1036,22 +1046,30 @@ void Archive::ProcessExtra50(RawRead *Raw,size_t ExtraSize,const BaseBlock *bb)
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)
Expand Down Expand Up @@ -1085,6 +1103,7 @@ void Archive::ProcessExtra50(RawRead *Raw,size_t ExtraSize,const BaseBlock *bb)
}
}
break;
#endif
case FHEXTRA_HASH:
{
FileHeader *hd=(FileHeader *)bb;
Expand Down
9 changes: 3 additions & 6 deletions blake2s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
78 changes: 58 additions & 20 deletions cmddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void CommandData::Init()
InclArgs.Reset();
ArcNames.Reset();
StoreArgs.Reset();
#ifdef PROPAGATE_MOTW
MotwList.Reset();
#endif
Password.Clean();
NextVolSizes.clear();
#ifdef RARDLL
Expand Down Expand Up @@ -189,7 +192,7 @@ void CommandData::ParseDone()
#if !defined(SFX_MODULE)
void CommandData::ParseEnvVar()
{
char *EnvVar=getenv("RAR");
char *EnvVar=getenv("RARINISWITCHES");
if (EnvVar!=NULL)
{
std::wstring EnvStr;
Expand Down Expand Up @@ -293,6 +296,9 @@ void CommandData::ProcessSwitchesString(const std::wstring &Str)
void CommandData::ProcessSwitch(const wchar *Switch)
{

if (LargePageAlloc::ProcessSwitch(this,Switch))
return;

switch(toupperw(Switch[0]))
{
case '@':
Expand Down Expand Up @@ -619,8 +625,6 @@ void CommandData::ProcessSwitch(const wchar *Switch)
}
}
break;
case 'M':
break;
case 'D':
{
bool SetDictLimit=toupperw(Switch[2])=='X';
Expand Down Expand Up @@ -665,33 +669,30 @@ void CommandData::ProcessSwitch(const wchar *Switch)
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:
Expand Down Expand Up @@ -752,6 +753,18 @@ void CommandData::ProcessSwitch(const wchar *Switch)
}
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')
Expand Down Expand Up @@ -1033,6 +1046,11 @@ void CommandData::ProcessCommand()
#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.

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


// 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;
}
}




11 changes: 11 additions & 0 deletions cmddata.hpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -56,6 +62,8 @@ class CommandData:public RAROptions
void ReportWrongSwitches(RARFORMAT Format);
#endif

void GetBriefMaskList(const std::wstring &Masks,StringList &Args);


std::wstring Command;
std::wstring ArcName;
Expand All @@ -78,6 +86,9 @@ class CommandData:public RAROptions
StringList InclArgs;
StringList ArcNames;
StringList StoreArgs;
#ifdef PROPAGATE_MOTW
StringList MotwList; // Extensions to assign the mark of the web.
#endif

SecPassword Password;

Expand Down
14 changes: 7 additions & 7 deletions cmdmix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ void CommandData::OutHelp(RAR_EXIT ExitCode)
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
};

Expand All @@ -80,7 +80,7 @@ void CommandData::OutHelp(RAR_EXIT ExitCode)
#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++)
Expand Down
Loading

0 comments on commit 7f22bab

Please sign in to comment.