Php 帮助解析resources.arsc?

Php 帮助解析resources.arsc?,php,android,parsing,resources,Php,Android,Parsing,Resources,我正试图解析resources.arsc文件中包含的资源,正如前面讨论的那样。我知道androidmanifest.xml文件标识位于.arsc文件中的资源。我已经成功地解析了.arsc文件的头,但我不知道如何解析资源本身 有人能帮我弄清楚如何解析.arsc文件中包含的资源吗 到目前为止,我的解析代码: <?php $doc = fopen('resources.arsc', 'r+'); for($i=1;$i<10;$i++){ $res[$i] = _unpack

我正试图解析resources.arsc文件中包含的资源,正如前面讨论的那样。我知道
androidmanifest.xml
文件标识位于.arsc文件中的资源。我已经成功地解析了.arsc文件的头,但我不知道如何解析资源本身

有人能帮我弄清楚如何解析.arsc文件中包含的资源吗

到目前为止,我的解析代码:

<?php

$doc = fopen('resources.arsc', 'r+');


for($i=1;$i<10;$i++){
    $res[$i] = _unpack('V', fread($doc, 4));
}


for ($i = 0, $j = $res[6]; $i <= $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>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(&$doc){
    $pos = ftell($doc);
    $count= 0;
    while($word = fread($doc, 4)){
        if(_unpack('V', $word)==-1)break;
    }

    $n = 1;
    if ($count < $n){
        while($word = peek_doc($doc, 4)){
            if(_unpack('V', $word) != -1)break;
            fread($doc, 4);
            $n++;
            if(isset($count) && $count >= $n)break;
        }
        echo 'skip '.$n.' chars<br />';
    }

}

function peek_doc(&$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];
}
?>
=$n)中断;
}
回显“跳过”。$n.“字符
”; } } 函数peek_doc(&$doc,$size){ $data=fread($doc,$size); fseek($doc,ftell($doc)-$size); 返回$data; } 函数_解包($m,$b){ //如果(!$b)返回“”; $res=拆包($m,$b); 返回$res[1]; } ?>
这是一个相当复杂的二进制文件。您需要更多的代码来解析它。:)

我的建议是使用与平台相同的代码,即可重新启动的相关类:

frameworks/base/include/utils/ResourceTypes.h frameworks/base/libs/utils/ResourceTypes.cpp

请注意,ResourceTypes.h还定义了资源表的完整结构(那里的类用来解析它)

您还可以使用aapt工具。这有许多用于从.apk解析资源相关数据的选项:

aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]
  badging          Print the label and icon for the app declared in APK.
  permissions      Print the permissions from the APK.
  resources        Print the resource table from the APK.
  configurations   Print the configurations in the APK.
  xmltree          Print the compiled xmls in the given assets.
  xmlstrings       Print the strings of the given compiled xml assets.

如果有一些其他数据不想用这些命令,请考虑修改框架/Base/Toes/AAPT中的工具代码,添加一些东西来解析你想要的东西。此工具正在使用ResTable解析资源