home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 27 / Pce27cd1.iso / Utilitarios / Essenciais / WinRAR / TechNote.txt < prev    next >
Text File  |  2000-12-08  |  10KB  |  377 lines

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