今天用了il

 

      首先声明本文章仅是技术上的研究。

目前再用的TreeView控件有一点不足,上网找了一下,发现RadTreeView控件可以弥补,但下载下来发现需要License,提示如下:You have not provided a valid license key or company, or you are trying to access the control by domain name, IP, or server name. Please, use http://localhost instead or obtain a 30-day trial key

于是又上网搜它的破解版,但是找到的似乎都不能用。后来搜到一篇利用ilasmildasm来破解的方法,链接如下(抱歉没找到原文的地址):

http://www.cn-doc.com/_soft_asp_tech_doc/2005_08_18_00/20050818005221440.htm

但是这一篇破解的是比较早的RadTreeView了,我下载的版本已经有所变化,但这篇文章确实给破解RadTreeView控件提供了思路:

1.       利用Reflector查看源代码,找出验证License的地方

2.       利用ildasm反编译RadTreeView.dll,生成中间代码文件

3.       修改中间代码中验证License的地方,使的它跳过验证

4.       利用ilasm编译中间代码,生成新的RadTreeView.dll

 

下面是我利用Reflector+ilasm+ildasm破解RadTreeView 6.0.3的过程。

 

1.首先利用Reflector打开RadTreeView.dll,直奔TreeView控件的Render方法,最终找到验证License的代码如下:

protected bool CheckLicenseKeys(out string errorMessage)
{
    errorMessage 
= new Licensing(this).CheckLicenseKeys();
    
return (string.Empty == errorMessage);
}

 

2.打开“Visual Studio .NET 2003 命令提示”(我用的是.net 1.1,转到RadTreeView.dll所在的文件夹,输入如下命令:ildasm RadTreeView.dl,这样就打开了一个图形界面:

 

 

选择文件/转储,将它导出到文件中

 

点击保存后,可以看到在保存的文件夹内,多了许多文件:

 

其中RadTreeView.il是中间代码文件,也就是我们要要修改的文件。用记事本打开RadTreeView.il文件,搜索我们上面找到的那个方法名CheckLicenseKeys,搜索到的代码如下:

 

    .method family hidebysig instance bool 
            CheckLicenseKeys([out] 
string& errorMessage) cil managed
    {
      
// 代码大小       28 (0x1c)
      .maxstack  2
      
.locals init (class Telerik.RadTreeviewUtils.Licensing V_0)
      
IL_0000:  ldarg.0
      
IL_0001:  newobj     instance void Telerik.RadTreeviewUtils.Licensing::.ctor(class Telerik.RadTreeviewUtils.RadControl)
      
IL_0006:  stloc.0
      
IL_0007:  ldarg.1
      
IL_0008:  ldloc.0
      
IL_0009:  callvirt   instance string Telerik.RadTreeviewUtils.Licensing::CheckLicenseKeys()
      
IL_000e:  stind.ref
      
IL_000f:  ldsfld     string [mscorlib]System.String::Empty
      
IL_0014:  ldarg.1
      
IL_0015:  ldind.ref
      
IL_0016:  call       bool [mscorlib]System.String::op_Equality(string,
                                                                     
string)
      
IL_001b:  ret
    } 
// end of method RadControl::CheckLicenseKeys

 

 

由于没研究过中间代码,所以这么简单的一段也看的不是很懂,后来找到一篇文章“专题:解密微软中间语言MSIL”,看完后依然不知道这段代码该怎么改。无奈之下,自己建了一个ClassLibrary项目,写了一个方法:

 

protected bool CheckLicenseKeys(out string errorMessage)
{
    errorMessage 
= "";
    
return true;
}

 

然后编译成dll,用ildasm反编译成中间代码,找到相应的代码段如下:

 

.method family hidebysig instance bool 
            CheckLicenseKeys([out] 
string& errorMessage) cil managed
    {
      
// 代码大小       13 (0xd)
      .maxstack  2
      
.locals init ([0bool CS$00000003$00000000)
      
IL_0000:  ldarg.1
      
IL_0001:  ldstr      ""
      
IL_0006:  stind.ref
      
IL_0007:  ldc.i4.1
      
IL_0008:  stloc.0
      
IL_0009:  br.s       IL_000b

      
IL_000b:  ldloc.0
      
IL_000c:  ret
// end of method Class1::CheckLicenseKeys

 

这样,我只需要把上面这个方法体去替换RadTreeView.il的方法体就行了。

修改完CheckLicenseKeys方法后,还需要把强名称验证给去掉,找到如下代码并删除:

 

  .publickey = (00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00   // .$..
                00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00   // .$..RSA1..
                CD 62 12 05 0E 7C CD 6F 51 AF 2C 41 FD CC 65 44   // .b|.oQ.,A..eD
                AC E3 CF 79 6A 19 49 C5 80 C3 FF 52 7C AC 91 1D   // yj.I.R|
                9B E0 5F AD 28 47 CE F4 E7 E5 EC 87 9F C9 4B E4   // .._.(G..K.
                9E 31 C7 97 C2 B8 39 25 C4 ED F6 AA 83 FA 78 A3   // .1.9%x.
                5A 47 C0 F4 7B 44 A8 F9 3F D1 44 A9 B7 96 BF 74   // ZG..{D..?.D.t
                9E 8D FC B3 99 82 11 52 A9 5C 7A 37 EB A3 82 B6   // .R.\z7.
                9D A5 8B 7A 1C 87 DA 5C ED 0B 7A 72 BA B1 3F 12   // z\..zr..?.
                52 C6 2F 50 DD 35 44 06 E6 F3 B0 4B AF F4 19 BD ) // R./P.5D.K.

 

3.接下来就是利用ilasm去编译修改后的中间代码了,在“Visual Studio .NET 2003 命令提示”里输入

 

ilasm /dll /output=RadTreeView.dll /Resource=RadTreeView.res RadTreeView.il

 

在一大串的提示的最下方,如果看到Operation completed successfully的提示,应该就是编译成功了。

编译完之后,在目录下面生成了一个新的RadTreeView.dll文件,用Reflector打开它验证一下,发现CheckLicenseKeys方法已经变成了我们想要的:

 

protected bool CheckLicenseKeys(out string errorMessage)
{
    errorMessage 
= "";
    
return true;
}
posted on 2008-08-20 16:36  向心力  阅读(2932)  评论(9编辑  收藏  举报