C# 使用reflector与reflexil实现代码注入

需求

1.         双击窗体,弹出无标题的messageBox

1.bmp

源码

using System;

using System.Windows.Forms;

 

namespace ReflexilDemo

{

    public class DemoForm : Form

    {

        public DemoForm()

        {

            //InitializeComponent();

            this.Click+=DisplayResultButton_Click;

        }

 

        private void ComputeAndDisplay(decimal x, decimal y)

        {

            MessageBox.Show(String.Format("{0}+{1}={2}", x, y, x + y));

        }

 

        private void DisplayResultButton_Click(object sender, EventArgs e)

        {

            decimal a=3.0M;

            decimal b=6.0M;

            ComputeAndDisplay(a, b);

        }

       

        static void Main()

   

        {

            DemoForm df=new DemoForm();

            df.ShowDialog();

           

            Console.Read ();

        }

    }

}

 

2.         注入代码后,双击窗体,弹出有标题的messageBox

2.bmp

 

 

实现

使用.NET ReflectorReflexil ,修改il代码实现。

由源码可知,messagebox的调用是在ComputeAndDisplay方法中完成的,所以我们需要修改此方法的il

实现步骤:

Reflexil打开 ComputeAndDisplay

 

 

1.jpg

 

 

插入字符串

2.jpg

修改MessageBoxShowstring----àMessageBox.Show(string,string)

3.jpg

4.jpg

5.jpg

 

 

 

选择Show(string,string),双击

6.jpg

 

 

然后保存修改后的结果

7.jpg

再次运行

8.jpg

posted @ 2009-10-08 20:59  b0b0  阅读(5999)  评论(5编辑  收藏  举报