Beispiel #1
0
        public static void SignPath(SignerSetting setting)
        {
            if (string.IsNullOrEmpty(setting.KeyFile))
            {
                setting.KeyFile = generateKey();
            }

            ProcessContext context = new ProcessContext(setting.Path);
            ProcessContext.CurrentContext = context;

            string publicKey = getPublicKey(context);

            System.Console.WriteLine(string.Format("Public Key Generated:\r\n\r\n{0}", publicKey));
            System.Console.WriteLine();

            System.Console.WriteLine("Files to process:");

            foreach (var file in context.Files)
            {
                System.Console.WriteLine(file.ID);

                foreach (var reference in file.References)
                {
                    System.Console.WriteLine(string.Format("   >   {0}", reference));
                }

                System.Console.WriteLine("Decompiling...");
                decompile(file, publicKey);
                recompile(file);
            }

            System.Console.WriteLine("Done.");
        }
Beispiel #2
0
        public static string getPublicKey(ProcessContext context)
        {
            //trial compile
            var file = context.Files[0];
            string path = Path.GetDirectoryName(file.FullName);

            decompile(file);
            recompile(file);

            Process process = new Process();
            process.StartInfo.FileName = SN;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;

            process.StartInfo.Arguments = string.Format(@"-T {0}\out\{1}", path, Path.GetFileName(file.FullName));

            process.Start();
            process.WaitForExit();

            string output = process.StandardOutput.ReadToEnd();

            string publicKey = output.Substring(output.Length - 18).Trim().ToUpper();

            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < publicKey.Length; i++)
            {
                builder.Append(publicKey[i]);

                if (i % 2 == 1)
                {
                    builder.Append(' ');
                }
            }

            publicKey = builder.ToString();

            return publicKey.Trim();
        }