1
0

archive.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef _RAR_ARCHIVE_
  2. #define _RAR_ARCHIVE_
  3. class PPack;
  4. class RawRead;
  5. class RawWrite;
  6. enum NOMODIFY_FLAGS
  7. {
  8. NMDF_ALLOWLOCK=1,NMDF_ALLOWANYVOLUME=2,NMDF_ALLOWFIRSTVOLUME=4
  9. };
  10. enum RARFORMAT {RARFMT_NONE,RARFMT14,RARFMT15,RARFMT50,RARFMT_FUTURE};
  11. enum ADDSUBDATA_FLAGS
  12. {
  13. ASDF_SPLIT = 1, // Allow to split archive just before header if necessary.
  14. ASDF_COMPRESS = 2, // Allow to compress data following subheader.
  15. ASDF_CRYPT = 4, // Encrypt data after subheader if password is set.
  16. ASDF_CRYPTIFHEADERS = 8 // Encrypt data after subheader only in -hp mode.
  17. };
  18. // RAR5 headers must not exceed 2 MB.
  19. #define MAX_HEADER_SIZE_RAR5 0x200000
  20. class Archive:public File
  21. {
  22. private:
  23. void UpdateLatestTime(FileHeader *CurBlock);
  24. void ConvertNameCase(wchar *Name);
  25. void ConvertFileHeader(FileHeader *hd);
  26. size_t ReadHeader14();
  27. size_t ReadHeader15();
  28. size_t ReadHeader50();
  29. void ProcessExtra50(RawRead *Raw,size_t ExtraSize,BaseBlock *bb);
  30. void RequestArcPassword();
  31. void UnexpEndArcMsg();
  32. void BrokenHeaderMsg();
  33. void UnkEncVerMsg(const wchar *Name,const wchar *Info);
  34. bool DoGetComment(Array<wchar> *CmtData);
  35. bool ReadCommentData(Array<wchar> *CmtData);
  36. #if !defined(RAR_NOCRYPT)
  37. CryptData HeadersCrypt;
  38. #endif
  39. ComprDataIO SubDataIO;
  40. bool DummyCmd;
  41. RAROptions *Cmd;
  42. RarTime LatestTime;
  43. int LastReadBlock;
  44. HEADER_TYPE CurHeaderType;
  45. bool SilentOpen;
  46. #ifdef USE_QOPEN
  47. QuickOpen QOpen;
  48. bool ProhibitQOpen;
  49. #endif
  50. public:
  51. Archive(RAROptions *InitCmd=NULL);
  52. ~Archive();
  53. static RARFORMAT IsSignature(const byte *D,size_t Size);
  54. bool IsArchive(bool EnableBroken);
  55. size_t SearchBlock(HEADER_TYPE HeaderType);
  56. size_t SearchSubBlock(const wchar *Type);
  57. size_t SearchRR();
  58. size_t ReadHeader();
  59. void CheckArc(bool EnableBroken);
  60. void CheckOpen(const wchar *Name);
  61. bool WCheckOpen(const wchar *Name);
  62. bool GetComment(Array<wchar> *CmtData);
  63. void ViewComment();
  64. void SetLatestTime(RarTime *NewTime);
  65. void SeekToNext();
  66. bool CheckAccess();
  67. bool IsArcDir();
  68. void ConvertAttributes();
  69. void VolSubtractHeaderSize(size_t SubSize);
  70. uint FullHeaderSize(size_t Size);
  71. int64 GetStartPos();
  72. void AddSubData(byte *SrcData,uint64 DataSize,File *SrcFile,
  73. const wchar *Name,uint Flags);
  74. bool ReadSubData(Array<byte> *UnpData,File *DestFile,bool TestMode);
  75. HEADER_TYPE GetHeaderType() {return CurHeaderType;}
  76. RAROptions* GetRAROptions() {return Cmd;}
  77. void SetSilentOpen(bool Mode) {SilentOpen=Mode;}
  78. #if 0
  79. void GetRecoveryInfo(bool Required,int64 *Size,int *Percent);
  80. #endif
  81. #ifdef USE_QOPEN
  82. bool Open(const wchar *Name,uint Mode=FMF_READ);
  83. int Read(void *Data,size_t Size);
  84. void Seek(int64 Offset,int Method);
  85. int64 Tell();
  86. void QOpenUnload() {QOpen.Unload();}
  87. void SetProhibitQOpen(bool Mode) {ProhibitQOpen=Mode;}
  88. #endif
  89. BaseBlock ShortBlock;
  90. MarkHeader MarkHead;
  91. MainHeader MainHead;
  92. CryptHeader CryptHead;
  93. FileHeader FileHead;
  94. EndArcHeader EndArcHead;
  95. SubBlockHeader SubBlockHead;
  96. FileHeader SubHead;
  97. CommentHeader CommHead;
  98. ProtectHeader ProtectHead;
  99. UnixOwnersHeader UOHead;
  100. EAHeader EAHead;
  101. StreamHeader StreamHead;
  102. int64 CurBlockPos;
  103. int64 NextBlockPos;
  104. RARFORMAT Format;
  105. bool Solid;
  106. bool Volume;
  107. bool MainComment;
  108. bool Locked;
  109. bool Signed;
  110. bool FirstVolume;
  111. bool NewNumbering;
  112. bool Protected;
  113. bool Encrypted;
  114. size_t SFXSize;
  115. bool BrokenHeader;
  116. bool FailedHeaderDecryption;
  117. #if !defined(RAR_NOCRYPT)
  118. byte ArcSalt[SIZE_SALT50];
  119. #endif
  120. bool Splitting;
  121. uint VolNumber;
  122. int64 VolWrite;
  123. uint64 AddingFilesSize;
  124. uint64 AddingHeadersSize;
  125. bool NewArchive;
  126. wchar FirstVolumeName[NM];
  127. };
  128. #endif