title: How to calculate CRC of a WinRAR file header?
body: <p>Talking about this: <a href="http://www.win-rar.com/index.php?id=24&amp;kb_article_id=162" rel="nofollow">http://www.win-rar.com/index.php?id=24&amp;kb_article_id=162</a></p>
  
  <p>I'm able to calculate the correct CRC of an archive header (MAIN_HEAD) by doing:</p>
  
  <pre><code>$crc = crc32(mb_substr($data, $blockOffset + 2, 11, '8bit'));
  $crc = dechex($crc);
  $crc = substr($crc, -4, 2) . substr($crc, -2, 2);
  $crc = hexdec($crc);
  </code></pre>
  
  <p>The first line will read "CRC of fields <strong>HEAD_TYPE to RESERVED2</strong>" as states in the documentation. As I noted, it works fine for the archive header.</p>
  
  <p>When I try to calculate the CRC of a file header it always spits out the wrong CRC for unknown reason. I did as the documentation says - "CRC of fields <strong>from HEAD_TYPE to FILEATTR</strong>" but it simply doesn't work. I've also tried different read-length variations in case the documentation is wrong and it might actually be <strong>from HEAD_TYPE to FILE_NAME</strong>. Everything without success.</p>
  
  <p>Anyone can give me a hint? I've also checked the unrar source code but it doesn't make me smarter, probably because I don't know C language at all...</p>