home *** CD-ROM | disk | FTP | other *** search
/ Freesoft 1999 February / Freesoft_1999-02_cd.bin / Recenz / Kompres / rarlnx25.sfx / technote.txt < prev    next >
Text File  |  1999-03-24  |  9KB  |  358 lines

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