Esempio n. 1
0
        // Functionality methods

        private void TestMet1()
        {
            if (structureViever.SelectedNode == null)
            {
                return;
            }
            TypeDefinition TypDef = structureViever.SelectedNode.Tag as TypeDefinition;

            if (TypDef == null)
            {
                return;
            }

            string     test = @"using System.Windows.Forms;
							namespace DefNamSp
							{
							  public class DefClass
							  {
								public void DefFunc()
								{
									MessageBox.Show(""Message Successfuly Injected"");
								}
							  }
							}"                            ;
            CSCompiler csc  = new CSCompiler(dataStruct.AssemblyDefinition);

            csc.Code = test;
            MethodDefinition md = csc.GetMethodDefinition(string.Empty, string.Empty);

            if (md == null)
            {
                return;
            }
            TypeDefinition tdret = (TypeDefinition)dataStruct.ILNodeManager.FindMemberByPath("-.System.Void");

            if (tdret == null)
            {
                return;
            }
            MethodDefinition md2 = new MethodDefinition("blub", MethodAttributes.Public, tdret);

            TypDef.Methods.Add(md2);

            CecilHelper.CloneMethodBody(md, md2);

            using (SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                Title = "Save to :",
                Filter = "Executables | *.exe;*.dll"
            })
            {
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    dataStruct.AssemblyDefinition.MainModule.Runtime = TargetRuntime.Net_4_0;
                    dataStruct.AssemblyDefinition.Write(saveFileDialog.FileName);
                    MessageBox.Show("Message Successfuly Injected");
                }
            }
        }
Esempio n. 2
0
        private void TypeCompiler_Click(object sender, EventArgs e)
        {
            string compileVar = CapsuleVarNamespaces
                                + CapsuleVarStart
                                + txtTypeCompile.Text
                                + CapsuleVarEnd;

            if (cSCompiler == null)
            {
                cSCompiler = new CSCompiler(dataStruct.AssemblyDefinition);
            }
            cSCompiler.Code = compileVar;
            MethodDefinition methodDefiniton = cSCompiler.GetMethodDefinition("B", "C");

            if (methodDefiniton == null)
            {
                return;
            }
            SetTypeReference(methodDefiniton.ReturnType);
        }