标签 apk 下的文章

获取apk的name,icon,version,permissions,RSA等信息

https://gist.github.com/forthxu/f42113205494abd54453

#!/bin/bash
#@author forthxu.com
#说明
#找到获取apk信息有两种方式
#一种解压后读取AndroidManifest.xml,解压最好不要通过unzip因为获取的是压缩过的内容,读取不准确,可用apktool反编译解压
#另外一种可通过aapt也就是官方sdk中提供的工具读取信息
#aapt和apktoool工具 https://code.google.com/p/android-apktool
#可能存在的问题 http://www.qiansw.com/centos-apk-apktool.html
#扩展阅读,汉化apk http://bbs.dospy.com/thread-9991523-1-354-1.html

#如果使用unzip解压的方法还可以通过以下方法解析XMl文件
#java可用 java -jar AXMLPrinter2.jar AndroidManifest.xml > AndroidManifest2.xml
#AXMLPrinter2.jar下载 https://code.google.com/p/android4me/
#AXMLPrinter2 php版http://blog.katcin.com/archives/69

#获取apk
if [ ! -s "${1}" ];then
    echo "usage:bash ${0} some.apk";
    exit;
fi
#获取文件后存储的位置
ex=./ex/;

echo "-----apk信息----";
#apk信息
badging=`aapt d badging $1`;
# echo $badging;

echo "-----apk icon----";
#获取apk icon
icons=`aapt d badging $1 | grep -E "application-icon|application:" | sed -e 's/.*\(res\/\w\{1,\}\-\w\{1,\}\/\w\{1,\}\.png\).*/\1/' | uniq`;
# echo $icons;
for icon in $icons;do
    echo $icon;
done

echo "-----解压图标 到 ${ex}----";
#解压图标
unzip -o $1 $icons -d $ex

echo "-----apk name----";
#获取apk name
name=`aapt d badging $1 | grep -E "application:" | sed -e "s/.*label='\(\w*\)'.*/\1/"`;
echo $name;

echo "-----apk 权限----";
#获取apk 权限
permissions=`aapt d permissions  $1 | awk -F " " '/uses-permission/ {print $2}'`;
# echo $permissions;
for permission in $permissions;do
    echo $permission;
done

echo "-----apk sdkVersion----";
#获取apk sdkVersion
sdkVersion=`aapt d badging $1 | grep -E "sdkVersion:" | sed -e "s/.*:'\(\w\{1,\}\)'.*/\1/"`;
echo $sdkVersion;

echo "-----apk targetSdkVersion----";
#获取apk targetSdkVersion
targetSdkVersion=`aapt d badging $1 | grep -E "targetSdkVersion:" | sed -e "s/.*:'\(\w\{1,\}\)'.*/\1/"`;
echo $targetSdkVersion;

echo "-----apk versionCode----";
#获取apk versionCode
versionCode=`aapt d badging $1 | grep -E "package:" | sed -e "s/.*versionCode='\(\w\{1,\}\)'.*/\1/"`;
echo $versionCode;

echo "-----apk versionName----";
#获取apk versionName
versionName=`aapt d badging $1 | grep -E "package:" | sed -e "s/.*versionName='\(\S\{1,\}\)'.*/\1/"`;
echo $versionName;

echo "-----apk package----";
#获取apk package
package=`aapt d badging $1 | grep -E "package:" | sed -e "s/.*name='\(\S\{1,\}\)'.*/\1/"`;
echo $package;

echo "-----apk supports-screens----";
#获取apk supports-screens
supports=`aapt d badging $1 | grep -E "supports-screens:" | sed -e "s/.*supports-screens:\(.\{1,\}\)/\1/"`;
echo $supports;

echo "-----解压证书 到 ${ex}----";
#解压证书
unzip -o $1 META-INF/CERT.RSA  -d $ex