private bool Wrlc4x1(string appDir, bool spfold, int version)
    {
        string text = string.Format("{0}-{1}-{2}-{3}-{4}", new object[]
        {
            this.TextBox4.Text,
            this.TextBox5.Text,
            this.TextBox6.Text,
            this.TextBox8.Text,
            this.TextBox9.Text
        });
        bool result;

        if (checked (text.Length + this.TextBox11.TextLength) != 26)
        {
            Interaction.MsgBox("Invalid Key must be \"22\" chars.", MsgBoxStyle.OkOnly, null);
            result = false;
        }
        else
        {
            List <byte> list = new List <byte>();
            list.AddRange(new byte[]
            {
                1,
                0,
                0,
                0
            });
            list.AddRange(Encoding.ASCII.GetBytes(string.Format("{0}-{1}", text, this.TextBox11.Text)));
            List <string> list2 = new List <string>
            {
                "<root>",
                "  <License id=\"Terms\">",
                "    <ClientProvidedVersion Value=\"\"/>",
                string.Format("    <DeveloperData Value=\"{0}\"/>", Convert.ToBase64String(list.ToArray())),
                "    <Features>"
            };
            List <int> list3 = LicHeader.ReadAll();
            try
            {
                List <int> .Enumerator enumerator = list3.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    int current = enumerator.Current;
                    list2.Add("      <Feature Value=\"" + current.ToString() + "\"/>");
                }
                ((IDisposable)enumerator).Dispose();
            }
            finally
            {
                //List<int>.Enumerator enumerator;
            }
            list2.Add("    </Features>");
            if (version > 0)
            {
                list2.Add("    <LicenseVersion Value=\"5.x\"/>");
            }
            else
            {
                list2.Add("    <LicenseVersion Value=\"4.x\"/>");
            }
            list2.Add("    <MachineBindings>");
            list2.Add("    </MachineBindings>");
            list2.Add("    <MachineID Value=\"\"/>");
            list2.Add("    <SerialHash Value=\"\"/>");
            list2.Add(string.Format("    <SerialMasked Value=\"{0}-XXXX\"/>", text));
            DateTime now = DateTime.Now;
            list2.Add(string.Format("    <StartDate Value=\"{0}T00:00:00\"/>", now.AddDays(-1.0).ToString("yyyy-MM-dd")));
            list2.Add("    <StopDate Value=\"\"/>");
            list2.Add(string.Format("    <UpdateDate Value=\"{0}T00:00:00\"/>", now.AddYears(10).ToString("yyyy-MM-dd")));
            list2.Add("  </License>");
            list2.Add("");
            list2.Add("<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">");
            list2.Add("<SignedInfo>");
            list2.Add("<CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/>");
            list2.Add("<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>");
            list2.Add("<Reference URI=\"#Terms\">");
            list2.Add("<Transforms>");
            list2.Add("<Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>");
            list2.Add("</Transforms>");
            list2.Add("<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>");
            list2.Add("<DigestValue>oeMc1KScgy617DHMPTxbYhqNjIM=</DigestValue>");
            list2.Add("</Reference>");
            list2.Add("</SignedInfo>");
            list2.Add("<SignatureValue>WuzMPTi0Ko1vffk9gf9ds/iU0b0K8UHaLpi4kWgm6q1am5MPTYYnzH1InaSWuzYo");
            list2.Add("EpJThKspOZdO0JISeEolNdJVf3JpsY55OsD8UaruvhwZn4r9pLeNSC7SzQ1rvAWP");
            list2.Add("h77XaHizhVVs15w6NYevP27LTxbZaem5L8Zs+34VKXQFeG4g0dEI/Jhl70TqE0CS");
            list2.Add("YNF+D0zqEtyMNHsh0Rq/vPLSzPXUN12jfPLZ3dO9B+9/mG7Ljd6emZjjLZUVuSKQ");
            list2.Add("uKxN5jlHZsm2kRMudijICV6YOWMPT+oZePlCg+BJQg5/xcN5aYVBDZhNeuNwQL1H");
            list2.Add("MPT/GJPxVuETgd9k8c4uDg==</SignatureValue>");
            list2.Add("</Signature>");
            list2.Add("</root>");
            string text2;
            if (version > 0)
            {
                text2 = "Unity_v5.x.ulf";
            }
            else
            {
                text2 = "Unity_v4.x.ulf";
            }
            string text3 = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Unity";
            if (spfold && !Directory.Exists(text3))
            {
                try
                {
                    Directory.CreateDirectory(text3);
                }
                catch (Exception expr_398)
                {
                    ProjectData.SetProjectError(expr_398);
                    Exception ex = expr_398;
                    spfold = false;
                    Interaction.MsgBox(ex.Message, MsgBoxStyle.OkOnly, null);
                    ProjectData.ClearProjectError();
                }
            }
            if (spfold)
            {
                if (File.Exists(text3 + "/" + text2))
                {
                    spfold = this.TestAtr(text3 + "/" + text2);
                    if (spfold)
                    {
                        DialogResult dialogResult = (DialogResult)Interaction.MsgBox(string.Format("Replace the \"{0}\\{1}\"?", text3, text2), MsgBoxStyle.YesNo | MsgBoxStyle.Question, null);
                        if (dialogResult != DialogResult.Yes)
                        {
                            list2.Clear();
                            result = true;
                            return(result);
                        }
                    }
                }
                if (spfold)
                {
                    try
                    {
                        File.WriteAllLines(text3 + "/" + text2, list2);
                    }
                    catch (Exception expr_42B)
                    {
                        ProjectData.SetProjectError(expr_42B);
                        Exception ex2 = expr_42B;
                        spfold = false;
                        Interaction.MsgBox(ex2.Message, MsgBoxStyle.OkOnly, null);
                        ProjectData.ClearProjectError();
                    }
                }
            }
            if (!spfold)
            {
                if (File.Exists(appDir + "/" + text2))
                {
                    if (!this.TestAtr(appDir + "/" + text2))
                    {
                        list2.Clear();
                        result = false;
                        return(result);
                    }
                    DialogResult dialogResult2 = (DialogResult)Interaction.MsgBox(string.Format("Replace the \"{0}\\{1}\"?", appDir, text2), MsgBoxStyle.YesNo | MsgBoxStyle.Question, null);
                    if (dialogResult2 != DialogResult.Yes)
                    {
                        list2.Clear();
                        result = true;
                        return(result);
                    }
                }
                try
                {
                    File.WriteAllLines(appDir + "/" + text2, list2);
                }
                catch (Exception expr_4C3)
                {
                    ProjectData.SetProjectError(expr_4C3);
                    Exception ex3 = expr_4C3;
                    list2.Clear();
                    Interaction.MsgBox(ex3.Message, MsgBoxStyle.OkOnly, null);
                    result = false;
                    ProjectData.ClearProjectError();
                    return(result);
                }
            }
            list2.Clear();
            result = true;
        }
        return(result);
    }
Beispiel #2
0
        private bool WriteLicenseToFile(string appDir, bool spfold, int version)
        {
            string text = string.Format("{0}-{1}-{2}-{3}-{4}", new object[]
            {
                this.textBox3.Text,
                this.textBox4.Text,
                this.textBox5.Text,
                this.textBox6.Text,
                this.textBox7.Text
            });

            if (text.Length + this.textBox8.TextLength != 26)
            {
                MessageBox.Show("Invalid Key must be \"22\" chars.", string.Empty, MessageBoxButtons.OK);
                return(false);
            }
            this.PrintDebug();
            Console.WriteLine(version);
            List <byte> list     = new List <byte>();
            List <byte> arg_9D_0 = list;

            byte[] expr_99 = new byte[4];
            expr_99[0] = 1;
            arg_9D_0.AddRange(expr_99);
            list.AddRange(Encoding.ASCII.GetBytes(string.Format("{0}-{1}", text, this.textBox8.Text)));
            if (version != 20172)
            {
                List <string> list2 = new List <string>
                {
                    "<root>",
                    "  <TimeStamp2 Value=\"cn/lkLOZ3vFvbQ==\"/>",
                    "  <TimeStamp Value=\"jWj8PXAeZMPzUw==\"/>",
                    "  <License id=\"Terms\">",
                    "    <ClientProvidedVersion Value=\"\"/>",
                    string.Format("    <DeveloperData Value=\"{0}\"/>", Convert.ToBase64String(list.ToArray())),
                    "    <Features>"
                };
                int[] array = LicHeader.ReadAll();
                for (int i = 0; i < array.Length; i++)
                {
                    int num = array[i];
                    list2.Add(string.Format("      <Feature Value=\"{0}\"/>", num));
                }
                list2.Add("    </Features>");
                if (version < 500)
                {
                    list2.Add("    <LicenseVersion Value=\"4.x\"/>");
                }
                if (version >= 500 && version < 2017)
                {
                    list2.Add("    <LicenseVersion Value=\"5.x\"/>");
                }
                if (version == 2017)
                {
                    list2.Add("    <LicenseVersion Value=\"2017.x\"/>");
                }
                if (version == 20171)
                {
                    list2.Add("    <LicenseVersion Value=\"6.x\"/>");
                }
                list2.Add("    <MachineBindings>");
                list2.Add("    </MachineBindings>");
                list2.Add("    <MachineID Value=\"\"/>");
                list2.Add("    <SerialHash Value=\"\"/>");
                list2.Add(string.Format("    <SerialMasked Value=\"{0}-XXXX\"/>", text));
                DateTime now = DateTime.Now;
                list2.Add(string.Format("    <StartDate Value=\"{0}T00:00:00\"/>", now.AddDays(-1.0).ToString("yyyy-MM-dd")));
                list2.Add("    <StopDate Value=\"\"/>");
                list2.Add(string.Format("    <UpdateDate Value=\"{0}T00:00:00\"/>", now.AddYears(10).ToString("yyyy-MM-dd")));
                list2.Add("  </License>");
                list2.Add("");
                list2.Add("<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">");
                list2.Add("<SignedInfo>");
                list2.Add("<CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/>");
                list2.Add("<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>");
                list2.Add("<Reference URI=\"#Terms\">");
                list2.Add("<Transforms>");
                list2.Add("<Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>");
                list2.Add("</Transforms>");
                list2.Add("<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>");
                list2.Add("<DigestValue>oeMc1KScgy617DHMPTxbYhqNjIM=</DigestValue>");
                list2.Add("</Reference>");
                list2.Add("</SignedInfo>");
                list2.Add("<SignatureValue>WuzMPTi0Ko1vffk9gf9ds/iU0b0K8UHaLpi4kWgm6q1am5MPTYYnzH1InaSWuzYo");
                list2.Add("EpJThKspOZdO0JISeEolNdJVf3JpsY55OsD8UaruvhwZn4r9pLeNSC7SzQ1rvAWP");
                list2.Add("h77XaHizhVVs15w6NYevP27LTxbZaem5L8Zs+34VKXQFeG4g0dEI/Jhl70TqE0CS");
                list2.Add("YNF+D0zqEtyMNHsh0Rq/vPLSzPXUN12jfPLZ3dO9B+9/mG7Ljd6emZjjLZUVuSKQ");
                list2.Add("uKxN5jlHZsm2kRMudijICV6YOWMPT+oZePlCg+BJQg5/xcN5aYVBDZhNeuNwQL1H");
                list2.Add("MPT/GJPxVuETgd9k8c4uDg==</SignatureValue>");
                list2.Add("</Signature>");
                list2.Add("</root>");
                string text2 = "";
                if (version < 500)
                {
                    text2 = "Unity_v4.x.ulf";
                }
                if (version >= 500 && version < 2017)
                {
                    text2 = "Unity_v5.x.ulf";
                }
                if (version == 2017)
                {
                    text2 = "Unity_v2017.x.ulf";
                }
                if (version == 20171)
                {
                    text2 = "Unity_lic.ulf";
                }
                string text3 = string.Empty;
                if (spfold)
                {
                    text3 = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Unity";
                    if (!Directory.Exists(text3))
                    {
                        try
                        {
                            Directory.CreateDirectory(text3);
                        }
                        catch (Exception arg_3E0_0)
                        {
                            spfold = false;
                            MessageBox.Show(arg_3E0_0.Message, string.Empty, MessageBoxButtons.OK);
                        }
                    }
                }
                if (spfold)
                {
                    if (File.Exists(text3 + "/" + text2))
                    {
                        spfold = this.TestAtr(text3 + "/" + text2);
                        if (spfold && MessageBox.Show(string.Format("Replace the \"{0}\\{1}\"?", text3, text2), string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.OK)
                        {
                            list2.Clear();
                            return(true);
                        }
                    }
                    if (spfold)
                    {
                        try
                        {
                            if (version < 500)
                            {
                                text2 = "Unity_v4.x.ulf";
                            }
                            if (version >= 500 && version < 2017)
                            {
                                text2 = "Unity_v5.x.ulf";
                            }
                            if (version == 2017)
                            {
                                text2 = "Unity_v2017.x.ulf";
                            }
                            if (version == 20171)
                            {
                                text2 = "Unity_lic.ulf";
                            }
                            if (text2 == "Unity_lic.ulf")
                            {
                                using (FileStream fileStream = new FileStream(text3 + "/" + text2, FileMode.Append))
                                {
                                    foreach (string current in list2)
                                    {
                                        byte[] bytes = Encoding.ASCII.GetBytes(string.Format("{0}\r", current));
                                        fileStream.Write(bytes, 0, bytes.Length);
                                    }
                                    fileStream.Flush();
                                    fileStream.Close();
                                    goto IL_540;
                                }
                            }
                            File.WriteAllLines(text3 + "/" + text2, list2);
                            IL_540 :;
                        }
                        catch (Exception arg_545_0)
                        {
                            spfold = false;
                            MessageBox.Show(arg_545_0.Message, string.Empty, MessageBoxButtons.OK);
                        }
                    }
                }
                if (!spfold)
                {
                    if (File.Exists(appDir + "/" + text2))
                    {
                        if (!this.TestAtr(appDir + "/" + text2))
                        {
                            list2.Clear();
                            return(false);
                        }
                        if (MessageBox.Show(string.Format("Replace the \"{0}\\{1}\"?", appDir, text2), string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.OK)
                        {
                            list2.Clear();
                            return(true);
                        }
                    }
                    try
                    {
                        if (version < 500)
                        {
                            text2 = "Unity_v4.x.ulf";
                        }
                        if (version >= 500 && version < 2017)
                        {
                            text2 = "Unity_v5.x.ulf";
                        }
                        if (version == 2017)
                        {
                            text2 = "Unity_v2017.x.ulf";
                        }
                        if (version == 20171)
                        {
                            text2 = "Unity_lic.ulf";
                        }
                        if (text2 == "Unity_lic.ulf")
                        {
                            using (FileStream fileStream2 = new FileStream(text3 + "/" + text2, FileMode.Append))
                            {
                                foreach (string current2 in list2)
                                {
                                    byte[] bytes2 = Encoding.ASCII.GetBytes(string.Format("{0}\r", current2));
                                    fileStream2.Write(bytes2, 0, bytes2.Length);
                                }
                                fileStream2.Flush();
                                fileStream2.Close();
                                goto IL_6A2;
                            }
                        }
                        File.WriteAllLines(text3 + "/" + text2, list2);
                        IL_6A2 :;
                    }
                    catch (Exception arg_6AA_0)
                    {
                        list2.Clear();
                        MessageBox.Show(arg_6AA_0.Message, string.Empty, MessageBoxButtons.OK);
                        bool result = false;
                        return(result);
                    }
                }
                list2.Clear();
                return(true);
            }
            string text4 = string.Format("{0}-{1}-{2}-{3}-{4}-{5}", new object[]
            {
                this.textBox3.Text,
                this.textBox4.Text,
                this.textBox5.Text,
                this.textBox6.Text,
                this.textBox7.Text,
                this.textBox8.Text
            });

            int[] array2 = LicHeader.ReadAll();
            if (text4.Length != 27)
            {
                MessageBox.Show("Invalid Key must be \"27\" chars.", string.Empty, MessageBoxButtons.OK);
                return(false);
            }
            string path  = "Unity_lic.ulf";
            string value = text4.Remove(text4.Length - 4, 4) + "XXXX";

            byte[] expr_780 = new byte[4];
            expr_780[0] = 1;
            string value2 = Convert.ToBase64String(expr_780.Concat(Encoding.ASCII.GetBytes(text4)).ToArray <byte>().ToArray <byte>());
            string value3 = "6.x";
            string value4 = "false";
            string value5 = "";
            string value6 = DateTime.UtcNow.AddDays(-1.0).ToString("s", CultureInfo.InvariantCulture);
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            string            value7       = "";
            string            value8       = "";
            string            value9       = "";
            string            value10      = "";
            string            value11      = DateTime.UtcNow.AddYears(10).ToString("s", CultureInfo.InvariantCulture);
            MemoryStream      memoryStream = new MemoryStream();
            XmlWriterSettings settings     = new XmlWriterSettings
            {
                Indent             = true,
                IndentChars        = "  ",
                NewLineChars       = "\n",
                OmitXmlDeclaration = true,
                Encoding           = Encoding.ASCII
            };

            using (XmlWriter xmlWriter = XmlWriter.Create(memoryStream, settings))
            {
                xmlWriter.WriteStartElement("root");
                xmlWriter.WriteStartElement("License");
                xmlWriter.WriteAttributeString("id", "Terms");
                xmlWriter.WriteStartElement("AlwaysOnline");
                xmlWriter.WriteAttributeString("Value", value4);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("ClientProvidedVersion");
                xmlWriter.WriteAttributeString("Value", value5);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("DeveloperData");
                xmlWriter.WriteAttributeString("Value", value2);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("Features");
                int[] array = array2;
                for (int i = 0; i < array.Length; i++)
                {
                    int num2 = array[i];
                    xmlWriter.WriteStartElement("Feature");
                    xmlWriter.WriteAttributeString("Value", num2.ToString());
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteFullEndElement();
                xmlWriter.WriteStartElement("InitialActivationDate");
                xmlWriter.WriteAttributeString("Value", value6);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("LicenseVersion");
                xmlWriter.WriteAttributeString("Value", value3);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("MachineBindings");
                foreach (KeyValuePair <string, string> current3 in dictionary)
                {
                    xmlWriter.WriteStartElement("Binding");
                    xmlWriter.WriteAttributeString("Key", current3.Key);
                    xmlWriter.WriteAttributeString("Value", current3.Value);
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteFullEndElement();
                xmlWriter.WriteStartElement("MachineID");
                xmlWriter.WriteAttributeString("Value", value7);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("SerialHash");
                xmlWriter.WriteAttributeString("Value", value8);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("SerialMasked");
                xmlWriter.WriteAttributeString("Value", value);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("StartDate");
                xmlWriter.WriteAttributeString("Value", value9);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("StopDate");
                xmlWriter.WriteAttributeString("Value", value10);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("UpdateDate");
                xmlWriter.WriteAttributeString("Value", value11);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
                xmlWriter.Flush();
            }
            memoryStream.Position = 0L;
            XmlDocument xmlDocument = new XmlDocument
            {
                PreserveWhitespace = true
            };

            xmlDocument.Load(memoryStream);
            SignedXml signedXml = new SignedXml(xmlDocument)
            {
                SigningKey = new RSACryptoServiceProvider()
            };
            Reference reference = new Reference
            {
                Uri = "#Terms"
            };

            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            signedXml.AddReference(reference);
            signedXml.ComputeSignature();
            StringBuilder stringBuilder = new StringBuilder();

            using (XmlWriter xmlWriter2 = XmlWriter.Create(stringBuilder, settings))
            {
                XmlDocument xmlDocument2 = new XmlDocument
                {
                    InnerXml = xmlDocument.InnerXml
                };
                XmlElement expr_B8D = xmlDocument2.DocumentElement;
                if (expr_B8D != null)
                {
                    expr_B8D.AppendChild(xmlDocument2.ImportNode(signedXml.GetXml(), true));
                }
                xmlDocument2.Save(xmlWriter2);
                xmlWriter2.Flush();
            }
            string contents = stringBuilder.Replace(" />", "/>").ToString();
            string text5    = spfold ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Unity") : appDir;
            string text6    = Path.Combine(text5, path);

            try
            {
                Directory.CreateDirectory(text5);
                if (File.Exists(text6) && this.TestAtr(text6) && MessageBox.Show(string.Format("Replace the \"{0}\"?", text6), string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    bool result = true;
                    return(result);
                }
                File.WriteAllText(text6, contents);
            }
            catch (Exception arg_C49_0)
            {
                MessageBox.Show(arg_C49_0.Message, string.Empty, MessageBoxButtons.OK);
                bool result = false;
                return(result);
            }
            return(true);
        }