home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / UTIL / Winrar / wrar330ro.exe / TechNote.txt < prev    next >
Encoding:
Text File  |  2003-09-23  |  8.8 KB  |  272 lines

  1.  
  2.                RAR version 3.30 - 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          old style comment header
  45. HEAD_TYPE=0x76          old style authenticity information
  46. HEAD_TYPE=0x77          old style subblock
  47. HEAD_TYPE=0x78          old style recovery record
  48. HEAD_TYPE=0x79          old style authenticity information
  49. HEAD_TYPE=0x7a          subblock
  50.  
  51.    Comment block is actually used only within other blocks and doesn't
  52. exist separately.
  53.  
  54.    Archive processing is made in the following manner:
  55.  
  56. 1. Read and check marker block
  57. 2. Read archive header
  58. 3. Read or skip HEAD_SIZE-sizeof(MAIN_HEAD) bytes
  59. 4. If end of archive encountered then terminate archive processing,
  60.    else read 7 bytes into fields HEAD_CRC, HEAD_TYPE, HEAD_FLAGS,
  61.    HEAD_SIZE.
  62. 5. Check HEAD_TYPE.
  63.    if HEAD_TYPE==0x74
  64.      read file header ( first 7 bytes already read )
  65.      read or skip HEAD_SIZE-sizeof(FILE_HEAD) bytes
  66.      if (HEAD_FLAGS & 0x100)
  67.        read or skip HIGH_PACK_SIZE*0x100000000+PACK_SIZE bytes
  68.      else
  69.        read or skip PACK_SIZE bytes
  70.    else
  71.      read corresponding HEAD_TYPE block:
  72.        read HEAD_SIZE-7 bytes
  73.        if (HEAD_FLAGS & 0x8000)
  74.          read ADD_SIZE bytes
  75. 6. go to 4.
  76.  
  77.  
  78.  ==========================================================================
  79.                                Block Formats
  80.  ==========================================================================
  81.  
  82.  
  83.    Marker block ( MARK_HEAD )
  84.  
  85.  
  86. HEAD_CRC        Always 0x6152
  87. 2 bytes
  88.  
  89. HEAD_TYPE       Header type: 0x72
  90. 1 byte
  91.  
  92. HEAD_FLAGS      Always 0x1a21
  93. 2 bytes
  94.  
  95. HEAD_SIZE       Block size = 0x0007
  96. 2 bytes
  97.  
  98.    The marker block is actually considered as a fixed byte
  99. sequence: 0x52 0x61 0x72 0x21 0x1a 0x07 0x00
  100.  
  101.  
  102.  
  103.    Archive header ( MAIN_HEAD )
  104.  
  105.  
  106. HEAD_CRC        CRC of fields HEAD_TYPE to RESERVED2
  107. 2 bytes
  108.  
  109. HEAD_TYPE       Header type: 0x73
  110. 1 byte
  111.  
  112. HEAD_FLAGS      Bit flags:
  113. 2 bytes
  114.                 0x0001  - Volume attribute (archive volume)
  115.                 0x0002  - Archive comment present
  116.                           RAR 3.x uses the separate comment block
  117.                           and does not set this flag.
  118.  
  119.                 0x0004  - Archive lock attribute
  120.                 0x0008  - Solid attribute (solid archive)
  121.                 0x0010  - New volume naming scheme ('volname.partN.rar')
  122.                 0x0020  - Authenticity information present
  123.                           RAR 3.x does not set this flag.
  124.  
  125.                 0x0040  - Recovery record present
  126.                 0x0080  - Block headers are encrypted
  127.                 0x0100  - First volume (set only by RAR 3.0 and later)
  128.  
  129.                 other bits in HEAD_FLAGS are reserved for
  130.                 internal use
  131.  
  132. HEAD_SIZE       Archive header total size including archive comments
  133. 2 bytes
  134.  
  135. RESERVED1       Reserved
  136. 2 bytes
  137.  
  138. RESERVED2       Reserved
  139. 4 bytes
  140.  
  141.  
  142.  
  143.    File header (File in archive)
  144.  
  145.  
  146. HEAD_CRC        CRC of fields from HEAD_TYPE to FILEATTR
  147. 2 bytes         and file name
  148.  
  149. HEAD_TYPE       Header type: 0x74
  150. 1 byte
  151.  
  152. HEAD_FLAGS      Bit flags:
  153. 2 bytes
  154.                 0x01 - file continued from previous volume
  155.                 0x02 - file continued in next volume
  156.                 0x04 - file encrypted with password
  157.  
  158.                 0x08 - file comment present
  159.                        RAR 3.x uses the separate comment block
  160.                        and does not set this flag.
  161.  
  162.                 0x10 - information from previous files is used (solid flag)
  163.                        (for RAR 2.0 and later)
  164.  
  165.                 bits 7 6 5 (for RAR 2.0 and later)
  166.  
  167.                      0 0 0    - dictionary size   64 KB
  168.                      0 0 1    - dictionary size  128 KB
  169.                      0 1 0    - dictionary size  256 KB
  170.                      0 1 1    - dictionary size  512 KB
  171.                      1 0 0    - dictionary size 1024 KB
  172.                      1 0 1    - dictionary size 2048 KB
  173.                      1 1 0    - dictionary size 4096 KB
  174.                      1 1 1    - file is directory
  175.  
  176.                0x100 - HIGH_PACK_SIZE and HIGH_UNP_SIZE fields
  177.                        are present. These fields are used to archive
  178.                        only very large files (larger than 2Gb),
  179.                        for smaller files these fields are absent.
  180.  
  181.                0x200 - FILE_NAME contains both usual and encoded
  182.                        Unicode name separated by zero. In this case
  183.                        NAME_SIZE field is equal to the length
  184.                        of usual name plus encoded Unicode name plus 1.
  185.  
  186.                0x400 - the header contains additional 8 bytes
  187.                        after the file name, which are required to
  188.                        increase encryption security (so called 'salt').
  189.  
  190.                0x800 - Version flag. It is an old file version,
  191.                        a version number is appended to file name as ';n'.
  192.  
  193.               0x1000 - Extended time field present.
  194.  
  195.               0x8000 - this bit always is set, so the complete
  196.                        block size is HEAD_SIZE + PACK_SIZE
  197.                        (and plus HIGH_PACK_SIZE, if bit 0x100 is set)
  198.  
  199. HEAD_SIZE       File header full size including file name and comments
  200. 2 bytes
  201.  
  202. PACK_SIZE       Compressed file size
  203. 4 bytes
  204.  
  205. UNP_SIZE        Uncompressed file size
  206. 4 bytes
  207.  
  208. HOST_OS         Operating system used for archiving
  209. 1 byte                 0 - MS DOS
  210.                        1 - OS/2
  211.                        2 - Win32
  212.                        3 - Unix
  213.                        4 - Mac OS
  214.                        5 - BeOS
  215.  
  216. FILE_CRC        File CRC
  217. 4 bytes
  218.  
  219. FTIME           Date and time in standard MS DOS format
  220. 4 bytes
  221.  
  222. UNP_VER         RAR version needed to extract file
  223. 1 byte
  224.                 Version number is encoded as
  225.                 10 * Major version + minor version.
  226.  
  227. METHOD          Packing method
  228. 1 byte
  229.                 0x30 - storing
  230.                 0x31 - fastest compression
  231.                 0x32 - fast compression
  232.                 0x33 - normal compression
  233.                 0x34 - good compression
  234.                 0x35 - best compression
  235.  
  236. NAME_SIZE       File name size
  237. 2 bytes
  238.  
  239. ATTR            File attributes
  240. 4 bytes
  241.  
  242. HIGH_PACK_SIZE  High 4 bytes of 64 bit value of compressed file size.
  243. 4 bytes         Optional value, presents only if bit 0x100 in HEAD_FLAGS
  244.                 is set.
  245.  
  246. HIGH_UNP_SIZE   High 4 bytes of 64 bit value of uncompressed file size.
  247. 4 bytes         Optional value, presents only if bit 0x100 in HEAD_FLAGS
  248.                 is set.
  249.  
  250. FILE_NAME       File name - string of NAME_SIZE bytes size
  251.  
  252. SALT            present if (HEAD_FLAGS & 0x400) != 0
  253. 8 bytes
  254.  
  255. EXT_TIME        present if (HEAD_FLAGS & 0x1000) != 0
  256. variable size
  257.  
  258. other new fields may appear here.
  259.  
  260.  
  261.  ==========================================================================
  262.                               Application notes
  263.  ==========================================================================
  264.  
  265.    1. To process an SFX archive you need to skip the SFX module searching
  266. for the marker block in the archive. There is no marker block sequence (0x52
  267. 0x61 0x72 0x21 0x1a 0x07 0x00) in the SFX module itself.
  268.  
  269.    2. The CRC is calculated using the standard polynomial 0xEDB88320. In
  270. case the size of the CRC is less than 4 bytes, only the low order bytes
  271. are used.
  272.