From 3dd4843b9ddc899a3657af9d916e945aa96b63ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 15 Oct 2007 23:49:42 +0000 Subject: [PATCH] Updated unrar to 3.7.8, patch by Ioan Molnar - thanks! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22584 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/unrar/Jamfile | 0 src/bin/unrar/arccmt.cpp | 4 ++++ src/bin/unrar/cmddata.cpp | 10 +++++++--- src/bin/unrar/dll.cpp | 3 ++- src/bin/unrar/extract.cpp | 5 +++++ src/bin/unrar/file.cpp | 4 +++- src/bin/unrar/filefn.cpp | 8 +++++++- src/bin/unrar/find.cpp | 2 +- src/bin/unrar/list.cpp | 5 +++++ src/bin/unrar/model.cpp | 10 ++++++++++ src/bin/unrar/model.hpp | 1 + src/bin/unrar/pathfn.cpp | 8 ++++++++ src/bin/unrar/rarvm.cpp | 16 +++++++++++----- src/bin/unrar/rdwrfn.cpp | 10 +++++++--- src/bin/unrar/readme.txt | 1 + src/bin/unrar/scantree.cpp | 15 +++++++++++++-- src/bin/unrar/system.cpp | 16 +++++----------- src/bin/unrar/system.hpp | 16 ++++++++++++++++ src/bin/unrar/unpack.cpp | 22 +++++++++++++++++----- src/bin/unrar/unpack.hpp | 1 - src/bin/unrar/unpack20.cpp | 4 +++- src/bin/unrar/unrar.rdef | 6 +++--- src/bin/unrar/version.hpp | 8 ++++---- src/bin/unrar/volume.cpp | 4 ++-- 24 files changed, 135 insertions(+), 44 deletions(-) mode change 100755 => 100644 src/bin/unrar/Jamfile mode change 100755 => 100644 src/bin/unrar/unrar.rdef diff --git a/src/bin/unrar/Jamfile b/src/bin/unrar/Jamfile old mode 100755 new mode 100644 diff --git a/src/bin/unrar/arccmt.cpp b/src/bin/unrar/arccmt.cpp index a8f71e9b7c..6ada2f03c4 100644 --- a/src/bin/unrar/arccmt.cpp +++ b/src/bin/unrar/arccmt.cpp @@ -46,9 +46,13 @@ bool Archive::GetComment(Array *CmtData,Array *CmtDataW) uint UnpCmtLength; if (OldFormat) { +#ifdef NOCRYPT + return(false); +#else UnpCmtLength=GetByte()+(GetByte()<<8); CmtLength-=2; DataIO.SetCmt13Encryption(); +#endif } else UnpCmtLength=CommHead.UnpSize; diff --git a/src/bin/unrar/cmddata.cpp b/src/bin/unrar/cmddata.cpp index 979c0303d9..41f3dd7e39 100644 --- a/src/bin/unrar/cmddata.cpp +++ b/src/bin/unrar/cmddata.cpp @@ -466,7 +466,7 @@ void CommandData::ProcessSwitch(char *Switch) case 'N': case 'X': if (Switch[1]!=0) - { + { StringList *Args=etoupper(Switch[0])=='N' ? InclArgs:ExclArgs; if (Switch[1]=='@' && !IsWildcard(Switch)) { @@ -957,7 +957,7 @@ void CommandData::OutHelp() #endif #ifndef _WIN_32 static MSGID Win32Only[]={ - MCHelpSwIEML,MCHelpSwVD,MCHelpSwAC,MCHelpSwAO,MCHelpSwOS,MCHelpSwIOFF, + MCHelpSwIEML,MCHelpSwVD,MCHelpSwAO,MCHelpSwOS,MCHelpSwIOFF, MCHelpSwEP2,MCHelpSwOC }; bool Found=false; @@ -974,6 +974,10 @@ void CommandData::OutHelp() if (Help[I]==MCHelpSwOW) continue; #endif +#if !defined(_WIN_32) && !defined(_EMX) + if (Help[I]==MCHelpSwAC) + continue; +#endif #ifndef SAVE_LINKS if (Help[I]==MCHelpSwOL) continue; @@ -1035,7 +1039,7 @@ bool CommandData::ExclCheck(char *CheckName,bool CheckFullPath) return(true); if (InclArgs->ItemsCount()==0) return(false); - if (ExclCheckArgs(InclArgs,CheckName,CheckFullPath,MATCH_WILDSUBPATH)) + if (ExclCheckArgs(InclArgs,CheckName,false,MATCH_WILDSUBPATH)) return(false); return(true); } diff --git a/src/bin/unrar/dll.cpp b/src/bin/unrar/dll.cpp index bf3538b744..f1a2cc90ea 100644 --- a/src/bin/unrar/dll.cpp +++ b/src/bin/unrar/dll.cpp @@ -326,12 +326,13 @@ void PASCAL RARSetProcessDataProc(HANDLE hArcData,PROCESSDATAPROC ProcessDataPro Data->Cmd.ProcessDataProc=ProcessDataProc; } - +#ifndef NOCRYPT void PASCAL RARSetPassword(HANDLE hArcData,char *Password) { DataSet *Data=(DataSet *)hArcData; strncpyz(Data->Cmd.Password,Password,ASIZE(Data->Cmd.Password)); } +#endif int PASCAL RARGetDllVersion() diff --git a/src/bin/unrar/extract.cpp b/src/bin/unrar/extract.cpp index 4871ec9234..e9d75173ba 100644 --- a/src/bin/unrar/extract.cpp +++ b/src/bin/unrar/extract.cpp @@ -143,6 +143,11 @@ EXTRACT_ARC_CODE CmdExtract::ExtractArchive(CommandData *Cmd) Arc.ViewComment(); + // RAR can close a corrupt encrypted archive + if (!Arc.IsOpened()) + return(EXTRACT_ARC_NEXT); + + while (1) { int Size=Arc.ReadHeader(); diff --git a/src/bin/unrar/file.cpp b/src/bin/unrar/file.cpp index 774f7c34bc..f8dba45d2b 100644 --- a/src/bin/unrar/file.cpp +++ b/src/bin/unrar/file.cpp @@ -253,10 +253,12 @@ void File::Flush() bool File::Delete() { - if (HandleType!=FILE_HANDLENORMAL || !AllowDelete) + if (HandleType!=FILE_HANDLENORMAL) return(false); if (hFile!=BAD_HANDLE) Close(); + if (!AllowDelete) + return(false); return(DelFile(FileName,FileNameW)); } diff --git a/src/bin/unrar/filefn.cpp b/src/bin/unrar/filefn.cpp index da76763ea6..1c43eaea9a 100644 --- a/src/bin/unrar/filefn.cpp +++ b/src/bin/unrar/filefn.cpp @@ -43,7 +43,7 @@ MKDIR_CODE MakeDir(const char *Name,const wchar *NameW,uint Attr) bool CreatePath(const char *Path,const wchar *PathW,bool SkipLastName) { -#ifdef _WIN_32 +#if defined(_WIN_32) || defined(_EMX) uint DirAttr=0; #else uint DirAttr=0777; @@ -211,6 +211,7 @@ Int64 GetFreeDisk(const char *Name) return(1457664); #elif defined(_EMX) int Drive=(!isalpha(Name[0]) || Name[1]!=':') ? 0:etoupper(Name[0])-'A'+1; +#ifndef _DJGPP if (_osmode == OS2_MODE) { FSALLOCATE fsa; @@ -221,12 +222,17 @@ Int64 GetFreeDisk(const char *Name) return(FreeSize); } else +#endif { union REGS regs,outregs; memset(®s,0,sizeof(regs)); regs.h.ah=0x36; regs.h.dl=Drive; +#ifdef _DJGPP + int86 (0x21,®s,&outregs); +#else _int86 (0x21,®s,&outregs); +#endif if (outregs.x.ax==0xffff) return(1457664); Int64 FreeSize=outregs.x.ax*outregs.x.cx; diff --git a/src/bin/unrar/find.cpp b/src/bin/unrar/find.cpp index 4b39284201..9885ee69f9 100644 --- a/src/bin/unrar/find.cpp +++ b/src/bin/unrar/find.cpp @@ -162,7 +162,7 @@ bool FindFile::FastFind(const char *FindMask,const wchar *FindMaskW,struct FindD return(false); } #ifdef _DJGPP - fd->FileAttr=chmod(FindMask,0); + fd->FileAttr=_chmod(FindMask,0); #elif defined(_EMX) fd->FileAttr=st.st_attr; #else diff --git a/src/bin/unrar/list.cpp b/src/bin/unrar/list.cpp index 9aed15469d..d5690064d8 100644 --- a/src/bin/unrar/list.cpp +++ b/src/bin/unrar/list.cpp @@ -38,6 +38,11 @@ void ListArchive(CommandData *Cmd) if (!Bare) { Arc.ViewComment(); + + // RAR can close a corrupt encrypted archive + if (!Arc.IsOpened()) + break; + mprintf("\n"); if (Arc.Solid) mprintf(St(MListSolid)); diff --git a/src/bin/unrar/model.cpp b/src/bin/unrar/model.cpp index efc69f42f9..abc73d2b8d 100644 --- a/src/bin/unrar/model.cpp +++ b/src/bin/unrar/model.cpp @@ -527,6 +527,16 @@ inline void ModelPPM::ClearMask() +// reset PPM variables after data error allowing safe resuming +// of further data processing +void ModelPPM::CleanUp() +{ + SubAlloc.StopSubAllocator(); + SubAlloc.StartSubAllocator(1); + StartModelRare(2); +} + + bool ModelPPM::DecodeInit(Unpack *UnpackRead,int &EscChar) { int MaxOrder=UnpackRead->GetChar(); diff --git a/src/bin/unrar/model.hpp b/src/bin/unrar/model.hpp index 8b577ac797..f39323bbb1 100644 --- a/src/bin/unrar/model.hpp +++ b/src/bin/unrar/model.hpp @@ -124,6 +124,7 @@ class ModelPPM inline void ClearMask(); public: ModelPPM(); + void CleanUp(); // reset PPM variables after data error bool DecodeInit(Unpack *UnpackRead,int &EscChar); int DecodeChar(); }; diff --git a/src/bin/unrar/pathfn.cpp b/src/bin/unrar/pathfn.cpp index ca2a58ad1c..e635d16178 100644 --- a/src/bin/unrar/pathfn.cpp +++ b/src/bin/unrar/pathfn.cpp @@ -334,6 +334,7 @@ bool EnumConfigPaths(char *Path,int Number) strcpy(RARFileName,Path); if (Number!=0) return(false); +#ifndef _DJGPP if (_osmode==OS2_MODE) { PTIB ptib; @@ -342,6 +343,7 @@ bool EnumConfigPaths(char *Path,int Number) DosQueryModuleName(ppib->pib_hmte,NM,Path); } else +#endif strcpy(Path,RARFileName); RemoveNameFromPath(Path); return(true); @@ -476,8 +478,12 @@ bool IsNameUsable(const char *Name) if (Name[0] && Name[1] && strchr(Name+2,':')!=NULL) return(false); for (const char *s=Name;*s!=0;s=charnext(s)) + { if (*s<32) return(false); + if (*s==' ' && IsPathDiv(s[1])) + return(false); + } #endif return(*Name!=0 && strpbrk(Name,"?*<>|\"")==NULL); } @@ -496,6 +502,8 @@ void MakeNameUsable(char *Name,bool Extended) #ifndef _UNIX if (s-Name>1 && *s==':') *s='_'; + if (*s==' ' && IsPathDiv(s[1])) + *s='_'; #endif } } diff --git a/src/bin/unrar/rarvm.cpp b/src/bin/unrar/rarvm.cpp index 3276c45df3..da212e6a88 100644 --- a/src/bin/unrar/rarvm.cpp +++ b/src/bin/unrar/rarvm.cpp @@ -179,8 +179,10 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize) VM_PreparedCommand *Cmd=PreparedCode; while (1) { +#ifndef NORARVM uint *Op1=GetOperand(&Cmd->Op1); uint *Op2=GetOperand(&Cmd->Op2); +#endif switch(Cmd->OpCode) { #ifndef NORARVM @@ -506,7 +508,7 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize) SET_VALUE(Cmd->ByteMode,Op1,Result); } break; -#endif +#endif // for #ifndef NORARVM case VM_RET: if (R[7]>=VM_MEMSIZE) return(true); @@ -767,6 +769,8 @@ void RarVM::Optimize(VM_PreparedProgram *Prg) case VM_CMP: Cmd->OpCode=Cmd->ByteMode ? VM_CMPB:VM_CMPD; continue; + default: + break; } if ((VM_CmdFlags[Cmd->OpCode] & VMCF_CHFLAGS)==0) continue; @@ -801,6 +805,8 @@ void RarVM::Optimize(VM_PreparedProgram *Prg) case VM_NEG: Cmd->OpCode=Cmd->ByteMode ? VM_NEGB:VM_NEGD; continue; + default: + break; } } } @@ -843,12 +849,12 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType) int DataSize=R[4]; uint FileOffset=R[6]; - if (DataSize>=VM_GLOBALMEMADDR) + if (DataSize>=VM_GLOBALMEMADDR || DataSize<4) break; const int FileSize=0x1000000; byte CmpByte2=FilterType==VMSF_E8E9 ? 0xe9:0xe8; - for (uint CurPos=0;CurPos=VM_GLOBALMEMADDR) + if (DataSize>=VM_GLOBALMEMADDR || DataSize<21) break; - uint CurPos=0; + int CurPos=0; FileOffset>>=4; diff --git a/src/bin/unrar/rdwrfn.cpp b/src/bin/unrar/rdwrfn.cpp index 955c254ec5..2454377239 100644 --- a/src/bin/unrar/rdwrfn.cpp +++ b/src/bin/unrar/rdwrfn.cpp @@ -62,9 +62,13 @@ int ComprDataIO::UnpRead(byte *Addr,uint Count) PackedCRC=CRC(PackedCRC,ReadAddr,ReadSize); } CurUnpRead+=RetCode; - ReadAddr+=RetCode; TotalRead+=RetCode; +#ifndef NOVOLUME + // these variable are not used below in NOVOLUME mode, so it is better + // to exclude these commands to avoid compiler warnings + ReadAddr+=RetCode; Count-=RetCode; +#endif UnpPackedSize-=RetCode; if (UnpPackedSize == 0 && UnpVolume) { @@ -230,7 +234,7 @@ void ComprDataIO::SetEncryption(int Method,char *Password,byte *Salt,bool Encryp } -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(NOCRYPT) void ComprDataIO::SetAV15Encryption() { Decryption=15; @@ -239,7 +243,7 @@ void ComprDataIO::SetAV15Encryption() #endif -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(NOCRYPT) void ComprDataIO::SetCmt13Encryption() { Decryption=13; diff --git a/src/bin/unrar/readme.txt b/src/bin/unrar/readme.txt index abd6248c58..41ee05caea 100644 --- a/src/bin/unrar/readme.txt +++ b/src/bin/unrar/readme.txt @@ -47,6 +47,7 @@ Steve Reid SHA-1 hash function Marcus Herbert makefile.unix file Tomasz Klim fixes for libunrar.so + Robert Riebisch makefile.dj and patches for DJGPP 4. Legal stuff diff --git a/src/bin/unrar/scantree.cpp b/src/bin/unrar/scantree.cpp index 5fc43b2b87..416de6df0d 100644 --- a/src/bin/unrar/scantree.cpp +++ b/src/bin/unrar/scantree.cpp @@ -154,8 +154,19 @@ int ScanTree::FindProc(FindData *FindData) bool Error=FindData->Error; #ifdef _WIN_32 - if (Error && strstr(CurMask,"System Volume Information\\")!=NULL) - Error=false; + if (Error) + { + // Do not display an error if we cannot scan contents of reparse + // point. Vista contains a lot of reparse (or junction) points, + // which are not accessible. + if ((FindData->FileAttr & FILE_ATTRIBUTE_REPARSE_POINT)!=0) + Error=false; + + // Do not display an error if we cannot scan contents of + // "System Volume Information" folder. Normally it is not accessible. + if (strstr(CurMask,"System Volume Information\\")!=NULL) + Error=false; + } #endif if (Cmd!=NULL && Cmd->ExclCheck(CurMask,true)) diff --git a/src/bin/unrar/system.cpp b/src/bin/unrar/system.cpp index 9f776dd35d..d5de22e516 100644 --- a/src/bin/unrar/system.cpp +++ b/src/bin/unrar/system.cpp @@ -12,11 +12,6 @@ void InitSystemOptions(int SleepTime) #if !defined(SFX_MODULE) && !defined(_WIN_CE) -#if defined(_WIN_32) && !defined(BELOW_NORMAL_PRIORITY_CLASS) -#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000 -#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 -#endif - void SetPriority(int Priority) { #ifdef _WIN_32 @@ -61,6 +56,11 @@ void SetPriority(int Priority) } SetPriorityClass(GetCurrentProcess(),PriorityClass); SetThreadPriority(GetCurrentThread(),PriorityLevel); + +// background mode for Vista, too slow for real life use +// if (WinNT()>=6 && Priority==1) +// SetPriorityClass(GetCurrentProcess(),PROCESS_MODE_BACKGROUND_BEGIN); + #endif } #endif @@ -79,12 +79,6 @@ void Wait() #if defined(_WIN_32) && !defined(_WIN_CE) && !defined(SFX_MODULE) && !defined(SHELL_EXT) -#ifndef SHTDN_REASON_MAJOR_APPLICATION -#define SHTDN_REASON_MAJOR_APPLICATION 0x00040000 -#define SHTDN_REASON_FLAG_PLANNED 0x80000000 -#define SHTDN_REASON_MINOR_MAINTENANCE 0x00000001 -#endif - void Shutdown() { HANDLE hToken; diff --git a/src/bin/unrar/system.hpp b/src/bin/unrar/system.hpp index 89582ecef0..d98e5a22ca 100644 --- a/src/bin/unrar/system.hpp +++ b/src/bin/unrar/system.hpp @@ -1,6 +1,22 @@ #ifndef _RAR_SYSTEM_ #define _RAR_SYSTEM_ +#ifdef _WIN_32 +#ifndef BELOW_NORMAL_PRIORITY_CLASS +#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000 +#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 +#endif +#ifndef PROCESS_MODE_BACKGROUND_BEGIN +#define PROCESS_MODE_BACKGROUND_BEGIN 0x00100000 +#define PROCESS_MODE_BACKGROUND_END 0x00200000 +#endif +#ifndef SHTDN_REASON_MAJOR_APPLICATION +#define SHTDN_REASON_MAJOR_APPLICATION 0x00040000 +#define SHTDN_REASON_FLAG_PLANNED 0x80000000 +#define SHTDN_REASON_MINOR_MAINTENANCE 0x00000001 +#endif +#endif + void InitSystemOptions(int SleepTime); void SetPriority(int Priority); void Wait(); diff --git a/src/bin/unrar/unpack.cpp b/src/bin/unrar/unpack.cpp index 8f394c4627..1b239ca5c4 100644 --- a/src/bin/unrar/unpack.cpp +++ b/src/bin/unrar/unpack.cpp @@ -43,6 +43,12 @@ void Unpack::Init(byte *Window) ExternalWindow=true; } UnpInitData(false); + +#ifndef SFX_MODULE + // RAR 1.5 decompression initialization + OldUnpInitData(false); + InitHuff(); +#endif } @@ -190,9 +196,6 @@ void Unpack::Unpack29(bool Solid) return; } - if (PPMError) - return; - while (true) { UnpPtr&=MAXWINMASK; @@ -218,7 +221,11 @@ void Unpack::Unpack29(bool Solid) int Ch=PPM.DecodeChar(); if (Ch==-1) { - PPMError=true; + PPM.CleanUp(); + + // turn off PPM compression mode in case of error, so UnRAR will + // call PPM.DecodeInit in case it needs to turn it on back later. + UnpBlockType=BLOCK_LZ; break; } if (Ch==PPMEscChar) @@ -935,13 +942,18 @@ void Unpack::UnpInitData(int Solid) LastDist=LastLength=0; // memset(Window,0,MAXWINSIZE); memset(UnpOldTable,0,sizeof(UnpOldTable)); + memset(&LD,0,sizeof(LD)); + memset(&DD,0,sizeof(DD)); + memset(&LDD,0,sizeof(LDD)); + memset(&RD,0,sizeof(RD)); + memset(&BD,0,sizeof(BD)); UnpPtr=WrPtr=0; PPMEscChar=2; + UnpBlockType=BLOCK_LZ; InitFilters(); } InitBitInput(); - PPMError=false; WrittenFileSize=0; ReadTop=0; ReadBorder=0; diff --git a/src/bin/unrar/unpack.hpp b/src/bin/unrar/unpack.hpp index 4def6a566f..75df302638 100644 --- a/src/bin/unrar/unpack.hpp +++ b/src/bin/unrar/unpack.hpp @@ -159,7 +159,6 @@ class Unpack:private BitInput bool UnpSomeRead; Int64 WrittenFileSize; bool FileExtracted; - bool PPMError; int PrevLowDist,LowDistRepCount; diff --git a/src/bin/unrar/unpack20.cpp b/src/bin/unrar/unpack20.cpp index 5091ed03c0..ce0ab1f3fd 100644 --- a/src/bin/unrar/unpack20.cpp +++ b/src/bin/unrar/unpack20.cpp @@ -269,10 +269,12 @@ void Unpack::UnpInitData20(int Solid) { if (!Solid) { - UnpChannelDelta=UnpCurChannel=0; + UnpAudioBlock=UnpChannelDelta=UnpCurChannel=0; UnpChannels=1; + memset(AudV,0,sizeof(AudV)); memset(UnpOldTable20,0,sizeof(UnpOldTable20)); + memset(MD,0,sizeof(MD)); } } diff --git a/src/bin/unrar/unrar.rdef b/src/bin/unrar/unrar.rdef old mode 100755 new mode 100644 index 8263e91e06..74d22c9196 --- a/src/bin/unrar/unrar.rdef +++ b/src/bin/unrar/unrar.rdef @@ -5,9 +5,9 @@ resource app_flags B_MULTIPLE_LAUNCH | B_BACKGROUND_APP; resource app_version { major = 3, middle = 7, - minor = 6, + minor = 8, variety = 0, internal = 0, - short_info = "3.76", - long_info = "3.76 Alexander Roshal" + short_info = "3.78", + long_info = "3.78 Alexander Roshal" }; diff --git a/src/bin/unrar/version.hpp b/src/bin/unrar/version.hpp index 3e628dd3ff..d29ecec81e 100644 --- a/src/bin/unrar/version.hpp +++ b/src/bin/unrar/version.hpp @@ -1,6 +1,6 @@ #define RARVER_MAJOR 3 -#define RARVER_MINOR 70 -#define RARVER_BETA 0 -#define RARVER_DAY 22 -#define RARVER_MONTH 5 +#define RARVER_MINOR 71 +#define RARVER_BETA 1 +#define RARVER_DAY 10 +#define RARVER_MONTH 9 #define RARVER_YEAR 2007 diff --git a/src/bin/unrar/volume.cpp b/src/bin/unrar/volume.cpp index 28f0757b29..9a79662850 100644 --- a/src/bin/unrar/volume.cpp +++ b/src/bin/unrar/volume.cpp @@ -97,7 +97,7 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,char Comman break; } } -#else +#else // RARDLL #if !defined(SFX_MODULE) && !defined(_WIN_CE) if (!RecoveryDone) @@ -123,8 +123,8 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,char Comman FailedOpen=true; break; } +#endif // RARDLL *NextNameW=0; -#endif } if (FailedOpen) {