예제 #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");
                }
            }
        }
 private void MenReplaceBody_Click(object sender, EventArgs e)
 {
     using (CodeForm codeForm = new CodeForm(OwnerDefinition))
     {
         if (codeForm.ShowDialog(this) == DialogResult.OK)
         {
             CecilHelper.CloneMethodBody(codeForm.MethodDefinition, OwnerDefinition);
             if (BodyReplaced != null)
             {
                 BodyReplaced(this, EventArgs.Empty);
             }
         }
     }
 }
예제 #3
0
 private void MenReplaceBody_Click(object sender, EventArgs e)
 {
     using (var codeForm = new CodeForm(OwnerDefinition))
     {
         if (codeForm.ShowDialog(this) == DialogResult.OK)
         {
             try
             {
                 CecilHelper.CloneMethodBody(codeForm.MethodDefinition, OwnerDefinition);
                 if (BodyReplaced != null)
                 {
                     BodyReplaced(this, EventArgs.Empty);
                 }
             }
             catch (ArgumentException ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }