예제 #1
0
 private static void ReadApplicationIcon(ApkInfo info, String line)
 {
     if (String.IsNullOrEmpty(line))
     {
         return;
     }
     string[] arr = line.Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries);
     info.ApplicationIcon = arr[arr.Length - 1];
 }
예제 #2
0
 private static void ReadPackage(ApkInfo info, String line)
 {
     if (String.IsNullOrEmpty(line))
     {
         return;
     }
     string[] arr = line.Split(new[] { ' ', '=', ':', '\'' }, StringSplitOptions.RemoveEmptyEntries);
     info.PackageName = arr[2];
     info.VersionCode = arr[4];
     info.VersionName = arr[6];
 }
예제 #3
0
 private static void AddIcons(ApkInfo info, String line)
 {
     //application-icon-160:'res/drawable/icon.png'
     if (String.IsNullOrEmpty(line))
     {
         return;
     }
     string[] arr = line.Split(new[] { ':', '\'' }, StringSplitOptions.RemoveEmptyEntries);
     if (arr.Length != 2)
     {
         return;
     }
     info.ApplicationIcons.Add(arr[0], arr[1]);
 }
예제 #4
0
        private static void AddFeature(ApkInfo info, String line)
        {
            //uses-implied-feature:'android.hardware.screen.portrait','one or more activities have specified a portrait orientation'
            if (String.IsNullOrEmpty(line))
            {
                return;
            }
            string[] arr = line.Split(new[] { ':', '\'', ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length != 3)
            {
                return;
            }
            var f = new ImpliedFeature(arr[1], arr[2]);

            info.ImpliedFeatures.Add(f);
        }
예제 #5
0
        public ApkInfo GetApkInfo(String apkPath)
        {
            ApkInfo info;

            using (var p = new Process())
            {
                p.StartInfo = new ProcessStartInfo(AaptPath, String.Format("d badging \"{0}\"", apkPath))
                {
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    StandardOutputEncoding = Encoding.UTF8,
                    StandardErrorEncoding  = Encoding.UTF8
                };
                p.Start();
                StreamReader output = p.StandardOutput;
                string       line   = output.ReadLine();
                if (String.IsNullOrEmpty(line) || !line.StartsWith("package"))
                {
                    throw new ArgumentException("参数不正确,无法正常解析APK包。输出结果为:" + line + Environment.NewLine +
                                                output.ReadToEnd());
                }
                info = new ApkInfo();
                do
                {
                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    foreach (var action in ActionMap)
                    {
                        if (line.StartsWith(action.Key, StringComparison.CurrentCultureIgnoreCase))
                        {
                            action.Value(info, line);
                        }
                    }
                } while (!String.IsNullOrEmpty(line = output.ReadLine()));
            }
            return(info);
        }