您的位置:首页 > 编程语言 > C#

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

2009-10-08 20:59 716 查看

需求

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



源码

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



实现

使用.NET Reflector与Reflexil ,修改il代码实现。

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

实现步骤:

l 用Reflexil打开 ComputeAndDisplay





l 插入字符串





l 修改MessageBox。Show(string)----àMessageBox.Show(string,string)













l 选择Show(string,string),双击





l 然后保存修改后的结果



l 再次运行

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: