title: Help parsing  resources.arsc?
body: <p>I'm trying to parse the resources contained in a resources.arsc file as discussed in <a href="https://stackoverflow.com/questions/2097813/how-to-parse-the-androidmanifest-xml-file-inside-an-apk-package">this</a> question. I know the <code>androidmanifest.xml</code> file identifies resources located in the .arsc file. I have successfully managed to parse the header of the .arsc file, I can't figure out how to parse the resources themselves.</p>
  
  <p>Can somebody please help me figure out how to parse the resources contained in an .arsc file?</p>
  
  <p>My parsing code so far:</p>
  
  <pre><code>&lt;?php
  
  $doc = fopen('resources.arsc', 'r+');
  
  
  for($i=1;$i&lt;10;$i++){
      $res[$i] = _unpack('V', fread($doc, 4));
  }
  
  
  for ($i = 0, $j = $res[6]; $i &lt;= $j; $i++)  {
      $word = fread($doc, 4);
      $stroffs[] = _unpack('V', $word);
  }
  
  
  $strings = array();
  
  $curroffs = 0;
  foreach($stroffs as $offs){
      //read length
      $len = _unpack('v', fread($doc, 2));
  
      //read string
      if($len&gt;0){
          $str = fread($doc, $len*2);
      }else{
          $str = '';
      }
      //null
      $wd = fread($doc, 2);
      //utf-16le
      $strings[] =  mb_convert_encoding($str, 'gbk', 'UTF-16LE');
  
      //curr offset
      $curroffs += ($len+1)*2 + 2;
  }
  
  
  $tpos = ftell($doc);
  
  read_doc_past_sentinel($doc);
  
  //fseek($doc, $tpos + $tpos % 4);
  
  $i = 0;
  
  $xmls = $strings;
  
  print_r($xmls);
  
  //------------------------------------
  //and then...somebody konw format or continue parse?
  //------------------------------------
  
  
  function read_doc_past_sentinel(&amp;$doc){
      $pos = ftell($doc);
      $count= 0;
      while($word = fread($doc, 4)){
          if(_unpack('V', $word)==-1)break;
      }
  
      $n = 1;
      if ($count &lt; $n){
          while($word = peek_doc($doc, 4)){
              if(_unpack('V', $word) != -1)break;
              fread($doc, 4);
              $n++;
              if(isset($count) &amp;&amp; $count &gt;= $n)break;
          }
          echo 'skip '.$n.' chars&lt;br /&gt;';
      }
  
  }
  
  function peek_doc(&amp;$doc, $size){
      $data = fread($doc, $size);
      fseek($doc, ftell($doc)-$size);
      return $data;
  }
  
  
  
  function _unpack($m, $b){
      //if(!$b)return '';
       $res = unpack($m, $b);
      return $res[1];
  }
  ?&gt;
  </code></pre>