Exemple #1
0
        private static void ListFiles(Unzip unzip)
        {
            var tab = unzip.Entries.Any(e => e.IsDirectory) ? "\t" : string.Empty;

            foreach (var entry in unzip.Entries.OrderBy(e => e.Name))
            {
                if (entry.IsFile)
                {
                    Console.WriteLine(tab + "{0}: {1} -> {2}", entry.Name, entry.CompressedSize, entry.OriginalSize);
                    continue;
                }

                Console.WriteLine(entry.Name);
            }

            Console.WriteLine();
        }
Exemple #2
0
        private static void ListFiles(Unzip unzip)
        {
            var tab = unzip.Entries.Any(e => e.IsDirectory) ? "\t" : string.Empty;

            foreach (var entry in unzip.Entries.OrderBy(e => e.Name))
            {
                if (entry.IsFile)
                {
                    Console.WriteLine(tab + "{0}: {1} -> {2}", entry.Name, entry.CompressedSize, entry.OriginalSize);
                    continue;
                }

                Console.WriteLine(entry.Name);
            }

            Console.WriteLine();
        }
Exemple #3
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Syntax: unzip Archive.zip TargetDirectory");
                return;
            }

            var archiveName = args.First();
            var outputDirectory = args.Last();

            using (var unzip = new Unzip(archiveName))
            {
                Console.WriteLine("Listing files in the archive:");
                ListFiles(unzip);

                Console.WriteLine("Extracting files from the archive:");
                unzip.ExtractProgress += (s, e) => Console.WriteLine("{0} of {1}: {2}", e.CurrentFile, e.TotalFiles, e.FileName);
                unzip.ExtractToDirectory(outputDirectory);
            }
        }
Exemple #4
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Syntax: unzip Archive.zip TargetDirectory");
                return;
            }

            var archiveName     = args.First();
            var outputDirectory = args.Last();

            using (var unzip = new Unzip(archiveName))
            {
                Console.WriteLine("Listing files in the archive:");
                ListFiles(unzip);

                Console.WriteLine("Extracting files from the archive:");
                unzip.ExtractProgress += (s, e) => Console.WriteLine("{0} of {1}: {2}", e.CurrentFile, e.TotalFiles, e.FileName);
                unzip.ExtractToDirectory(outputDirectory);
            }
        }
        public string FingerprintFromApk()
        {
            string fingerprint = "";

            if(File.Exists(_apk))
            {
                using (var unzip = new Unzip (_apk))
                {
                    foreach (var entry in unzip.Entries)
                    {
                        if (entry.Name.ToLower().EndsWith (".rsa"))
                        {
                            unzip.Extract (entry.Name, "temp.rsa");
                        }
                    }
                }
                String output;
                using (Process p = new Process ())
                {
                    p.StartInfo.FileName = _keytool;
                    p.StartInfo.Arguments = " -v -printcert -file ./temp.rsa";
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError = true;

                    using (AutoResetEvent outputWaitHandle = new AutoResetEvent (false))
                    using (AutoResetEvent errorWaitHandle = new AutoResetEvent (false)) {
                        output = HandleOutput (p, outputWaitHandle, errorWaitHandle, -1, false);
                        fingerprint = ExtractMd5Fingerprint (output);
                        File.Delete ("./temp.rsa");

                    }
                }
            }
            return fingerprint;
        }
        private void ResignApk()
        {
            string unpackDirectory = "temp";
            Directory.CreateDirectory (unpackDirectory);

            using (var unzip = new Unzip (_apkLocation)) {
                foreach (var entry in unzip.Entries) {
                    if (!entry.Name.StartsWith ("META-INF/")) {
                        string[] nameSplit = Regex.Split (entry.Name, "/");
                        StringBuilder sb = new StringBuilder ();
                        sb.Append (string.Format("{0}/", unpackDirectory));
                        for (var i = 0; i < nameSplit.Length - 1; i++) {
                            sb.Append (string.Format ("{0}/", nameSplit [i]));
                            if (!Directory.Exists (sb.ToString ())) {
                                Directory.CreateDirectory (sb.ToString ());
                            }

                        }
                        unzip.Extract (entry.Name, string.Format ("{0}/{1}", unpackDirectory, entry.Name));
                    }

                }
            }
            _apkLocation = PackageAndSignApk ("TestApk.apk", unpackDirectory);
        }
        private void RepackageTestServer()
        {
            string testServer = string.Format("{0}{1}",Directory.GetCurrentDirectory (), "/Resources/TestServer.apk");
            string testServerLocation = string.Format ("{0}{1}", Directory.GetCurrentDirectory(), "/testServer");
            string tempManifestLocation = string.Format ("{0}{1}", testServerLocation, "/AndroidManifest.xml");

            if (File.Exists (testServer) && File.Exists(tempManifestLocation))
            {
                using (var unzip = new Unzip (testServer))
                {
                    foreach (var entry in unzip.Entries)
                    {
                        if (!entry.Name.Equals("AndroidManifest.xml"))
                        {
                            string[] nameSplit = Regex.Split (entry.Name, "/");
                            StringBuilder sb = new StringBuilder ();
                            sb.Append ("testServer/");
                            for (var i = 0; i < nameSplit.Length - 1; i++)
                            {
                                sb.Append (string.Format("{0}/", nameSplit [i]));
                                if(!Directory.Exists(sb.ToString()))
                                {
                                    Directory.CreateDirectory (sb.ToString ());
                                }

                            }
                            unzip.Extract (entry.Name, string.Format("{0}/{1}", testServerLocation, entry.Name));
                        }
                    }
                }
            }
            _testServerApkLocation = PackageAndSignApk ("TestServer.apk", testServerLocation);
        }
        private void PrepareTestServer()
        {
            string manifestLocation = string.Format("{0}{1}",Directory.GetCurrentDirectory (), "/Resources/AndroidManifest.xml");
            string testServerLocation = string.Format ("{0}{1}", Directory.GetCurrentDirectory(), "/testServer");
            string tempManifestLocation = string.Format ("{0}{1}", testServerLocation, "/AndroidManifest.xml");
            string dummyApk = string.Format("{0}/{1}",Directory.GetCurrentDirectory (),"dummy.apk");
            Directory.CreateDirectory (testServerLocation);

            if (File.Exists (manifestLocation))
            {
                string output;
                string fileContent = File.ReadAllText(manifestLocation);
                fileContent = fileContent.Replace ("#targetPackage#", _packageName);
                fileContent = fileContent.Replace ("#testPackage#", string.Format("{0}{1}",_packageName, ".test"));
                using (StreamWriter file = new StreamWriter(tempManifestLocation, true))
                {
                    file.Write(fileContent);
                }
                using (Process p = new Process ())
                {
                    p.StartInfo.FileName = _aaptLocation;
                    p.StartInfo.Arguments = string.Format("package -M {0} -I {1}/{2} -F {3}", tempManifestLocation, _androidVersionHelper.GetHighestPlatformLocation(), "android.jar", dummyApk);
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError = true;

                    using (AutoResetEvent outputWaitHandle = new AutoResetEvent (false))
                    using (AutoResetEvent errorWaitHandle = new AutoResetEvent (false))
                    {
                        output = HandleOutput (p, outputWaitHandle, errorWaitHandle, -1, false);
                        Console.WriteLine (output);
                        using (var unzip = new Unzip (dummyApk))
                        {
                            unzip.Extract ("AndroidManifest.xml", tempManifestLocation);
                        }
                        RepackageTestServer ();
                    }
                }
            }
        }
Exemple #9
0
        public static void Main(string[] args)
        {
            var finalargs = new List<string>(args);

              if (!finalargs.Contains ("-d")) {
            finalargs.Add ("-d");
            finalargs.Add (Directory.GetCurrentDirectory ());
              }

              if (!finalargs.Contains ("-h")) {
            finalargs.Add ("-h");
            finalargs.Add (HOME);
              }

              args = finalargs.ToArray();

              bool doUpdate = args.Length > 0 && args[0] == "update";

              if (!Directory.Exists (HOME) || (doUpdate)) {
            if (Directory.Exists (HOME)) {
              Console.Write("Deleting " + HOME);
              DirectoryDelete (HOME);
              Console.ForegroundColor = ConsoleColor.Magenta;
              Console.WriteLine(" [DONE]");
              Console.ResetColor();
            }

            if (args.Length > 1) {
              Console.Write("Copying " + args[1]);
              DirectoryCopy (args [1], HOME);
              Console.ForegroundColor = ConsoleColor.Magenta;
              Console.WriteLine(" [DONE]");
              Console.ResetColor();
              Console.WriteLine ("Installed to " + HOME);
              return;
            }

            Console.Write("Downloading " + URL);

            using (var client = new WebClient ()) {
              client.DownloadFile (URL, ZIP);
            }

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(" [DONE]");
            Console.ResetColor();

            Console.Write("Extracting " + ZIP);
            using (var unzip = new Unzip (ZIP)) {
              unzip.ExtractToDirectory (HOME_DIR);
            }

            Directory.Move (HOME_ORIG, HOME);
            File.Delete (ZIP);

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(" [DONE]");
            Console.ResetColor();
            Console.WriteLine ("Installed to " + HOME);

            if (doUpdate) return;
              }

              Assembly.LoadFile(Path.Combine(BOOT, "KopiLua.dll"));
              Assembly.LoadFile(Path.Combine(BOOT, "Microsoft.Web.XmlTransform.dll"));
              Assembly.LoadFile(Path.Combine(BOOT, "NLua.dll"));
              Assembly.LoadFile(Path.Combine(BOOT, "NuGet.Core.dll"));

              var kaizo = Assembly.LoadFile (Path.Combine (BOOT, "kaizo.exe"));

              kaizo.GetType("Kaizo.MainClass").GetMethod("Main", BindingFlags.Public | BindingFlags.Static).Invoke (null, new[] { finalargs.ToArray() });
        }