工具:ildasm,ilasm,vs2005
做为Helloworld,为方面大家理解il语言与c#(为例)之间的对应关系,我们破解自己写的Hello world
S1: 使用vs2005建一个控件库UserControl1,里面有一个显示版权信息的函数:
/**/
/// <summary>
/// 如果没有通过版本校验,提示用户需要注册
/// </summary>
/// <param name="regest">是否通过版权校验</param>
private void PaintInfo( bool regest)
... {
this.label1.Text = "";
if (!regest)
...{
this.label1.Text = "需要注册";
}
}
/// 如果没有通过版本校验,提示用户需要注册
/// </summary>
/// <param name="regest">是否通过版权校验</param>
private void PaintInfo( bool regest)
... {
this.label1.Text = "";
if (!regest)
...{
this.label1.Text = "需要注册";
}
}
S2: 编译生成DLL
S3:使用ildasm将dll打开,后转存为一个il文件。用记事本打开,在里面会找到
.method
private
hidebysig instance
void
PaintInfo() cil managed
... {
// 代码大小 48 (0x30)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld class [System.Windows.Forms]System.Windows.Forms.Label Demo.UserControl1::label1
IL_0007: ldstr ""
IL_000c: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_0011: nop
IL_0012: ldarg.0
IL_0013: ldfld bool Demo.UserControl1::regest
IL_0018: stloc.0
IL_0019: ldloc.0
IL_001a: brtrue.s IL_002f // 关键的来了
IL_001c: nop
IL_001d: ldarg.0
IL_001e: ldfld class [System.Windows.Forms]System.Windows.Forms.Label Demo.UserControl1::label1
IL_0023: ldstr bytearray (00 97 81 89 E8 6C 8C 51 ) // .....l.Q
IL_0028: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_002d: nop
IL_002e: nop
IL_002f: ret
} // end of method UserControl1::PaintInfo
PaintInfo() cil managed
... {
// 代码大小 48 (0x30)
.maxstack 2
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld class [System.Windows.Forms]System.Windows.Forms.Label Demo.UserControl1::label1
IL_0007: ldstr ""
IL_000c: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_0011: nop
IL_0012: ldarg.0
IL_0013: ldfld bool Demo.UserControl1::regest
IL_0018: stloc.0
IL_0019: ldloc.0
IL_001a: brtrue.s IL_002f // 关键的来了
IL_001c: nop
IL_001d: ldarg.0
IL_001e: ldfld class [System.Windows.Forms]System.Windows.Forms.Label Demo.UserControl1::label1
IL_0023: ldstr bytearray (00 97 81 89 E8 6C 8C 51 ) // .....l.Q
IL_0028: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_002d: nop
IL_002e: nop
IL_002f: ret
} // end of method UserControl1::PaintInfo
简简单单的把IL_001a: brtrue.s IL_002f 。。。改成IL_001a: brfalse.s IL_002f 。保存
s4: 使用命令ilasm xxx /dll 再次编译成Dll
OK,保证成功!
过程就这么简单!师兄们自己去体会知识点!