精华内容
下载资源
问答
  • PC上查看/解析APK包名
    2021-06-08 09:44:10

    E:\apktools>aapt d badging jj.apk | grep 'package:'

    package: name='com.roguerocketgames.m3s' versionCode='6' versionName='0.7.3'

    appt还有更多的功能,对apk的解析非常容易,可以查看它帮助

    Android Asset Packaging Tool

    Usage:

    aapt l[ist] [-v] [-a] file.{zip,jar,apk}

    List contents of Zip-compatible archive.

    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.

    aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \

    [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \

    [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \

    [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \

    [--rename-manifest-package PACKAGE] \

    [--rename-instrumentation-target-package PACKAGE] \

    [--utf16] [--auto-add-overlay] \

    [--max-res-version VAL] \

    [-I base-package [-I base-package ...]] \

    [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file]

    \

    [-S resource-sources [-S resource-sources ...]] \

    [-F apk-file] [-J R-file-dir] \

    [--product product1,product2,...] \

    [-c CONFIGS] [--preferred-configurations CONFIGS] \

    [raw-files-dir [raw-files-dir] ...] \

    [--output-text-symbols DIR]

    Package the android resources. It will read assets and resources that are

    supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R

    options control which files are output.

    更多相关内容
  • Java解析apk文件

    2015-01-14 14:16:05
    解析apk文件,从apk中可以拿到版本号码,版本名称,包名,权限, 支持的android平台最低版本号,支持的SDK版,建议的SDK版本,应用程序名,程序的图标等一系列信息。
  • tmp.startsWith("package")) { 122 throw new Exception("参数不正确,无法正常解析APK包。输出结果为:\n" + tmp + "..."); 123 } 124 apkInfo = new ApkInfo(); 125 do { 126 setApkInfoProperty(apkInfo, tmp); ...

    1 package com.apkutils;

    2

    3 import java.io.BufferedReader;

    4 import java.io.Closeable;

    5 import java.io.File;

    6 import java.io.FileInputStream;

    7 import java.io.IOException;

    8 import java.io.InputStream;

    9 import java.io.InputStreamReader;

    10 import java.util.HashMap;

    11 import java.util.Map;

    12 import java.util.Properties; 16

    13

    14 /**

    15 * apk工具类。封装了获取Apk信息的方法。

    16 *

    17 * @author @author tony

    18 *

    19 *

    20 * version description

    21 * V0.2.1 修改程序名字为从路径中获得。

    22 *

    23 */

    24 public class ApkUtil {

    25 public static final String VERSION_CODE = "versionCode";

    26 public static final String VERSION_NAME = "versionName";

    27 public static final String SDK_VERSION = "sdkVersion";

    28 public static final String TARGET_SDK_VERSION = "targetSdkVersion";

    29 public static final String USES_PERMISSION = "uses-permission";

    30 public static final String APPLICATION_LABEL = "application-label";

    31 public static final String APPLICATION_ICON = "application-icon";

    32 public static final String USES_FEATURE = "uses-feature";

    33 public static final String USES_IMPLIED_FEATURE = "uses-implied-feature";

    34 public static final String SUPPORTS_SCREENS = "supports-screens";

    35 public static final String SUPPORTS_ANY_DENSITY = "supports-any-density";

    36 public static final String DENSITIES = "densities";

    37 public static final String PACKAGE = "package";

    38 public static final String APPLICATION = "application:";

    39 public static final String LAUNCHABLE_ACTIVITY = "launchable-activity";

    40

    41 // api ---- os

    42 static Map OSVersion = new HashMap();

    43

    44 static {

    45 OSVersion.put("3", "1.5");

    46 OSVersion.put("4", "1.6");

    47 OSVersion.put("5", "2.0");

    48 OSVersion.put("6", "2.0.1");

    49 OSVersion.put("7", "2.1");

    50 OSVersion.put("8", "2.2");

    51 OSVersion.put("9", "2.3");

    52 OSVersion.put("10", "2.3.3");

    53 OSVersion.put("11", "3.0");

    54 OSVersion.put("12", "3.1");

    55 OSVersion.put("13", "3.2");

    56 OSVersion.put("14", "4.0");

    57 OSVersion.put("15", "4.0.3");

    58 OSVersion.put("16", "4.1.1");

    59 OSVersion.put("17", "4.2");

    60 OSVersion.put("18", "4.3");

    61 OSVersion.put("19", "4.4");

    62 }

    63

    64 private static final String SPLIT_REGEX = "(: )|(=')|(' )|'";

    65 private static final String FEATURE_SPLIT_REGEX = "(:')|(',')|'";

    66 /**

    67 * aapt所在的目录。

    68 */

    69 private String mAaptPath = "D:\\App\\";//winOS

    70 //private String mAaptPath = ApkUtil.class.getClassLoader().getResource("").getPath();//linux

    71

    72 static String[] shellCommand;

    73 static String softName = "";

    74 static {

    75 shellCommand = new String[2];

    76 final String anOSName = System.getProperty("os.name");

    77 if (anOSName.toLowerCase().startsWith("windows")) {

    78 // Windows XP, Vista ...

    79 shellCommand[0] = "cmd";

    80 shellCommand[1] = "/C";

    81 softName = "aapt.exe";

    82 } else {

    83 // Unix, Linux ...

    84 shellCommand[0] = "/bin/sh";

    85 shellCommand[1] = "-c";

    86 softName = "aapt";

    87 }

    88 }

    89

    90 /***

    91 * apkPath

    92 */

    93 static String apkPath = "C:/Users/win7/Desktop/Android/baiduyinyue_49.apk";

    94

    95 /**

    96 * 返回一个apk程序的信息。

    97 *

    98 * @param apkPath

    99 * apk的路径。

    100 * @return apkInfo 一个Apk的信息。

    101 */

    102 public ApkInfo getApkInfo(String apkPath) throws Exception {

    103 String command = mAaptPath + softName + "d badging \"" + apkPath

    104 + "\"";

    105 Process process;

    106 try {

    107 process = Runtime.getRuntime().exec(

    108 new String[] {shellCommand[0], shellCommand[1], command});

    109 } catch (IOException e) {

    110 process = null;

    111 throw e;

    112 }

    113

    114 ApkInfo apkInfo = null;

    115 if(process != null){

    116 InputStream is = process.getInputStream();

    117 BufferedReader br = new BufferedReader(

    118 new InputStreamReader(is, "utf8"));

    119 String tmp = br.readLine();

    120 try {

    121 if (tmp == null || !tmp.startsWith("package")) {

    122 throw new Exception("参数不正确,无法正常解析APK包。输出结果为:\n" + tmp + "...");

    123 }

    124 apkInfo = new ApkInfo();

    125 do {

    126 setApkInfoProperty(apkInfo, tmp);

    127 } while ((tmp = br.readLine()) != null);

    128 } catch (Exception e) {

    129 throw e;

    130 } finally {

    131 process.destroy();

    132 closeIO(is);

    133 closeIO(br);

    134 }

    135 }

    136 return apkInfo;

    137 }

    138

    139 /**

    140 * 设置APK的属性信息。

    141 *

    142 * @param apkInfo

    143 * @param source

    144 */

    145 private void setApkInfoProperty(ApkInfo apkInfo, String source) {

    146 if (source.startsWith(PACKAGE)) {

    147 splitPackageInfo(apkInfo, source);

    148 } else if (source.startsWith(LAUNCHABLE_ACTIVITY)) {

    149 apkInfo.setLaunchableActivity(getPropertyInQuote(source));

    150 } else if (source.startsWith(SDK_VERSION)) {

    151 apkInfo.setSdkVersion(getPropertyInQuote(source));

    152 apkInfo.setMinOSVersion(OSVersion.get(getPropertyInQuote(source)));

    153 } else if (source.startsWith(TARGET_SDK_VERSION)) {

    154 apkInfo.setTargetSdkVersion(getPropertyInQuote(source));

    155 } else if (source.startsWith(USES_PERMISSION)) {

    156 apkInfo.addToUsesPermissions(getPropertyInQuote(source));

    157 } else if (source.startsWith(APPLICATION_LABEL)) {

    158 apkInfo.setApplicationLable(getPropertyInQuote(source));

    159 } else if (source.startsWith(APPLICATION_ICON)) {

    160 apkInfo.addToApplicationIcons(getKeyBeforeColon(source),

    161 getPropertyInQuote(source));

    162 } else if (source.startsWith(APPLICATION)) {

    163 String[] rs = source.split("( icon=')|'");

    164 apkInfo.setApplicationIcon(rs[rs.length - 1]);

    165 } else if (source.startsWith(USES_FEATURE)) {

    166 apkInfo.addToFeatures(getPropertyInQuote(source));

    167 } else if (source.startsWith(USES_IMPLIED_FEATURE)) {

    168 apkInfo.addToImpliedFeatures(getFeature(source));

    169 } else {

    170

    171 }

    172 try {

    173 apkInfo.setApkFileSize(getFileSizes(new File(apkPath)));

    174 } catch (Exception e) {

    175 e.printStackTrace();

    176 }

    177 }

    178

    179 private ImpliedFeature getFeature(String source) {

    180 String[] result = source.split(FEATURE_SPLIT_REGEX);

    181 ImpliedFeature impliedFeature = new ImpliedFeature(result[1], result[2]);

    182 return impliedFeature;

    183 }

    184

    185 /**

    186 * 返回出格式为name: 'value'中的value内容。

    187 *

    188 * @param source

    189 * @return

    190 */

    191 private String getPropertyInQuote(String source) {

    192 int index = source.indexOf("'") + 1;

    193 return source.substring(index, source.indexOf('\'', index));

    194 }

    195

    196 /**

    197 * 返回冒号前的属性名称

    198 *

    199 * @param source

    200 * @return

    201 */

    202 private String getKeyBeforeColon(String source) {

    203 return source.substring(0, source.indexOf(':'));

    204 }

    205

    206 /**

    207 * 分离出包名、版本等信息。

    208 *

    209 * @param apkInfo

    210 * @param packageSource

    211 */

    212 private void splitPackageInfo(ApkInfo apkInfo, String packageSource) {

    213 String[] packageInfo = packageSource.split(SPLIT_REGEX);

    214 apkInfo.setPackageName(packageInfo[2]);

    215 apkInfo.setVersionCode(packageInfo[4]);

    216 apkInfo.setVersionName(packageInfo[6]);

    217 }

    218

    219 /**

    220 * 释放资源。

    221 *

    222 * @param c

    223 * 将关闭的资源

    224 */

    225 private final void closeIO(Closeable c) {

    226 if (c != null) {

    227 try {

    228 c.close();

    229 } catch (IOException e) {

    230 e.printStackTrace();

    231 }

    232 }

    233 }

    234

    235 public static void main(String[] args) {

    236 try {

    237 ApkInfo apkInfo = new ApkUtil().getApkInfo(apkPath);

    238 System.out.println(apkInfo);

    239 IconUtil.extractFileFromApk(apkPath, apkInfo.getApplicationIcon(),

    240 "D:\\icon.png");

    241 } catch (Exception e) {

    242 e.printStackTrace();

    243 }

    244 }

    245

    246 public String getmAaptPath() {

    247 return mAaptPath;

    248 }

    249

    250 public void setmAaptPath(String mAaptPath) {

    251 this.mAaptPath = mAaptPath;

    252 }

    253

    254 // 取得文件大小

    255 public static long getFileSizes(File f) throws Exception {

    256 long s = 0;

    257 if (f.exists()) {

    258 FileInputStream fis = null;

    259 fis = new FileInputStream(f);

    260 s = fis.available();

    261 } else {

    262 System.out.println("文件不存在");

    263 }

    264 return s;

    265 }

    266 }

    展开全文
  • aapt命令获取apk详细信息(包名、版本号、版本名称、兼容api级别、启动Activity等) 1.下载安卓SDK 2.配置系统环境变量 !...3.找到sdk目录进入到,如下图...aapt dump badging 要解析apk路径 最终获得如下图所示 ...

    aapt命令获取apk详细信息(包名、版本号、版本名称、兼容api级别、启动Activity等)

    1.下载安卓SDK

    2.配置系统环境变量

    ![在这里插入图片描述](https://img-blog.csdnimg.cn/f198391dedb8435bafe1e12be6ad99a5.png在这里插入图片描述

    3.找到sdk目录进入到,如下图,在此打开cmd命令行

    在这里插入图片描述

    4.输入命令

    aapt dump badging 要解析的apk路径
    

    最终获得如下图所示

    在这里插入图片描述
    新的apk替换旧的apk需要满足的三个条件

    1. apk包名需一样
    2. 版本号不能低于之前的
    3. 证书必须是同一个
    展开全文
  • 此工具用于解析 Android apk安装包,获取基础数据,反编译java源码 稍后支持解析 IOS ipa安装包基础数据 使用技术 名称 地址 electron electron-vue element 使用工具 名称 地址 aapt Android Sdk -> build-tools adb ...
  • .net core 从(本地)服务器获取APK文件并解析APK信息

    1、apk解析除了使用客户端利用aapt.exe、unzip.exe开发客户端解析外,还可以直接利用服务进行解析

    /// <summary>
    /// 从本地服务器获取APK文件并解析APK信息
    /// </summary>
    /// <param name="fileName">APK文件的完整路径</param>
    /// <returns></returns>
    [HttpPost, HttpGet, HttpOptions, CorsOptions]
    public IActionResult DecodeAPK(string fileName)
    {
        if(fileName.IndexOf(".apk") == -1 && fileName.IndexOf(".zip") == -1)
        {
            return ErrorResult("未获取到APP上传路径!", 111111);
        }
        // 从服务器取文件
        if(!string.IsNullOrWhiteSpace(fileName))
        {
            fileName = fileName.Replace(@"\", @" / ");
            ApkInfo apk = new ApkInfo();
            // 处理apk信息
            try
                apk = ReadAPK.ReadApkFromPath(fileName);
            catch(Exception ex)
                return ErrorResult("APP上传失败!--> APK解析失败,失败原因为:" + ex.Message, 111150);
            return SuccessResult(apk, "APK解析成功");
        }
        else
            return ErrorResult("APP上传失败!--> 从服务器获取APK文件失败,请联系网站管理员!", 111151);
    }

    2、ReadAPK  APK解析帮助类

    /// <summary>
    /// 读取APK信息
    /// </summary>
    public class ReadAPK
    {
        /// <summary>
        /// 从上传apk的路径读取并解析apk信息
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static ApkInfo ReadApkFromPath(string path)
        {
            byte[] manifestData = null;
            byte[] resourcesData = null;
            var manifest = "AndroidManifest.xml";
            var resources = "resources.arsc";
            //读取apk,通过解压的方式读取
            using(var zip = ZipFile.Read(path))
            {
                using(Stream zipstream = zip[manifest].OpenReader())
                {
                    //将解压出来的文件保存到一个路径(必须这样)
                    using(var fileStream = File.Create(manifest, (int) zipstream.Length))
                    {
                        manifestData = new byte[zipstream.Length];
                        zipstream.Read(manifestData, 0, manifestData.Length);
                        fileStream.Write(manifestData, 0, manifestData.Length);
                    }
                }
                using(Stream zipstream = zip[resources].OpenReader())
                {
                    //将解压出来的文件保存到一个路径(必须这样)
                    using(var fileStream = File.Create(resources, (int) zipstream.Length))
                    {
                        resourcesData = new byte[zipstream.Length];
                        zipstream.Read(resourcesData, 0, resourcesData.Length);
                        fileStream.Write(resourcesData, 0, resourcesData.Length);
                    }
                }
            }
            ApkReader apkReader = new ApkReader();
            ApkInfo info = apkReader.extractInfo(manifestData, resourcesData);
            return info;
        }
    }

    3、APK解析类

    注:此段代码解析APK时,若APK包含中文会极其的卡顿,建议上传前先用Npinyin重命名再次上传,至于原因已提交GitHub,暂未得到回复,所以先自己重命名再上传吧

    Wrong Local header signature: 0xFF8

    public class ApkReader
    {
        private static int VER_ID = 0;
        private static int ICN_ID = 1;
        private static int LABEL_ID = 2;
        String[] VER_ICN = new String[3];
        String[] TAGS = {
            "manifest", "application", "activity"
        };
        String[] ATTRS = {
            "android:", "a:", "activity:", "_:"
        };
        Dictionary < String, object > entryList = new Dictionary < String, object > ();
        List < String > tmpFiles = new List < String > ();
        public String fuzzFindInDocument(XmlDocument doc, String tag, String attr)
        {
            foreach(String t in TAGS)
            {
                XmlNodeList nodelist = doc.GetElementsByTagName(t);
                for(int i = 0; i < nodelist.Count; i++)
                {
                    XmlNode element = (XmlNode) nodelist.Item(i);
                    if(element.NodeType == XmlNodeType.Element)
                    {
                        XmlAttributeCollection map = element.Attributes;
                        for(int j = 0; j < map.Count; j++)
                        {
                            XmlNode element2 = map.Item(j);
                            if(element2.Name.EndsWith(attr))
                            {
                                return element2.Value;
                            }
                        }
                    }
                }
            }
            return null;
        }
        private XmlDocument initDoc(String xml)
        {
            XmlDocument retval = new XmlDocument();
            retval.LoadXml(xml);
            retval.DocumentElement.Normalize();
            return retval;
        }
        private void extractPermissions(ApkInfo info, XmlDocument doc)
        {
            ExtractPermission(info, doc, "uses-permission", "name");
            ExtractPermission(info, doc, "permission-group", "name");
            ExtractPermission(info, doc, "service", "permission");
            ExtractPermission(info, doc, "provider", "permission");
            ExtractPermission(info, doc, "activity", "permission");
        }
        private bool readBoolean(XmlDocument doc, String tag, String attribute)
        {
            String str = FindInDocument(doc, tag, attribute);
            bool ret = false;
            try
            {
                ret = Convert.ToBoolean(str);
            }
            catch
            {
                ret = false;
            }
            return ret;
        }
        private void extractSupportScreens(ApkInfo info, XmlDocument doc)
        {
            info.supportSmallScreens = readBoolean(doc, "supports-screens", "android:smallScreens");
            info.supportNormalScreens = readBoolean(doc, "supports-screens", "android:normalScreens");
            info.supportLargeScreens = readBoolean(doc, "supports-screens", "android:largeScreens");
            if(info.supportSmallScreens || info.supportNormalScreens || info.supportLargeScreens) info.supportAnyDensity = false;
        }
        public ApkInfo extractInfo(byte[] manifest_xml, byte[] resources_arsx)
        {
            string manifestXml = string.Empty;
            APKManifest manifest = new APKManifest();
            try
            {
                manifestXml = manifest.ReadManifestFileIntoXml(manifest_xml);
            }
            catch(Exception ex)
            {
                throw ex;
            }
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(manifestXml);
            return extractInfo(doc, resources_arsx);
        }
        public ApkInfo extractInfo(XmlDocument manifestXml, byte[] resources_arsx)
        {
            ApkInfo info = new ApkInfo();
            VER_ICN[VER_ID] = "";
            VER_ICN[ICN_ID] = "";
            VER_ICN[LABEL_ID] = "";
            try
            {
                XmlDocument doc = manifestXml;
                if(doc == null) throw new Exception("Document initialize failed");
                info.resourcesFileName = "resources.arsx";
                info.resourcesFileBytes = resources_arsx;
                // Fill up the permission field  不需要返回,注释
                //extractPermissions(info, doc);
                // Fill up some basic fields
                info.minSdkVersion = FindInDocument(doc, "uses-sdk", "minSdkVersion");
                info.targetSdkVersion = FindInDocument(doc, "uses-sdk", "targetSdkVersion");
                info.versionCode = FindInDocument(doc, "manifest", "versionCode");
                info.versionName = FindInDocument(doc, "manifest", "versionName");
                info.packageName = FindInDocument(doc, "manifest", "package");
                int labelID;
                info.label = FindInDocument(doc, "application", "label");
                if(info.label.StartsWith("@")) VER_ICN[LABEL_ID] = info.label;
                else if(int.TryParse(info.label, out labelID)) VER_ICN[LABEL_ID] = String.Format("@{0}", labelID.ToString("X4"));
                // Fill up the support screen field  不需要返回,注释
                //extractSupportScreens(info, doc);
                if(info.versionCode == null) info.versionCode = fuzzFindInDocument(doc, "manifest", "versionCode");
                if(info.versionName == null) info.versionName = fuzzFindInDocument(doc, "manifest", "versionName");
                else if(info.versionName.StartsWith("@")) VER_ICN[VER_ID] = info.versionName;
                String id = FindInDocument(doc, "application", "android:icon");
                if(null == id)
                {
                    id = fuzzFindInDocument(doc, "manifest", "icon");
                }
                if(null == id)
                {
                    Debug.WriteLine("icon resId Not Found!");
                    return info;
                }#
                region 获取APK名称的代码暂时注释, 运行时间太卡顿
                // Find real strings
                if(!info.hasIcon && id != null)
                {
                    if(id.StartsWith("@android:")) VER_ICN[ICN_ID] = "@" + (id.Substring("@android:".Length));
                    else VER_ICN[ICN_ID] = String.Format("@{0}", Convert.ToInt32(id).ToString("X4"));
                    List < String > resId = new List < String > ();
                    for(int i = 0; i < VER_ICN.Length; i++)
                    {
                        if(VER_ICN[i].StartsWith("@")) resId.Add(VER_ICN[i]);
                    }
                    ApkResourceFinder finder = new ApkResourceFinder();
                    info.resStrings = finder.processResourceTable(info.resourcesFileBytes, resId);
                    if(!VER_ICN[VER_ID].Equals(""))
                    {
                        List < String > versions = null;
                        if(info.resStrings.ContainsKey(VER_ICN[VER_ID].ToUpper())) versions = info.resStrings[VER_ICN[VER_ID].ToUpper()];
                        if(versions != null)
                        {
                            if(versions.Count > 0) info.versionName = versions[0];
                        }
                        else
                        {
                            throw new Exception("VersionName Cant Find in resource with id " + VER_ICN[VER_ID]);
                        }
                    }
                    List < String > iconPaths = null;
                    if(info.resStrings.ContainsKey(VER_ICN[ICN_ID].ToUpper())) iconPaths = info.resStrings[VER_ICN[ICN_ID].ToUpper()];
                    if(iconPaths != null && iconPaths.Count > 0)
                    {
                        info.iconFileNameToGet = new List < String > ();
                        info.iconFileName = new List < string > ();
                        foreach(String iconFileName in iconPaths)
                        {
                            if(iconFileName != null)
                            {
                                if(iconFileName.Contains(@"/"))
                                {
                                    info.iconFileNameToGet.Add(iconFileName);
                                    info.iconFileName.Add(iconFileName);
                                    info.hasIcon = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Icon Cant Find in resource with id " + VER_ICN[ICN_ID]);
                    }
                    if(!VER_ICN[LABEL_ID].Equals(""))
                    {
                        List < String > labels = null;
                        if(info.resStrings.ContainsKey(VER_ICN[LABEL_ID])) labels = info.resStrings[VER_ICN[LABEL_ID]];
                        if(labels.Count > 0)
                        {
                            info.label = labels[0];
                        }
                    }
                }#
                endregion
            }
            catch(Exception e)
            {
                throw e;
            }
            return info;
        }
        private void ExtractPermission(ApkInfo info, XmlDocument doc, String keyName, String attribName)
        {
            XmlNodeList usesPermissions = doc.GetElementsByTagName(keyName);
            if(usesPermissions != null)
            {
                for(int s = 0; s < usesPermissions.Count; s++)
                {
                    XmlNode permissionNode = usesPermissions.Item(s);
                    if(permissionNode.NodeType == XmlNodeType.Element)
                    {
                        XmlNode node = permissionNode.Attributes.GetNamedItem(attribName);
                        if(node != null) info.Permissions.Add(node.Value);
                    }
                }
            }
        }
        private String FindInDocument(XmlDocument doc, String keyName, String attribName)
        {
            XmlNodeList usesPermissions = doc.GetElementsByTagName(keyName);
            if(usesPermissions != null)
            {
                for(int s = 0; s < usesPermissions.Count; s++)
                {
                    XmlNode permissionNode = usesPermissions.Item(s);
                    if(permissionNode.NodeType == XmlNodeType.Element)
                    {
                        XmlNode node = permissionNode.Attributes.GetNamedItem(attribName);
                        if(node != null) return node.Value;
                    }
                }
            }
            return null;
        }
    }

    4、APK解析返回类

    public class ApkInfo
    {
        /// <summary>
        /// APK名称
        /// </summary>
        public string label
        {
            get;
            set;
        }
        /// <summary>
        /// APK版本号
        /// </summary>
        public string versionName
        {
            get;
            set;
        }
        /// <summary>
        /// APK版本编号
        /// </summary>
        public string versionCode
        {
            get;
            set;
        }
        /// <summary>
        /// APK支持的最小SDK版本
        /// </summary>
        public string minSdkVersion
        {
            get;
            set;
        }
        /// <summary>
        /// APK的目标SDK版本
        /// </summary>
        public string targetSdkVersion
        {
            get;
            set;
        }
        /// <summary>
        /// APK包名称
        /// </summary>
        public string packageName
        {
            get;
            set;
        }
        public static int FINE = 0;
        public static int NULL_VERSION_CODE = 1;
        public static int NULL_VERSION_NAME = 2;
        public static int NULL_PERMISSION = 3;
        public static int NULL_ICON = 4;
        public static int NULL_CERT_FILE = 5;
        public static int BAD_CERT = 6;
        public static int NULL_SF_FILE = 7;
        public static int BAD_SF = 8;
        public static int NULL_MANIFEST = 9;
        public static int NULL_RESOURCES = 10;
        public static int NULL_DEX = 13;
        public static int NULL_METAINFO = 14;
        public static int BAD_JAR = 11;
        public static int BAD_READ_INFO = 12;
        public static int NULL_FILE = 15;
        public static int HAS_REF = 16;
        // 其他不返回属性权限、其他资源文件等等
        public List < String > Permissions;
        public List < String > iconFileName;
        public List < String > iconFileNameToGet;
        public List < String > iconHash;
        public String resourcesFileName;
        public byte[] resourcesFileBytes;
        public bool hasIcon;
        public bool supportSmallScreens;
        public bool supportNormalScreens;
        public bool supportLargeScreens;
        public bool supportAnyDensity;
        public Dictionary < String, List < String >> resStrings;
        public Dictionary < String, String > layoutStrings;
        public static bool supportSmallScreen(byte[] dpi)
        {
            if(dpi[0] == 1) return true;
            return false;
        }
        public static bool supportNormalScreen(byte[] dpi)
        {
            if(dpi[1] == 1) return true;
            return false;
        }
        public static bool supportLargeScreen(byte[] dpi)
            {
                if(dpi[2] == 1) return true;
                return false;
            }
            //public byte[] getDPI()
            //{
            //    byte[] dpi = new byte[3];
            //    if (this.supportAnyDensity)
            //    {
            //        dpi[0] = 1;
            //        dpi[1] = 1;
            //        dpi[2] = 1;
            //    }
            //    else
            //    {
            //        if (this.supportSmallScreens)
            //            dpi[0] = 1;
            //        if (this.supportNormalScreens)
            //            dpi[1] = 1;
            //        if (this.supportLargeScreens)
            //            dpi[2] = 1;
            //    }
            //    return dpi;
            //}
        public ApkInfo()
        {
            hasIcon = false;
            supportSmallScreens = false;
            supportNormalScreens = false;
            supportLargeScreens = false;
            supportAnyDensity = true;
            versionCode = null;
            versionName = null;
            iconFileName = null;
            iconFileNameToGet = null;
            Permissions = new List < String > ();
        }
        private bool isReference(List < String > strs)
        {
            try
            {
                foreach(String str in strs)
                {
                    if(isReference(str)) return true;
                }
            }
            catch(Exception e)
            {
                throw e;
            }
            return false;
        }
        private bool isReference(String str)
        {
            try
            {
                if(str != null && str.StartsWith("@"))
                {
                    int.Parse(str, System.Globalization.NumberStyles.HexNumber);
                    return true;
                }
            }
            catch(Exception e)
            {
                throw e;
            }
            return false;
        }
    }

    以上就是.net core 从(本地)服务器获取APK文件并解析APK信息的介绍,做此记录,如有帮助,欢迎点赞关注收藏!

    展开全文
  • APK是如何被解析的?

    2021-03-19 09:46:22
    前言在本系列的前面文章中,我介绍了PackageInstaller的初始化和安装APK过程、PMS处理APK的安装和PMS的创建过程,这些文章中经常会涉及到一个类,那就是PackageParser,它用来在APK的安装过程中解析APK,那么APK是...
  • 关于解析apk文件的详细步骤《1》

    千次阅读 2019-10-17 10:27:47
    先把下载好的aapt解析文件包工具放在某个盘的目录下,![在这里插入图片描述]... (解析apk常用属性) public class ApkUtil { public static final String VERSION_CODE = "versionCode";...
  • 从网上找到的,不过找不到来源了,需要你的服务器端安装有AndroidSDK工具,并且可以被PHP运行,这个代码还可以获得应用的名称(application下的android:label)function readApkInfoFromFile($aapt_file, $apk_file, $...
  • Java解析APK信息,使用ApkFile

    千次阅读 2017-05-09 10:25:01
    由于这两天工作需要写一个自动发包的平台,需要写一个解析APK信息的工具类,这里用到了 Apk Parser(https://github.com/xiaxiaocao/apk-parser), 这是一个纯Java实现的Apk解析Lib,也是现存的功能最强的Apk Parser...
  • java解析apk安装包信息

    千次阅读 2015-07-16 09:11:46
    网上找了些关于解析apk安装包的博客: 但是是在非 WEB 项目下运行,但我们公司项目需求是web项目下解析apk安装包信息,然后供其他系统调用时候参考apk是不是需要升级,所有不能够用网络上的代码,和jar包来解析,...
  • 解析apk获取icon图标兼容linux和window

    热门讨论 2013-05-21 11:24:16
    纯java 不使用andoird SDK 解析android应用apk获取其icon图标 aapt及aaot.exe 取自andorid sdk
  • [ADB] Starting 'D:\Program Files (x86)\Android\android-sdk\build-tools\29.0.3\apksigner.bat' with args '["verify","--print-certs","C:\\Users\\huxuejing\\AppData\\Local\\Programs\\Appium\\resources\\...
  • 利用aapt解析apk文件

    2015-12-22 14:33:46
     * 利用aapt解析apk文件  * 需要依赖aapt工具  * 需要依赖PHP的ZIP包函数支持。  */ class AaptParseApk{ const DS=DIRECTORY_SEPARATOR; private $aaptPath;//aapt 应用程序 private $apkPath;//apk...
  • 程序自动开启其他APK 需要知道 包名和主Activity Android SDK platform-tools目录下有个aapt.exe 可以帮忙解析其他APK的包名和主Activity 需要先确定环境变量中的配置可以正常使用aapt.exe
  • (如需解析文件签名,建议用MD5工具类) public class MD5Util { public static void main(String[] args) { String str = "123456"; System.out.println(md5(str)); } // 十六进制下数字到字符的映射数组 ...
  • 解析Android SDK问题

    2021-06-05 19:03:01
    我正在开发使用Parse SDK的应用程序。它在一年前工作,但现在它不工作和崩溃。 另外我在Android Studio 2.2.3上进行调试,我可以调试应用程序,但是当...解析Android SDK问题这里是崩溃FATAL EXCEPTION: main Proces...
  • 市面上纯Java解析Android SDK的方式其实较为单一,在这里我先列举【apk-parser】这套体系的解决方案 step1:引入依赖 <dependency> <groupId>net.dongliu</groupId> <artifactId>apk-...
  • Java解析APK获取版本信息

    千次阅读 2018-07-02 18:03:48
    Android项目迭代中,常常将APKAPK的信息提交到后台,然后后台开发人员提供API给Android调用,返回迭代更新的内容以及apk,可以我们在提交APK的时候可以会本次更新的版本号比上次低,导致Android前端下载最新的APK...
  • Android Apk解析

    千次阅读 2017-09-25 19:21:44
    本文主要解释APK的结构,以及其相关的解析过程.内容分为两部分,一部分是反编译的类文件查看,一部分是其它的文件查看.(拿到一个apk还是可以获取不少信息的,想想还有点小激动) apk的文件就是一个普通的归档文件,...
  • 从源码角度解析Android中APK安装过程

    千次阅读 2018-11-28 15:37:40
    从源码角度解析Android中APK的安装过程 1. Android中APK简介 Android应用Apk的安装有如下四种方式: 1.1 系统应用安装 没有安装界面,在开机时自动完成 1.2 网络下载应用安装 没有安装界面,在应用市场完成 1.3 ...
  • Java 调用 aapt 解析 Apk

    千次阅读 2017-02-25 21:16:14
    Java 调用 aapt 解析 Apk
  • 在 PackageManagerService(1)扫描前的准备 文章中,分析了 PKMS ( PackageManagerService ) 在扫描之前的准备工作,这篇文章来分析扫描目录并解析APK的过程。 扫描目录并解析APK这个过程,伴随着大量升级相关的代码...
  • Java解析apk、ipa图标,包名,应用名称,版本号

    万次阅读 热门讨论 2016-12-13 17:46:43
    这篇文章主要针对apk、ipa解析图标,当然也会顺带解析其他一些基本信息, 比如:包名、版本号、版本名、应用名称。 之前google了好多文章,没有完整的可以解决图标的博文。今天我就为大家带来一篇。 首先给...
  • 使用apk-parser解析apk

    千次阅读 2018-03-21 14:37:16
    项目里需要用java代码解析apk包的版本号、版本名称等信息,一开始用的AXmlResourceParser工具解析的,结果发现解析出错 java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock....
  • ApkHelper文件查看工具

    2019-02-26 21:16:31
    一款便捷的APK信息查看工具,可以快速获取安装包的信息。
  • Android Studio打包.so库到apk中实例详解由于在原来的ADT的Eclipse环境中,用ndk_build工具生成了相应的各个.so库文件之后,eclipse工具就会自动把这些库导入到apk中。而Android Studio目前为止(1.1.0版本)还无法...
  • 原来是因为TargetSDKVersion为30的情况下,必须用V2以上的签名模式才可以成功。 但是因为MTP加固涉及到重签,而用的重签版本之前太老了,还是v1的,所以导致加固后的包都安装失败。
  • ApkParser.zip

    2020-08-06 17:21:38
    $filename = 'benben.apk';//apk所在的路径地址 $apkParser = new Parser($filename); $apkParser->getManifest()->getPackageName(); //获取apk包名 $apkParser->getManifest()->getVersionCode(); //获取apk...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 24,920
精华内容 9,968
关键字:

解析apk的sdk