/* PAYLOAD CREATION AND INJECTION *******************************************************/ private void CompileAndInject() { Compiler compiler = new Compiler(); string[] references = { "System.dll", "System.Core.dll", "mscorlib.dll", "System.Windows.Forms.dll" }; compiler.SetReferences(references); String outputFile = "tmpres.exe"; compiler.SetOutput(outputFile); /* compile the user's code */ try { compiler.Compile(richTextBox1.Text); } catch (Exception e) { richTextBox2.Text = e.ToString(); return; } richTextBox2.Text = "Compilation OK!"; /* create a new temporary assembly for our compilation result */ AssemblyHandler tmpAssembly = new AssemblyHandler(); tmpAssembly.LoadAssembly(outputFile); /* copy the method to the main assembly */ tmpAssembly.CopyMethodToAssembly(assemblyToInject, typeNameToInject, methodNameToInject, "das", "boot"); SaveAssembly(); this.Close(); }
private void LoadAssembly(String fileName) { if (assemblyToInject.LoadAssembly(fileName) != true) { return; } assemblyToInject.ReadMethodsToTree(this.treeView1); richTextBox1.Clear(); richTextBox1.AppendText("Assembly Loaded." + Environment.NewLine); richTextBox1.AppendText(assemblyToInject.GetRuntime() + " dependant." + Environment.NewLine); }