headers.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #ifndef _RAR_HEADERS_
  2. #define _RAR_HEADERS_
  3. #define SIZEOF_MARKHEAD 7
  4. #define SIZEOF_OLDMHD 7
  5. #define SIZEOF_NEWMHD 13
  6. #define SIZEOF_OLDLHD 21
  7. #define SIZEOF_NEWLHD 32
  8. #define SIZEOF_SHORTBLOCKHEAD 7
  9. #define SIZEOF_LONGBLOCKHEAD 11
  10. #define SIZEOF_SUBBLOCKHEAD 14
  11. #define SIZEOF_COMMHEAD 13
  12. #define SIZEOF_PROTECTHEAD 26
  13. #define SIZEOF_AVHEAD 14
  14. #define SIZEOF_SIGNHEAD 15
  15. #define SIZEOF_UOHEAD 18
  16. #define SIZEOF_MACHEAD 22
  17. #define SIZEOF_EAHEAD 24
  18. #define SIZEOF_BEEAHEAD 24
  19. #define SIZEOF_STREAMHEAD 26
  20. #define PACK_VER 29
  21. #define PACK_CRYPT_VER 29
  22. #define UNP_VER 36
  23. #define CRYPT_VER 29
  24. #define AV_VER 20
  25. #define PROTECT_VER 20
  26. #define MHD_VOLUME 0x0001U
  27. // Old style main archive comment embed into main archive header. Must not
  28. // be used in new archives anymore. Must never be used with MHD_ENCRYPTVER
  29. // or other flags changing the size of main header. RAR expects the fixed
  30. // size of main header preceding the comment if MHD_COMMENT is found.
  31. #define MHD_COMMENT 0x0002U
  32. #define MHD_LOCK 0x0004U
  33. #define MHD_SOLID 0x0008U
  34. #define MHD_PACK_COMMENT 0x0010U
  35. #define MHD_NEWNUMBERING 0x0010U
  36. #define MHD_AV 0x0020U
  37. #define MHD_PROTECT 0x0040U
  38. #define MHD_PASSWORD 0x0080U
  39. #define MHD_FIRSTVOLUME 0x0100U
  40. #define MHD_ENCRYPTVER 0x0200U
  41. #define LHD_SPLIT_BEFORE 0x0001U
  42. #define LHD_SPLIT_AFTER 0x0002U
  43. #define LHD_PASSWORD 0x0004U
  44. // Old style file comment embed into file header. Must not be used
  45. // in new archives anymore.
  46. #define LHD_COMMENT 0x0008U
  47. #define LHD_SOLID 0x0010U
  48. #define LHD_WINDOWMASK 0x00e0U
  49. #define LHD_WINDOW64 0x0000U
  50. #define LHD_WINDOW128 0x0020U
  51. #define LHD_WINDOW256 0x0040U
  52. #define LHD_WINDOW512 0x0060U
  53. #define LHD_WINDOW1024 0x0080U
  54. #define LHD_WINDOW2048 0x00a0U
  55. #define LHD_WINDOW4096 0x00c0U
  56. #define LHD_DIRECTORY 0x00e0U
  57. #define LHD_LARGE 0x0100U
  58. #define LHD_UNICODE 0x0200U
  59. #define LHD_SALT 0x0400U
  60. #define LHD_VERSION 0x0800U
  61. #define LHD_EXTTIME 0x1000U
  62. #define LHD_EXTFLAGS 0x2000U
  63. #define SKIP_IF_UNKNOWN 0x4000U
  64. #define LONG_BLOCK 0x8000U
  65. #define EARC_NEXT_VOLUME 0x0001U // Not last volume.
  66. #define EARC_DATACRC 0x0002U // Store CRC32 of RAR archive (now is used only in volumes).
  67. #define EARC_REVSPACE 0x0004U // Reserve space for end of REV file 7 byte record.
  68. #define EARC_VOLNUMBER 0x0008U // Store a number of current volume.
  69. enum HEADER_TYPE {
  70. MARK_HEAD=0x72,MAIN_HEAD=0x73,FILE_HEAD=0x74,COMM_HEAD=0x75,AV_HEAD=0x76,
  71. SUB_HEAD=0x77,PROTECT_HEAD=0x78,SIGN_HEAD=0x79,NEWSUB_HEAD=0x7a,
  72. ENDARC_HEAD=0x7b
  73. };
  74. enum { EA_HEAD=0x100,UO_HEAD=0x101,MAC_HEAD=0x102,BEEA_HEAD=0x103,
  75. NTACL_HEAD=0x104,STREAM_HEAD=0x105 };
  76. enum HOST_SYSTEM {
  77. HOST_MSDOS=0,HOST_OS2=1,HOST_WIN32=2,HOST_UNIX=3,HOST_MACOS=4,
  78. HOST_BEOS=5,HOST_MAX
  79. };
  80. #define SUBHEAD_TYPE_CMT "CMT"
  81. #define SUBHEAD_TYPE_ACL "ACL"
  82. #define SUBHEAD_TYPE_STREAM "STM"
  83. #define SUBHEAD_TYPE_UOWNER "UOW"
  84. #define SUBHEAD_TYPE_AV "AV"
  85. #define SUBHEAD_TYPE_RR "RR"
  86. #define SUBHEAD_TYPE_OS2EA "EA2"
  87. #define SUBHEAD_TYPE_BEOSEA "EABE"
  88. /* new file inherits a subblock when updating a host file */
  89. #define SUBHEAD_FLAGS_INHERITED 0x80000000
  90. #define SUBHEAD_FLAGS_CMT_UNICODE 0x00000001
  91. struct OldMainHeader
  92. {
  93. byte Mark[4];
  94. ushort HeadSize;
  95. byte Flags;
  96. };
  97. struct OldFileHeader
  98. {
  99. uint PackSize;
  100. uint UnpSize;
  101. ushort FileCRC;
  102. ushort HeadSize;
  103. uint FileTime;
  104. byte FileAttr;
  105. byte Flags;
  106. byte UnpVer;
  107. byte NameSize;
  108. byte Method;
  109. };
  110. struct MarkHeader
  111. {
  112. byte Mark[7];
  113. };
  114. struct BaseBlock
  115. {
  116. ushort HeadCRC;
  117. HEADER_TYPE HeadType; // 1 byte.
  118. ushort Flags;
  119. ushort HeadSize;
  120. bool IsSubBlock()
  121. {
  122. if (HeadType==SUB_HEAD)
  123. return(true);
  124. if (HeadType==NEWSUB_HEAD && (Flags & LHD_SOLID)!=0)
  125. return(true);
  126. return(false);
  127. }
  128. };
  129. struct BlockHeader:BaseBlock
  130. {
  131. union {
  132. uint DataSize;
  133. uint PackSize;
  134. };
  135. };
  136. struct MainHeader:BaseBlock
  137. {
  138. ushort HighPosAV;
  139. uint PosAV;
  140. byte EncryptVer;
  141. };
  142. #define SALT_SIZE 8
  143. struct FileHeader:BlockHeader
  144. {
  145. uint UnpSize;
  146. byte HostOS;
  147. uint FileCRC;
  148. uint FileTime;
  149. byte UnpVer;
  150. byte Method;
  151. ushort NameSize;
  152. union {
  153. uint FileAttr;
  154. uint SubFlags;
  155. };
  156. /* optional */
  157. uint HighPackSize;
  158. uint HighUnpSize;
  159. /* names */
  160. char FileName[NM];
  161. wchar FileNameW[NM];
  162. /* optional */
  163. Array<byte> SubData;
  164. byte Salt[SALT_SIZE];
  165. RarTime mtime;
  166. RarTime ctime;
  167. RarTime atime;
  168. RarTime arctime;
  169. /* dummy */
  170. int64 FullPackSize;
  171. int64 FullUnpSize;
  172. void Clear(size_t SubDataSize)
  173. {
  174. SubData.Alloc(SubDataSize);
  175. Flags=LONG_BLOCK;
  176. SubFlags=0;
  177. }
  178. bool CmpName(const char *Name)
  179. {
  180. return(strcmp(FileName,Name)==0);
  181. }
  182. FileHeader& operator = (FileHeader &hd)
  183. {
  184. SubData.Reset();
  185. memcpy(this,&hd,sizeof(*this));
  186. SubData.CleanData();
  187. SubData=hd.SubData;
  188. return(*this);
  189. }
  190. };
  191. struct EndArcHeader:BaseBlock
  192. {
  193. // Optional CRC32 of entire archive up to start of EndArcHeader block.
  194. // Present if EARC_DATACRC flag is set.
  195. uint ArcDataCRC;
  196. // Optional number of current volume.
  197. // Present if EARC_VOLNUMBER flag is set.
  198. ushort VolNumber;
  199. // 7 additional zero bytes can be stored here if EARC_REVSPACE is set.
  200. };
  201. // SubBlockHeader and its successors were used in RAR 2.x format.
  202. // RAR 3.x uses FileHeader with NEWSUB_HEAD HeadType for subblocks.
  203. struct SubBlockHeader:BlockHeader
  204. {
  205. ushort SubType;
  206. byte Level;
  207. };
  208. struct CommentHeader:BaseBlock
  209. {
  210. ushort UnpSize;
  211. byte UnpVer;
  212. byte Method;
  213. ushort CommCRC;
  214. };
  215. struct ProtectHeader:BlockHeader
  216. {
  217. byte Version;
  218. ushort RecSectors;
  219. uint TotalBlocks;
  220. byte Mark[8];
  221. };
  222. struct AVHeader:BaseBlock
  223. {
  224. byte UnpVer;
  225. byte Method;
  226. byte AVVer;
  227. uint AVInfoCRC;
  228. };
  229. struct SignHeader:BaseBlock
  230. {
  231. uint CreationTime;
  232. ushort ArcNameSize;
  233. ushort UserNameSize;
  234. };
  235. struct UnixOwnersHeader:SubBlockHeader
  236. {
  237. ushort OwnerNameSize;
  238. ushort GroupNameSize;
  239. /* dummy */
  240. char OwnerName[NM];
  241. char GroupName[NM];
  242. };
  243. struct EAHeader:SubBlockHeader
  244. {
  245. uint UnpSize;
  246. byte UnpVer;
  247. byte Method;
  248. uint EACRC;
  249. };
  250. struct StreamHeader:SubBlockHeader
  251. {
  252. uint UnpSize;
  253. byte UnpVer;
  254. byte Method;
  255. uint StreamCRC;
  256. ushort StreamNameSize;
  257. /* dummy */
  258. byte StreamName[NM];
  259. };
  260. struct MacFInfoHeader:SubBlockHeader
  261. {
  262. uint fileType;
  263. uint fileCreator;
  264. };
  265. #endif