Ejemplo n.º 1
0
        void GetInfoComplete(ApkInfo info)
        {
            _name.Content    = info.appName;
            _version.Content = info.versionName;
            _sign.Text       = info.sign;
            BitmapImage bi = GetImage("apk\\" + info.icon);

            _icon.Source = bi;
        }
Ejemplo n.º 2
0
        void ApkInfoThread()
        {
            ProcessStartInfo pi = new ProcessStartInfo();

            pi.FileName               = "cmd.exe";
            pi.Arguments              = "/c aapt.exe d badging " + apkFile + " > dump.txt";
            pi.UseShellExecute        = false;
            pi.CreateNoWindow         = true;
            pi.RedirectStandardOutput = false;
            Process p = Process.Start(pi);

            p.WaitForExit();
            ApkInfo apkInfo = new ApkInfo();

            using (StreamReader sr = new StreamReader("dump.txt")) {
                string line = null;
                while ((line = sr.ReadLine()) != null)
                {
                    apkInfo.Parse(line);
                }
            }

            // unzip apk
            if (Directory.Exists("apk"))
            {
                Directory.Delete("apk", true);
            }
            pi                        = new ProcessStartInfo();
            pi.FileName               = "unzip.bat";
            pi.Arguments              = apkFile;
            pi.UseShellExecute        = false;
            pi.CreateNoWindow         = true;
            pi.RedirectStandardOutput = true;
            p = Process.Start(pi);
            p.WaitForExit();

            //get sign
            if (Directory.Exists("apk"))
            {
                pi                        = new ProcessStartInfo();
                pi.FileName               = "getsign.bat";
                pi.UseShellExecute        = false;
                pi.CreateNoWindow         = true;
                pi.RedirectStandardOutput = true;
                p            = Process.Start(pi);
                apkInfo.sign = "";
                for (int i = 0; i < 3; i++)
                {
                    apkInfo.sign += p.StandardOutput.ReadLine() + "\n";
                }
                p.WaitForExit();
            }

            Dispatcher.Invoke((ApkInfoDelegate)GetInfoComplete, apkInfo);
        }
Ejemplo n.º 3
0
        public void ReadApkFromPath(string path)
        {
            manifest = false;
            resource = false;
            byte[] manifestData  = null;
            byte[] resourcesData = null;

            using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(path)))
            {
                using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    ICSharpCode.SharpZipLib.Zip.ZipFile  zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream);
                    ICSharpCode.SharpZipLib.Zip.ZipEntry item;
                    while (true)
                    {
                        if (manifest && resource)
                        {
                            break;
                        }
                        item = zip.GetNextEntry();
                        if (item != null)
                        {
                            try
                            {
                                if (item.Name.ToLower() == "androidmanifest.xml")
                                {
                                    manifestData = new byte[50 * 1024];
                                    using (Stream strm = zipfile.GetInputStream(item))
                                    {
                                        strm.Read(manifestData, 0, manifestData.Length);
                                    }
                                    manifest = true;
                                }
                                if (item.Name.ToLower() == "resources.arsc")
                                {
                                    using (Stream strm = zipfile.GetInputStream(item))
                                    {
                                        using (BinaryReader s = new BinaryReader(strm))
                                        {
                                            resourcesData = s.ReadBytes((int)s.BaseStream.Length);
                                        }
                                    }
                                    resource = true;
                                }
                            }
                            catch
                            {
                                // MessageBox.Show("err");
                            }
                        }
                    }
                }
            }

            ApkInfo info = null;

            try
            {
                ApkReader apkReader = new ApkReader();
                info = apkReader.extractInfo(manifestData, resourcesData);
            }
            catch
            {
                textBox1.AppendText("Read androidmanifest.xml Failed!" + "\n");
                return;
            }

            textBox1.AppendText(string.Format("Package Name: {0}", info.packageName) + "\n");
            PkgName.Text = info.packageName;

            textBox1.AppendText(string.Format("Name: {0}", info.label) + "\n");
            AppName.Text = info.label;
            Directory.CreateDirectory("icons");
            ExtractFileAndSave(path, info.iconFileName[0], @"icons\", info.packageName);
            if (File.Exists(@"icons\" + info.packageName + ".png"))
            {
                Image.ImageLocation = @"icons\" + info.packageName + ".png";
            }
            textBox1.AppendText(string.Format("Version Name: {0}", info.versionName) + "\n");
            textBox1.AppendText(string.Format("Version Code: {0}", info.versionCode) + "\n");
            VersionName.Text = info.versionName;
            VersionCode.Text = info.versionCode;
            textBox1.AppendText(string.Format("App Has Icon: {0}", info.hasIcon) + "\n");
            if (info.iconFileName.Count > 0)
            {
                Console.WriteLine(string.Format("App Icon: {0}", info.iconFileName[0]) + "\n");
            }
            textBox1.AppendText(string.Format("Min SDK Version: {0}", info.minSdkVersion) + "\n");
            textBox1.AppendText(string.Format("Target SDK Version: {0}", info.targetSdkVersion) + "\n");

            if (info.Permissions != null && info.Permissions.Count > 0)
            {
                textBox1.AppendText("Permissions:" + "\n");
                info.Permissions.ForEach(f =>
                {
                    textBox1.AppendText(string.Format("   {0}", f) + "\n");
                });
            }
            else
            {
                textBox1.AppendText("No Permissions Found" + "\n");
            }
            textBox1.AppendText(string.Format("Supports Any Density: {0}", info.supportAnyDensity) + "\n");
            textBox1.AppendText(string.Format("Supports Large Screens: {0}", info.supportLargeScreens) + "\n");
            textBox1.AppendText(string.Format("Supports Normal Screens: {0}", info.supportNormalScreens) + "\n");
            textBox1.AppendText(string.Format("Supports Small Screens: {0}", info.supportSmallScreens) + "\n");
            return;
        }