Esempio n. 1
0
        private static DumpModel dump(string path)
        {
            if (!File.Exists(path))
            {
                throw new IOException("File not found.");
            }

            var output = new List <string>();
            var aapt   = new AAPTool();

            aapt.Start(string.Format("dump badging \"{0}\"", path));

            while (!aapt.StandardOutput.EndOfStream)
            {
                // Read output line by line, more convenient for parse (than ReadToEnd)
                output.Add(aapt.StandardOutput.ReadLine());
            }

            while (!aapt.StandardError.EndOfStream)
            {
                output.Add(aapt.StandardError.ReadLine());
            }

            aapt.WaitForExit();
            aapt.Close();

            // An error have only 2 messages
            return(new DumpModel(path, output.Count > 5, output));
        }
        private static DumpModel dump(
            string path, DumpTypes type, Func <string, int, bool> callback)
        {
            int index      = 0;
            var terminated = false;
            var msg        = string.Empty;
            var aapt       = new AAPTool();
            var output     = new List <string>();

            switch (type)
            {
            case DumpTypes.Manifest:
                aapt.Start($"{command} {manifest} \"{path}\"");
                break;

            case DumpTypes.Resources:
                aapt.Start($"{command} {resources} \"{path}\"");
                break;

            case DumpTypes.ManifestTree:
                aapt.Start($"{command} {manifestTree} \"{path}\" AndroidManifest.xml");
                break;
                //default:
                //    return new DumpModel(path, false, output);
            }

            while (!aapt.StandardOutput.EndOfStream && !terminated)
            {
                msg = aapt.StandardOutput.ReadLine();

                if (callback(msg, index))
                {
                    terminated = true;
                    try {
                        aapt.Kill();
                    }
                    catch { }
                }
                if (!terminated)
                {
                    index++;
                }
                output.Add(msg);
            }

            while (!aapt.StandardError.EndOfStream)
            {
                output.Add(aapt.StandardError.ReadLine());
            }

            try {
                aapt.WaitForExit();
                aapt.Close();
                aapt.Dispose();
            }
            catch { }

            return(new DumpModel(path, output.Count > 2, output));
        }
Esempio n. 3
0
        private static Dictionary <string, Icon> ExtractIconTable(string path, string iconID)
        {
            if (string.IsNullOrEmpty(iconID))
            {
                return(new Dictionary <string, Icon>());
            }

            var matchedEntry = false;
            var indexes      = new List <int>(); // Get position of icon in resource list
            var resTable     = AAPTool.dumpResources(path, (m, i) => {
                // Dump resources and get icons,
                // terminate when meet the end of mipmap entry,
                // icons are in 'drawable' or 'mipmap' resource
                if (m.Contains(iconID) && !m.Contains("flags"))
                {
                    indexes.Add(i);
                }

                if (!matchedEntry)
                {
                    if (m.Contains("mipmap/"))
                    {
                        matchedEntry = true;    // Begin mipmap entry
                    }
                }
                else
                {
                    if (m.Contains("entry"))    // Next entry, terminate
                    {
                        matchedEntry = false;
                        return(true);
                    }
                }
                return(false);
            });

            return(createIconTable(indexes, resTable.Messages));
        }
Esempio n. 4
0
        /// <summary>
        /// Extract resource id of launch icon from manifest tree
        /// </summary>
        /// <param name="path"></param>
        /// <returns>icon id</returns>
        private static string ExtractIconID(string path)
        {
            int iconIndex    = 0;
            var manifestTree = AAPTool.dumpManifestTree(
                path,
                (m, i) => {
                if (m.Contains("android:icon"))
                {
                    iconIndex = i;
                    return(true);
                }
                return(false);
            }
                );

            if (manifestTree.isSuccess)
            {
                string msg = manifestTree.Messages[iconIndex];
                return(msg.Split('@')[1]);
            }

            return(string.Empty);
        }
Esempio n. 5
0
 public static DumpModel ExtractManifest(string path)
 {
     return(AAPTool.dumpManifest(path));
 }