home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 October / PCWorld_2002-10_cd.bin / Software / Topware / winrar / wrar30cz.exe / TechNote.txt < prev    next >
Encoding:
Text File  |  2002-01-31  |  10.4 KB  |  386 lines

  1.  
  2.                RAR version 3.00 - 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.                 0x01    - Volume attribute (archive volume)
  114.                 0x02    - Archive comment present
  115.                 0x04    - Archive lock attribute
  116.                 0x08    - Solid attribute (solid archive)
  117.                 0x10    - New volume naming scheme ('volname.partN.rar')
  118.                 0x20    - Authenticity information present
  119.                 0x40    - Recovery record present
  120.                 0x80    - Block headers are encrypted
  121.  
  122.                 other bits in HEAD_FLAGS are reserved for
  123.                 internal use
  124.  
  125. HEAD_SIZE       Archive header total size including archive comments
  126. 2 bytes
  127.  
  128. RESERVED1       Reserved
  129. 2 bytes
  130.  
  131. RESERVED2       Reserved
  132. 4 bytes
  133.  
  134.  
  135. Comment block   present if (HEAD_FLAGS & 0x02) != 0
  136.  
  137.  
  138.  
  139.    File header (File in archive)
  140.  
  141.  
  142. HEAD_CRC        CRC of fields from HEAD_TYPE to FILEATTR
  143. 2 bytes         and file name
  144.  
  145. HEAD_TYPE       Header type: 0x74
  146. 1 byte
  147.  
  148. HEAD_FLAGS      Bit flags:
  149. 2 bytes
  150.                 0x01 - file continued from previous volume
  151.                 0x02 - file continued in next volume
  152.                 0x04 - file encrypted with password
  153.                 0x08 - file comment present
  154.                 0x10 - information from previous files is used (solid flag)
  155.                        (for RAR 2.0 and later)
  156.  
  157.                 bits 7 6 5 (for RAR 2.0 and later)
  158.  
  159.                      0 0 0    - dictionary size   64 KB
  160.                      0 0 1    - dictionary size  128 KB
  161.                      0 1 0    - dictionary size  256 KB
  162.                      0 1 1    - dictionary size  512 KB
  163.                      1 0 0    - dictionary size 1024 KB
  164.                      1 0 1    - dictionary size 2048 KB
  165.                      1 1 0    - dictionary size 4096 KB
  166.                      1 1 1    - file is directory
  167.  
  168.                0x100 - HIGH_PACK_SIZE and HIGH_UNP_SIZE fields
  169.                        are present. These fields are used to archive
  170.                        only very large files (larger than 2Gb),
  171.                        for smaller files these fields are absent.
  172.  
  173.                0x200 - FILE_NAME contains both usual and encoded
  174.                        Unicode name separated by zero. In this case
  175.                        NAME_SIZE field is equal to the length
  176.                        of usual name plus encoded Unicode name plus 1.
  177.  
  178.                0x400 - the header contains additional 8 bytes
  179.                        after the file name, which are required to
  180.                        increase encryption security (so called 'salt').
  181.  
  182.                0x800 - Version flag. It is an old file version,
  183.                        a version number is appended to file name as ';n'.
  184.  
  185.               0x8000 - this bit always is set, so the complete
  186.                        block size is HEAD_SIZE + PACK_SIZE
  187.                        (and plus HIGH_PACK_SIZE, if bit 0x100 is set)
  188.  
  189. HEAD_SIZE       File header full size including file name and comments
  190. 2 bytes
  191.  
  192. PACK_SIZE       Compressed file size
  193. 4 bytes
  194.  
  195. UNP_SIZE        Uncompressed file size
  196. 4 bytes
  197.  
  198. HOST_OS         Operating system used for archiving
  199. 1 byte                 0 - MS DOS
  200.                        1 - OS/2
  201.                        2 - Win32
  202.                        3 - Unix
  203.                        4 - Mac OS
  204.                        5 - BeOS
  205.  
  206. FILE_CRC        File CRC
  207. 4 bytes
  208.  
  209. FTIME           Date and time in standard MS DOS format
  210. 4 bytes
  211.  
  212. UNP_VER         RAR version needed to extract file
  213. 1 byte
  214.  
  215. METHOD          Packing method
  216. 1 byte
  217.  
  218. NAME_SIZE       File name size
  219. 2 bytes
  220.  
  221. ATTR            File attributes
  222. 4 bytes
  223.  
  224. HIGH_PACK_SIZE  High 4 bytes of 64 bit value of compressed file size.
  225. 4 bytes         Optional value, presents only if bit 0x100 in HEAD_FLAGS
  226.                 is set.
  227.  
  228. HIGH_UNP_SIZE   High 4 bytes of 64 bit value of uncompressed file size.
  229. 4 bytes         Optional value, presents only if bit 0x100 in HEAD_FLAGS
  230.                 is set.
  231.  
  232. FILE_NAME       File name - string of NAME_SIZE bytes size
  233.  
  234.  
  235. Comment block   present if (HEAD_FLAGS & 0x08) != 0
  236.  
  237.  
  238.  
  239.   Comment block
  240.  
  241.  
  242. HEAD_CRC        CRC of fields from HEAD_TYPE to COMM_CRC
  243. 2 bytes
  244.  
  245. HEAD_TYPE       Header type: 0x75
  246. 1 byte
  247.  
  248. HEAD_FLAGS      Bit flags
  249. 2 bytes
  250.  
  251. HEAD_SIZE       Comment header size + comment size
  252. 2 bytes
  253.  
  254. UNP_SIZE        Uncompressed comment size
  255. 2 bytes
  256.  
  257. UNP_VER         RAR version needed to extract comment
  258. 1 byte
  259.  
  260. METHOD          Packing method
  261. 1 byte
  262.  
  263. COMM_CRC        Comment CRC
  264. 2 bytes
  265.  
  266. COMMENT         Comment text
  267.  
  268.  
  269.  
  270.   Extra info block
  271.  
  272.  
  273. HEAD_CRC        Block CRC
  274. 2 bytes
  275.  
  276. HEAD_TYPE       Header type: 0x76
  277. 1 byte
  278.  
  279. HEAD_FLAGS      Bit flags
  280. 2 bytes
  281.  
  282. HEAD_SIZE       Total block size
  283. 2 bytes
  284.  
  285. INFO            Other data
  286.  
  287.  
  288.   Subblock
  289.  
  290. An object in the archive (the block or header) can be followed
  291. by a subblock. The subblock is dependent upon the main object.
  292. Subblock can be erased or moved to a new version of the archive
  293. when it is updated.
  294.  
  295.  The subblock contains the following fields:
  296.  
  297. HEAD_CRC        Block CRC
  298. 2 bytes
  299.  
  300. HEAD_TYPE       Header type: 0x77
  301. 1 byte
  302.  
  303. HEAD_FLAGS      Bit flags
  304. 2 bytes
  305.                 (HEAD_FLAGS & 0x8000) == 1, because full
  306.                 block size is HEAD_SIZE + DATA_SIZE
  307.  
  308. HEAD_SIZE       Total block size
  309. 2 bytes
  310.  
  311. DATA_SIZE       Total data size
  312. 4 bytes
  313.  
  314. SUB_TYPE        Subblock type
  315. 2 bytes
  316.  
  317. RESERVED        Must be 0
  318. 1 byte
  319.  
  320. Other           Other fields depending on the subblock type
  321. fields
  322.  
  323.  
  324.   OS/2 extended attributes subblock
  325.  
  326.  
  327. HEAD_CRC        Block CRC
  328. 2 bytes
  329.  
  330. HEAD_TYPE       Header type: 0x77
  331. 1 byte
  332.  
  333. HEAD_FLAGS      Bit flags
  334. 2 bytes
  335.                 (HEAD_FLAGS & 0x8000) == 1, because full
  336.                 block size is HEAD_SIZE + DATA_SIZE
  337.  
  338. HEAD_SIZE       Total block size
  339. 2 bytes
  340.  
  341. DATA_SIZE       Total data size (packed extended attributes size)
  342. 4 bytes
  343.  
  344. SUB_TYPE        0x100
  345. 2 bytes
  346.  
  347. RESERVED        Must be 0
  348. 1 byte
  349.  
  350. UNP_SIZE        Uncompressed extended attributes size
  351. 4 bytes
  352.  
  353. UNP_VER         RAR version needed to extract extended attributes
  354. 1 byte
  355.  
  356. METHOD          Packing method
  357. 1 byte
  358.  
  359. EA_CRC          Extended attributes CRC
  360. 4 bytes
  361.  
  362.  
  363.  ==========================================================================
  364.                               Application notes
  365.  ==========================================================================
  366.  
  367.    1. To process an SFX archive you need to skip the SFX module searching
  368. for the marker block in the archive. There is no marker block sequence (0x52
  369. 0x61 0x72 0x21 0x1a 0x07 0x00) in the SFX module itself.
  370.  
  371.    2. The CRC is calculated using the standard polynomial 0xEDB88320. In
  372. case the size of the CRC is less than 4 bytes, only the low order bytes
  373. are used.
  374.  
  375.    3. Packing method encoding:
  376.          0x30 - storing
  377.          0x31 - fastest compression
  378.          0x32 - fast compression
  379.          0x33 - normal compression
  380.          0x34 - good compression
  381.          0x35 - best compression
  382.  
  383.    4. The RAR extraction version number is encoded as 10 * Major version
  384. + minor version.
  385.  
  386.