home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 Extra / Chip_Extra_1999.iso / share / aktuell / mimarzip / m8vcs99.exe / MimarSinan ACE Wrapper (ACE) / ace12b / TECHNOTE.DOC < prev    next >
Encoding:
Text File  |  1998-05-18  |  11.6 KB  |  319 lines

  1.                                       Copyright by Marcel Lemke, May 1998
  2.  
  3.  
  4.     Technical information of the archiver ACE v1.2
  5.    ────────────────────────────────────────────────
  6.  
  7.  
  8.      1. Block format
  9.      2. Block types
  10.        2.1. Archive header
  11.        2.2. File block
  12.        2.3. Recovery record
  13.  
  14.      3. Archive processing
  15.      4. Building CRCs
  16.        4.1. C source
  17.        4.2. Pascal source
  18.  
  19.  
  20. ──────────────────────────────────────────────────────────────────────────────
  21.  
  22.  
  23.   1. Block format
  24.  ─────────────────
  25.  
  26.     The whole archive consists of blocks which vary in size.
  27.  
  28.     Structure:
  29.  
  30.     bytes   meaning       discription
  31.  
  32.      2      HEAD_CRC      CRC16 over block up from HEAD_TYPE
  33.      2      HEAD_SIZE     size of the block from HEAD_TYPE
  34.                             up to the beginning of the ADDSIZE block
  35.  
  36.      1      HEAD_TYPE     indicates type of block (see chapter 2.)
  37.      2      HEAD_FLAGS    flags related to the block and its content
  38.                             for all blocks these flags are valid:
  39.  
  40.                              bit  discription
  41.  
  42.                               0   ADDSIZE field present
  43.                               1   Block includes a comment
  44.  
  45.     [4]     ADDSIZE       an optional field which represents the size of
  46.                           an additional block without specified structure
  47.                            (no HEAD_CRC, HEAD_SIZE etc.)
  48.      ?      OTHER FIELDS
  49.  
  50.  
  51.   2. Block types
  52.  ────────────────
  53.  
  54.    2.1. Archive header
  55.   ─────────────────────
  56.       The archive header is the first block of each archive or volume.
  57.  
  58.       Structure:
  59.  
  60.       bytes   meaning       discription
  61.  
  62.        2      HEAD_CRC      CRC16 over block up from HEAD_TYPE
  63.        2      HEAD_SIZE     size of the block from HEAD_TYPE
  64.                               up to the last byte of this block
  65.  
  66.        1      HEAD_TYPE     archive header type is 0
  67.        2      HEAD_FLAGS    contains most important information about the
  68.                             archive
  69.  
  70.                                bit  discription
  71.  
  72.                                 0   0  (no ADDSIZE field)
  73.                                 1   presence of a main comment
  74.  
  75.                                 9   SFX-archive
  76.                                 10  dictionary size limited to 256K
  77.                                     (because of a junior SFX)
  78.                                 11  archive consists of multiple volumes
  79.                                 12  main header contains AV-string
  80.                                 13  recovery record present
  81.                                 14  archive is locked
  82.                                 15  archive is solid
  83.  
  84.        7      ACESIGN       fixed string: '**ACE**' serves to find the
  85.                               archive header
  86.  
  87.        1      VER_EXTRACT   version needed to extract archive
  88.        1      VER_CREATED   version used to create the archive
  89.        1      HOST_CREATED  HOST-OS for ACE used to create the archive
  90.  
  91.                                value   host
  92.  
  93.                                 0      MS-DOS
  94.                                 1      OS/2
  95.                                 2      Win32
  96.                                 3      Unix
  97.                                 4      MAC-OS
  98.                                 5      Win NT
  99.                                 6      Primos
  100.                                 7      APPLE GS
  101.                                 8      ATARI
  102.                                 9      VAX VMS
  103.                                 10     AMIGA
  104.                                 11     NEXT
  105.  
  106.        1      VOLUME_NUM        which volume of a multi-volume-archive is it?
  107.        4      TIME_CREATED      date and time in MS-DOS format
  108.        8      RESERVED          8 bytes reserved for the future
  109.       [1]     AV_SIZE           size of the following AV string
  110.       [?]     AV                the AV string itself
  111.       [2]     COMMENT_SIZE      compressed size of the following comment
  112.       [?]     COMMENT           compressed data of comment
  113.        ?      RESERVED
  114.  
  115.       Comments are compressed using simple LZP+huffman. Sources how to create
  116.       those compressed comments might be published sometime.
  117.  
  118.    2.2. File block
  119.   ─────────────────
  120.       Directories are stored in this type of block, too. There is no extra
  121.       block structure.
  122.  
  123.       Structure:
  124.  
  125.       bytes   meaning       discription
  126.  
  127.        2      HEAD_CRC      CRC16 over block up from HEAD_TYPE
  128.        2      HEAD_SIZE     size of the block up from HEAD_TYPE
  129.                               up to the beginning of the compressed data
  130.  
  131.        1      HEAD_TYPE     file header type is 1
  132.        2      HEAD_FLAGS
  133.                                bit  discription
  134.  
  135.                                 0   1 (ADDSIZE field present)
  136.                                 1   presence of file comment
  137.  
  138.                                 12  file continued from previous volume
  139.                                 13  file continues on the next volume
  140.                                 14  file encrypted with password
  141.                                 15  solid-flag: file compressed using data
  142.                                       of previous files of the archive
  143.  
  144.        4      PACK_SIZE     this is the ADDSIZE field;
  145.                             the additional block contains compressed file data
  146.                               without exception
  147.        4      ORIG_SIZE     the original size of the file
  148.        4      FTIME         file date and file time in MS-DOS format
  149.        4      ATTR          attributes of the file
  150.        4      CRC32         checksum over the compressed file
  151.        4      TECH_INFO
  152.  
  153.                bytes
  154.                 1           type of compression
  155.                               0  store
  156.                               1  ACE_LZ77_1
  157.  
  158.                 1           quality of compression
  159.                               0  fastest
  160.                               1  fast
  161.                               2  normal
  162.                               3  good
  163.                               4  best
  164.  
  165.                 2           parameter for decompression
  166.  
  167.        2      RESERVED
  168.        2      FNAME_SIZE    size of filename string in bytes
  169.        1      FNAME         filename string (OEM)
  170.       [2]     COMM_SIZE     compressed size of file comment
  171.       [?]     COMMENT       file comment
  172.        ?      RESERVED
  173.     -------------------------------------------
  174.       compressed file data (size is PACK_SIZE)
  175.  
  176.  
  177.    2.3. Recovery record
  178.   ──────────────────────
  179.       The protection by recovery records works this way:
  180.       See the whole archive as a sequence of blocks with a defined length.
  181.       Build checksums over these blocks to determine (later) whether a block
  182.       has been damaged or not. Xor all blocks to one.
  183.       Save this xor-block and the checksums. To restore a damaged block
  184.       all undamaged blocks have to be xor'd with the xor-block.
  185.  
  186.  
  187.       Structure:
  188.  
  189.        2      HEAD_CRC      CRC16 over block up from HEAD_TYPE
  190.        2      HEAD_SIZE     size of the block up from HEAD_TYPE
  191.  
  192.        1      HEAD_TYPE     header type of recovery records is 2
  193.        2      HEAD_FLAGS
  194.                                bit  discription
  195.  
  196.                                 0   1 (ADDSIZE field present)
  197.        4      REC_BLK_SIZE  ADDSIZE field; size of recovery data
  198.        7      ACESIGN       string: '**ACE**';
  199.                               allows search for this block with destroyed
  200.                               archive structure
  201.        4      REL_STRT      relative start (to this block) of the data this
  202.                               block is mode of
  203.        4      NUM_BLKS      number of blocks the data is splitten in
  204.        4      CL_SIZE       size of these blocks
  205.        2      REC_CRC       CRC16 over recovery data
  206.     ------------------------
  207.       recovery data:
  208.  
  209.        2      1st CRC16     CRC over the first block of the archive
  210.        2      2nd CRC16     CRC over the second block of the archive
  211.        .      .
  212.        .      .
  213.        2  NUM_BLKSth CRC16  CRC over the last block (up to the recovery
  214.                               record) of the archive
  215.       CL_SIZE XOR-DATA      contains the xor'd data of all the blocks
  216.                               the archive has been splitten in for this
  217.                               process
  218.  
  219.   3. Archive processing
  220.  ───────────────────────
  221.  
  222.     For processing an archive you first need to get the start offset of it
  223.     in a certain file. The way to do so is:
  224.  
  225.       1.) search for the acesign ('**ACE**')
  226.       2.) read a block from (acesign_position-7)
  227.             (because the acesign is at offset 7 in the archive header)
  228.       3.) build the checksum of this block and check it against HEAD_CRC;
  229.             if they do not match go to step 1.)
  230.  
  231.     After you got the start you can read one block after another like this:
  232.       1.) read HEAD_CRC and HEAD_SIZE
  233.       2.) read HEAD_SIZE bytes;
  234.            build the CRC of them and check it against HEAD_CRC;
  235.            the archive is broken if the CRCs do not match
  236.       3.) interpret the contents of the block
  237.       4.) skip ADDSIZE bytes if ADDSIZE is present
  238.     Do so until the EOF of the archive.
  239.  
  240.     See next chapter how to build CRCs.
  241.  
  242.  
  243.   4. Building CRCs
  244.  ──────────────────
  245.  
  246.     This chapter contains sources how to build a "CRC32". The full 32 bits
  247.     are needed at the file checksums only. In the headers there are only
  248.     the lower 16 bits of a CRC32 value saved.
  249.  
  250.     To initialize "getcrc" just call "make_crc_table". To get a CRC of a
  251.     block inititalize your CRC variable with CRC_MASK. Then use getcrc to
  252.     update this variable.
  253.  
  254.     example how to check the CRC of an header:
  255.       make_crctable();                                // only once
  256.       ...
  257.       crc=CRC_MASK;                                   // initialize CRC
  258.       crc=getcrc(crc,&head.HEAD_TYPE,head.HEAD_SIZE); // update CRC
  259.  
  260.                                                       // check lower 16 bits
  261.       if (UWORD(crc)!=UWORD(head.HEAD_CRC)) error_archive_broken();
  262.  
  263.    4.1. C source
  264.   ───────────────
  265.  
  266. ──────cut────────────   ────────────   ────────────   ────────────
  267.         #define CRCPOLY 0xEDB88320
  268.         #define CRC_MASK 0xFFFFFFFF
  269.  
  270.         make_crctable()
  271.         {
  272.         unsigned r,i,j;
  273.           for (i=0;i<=255;i++) {
  274.             for (r=i,j=8;j;j--)
  275.               r=(r&1)?(r>>1)^CRCPOLY:(r>>1);
  276.             crctable[i] = r;
  277.           }
  278.         }
  279.  
  280.         unsigned long getcrc(unsigned long crc,unsigned char *addr,int len)
  281.         {
  282.           while (len--)
  283.             crc=crctable[(unsigned char)crc^(*addr++)]^(crc>>8);
  284.           return(crc);
  285.         }
  286. ──────cut────────────   ────────────   ────────────   ────────────
  287.  
  288.    4.2. Pascal source
  289.   ────────────────────
  290.  
  291. ──────cut────────────   ────────────   ────────────   ────────────
  292.         const CRCPOLY=$EDB88320;CRC_MASK=$FFFFFFFF;
  293.         type tbytear=array[0..60000] of byte;
  294.              tbptr=^tbytear;
  295.  
  296.         procedure make_crctable;
  297.         var i,j:integer;
  298.             r:longint;
  299.         begin
  300.           for i:=0 to 255 do begin
  301.             r:=i;
  302.             for j:=8 downto 1 do
  303.               if (r and 1)>0 then r:=(r shr 1) xor CRCPOLY else r:=r shr 1;
  304.             crctable[i]:=r;
  305.           end;
  306.         end;
  307.  
  308.         function getcrc(crc:longint;addr:tbptr;len:integer):longint;
  309.         var i:word;
  310.         begin
  311.           i:=0;
  312.           while (len>0) do begin
  313.             crc:=crctable[(byte(crc)) xor (addr^[i])] xor (longint(crc) shr 8);
  314.             dec(len);inc(i);
  315.           end;
  316.           getcrc:=crc;
  317.         end;
  318. ──────cut────────────   ────────────   ────────────   ────────────
  319.