chenquincy / app-info-parser

A javascript parser for parsing .ipa or .apk files. IPA/APK文件 js 解析器
MIT License
490 stars 113 forks source link

解析APK图标时得到一个XML。附带一个临时解决方案 #65

Open LEORChn opened 3 years ago

LEORChn commented 3 years ago

测试APK:知乎 v5.8.1

下载APK:https://github.com/LEORChn/ContentDelivery/releases/download/temp/zhihu_5.8.1.apk (如果没有特殊需要,在一段时间后会清除。)

浏览器:Chrome 43

new AppInfoParser(file).parse().then(function(e){
  console.log(e.icon);
  // 预期表现:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimH...
  // 实际表现:data:image/png;base64,AwAIAMgAAAABABwAZAAAAAMAAAAAAAAAAAEAACgAAA...
});

临时解决方案 in dist/app-info-parser.js

code with lines tag

// is it png?
if((apkInfo.icon || '').contains(';base64,iVBORw0K')){
  // yes it is png
  resolve(apkInfo);
}else{
  // no it is not png but maybe xml
  var xml = new BinaryXmlParser(iconBuffer).parse();
  if(xml.nodeName == 'bitmap'){
    // xml.attributes[0].typedValue.value = 'resourceId:0x7f0d0002'
    var iconRef = xml.attributes[0].typedValue.value.split(':')[1].toUpperCase().replace('0X', '@');
    _this2.getEntry(resourceMap[iconRef][0]).then(function (iconBuffer) {
      apkInfo.icon = getBase64FromBuffer(iconBuffer);
      resolve(apkInfo);
    });
  }else{
    // exception... but when? i dont know.
    resolve(apkInfo);
  }
}
chenquincy commented 3 years ago

@LEORChn 抱歉,在封闭开发中,暂时没有精力解决问题。看起来像是 apk 的图标路径解析,等有时间会修复~