home *** CD-ROM | disk | FTP | other *** search
/ Level 2003 February / Level_02_2003.iso / Software / Winrar / wrar310.exe / TechNote.txt < prev    next >
Encoding:
Text File  |  2002-10-04  |  10.4 KB  |  387 lines

  1.  
  2.                RAR version 3.10 - Technical information
  3.                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4.  
  5.  THE ARCHIVE FORMAT DESCRIBED BELOW IS ONLY VALID FOR VERSIONS SINCE 1.50
  6.  
  7.  ==========================================================================
  8.                          RAR archive file format
  9.  ==========================================================================
  10.  
  11.    Archive file consists of variable length blocks. The order of these
  12. blocks may vary, but the first block must be a marker block followed by
  13. an archive header block.
  14.  
  15.    Each block begins with the following fields:
  16.  
  17. HEAD_CRC       2 bytes     CRC of total block or block part
  18. HEAD_TYPE      1 byte      Block type
  19. HEAD_FLAGS     2 bytes     Block flags
  20. HEAD_SIZE      2 bytes     Block size
  21. ADD_SIZE       4 bytes     Optional field - added block size
  22.  
  23.    Field ADD_SIZE present only if (HEAD_FLAGS & 0x8000) != 0
  24.  
  25.    Total block size is HEAD_SIZE if (HEAD_FLAGS & 0x8000) == 0
  26. and HEAD_SIZE+ADD_SIZE if the field ADD_SIZE is present - when
  27. (HEAD_FLAGS & 0x8000) != 0.
  28.  
  29.    In each block the followings bits in HEAD_FLAGS have the same meaning:
  30.  
  31.   0x4000 - if set, older RAR versions will ignore the block
  32.            and remove it when the archive is updated.
  33.            if clear, the block is copied to the new archive
  34.            file when the archive is updated;
  35.  
  36.   0x8000 - if set, ADD_SIZE field is present and the full block
  37.            size is HEAD_SIZE+ADD_SIZE.
  38.  
  39.   Declared block types:
  40.  
  41. HEAD_TYPE=0x72          marker block
  42. HEAD_TYPE=0x73          archive header
  43. HEAD_TYPE=0x74          file header
  44. HEAD_TYPE=0x75          comment header
  45. HEAD_TYPE=0x76          old style authenticity information
  46. HEAD_TYPE=0x77          subblock
  47. HEAD_TYPE=0x78          recovery record
  48. HEAD_TYPE=0x79          authenticity information
  49.  
  50.    Comment block is actually used only within other blocks and doesn't
  51. exist separately.
  52.  
  53.    Archive processing is made in the following manner:
  54.  
  55. 1. Read and check marker block
  56. 2. Read archive header
  57. 3. Read or skip HEAD_SIZE-sizeof(MAIN_HEAD) bytes
  58. 4. If end of archive encountered then terminate archive processing,
  59.    else read 7 bytes into fields HEAD_CRC, HEAD_TYPE, HEAD_FLAGS,
  60.    HEAD_SIZE.
  61. 5. Check HEAD_TYPE.
  62.    if HEAD_TYPE==0x74
  63.      read file header ( first 7 bytes already read )
  64.      read or skip HEAD_SIZE-sizeof(FILE_HEAD) bytes
  65.      if (HEAD_FLAGS & 0x100)
  66.        read or skip HIGH_PACK_SIZE*0x100000000+PACK_SIZE bytes
  67.      else
  68.        read or skip PACK_SIZE bytes
  69.    else
  70.      read corresponding HEAD_TYPE block:
  71.        read HEAD_SIZE-7 bytes
  72.        if (HEAD_FLAGS & 0x8000)
  73.          read ADD_SIZE bytes
  74. 6. go to 4.
  75.  
  76.  
  77.  ==========================================================================
  78.                                Block Formats
  79.  ==========================================================================
  80.  
  81.  
  82.    Marker block ( MARK_HEAD )
  83.  
  84.  
  85. HEAD_CRC        Always 0x6152
  86. 2 bytes
  87.  
  88. HEAD_TYPE       Header type: 0x72
  89. 1 byte
  90.  
  91. HEAD_FLAGS      Always 0x1a21
  92. 2 bytes
  93.  
  94. HEAD_SIZE       Block size = 0x0007
  95. 2 bytes
  96.  
  97.    The marker block is actually considered as a fixed byte
  98. sequence: 0x52 0x61 0x72 0x21 0x1a 0x07 0x00
  99.  
  100.  
  101.  
  102.    Archive header ( MAIN_HEAD )
  103.  
  104.  
  105. HEAD_CRC        CRC of fields HEAD_TYPE to RESERVED2
  106. 2 bytes
  107.  
  108. HEAD_TYPE       Header type: 0x73
  109. 1 byte
  110.  
  111. HEAD_FLAGS      Bit flags:
  112. 2 bytes
  113.                 0x0001  - Volume attribute (archive volume)
  114.                 0x0002  - Archive comment present
  115.                 0x0004  - Archive lock attribute
  116.                 0x0008  - Solid attribute (solid archive)
  117.                 0x0010  - New volume naming scheme ('volname.partN.rar')
  118.                 0x0020  - Authenticity information present
  119.                 0x0040  - Recovery record present
  120.                 0x0080  - Block headers are encrypted
  121.                 0x0100  - First volume (set only by RAR 3.0 and later)
  122.  
  123.                 other bits in HEAD_FLAGS are reserved for
  124.                 internal use
  125.  
  126. HEAD_SIZE       Archive header total size including archive comments
  127. 2 bytes
  128.  
  129. RESERVED1       Reserved
  130. 2 bytes
  131.  
  132. RESERVED2       Reserved
  133. 4 bytes
  134.  
  135.  
  136. Comment block   present if (HEAD_FLAGS & 0x02) != 0
  137.  
  138.  
  139.  
  140.    File header (File in archive)
  141.  
  142.  
  143. HEAD_CRC        CRC of fields from HEAD_TYPE to FILEATTR
  144. 2 bytes         and file name
  145.  
  146. HEAD_TYPE       Header type: 0x74
  147. 1 byte
  148.  
  149. HEAD_FLAGS      Bit flags:
  150. 2 bytes
  151.                 0x01 - file continued from previous volume
  152.                 0x02 - file continued in next volume
  153.                 0x04 - file encrypted with password
  154.                 0x08 - file comment present
  155.                 0x10 - information from previous files is used (solid flag)
  156.                        (for RAR 2.0 and later)
  157.  
  158.                 bits 7 6 5 (for RAR 2.0 and later)
  159.  
  160.                      0 0 0    - dictionary size   64 KB
  161.                      0 0 1    - dictionary size  128 KB
  162.                      0 1 0    - dictionary size  256 KB
  163.                      0 1 1    - dictionary size  512 KB
  164.                      1 0 0    - dictionary size 1024 KB
  165.                      1 0 1    - dictionary size 2048 KB
  166.                      1 1 0    - dictionary size 4096 KB
  167.                      1 1 1    - file is directory
  168.  
  169.                0x100 - HIGH_PACK_SIZE and HIGH_UNP_SIZE fields
  170.                        are present. These fields are used to archive
  171.                        only very large files (larger than 2Gb),
  172.                        for smaller files these fields are absent.
  173.  
  174.                0x200 - FILE_NAME contains both usual and encoded
  175.                        Unicode name separated by zero. In this case
  176.                        NAME_SIZE field is equal to the length
  177.                        of usual name plus encoded Unicode name plus 1.
  178.  
  179.                0x400 - the header contains additional 8 bytes
  180.                        after the file name, which are required to
  181.                        increase encryption security (so called 'salt').
  182.  
  183.                0x800 - Version flag. It is an old file version,
  184.                        a version number is appended to file name as ';n'.
  185.  
  186.               0x8000 - this bit always is set, so the complete
  187.                        block size is HEAD_SIZE + PACK_SIZE
  188.                        (and plus HIGH_PACK_SIZE, if bit 0x100 is set)
  189.  
  190. HEAD_SIZE       File header full size including file name and comments
  191. 2 bytes
  192.  
  193. PACK_SIZE       Compressed file size
  194. 4 bytes
  195.  
  196. UNP_SIZE        Uncompressed file size
  197. 4 bytes
  198.  
  199. HOST_OS         Operating system used for archiving
  200. 1 byte                 0 - MS DOS
  201.                        1 - OS/2
  202.                        2 - Win32
  203.                        3 - Unix
  204.                        4 - Mac OS
  205.                        5 - BeOS
  206.  
  207. FILE_CRC        File CRC
  208. 4 bytes
  209.  
  210. FTIME           Date and time in standard MS DOS format
  211. 4 bytes
  212.  
  213. UNP_VER         RAR version needed to extract file
  214. 1 byte
  215.  
  216. METHOD          Packing method
  217. 1 byte
  218.  
  219. NAME_SIZE       File name size
  220. 2 bytes
  221.  
  222. ATTR            File attributes
  223. 4 bytes
  224.  
  225. HIGH_PACK_SIZE  High 4 bytes of 64 bit value of compressed file size.
  226. 4 bytes         Optional value, presents only if bit 0x100 in HEAD_FLAGS
  227.                 is set.
  228.  
  229. HIGH_UNP_SIZE   High 4 bytes of 64 bit value of uncompressed file size.
  230. 4 bytes         Optional value, presents only if bit 0x100 in HEAD_FLAGS
  231.                 is set.
  232.  
  233. FILE_NAME       File name - string of NAME_SIZE bytes size
  234.  
  235.  
  236. Comment block   present if (HEAD_FLAGS & 0x08) != 0
  237.  
  238.  
  239.  
  240.   Comment block
  241.  
  242.  
  243. HEAD_CRC        CRC of fields from HEAD_TYPE to COMM_CRC
  244. 2 bytes
  245.  
  246. HEAD_TYPE       Header type: 0x75
  247. 1 byte
  248.  
  249. HEAD_FLAGS      Bit flags
  250. 2 bytes
  251.  
  252. HEAD_SIZE       Comment header size + comment size
  253. 2 bytes
  254.  
  255. UNP_SIZE        Uncompressed comment size
  256. 2 bytes
  257.  
  258. UNP_VER         RAR version needed to extract comment
  259. 1 byte
  260.  
  261. METHOD          Packing method
  262. 1 byte
  263.  
  264. COMM_CRC        Comment CRC
  265. 2 bytes
  266.  
  267. COMMENT         Comment text
  268.  
  269.  
  270.  
  271.   Extra info block
  272.  
  273.  
  274. HEAD_CRC        Block CRC
  275. 2 bytes
  276.  
  277. HEAD_TYPE       Header type: 0x76
  278. 1 byte
  279.  
  280. HEAD_FLAGS      Bit flags
  281. 2 bytes
  282.  
  283. HEAD_SIZE       Total block size
  284. 2 bytes
  285.  
  286. INFO            Other data
  287.  
  288.  
  289.   Subblock
  290.  
  291. An object in the archive (the block or header) can be followed
  292. by a subblock. The subblock is dependent upon the main object.
  293. Subblock can be erased or moved to a new version of the archive
  294. when it is updated.
  295.  
  296.  The subblock contains the following fields:
  297.  
  298. HEAD_CRC        Block CRC
  299. 2 bytes
  300.  
  301. HEAD_TYPE       Header type: 0x77
  302. 1 byte
  303.  
  304. HEAD_FLAGS      Bit flags
  305. 2 bytes
  306.                 (HEAD_FLAGS & 0x8000) == 1, because full
  307.                 block size is HEAD_SIZE + DATA_SIZE
  308.  
  309. HEAD_SIZE       Total block size
  310. 2 bytes
  311.  
  312. DATA_SIZE       Total data size
  313. 4 bytes
  314.  
  315. SUB_TYPE        Subblock type
  316. 2 bytes
  317.  
  318. RESERVED        Must be 0
  319. 1 byte
  320.  
  321. Other           Other fields depending on the subblock type
  322. fields
  323.  
  324.  
  325.   OS/2 extended attributes subblock
  326.  
  327.  
  328. HEAD_CRC        Block CRC
  329. 2 bytes
  330.  
  331. HEAD_TYPE       Header type: 0x77
  332. 1 byte
  333.  
  334. HEAD_FLAGS      Bit flags
  335. 2 bytes
  336.                 (HEAD_FLAGS & 0x8000) == 1, because full
  337.                 block size is HEAD_SIZE + DATA_SIZE
  338.  
  339. HEAD_SIZE       Total block size
  340. 2 bytes
  341.  
  342. DATA_SIZE       Total data size (packed extended attributes size)
  343. 4 bytes
  344.  
  345. SUB_TYPE        0x100
  346. 2 bytes
  347.  
  348. RESERVED        Must be 0
  349. 1 byte
  350.  
  351. UNP_SIZE        Uncompressed extended attributes size
  352. 4 bytes
  353.  
  354. UNP_VER         RAR version needed to extract extended attributes
  355. 1 byte
  356.  
  357. METHOD          Packing method
  358. 1 byte
  359.  
  360. EA_CRC          Extended attributes CRC
  361. 4 bytes
  362.  
  363.  
  364.  ==========================================================================
  365.                               Application notes
  366.  ==========================================================================
  367.  
  368.    1. To process an SFX archive you need to skip the SFX module searching
  369. for the marker block in the archive. There is no marker block sequence (0x52
  370. 0x61 0x72 0x21 0x1a 0x07 0x00) in the SFX module itself.
  371.  
  372.    2. The CRC is calculated using the standard polynomial 0xEDB88320. In
  373. case the size of the CRC is less than 4 bytes, only the low order bytes
  374. are used.
  375.  
  376.    3. Packing method encoding:
  377.          0x30 - storing
  378.          0x31 - fastest compression
  379.          0x32 - fast compression
  380.          0x33 - normal compression
  381.          0x34 - good compression
  382.          0x35 - best compression
  383.  
  384.    4. The RAR extraction version number is encoded as 10 * Major version
  385. + minor version.
  386.  
  387.