Skip to content

Commit

Permalink
Update unrar to 7.0b1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 committed Nov 21, 2023
1 parent 2e74b23 commit 6400e68
Show file tree
Hide file tree
Showing 110 changed files with 3,927 additions and 2,820 deletions.
63 changes: 30 additions & 33 deletions vendor/unrar/arccmt.cpp
@@ -1,6 +1,6 @@
static bool IsAnsiEscComment(const wchar *Data,size_t Size);

bool Archive::GetComment(Array<wchar> *CmtData)
bool Archive::GetComment(std::wstring &CmtData)
{
if (!MainComment)
return false;
Expand All @@ -11,7 +11,7 @@ bool Archive::GetComment(Array<wchar> *CmtData)
}


bool Archive::DoGetComment(Array<wchar> *CmtData)
bool Archive::DoGetComment(std::wstring &CmtData)
{
#ifndef SFX_MODULE
uint CmtLength;
Expand Down Expand Up @@ -101,67 +101,64 @@ bool Archive::DoGetComment(Array<wchar> *CmtData)
// 4x memory for OEM to UTF-8 output here.
OemToCharBuffA((char *)UnpData,(char *)UnpData,(DWORD)UnpDataSize);
#endif
CmtData->Alloc(UnpDataSize+1);
memset(CmtData->Addr(0),0,CmtData->Size()*sizeof(wchar));
CharToWide((char *)UnpData,CmtData->Addr(0),CmtData->Size());
CmtData->Alloc(wcslen(CmtData->Addr(0)));
// CmtData.resize(UnpDataSize+1);
CharToWide((const char *)UnpData,CmtData);
// CmtData.resize(wcslen(CmtData->data()));
}
}
}
else
{
if (CmtLength==0)
return false;
Array<byte> CmtRaw(CmtLength);
int ReadSize=Read(&CmtRaw[0],CmtLength);
std::vector<byte> CmtRaw(CmtLength);
int ReadSize=Read(CmtRaw.data(),CmtLength);
if (ReadSize>=0 && (uint)ReadSize<CmtLength) // Comment is shorter than declared.
{
CmtLength=ReadSize;
CmtRaw.Alloc(CmtLength);
CmtRaw.resize(CmtLength);
}

if (Format!=RARFMT14 && CommHead.CommCRC!=(~CRC32(0xffffffff,&CmtRaw[0],CmtLength)&0xffff))
{
uiMsg(UIERROR_CMTBROKEN,FileName);
return false;
}
CmtData->Alloc(CmtLength+1);
CmtRaw.Push(0);
// CmtData.resize(CmtLength+1);
CmtRaw.push_back(0);
#ifdef _WIN_ALL
// If we ever decide to extend it to Android, we'll need to alloc
// 4x memory for OEM to UTF-8 output here.
OemToCharA((char *)&CmtRaw[0],(char *)&CmtRaw[0]);
OemToCharA((char *)CmtRaw.data(),(char *)CmtRaw.data());
#endif
CharToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
CmtData->Alloc(wcslen(CmtData->Addr(0)));
CharToWide((const char *)CmtRaw.data(),CmtData);
// CmtData->resize(wcslen(CmtData->data()));
}
#endif
return CmtData->Size() > 0;
return CmtData.size() > 0;
}


bool Archive::ReadCommentData(Array<wchar> *CmtData)
bool Archive::ReadCommentData(std::wstring &CmtData)
{
Array<byte> CmtRaw;
std::vector<byte> CmtRaw;
if (!ReadSubData(&CmtRaw,NULL,false))
return false;
size_t CmtSize=CmtRaw.Size();
CmtRaw.Push(0);
CmtData->Alloc(CmtSize+1);
size_t CmtSize=CmtRaw.size();
CmtRaw.push_back(0);
// CmtData->resize(CmtSize+1);
if (Format==RARFMT50)
UtfToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
UtfToWide((char *)CmtRaw.data(),CmtData);
else
if ((SubHead.SubFlags & SUBHEAD_FLAGS_CMT_UNICODE)!=0)
{
RawToWide(&CmtRaw[0],CmtData->Addr(0),CmtSize/2);
(*CmtData)[CmtSize/2]=0;

CmtData=RawToWide(CmtRaw);
}
else
{
CharToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
CharToWide((const char *)CmtRaw.data(),CmtData);
}
CmtData->Alloc(wcslen(CmtData->Addr(0))); // Set buffer size to actual comment length.
// CmtData->resize(wcslen(CmtData->data())); // Set buffer size to actual comment length.
return true;
}

Expand All @@ -170,15 +167,15 @@ void Archive::ViewComment()
{
if (Cmd->DisableComment)
return;
Array<wchar> CmtBuf;
if (GetComment(&CmtBuf)) // In GUI too, so "Test" command detects broken comments.
std::wstring CmtBuf;
if (GetComment(CmtBuf)) // In GUI too, so "Test" command detects broken comments.
{
size_t CmtSize=CmtBuf.Size();
wchar *ChPtr=wcschr(&CmtBuf[0],0x1A);
if (ChPtr!=NULL)
CmtSize=ChPtr-&CmtBuf[0];
size_t CmtSize=CmtBuf.size();
auto EndPos=CmtBuf.find(0x1A);
if (EndPos!=std::wstring::npos)
CmtSize=EndPos;
mprintf(L"\n");
OutComment(&CmtBuf[0],CmtSize);
OutComment(CmtBuf);
}
}

Expand Down
33 changes: 26 additions & 7 deletions vendor/unrar/archive.cpp
Expand Up @@ -39,7 +39,6 @@ Archive::Archive(CommandData *InitCmd)
VolWrite=0;
AddingFilesSize=0;
AddingHeadersSize=0;
*FirstVolumeName=0;

Splitting=false;
NewArchive=false;
Expand Down Expand Up @@ -74,15 +73,15 @@ void Archive::CheckArc(bool EnableBroken)


#if !defined(SFX_MODULE)
void Archive::CheckOpen(const wchar *Name)
void Archive::CheckOpen(const std::wstring &Name)
{
TOpen(Name);
CheckArc(false);
}
#endif


bool Archive::WCheckOpen(const wchar *Name)
bool Archive::WCheckOpen(const std::wstring &Name)
{
if (!WOpen(Name))
return false;
Expand Down Expand Up @@ -148,9 +147,9 @@ bool Archive::IsArchive(bool EnableBroken)
}
else
{
Array<char> Buffer(MAXSFXSIZE);
std::vector<char> Buffer(MAXSFXSIZE);
long CurPos=(long)Tell();
int ReadSize=Read(&Buffer[0],Buffer.Size()-16);
int ReadSize=Read(Buffer.data(),Buffer.size()-16);
for (int I=0;I<ReadSize;I++)
if (Buffer[I]==0x52 && (Type=IsSignature((byte *)&Buffer[I],ReadSize-I))!=RARFMT_NONE)
{
Expand Down Expand Up @@ -265,7 +264,7 @@ bool Archive::IsArchive(bool EnableBroken)
Seek(SavePos,SEEK_SET);
}
if (!Volume || FirstVolume)
wcsncpyz(FirstVolumeName,FileName,ASIZE(FirstVolumeName));
FirstVolumeName=FileName;

return true;
}
Expand Down Expand Up @@ -301,7 +300,7 @@ uint Archive::FullHeaderSize(size_t Size)


#ifdef USE_QOPEN
bool Archive::Open(const wchar *Name,uint Mode)
bool Archive::Open(const std::wstring &Name,uint Mode)
{
// Important if we reuse Archive object and it has virtual QOpen
// file position not matching real. For example, for 'l -v volname'.
Expand Down Expand Up @@ -336,3 +335,23 @@ int64 Archive::Tell()
}
#endif


// Return 0 if dictionary size is invalid. If size is RAR7 only, return
// the adjusted nearest bottom value. Return header flags in Flags.
uint64 Archive::GetWinSize(uint64 Size,uint &Flags)
{
Flags=0;
// Allow 128 KB - 1 TB range.
if (Size<0x20000 || Size>0x10000000000ULL)
return 0;
uint64 Pow2=0x20000; // Power of 2 dictionary size.
for (;2*Pow2<=Size;Pow2*=2)
Flags+=FCI_DICT_BIT0;
if (Size==Pow2)
return Size; // If 'Size' is the power of 2, return it as is.

// Get the number of Pow2/32 to add to Pow2 for nearest value not exceeding 'Size'.
uint64 Fraction=(Size-Pow2)/(Pow2/32);
Flags+=(uint)Fraction*FCI_DICT_FRACT0;
return Pow2+Fraction*(Pow2/32);
}
37 changes: 23 additions & 14 deletions vendor/unrar/archive.hpp
Expand Up @@ -27,7 +27,7 @@ class Archive:public File
{
private:
void UpdateLatestTime(FileHeader *CurBlock);
void ConvertNameCase(wchar *Name);
void ConvertNameCase(std::wstring &Name);
void ConvertFileHeader(FileHeader *hd);
size_t ReadHeader14();
size_t ReadHeader15();
Expand All @@ -36,9 +36,9 @@ class Archive:public File
void RequestArcPassword(RarCheckPassword *SelPwd);
void UnexpEndArcMsg();
void BrokenHeaderMsg();
void UnkEncVerMsg(const wchar *Name,const wchar *Info);
bool DoGetComment(Array<wchar> *CmtData);
bool ReadCommentData(Array<wchar> *CmtData);
void UnkEncVerMsg(const std::wstring &Name,const std::wstring &Info);
bool DoGetComment(std::wstring &CmtData);
bool ReadCommentData(std::wstring &CmtData);

#if !defined(RAR_NOCRYPT)
CryptData HeadersCrypt;
Expand Down Expand Up @@ -67,9 +67,9 @@ class Archive:public File
size_t SearchRR();
size_t ReadHeader();
void CheckArc(bool EnableBroken);
void CheckOpen(const wchar *Name);
bool WCheckOpen(const wchar *Name);
bool GetComment(Array<wchar> *CmtData);
void CheckOpen(const std::wstring &Name);
bool WCheckOpen(const std::wstring &Name);
bool GetComment(std::wstring &CmtData);
void ViewComment();
void SetLatestTime(RarTime *NewTime);
void SeekToNext();
Expand All @@ -79,23 +79,28 @@ class Archive:public File
void VolSubtractHeaderSize(size_t SubSize);
uint FullHeaderSize(size_t Size);
int64 GetStartPos();
void AddSubData(byte *SrcData,uint64 DataSize,File *SrcFile,
void AddSubData(const byte *SrcData,uint64 DataSize,File *SrcFile,
const wchar *Name,uint Flags);
bool ReadSubData(Array<byte> *UnpData,File *DestFile,bool TestMode);
bool ReadSubData(std::vector<byte> *UnpData,File *DestFile,bool TestMode);
HEADER_TYPE GetHeaderType() {return CurHeaderType;}
CommandData* GetCommandData() {return Cmd;}
void SetSilentOpen(bool Mode) {SilentOpen=Mode;}
#if 0
void GetRecoveryInfo(bool Required,int64 *Size,int *Percent);
#endif
#ifdef USE_QOPEN
bool Open(const wchar *Name,uint Mode=FMF_READ);
int Read(void *Data,size_t Size);
void Seek(int64 Offset,int Method);
int64 Tell();
bool Open(const std::wstring &Name,uint Mode=FMF_READ) override;
int Read(void *Data,size_t Size) override;
void Seek(int64 Offset,int Method) override;
int64 Tell() override;
void QOpenUnload() {QOpen.Unload();}
void SetProhibitQOpen(bool Mode) {ProhibitQOpen=Mode;}
#endif
static uint64 GetWinSize(uint64 Size,uint &Flags);

// Needed to see wstring based Open from File. Otherwise compiler finds
// Open in Archive and doesn't check the base class overloads.
using File::Open;

BaseBlock ShortBlock;
MarkHeader MarkHead;
Expand Down Expand Up @@ -135,12 +140,16 @@ class Archive:public File

uint VolNumber;
int64 VolWrite;

// Total size of files adding to archive. Might also include the size of
// files repacked in solid archive.
uint64 AddingFilesSize;

uint64 AddingHeadersSize;

bool NewArchive;

wchar FirstVolumeName[NM];
std::wstring FirstVolumeName;
};


Expand Down

0 comments on commit 6400e68

Please sign in to comment.