欢迎来到 嗅灵易学

零基础也能上手的脚本技术课,一对一答疑带你入门

续! (11千字)

续! (11千字)

第二部分,diy msil
我们现在要找到那个注册按钮事件,这样我们才能加入自己的处理,来看看在哪里:就在frmRegistry::BtnRegistry_Click,
.method private instance void  BtnRegistry_Click(object sender,
                                                class [mscorlib]System.EventArgs e) cil managed
{
  // Code size      247 (0xf7)
  .maxstack  4
  IL_0000:  nop
  IL_0001:  ldarg.0
  IL_0002:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtSN()
  IL_0007:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()//得到你输入的注册码
  IL_000c:  ldstr      ""
  IL_0011:  ldc.i4.0
  IL_0012:  call      int32 [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.StringType::StrCmp(string,
                                                                                                              string,
                                                                                                              bool)
  IL_0017:  ldc.i4.0
  IL_0018:  bne.un.s  IL_0033  //比较是不是空,不是就跳,是就输出错误信息
  IL_001a:  ldstr      bytearray (A8 60 D8 8F A1 6C 09 67 93 8F 65 51 E8 6C 8C 51  // .`...l.g..eQ.l.Q
                                  01 78 62 54 21 00 )                              // .xbT!.
  IL_001f:  ldstr      bytearray (19 95 EF 8B )
  IL_0024:  ldc.i4.0
  IL_0025:  ldc.i4.s  16
  IL_0027:  call      valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,
                                                                                                                                                    string,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxButtons,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxIcon)
  IL_002c:  pop
  IL_002d:  nop
  IL_002e:  br        IL_00f5
  IL_0033:  nop
  IL_0034:  ldarg.0
  IL_0035:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtUserName()
  IL_003a:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text() //得到用户名
  IL_003f:  ldstr      ""
  IL_0044:  ldc.i4.0
  IL_0045:  call      int32 [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.StringType::StrCmp(string,
                                                                                                              string,
                                                                                                              bool)
  IL_004a:  ldc.i4.0
  IL_004b:  bne.un.s  IL_0066  //比较是不是空,不是就跳,是就输出错误信息
  IL_004d:  ldstr      bytearray (F7 8B 28 75 57 5B CD 6B FB 6D 99 51 A8 60 84 76  // ..(uW[.k.m.Q.`.v
                                  28 75 37 62 0D 54 21 00 )                        // (u7b.T!.
  IL_0052:  ldstr      bytearray (19 95 EF 8B )
  IL_0057:  ldc.i4.0
  IL_0058:  ldc.i4.s  16
  IL_005a:  call      valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,
                                                                                                                                                    string,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxButtons,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxIcon)
  IL_005f:  pop
  IL_0060:  nop
  IL_0061:  br        IL_00f5
  IL_0066:  nop
  IL_0067:  ldarg.0
  IL_0068:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtSN()
  IL_006d:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()
  IL_0072:  ldarg.0
  IL_0073:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtUserName()
  IL_0078:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()
  IL_007d:  call      string WinXP_Manager.MyClsOther/MyClsRegister::FromHDSNGetRegisterCode(string)  //这里会得到这确的注册码然后与我们输入的作比较
  IL_0082:  ldc.i4.0
  IL_0083:  call      int32 [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.StringType::StrCmp(string,
                                                                                                              string,
                                                                                                              bool)
  IL_0088:  ldc.i4.0
  IL_0089:  bne.un.s  IL_00c3  //不等就跳去显示出错框
  IL_008b:  ldarg.0
  IL_008c:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtSN()
  IL_0091:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()
  IL_0096:  ldarg.0
  IL_0097:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtUserName()
  IL_009c:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()
  IL_00a1:  call      void WinXP_Manager.MyClsOther/MyClsRegister::WriteRegisterCode(string,
                                                                                      string)
  IL_00a6:  nop
  IL_00a7:  ldstr      bytearray (A8 60 F2 5D CF 7E 10 62 9F 52 E8 6C 8C 51 21 00  // .`.].~.b.R.l.Q!.
                                  F7 8B CD 91 B0 65 2F 54 A8 52 2C 67 6F 8F F6 4E  // .....e/T.R,go..N
                                  2E 00 )                                          // ..
  IL_00ac:  ldstr      bytearray (E8 6C 8C 51 8C 5B 10 62 )                        // .l.Q.[.b
  IL_00b1:  ldc.i4.0
  IL_00b2:  ldc.i4.s  64
  IL_00b4:  call      valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,
                                                                                                                                                    string,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxButtons,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxIcon)
  IL_00b9:  pop
  IL_00ba:  ldarg.0
  IL_00bb:  callvirt  instance void [System.Windows.Forms]System.Windows.Forms.Form::Close()
  IL_00c0:  nop
  IL_00c1:  br.s      IL_00f4
  IL_00c3:  nop        //这里开始是来显示出错信息
  IL_00c4:  ldstr      bytearray (A8 60 93 8F 65 51 84 76 E8 6C 8C 51 01 78 0D 4E  // .`..eQ.v.l.Q.x.N
                                  63 6B 6E 78 21 00 )                              // cknx!.  //这个是框里显示的字符串,我们就把它改成显示正确注册码
  IL_00c9:  ldstr      bytearray (19 95 EF 8B )
  IL_00ce:  ldc.i4.0
  IL_00cf:  ldc.i4.s  16
  IL_00d1:  call      valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,
                                                                                                                                                    string,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxButtons,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxIcon)
  IL_00d6:  pop
  IL_00d7:  ldarg.0
  IL_00d8:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtSN()
  IL_00dd:  ldstr      ""
  IL_00e2:  callvirt  instance void [System.Windows.Forms]System.Windows.Forms.TextBox::set_Text(string)
  IL_00e7:  nop
  IL_00e8:  ldarg.0
  IL_00e9:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtSN()
  IL_00ee:  callvirt  instance bool [System.Windows.Forms]System.Windows.Forms.Control::Focus()
  IL_00f3:  pop
  IL_00f4:  nop
  IL_00f5:  nop
  IL_00f6:  ret
} // end of method frmRegistry::BtnRegistry_Click
来看看我改的:(改法很多,主要就是注意尽量不要破坏源程序的东西,而且msil增加字节我还不会,所以只有修改掉队我们的目的无用的东西)
  IL_0089:  bne.un.s  IL_00b8  //这个跳传要注意修正,要不肯定出错
  IL_008b:  ldarg.0
  IL_008c:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtSN()
  IL_0091:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()
  IL_0096:  ldarg.0
  IL_0097:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtUserName()
  IL_009c:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()
  IL_00a1:  call      void WinXP_Manager.MyClsOther/MyClsRegister::WriteRegisterCode(string,
                                                                                      string)
  IL_00a6:  nop        为了避免jit的错误翻译,把会引起混乱的东西全都nop
  IL_00a7:  nop
  IL_00a8:  nop
  IL_00a9:  nop
  IL_00aa:  nop
  IL_00ab:  nop
  IL_00ac:  nop
  IL_00ad:  nop
  IL_00ae:  nop
  IL_00af:  nop
  IL_00b0:  nop
  IL_00b1:  nop
  IL_00b2:  nop
  IL_00b3:  nop
  IL_00b4:  nop
  IL_00b5:  nop
  IL_00b6:  nop
  IL_00b7:  nop
  IL_00b8:  nop        //从这里开始
  IL_00b9:  ldarg.0    //这个都有,具体原因还不大清楚,照猫画虎把!
  IL_00ba:  callvirt  instance class [System.Windows.Forms]System.Windows.Forms.TextBox WinXP_Manager.frmRegistry::get_txtUserName()
  IL_00bf:  callvirt  instance string [System.Windows.Forms]System.Windows.Forms.TextBox::get_Text()
  IL_00c4:  call      string WinXP_Manager.MyClsOther/MyClsRegister::FromHDSNGetRegisterCode(string)//用这3个call就得到了要显示的正确注册码
  IL_00c9:  ldstr      bytearray (19 95 EF 8B )
  IL_00ce:  ldc.i4.0
  IL_00cf:  ldc.i4.s  16
  IL_00d1:  call      valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string,
                                                                                                                                                    string,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxButtons,
                                                                                                                                                    valuetype [System.Windows.Forms]System.Windows.Forms.MessageBoxIcon)
  IL_00d6:  pop
其他不变,用16进制编辑器改,对应的机器码一样照搬,跳传命令的第二个字节是从跳传语句开始到目的的偏移,至于call不象传统的汇编使用偏移量,而是都固定的,原因应该是msil在pe头部有完整的表来描述所有方法把。
终于完成,休息一下:)

注意:上传附件及图片大小不得大于30M。

⚠️ 版权声明:
本博客所有内容(含教程、源码、工具)仅供个人技术学习与研究交流使用,严禁商用、倒卖、二次分发及非法用途
未经作者书面授权,任何组织或个人不得转载、复制或用于其他平台,违者将追究相关责任。

0 0 0 举报
复制成功