编辑IL文件 修改DLL文件的方法

2019-12-30 16:44:45于丽

如:KS.Gantt.DLL 为例

1、使用ILSpy反编译 工具

2、利用ildasm反编译 KS.Gantt.dll  生成IL中间代码 一般会生成 *.il 和*.res 一些其它资源文件 *.resources

3、然后用记事本修改IL文件

4、然后用ilasm编译中间代码,生成新的KS.Gantt.dll

5、在项目中使用 查看效果

破解过程

1 我找到了Gantt 控件的验证的代码

dll编辑修改

2 利用ildasm反编译 KS.Gantt.dll

dll编辑修改

3 打开IL文件找到对应的代码然后删除掉 如果不会 去学习一哈 怎么使用IL

哈哈 就这个。。


.try
  {
   IL_0260: ldarg.0
   IL_0261: ldtoken  KS.Gantt.Gantt
   IL_0266: call    class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
   IL_026b: ldarg.0
   IL_026c: call    class [System]System.ComponentModel.License [System]System.ComponentModel.LicenseManager::Validate(class [mscorlib]System.Type,
                                                               object)
   IL_0271: stfld   class [System]System.ComponentModel.License KS.Gantt.Gantt::license
   IL_0276: leave.s  IL_0297

  } // end .try
  catch [mscorlib]System.Exception 
  {
   IL_0278: pop
   IL_0279: call    bool [mscorlib]System.Diagnostics.Debugger::get_IsAttached()
   IL_027e: brtrue.s  IL_0295

   IL_0280: newobj   instance void KS.Gantt.frmAbout::.ctor()
   IL_0285: stloc.0
   IL_0286: ldloc.0
   IL_0287: callvirt  instance valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.Form::ShowDialog()
   IL_028c: pop
   IL_028d: ldloc.0
   IL_028e: callvirt  instance void [System]System.ComponentModel.Component::Dispose()
   IL_0293: ldnull
   IL_0294: stloc.0
   IL_0295: leave.s  IL_0297

  } 

4 然后用ilasm编译中间代码


ilasm /dll /output=D:MyDllKS.Gantt.dll /Resource=D:MyDllGantt.res D:MyDllGantt.il


dll编辑修改

我一看到这几个单词。我就知道成功了。。

5 然后在去验证一哈DLL文件

dll编辑修改

那个授权验证代码不在了哈。。

不过呢。后来我测试 。我发现在这个DLL不能用的。运行会报这个错的


Unhandled Exception: System.IO.FileLoadException: Strong name validation failed 

所以又得删除那个签名,删除以下所有内容