Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using Microsoft.CSharp;
- using System.CodeDom.Compiler;
- using System.Reflection;
- using System.Diagnostics;
- namespace SimpleBinder
- {
- class mainFrm : Form
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new mainFrm());
- }
- private TextBox textBox1;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.button1 = new System.Windows.Forms.Button();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(12, 38);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(260, 23);
- this.button1.TabIndex = 1;
- this.button1.Text = "Bind";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(12, 12);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(129, 20);
- this.textBox2.TabIndex = 3;
- this.textBox2.Text = "File";
- this.textBox2.Click += new System.EventHandler(this.textBox2_Click);
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(143, 12);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(129, 20);
- this.textBox1.TabIndex = 4;
- this.textBox1.Text = "Target";
- this.textBox1.Click += new System.EventHandler(this.textBox1_Click);
- //
- // Form1
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(284, 68);
- this.Controls.Add(this.textBox1);
- this.Controls.Add(this.textBox2);
- this.Controls.Add(this.button1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
- this.Name = "Form1";
- this.ShowIcon = false;
- this.ShowInTaskbar = false;
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.TextBox textBox2;
- public mainFrm()
- {
- InitializeComponent();
- }
- private void textBox1_Click(object sender, EventArgs e)
- {
- var diag = new SaveFileDialog();
- if (diag.ShowDialog() == DialogResult.OK)
- {
- textBox1.Text = diag.FileName;
- }
- }
- private void textBox2_Click(object sender, EventArgs e)
- {
- var diag = new OpenFileDialog();
- if (diag.ShowDialog() == DialogResult.OK)
- {
- textBox2.Text = diag.FileName;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- CSharpCodeProvider codeProvider = new CSharpCodeProvider();
- CompilerParameters parameters = new CompilerParameters();
- parameters.GenerateExecutable = true;
- parameters.OutputAssembly = "stub.exe";
- parameters.MainClass = "SimpleBinder.Stub";
- parameters.IncludeDebugInformation = false;
- // Add available assemblies - this should be enough for the simplest
- // applications.
- foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
- parameters.ReferencedAssemblies.Add(asm.Location);
- String code = Properties.Resources.Stub;
- CompilerResults results = codeProvider.CreateCompiler().CompileAssemblyFromSource(parameters, code);
- if (results.Errors.Count == 0)
- {
- try
- {
- var source = File.ReadAllBytes("stub.exe");
- var target = File.ReadAllBytes(textBox2.Text);
- var data = new byte[1024];
- var arr = new byte[source.Length + target.Length + data.Length];
- var info = Encoding.UTF8.GetBytes(textBox1.Text + "|" + target.Length + "|");
- Array.Copy(info, data, info.Length);
- Array.Copy(source, 0, arr, 0, source.Length);
- Array.Copy(target, 0, arr, source.Length, target.Length);
- Array.Copy(data, 0, arr, source.Length + target.Length, data.Length);
- File.WriteAllBytes("stub.exe", arr);
- MessageBox.Show("Binding successed");
- }
- catch { MessageBox.Show("Binding failed"); }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement