Beispiel #1
0
        void Save(string file)
        {
            TLYFile t = GetSaveFile();

            LasterHelper.SetEnvironmentPath(file);

            t.Save(file);
            LastFile = file;
        }
Beispiel #2
0
        void generateExeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sv = new SaveFileDialog())
            {
                sv.Filter     = "Exe file|*.exe";
                sv.DefaultExt = "exe";

                if (sv.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                string pwd = FCreatePassword.ShowForm();
                if (string.IsNullOrEmpty(pwd))
                {
                    return;
                }

                // Copiar librerias
                if (Path.GetDirectoryName(Application.ExecutablePath) != Path.GetDirectoryName(sv.FileName))
                {
                    if (MessageBox.Show("Do you want to copy dll files to?", "Library files", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        foreach (string file in Directory.GetFiles(Path.GetDirectoryName(Application.ExecutablePath), "*.dll", SearchOption.TopDirectoryOnly))
                        {
                            string dest = Path.Combine(Path.GetDirectoryName(sv.FileName), Path.GetFileName(file));
                            if (dest == file)
                            {
                                continue;
                            }

                            if (File.Exists(dest))
                            {
                                File.Delete(dest);
                            }
                            File.Copy(file, dest);
                        }
                    }
                }

                byte[] hash = Encoding.UTF8.GetBytes(pwd);
                hash = HashHelper.HashRaw(HashHelper.EHashType.Sha512, hash, 0, hash.Length);

                TLYFile      t      = GetSaveFile();
                PacketHeader header = new PacketHeader()
                {
                    H = hash,
                    D = Encoding.UTF8.GetBytes(t.Save())
                };

                header.Encrypt(true);

                // Leer exe original
                byte[] ar = File.ReadAllBytes(Application.ExecutablePath);

                using (FileStream fs = new FileStream(sv.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    // Escribir exe
                    fs.Write(ar, 0, ar.Length);

                    // Escribir contenido comprimido, en UTF8
                    ar = Encoding.UTF8.GetBytes(SerializationHelper.Serialize(header, SerializationHelper.EFormat.Json));
                    ar = CompressHelper.Compress(ar, 0, ar.Length, true);
                    fs.Write(ar, 0, ar.Length);

                    // Grabar tamaño añadido
                    ar = BitConverter.GetBytes(ar.Length);
                    fs.Write(ar, 0, ar.Length);

                    // Grabar palabra clave de fin de archivo
                    ar = Encoding.ASCII.GetBytes("PACK");
                    fs.Write(ar, 0, ar.Length);
                }

                Pr.Process.Start(Path.GetDirectoryName(sv.FileName));
            }
        }