.NET中ildasm和ilasm命令的使用

ildasm和ilasm命令的使用

http://blog.163.com/zhchf_52@yeah/blog/static/6782297420111022633807/

2.创建一个新的随机密钥对:
sn -k Interop.Scripting.snk
3.反编译目标程序集
ildasm Interop.Scripting.dll /out=Interop.Scripting.il
3.重新编译,附带强命名参数
ilasm Interop.Scripting.il /dll /resource=Interop.Scripting.res /key=Interop.Scripting.snk /optimize
4.验证签名信息

sn -v Interop.Scripting.dll

使用ildasm命令将程序集转换为il
ildasm [DLLPATH] /output=[OUTPUTPATH]

在Reflector中把需要修改的方法拷贝到使用VS新建的一个项目的类中,通过添加引用,使这个方法能正常编译成功,然后就可以根据需要修改代码,然后编译该新建的项目,也使用ildasm命令将其发编译,然后在记事本中打开该发编译il文件,查找到该方法,然后拷贝该方法替换源程序集反编译il文件,最后使用ilasm命令将il文件编译为dll,使用reflector打开新编译的dll,看看修改结果。

举例:
原始dll App_Code.dll中GBO类中方法AddTopNewsToAllData有逻辑错误,需要修改
[操作之前先备份一下该程序集]
使用ildasm命令反编译ildasm d:\\App_Code.dll /output=d:\\App_Code\\App_Code.il
然后在App_Code目录下会产生

App_Code.ilApp_Code.res这两个文件


昨天画了半个多小时把 SQLDBCompare 这个.NET 程序给破解了一下,本来只有15天的试用期,破解以后就没有这个问题了,hoho。 

现在我写一个简单的实例程序来提一下使用.NET SDK 中的几个有用的工具来修改别人的代码逻辑。比如拿掉注册信息,等等。当然这里只是一个学习用途。 emsmiled.gif 

比如我有个程序,用户输入一个 ID,如果大于100 则改用户是合法的用户,否则就是非法的。程序比较简单,主要是 Demo 
我希望修改一下输入任何 ID,都是合法用户。 

为了方面,我们直接用记事本写一个简单的程序。 

None.gif using System; 
None.gif 
None.gif public  class DemoCrack 
ExpandedBlockStart.gif
InBlock.gif    public static void  Main() 
ExpandedSubBlockStart.gif    { 
InBlock.gif        System.Console.WriteLine("Enter your ID"); 
InBlock.gif        string s=Console.ReadLine(); 
InBlock.gif        int j=System.Int32.Parse(s); 
InBlock.gif        if(IsValid(j)==true
ExpandedSubBlockStart.gif            { 
InBlock.gif                Console.WriteLine("You are valid User"); 
ExpandedSubBlockEnd.gif            } 
InBlock.gif        else 
ExpandedSubBlockStart.gif            { 
InBlock.gif                Console.WriteLine("Invalid user"); 
ExpandedSubBlockEnd.gif            } 
ExpandedSubBlockEnd.gif    } 
InBlock.gif 
InBlock.gif    public static  bool IsValid(int i) 
ExpandedSubBlockStart.gif    { 
InBlock.gif        if(i>100) 
ExpandedSubBlockStart.gif            { 
InBlock.gif                return true
ExpandedSubBlockEnd.gif            } 
InBlock.gif        else 
ExpandedSubBlockStart.gif            { 
InBlock.gif                return false
ExpandedSubBlockEnd.gif            } 
ExpandedSubBlockEnd.gif    } 
ExpandedBlockEnd.gif}

文件另存为 DemoCrack.cs 

然后编译这个应用程序,为了让大家容易读懂 中间代码,我加入调试信息。 
运行 
csc DemoCrack.cs /debug+ 

DemoCrack.exe 就编译好了。 而这个 Exe 一般就是我们通常拿到别人写的组件或者应用 
运行这个exe 

DemoCrack.exe 

Enter your ID 
12 
Invalid user 

Enter your ID 
120 
You are valid User 


假设我们现在只有 DemoCrack.exe 这个文件,我希望用户输入任何ID 都是合法的用户,接下来就是我们使用三个工具的时候了:) 

你可以使用reflector 看一下这个源代码,一看就知道如何去修改代码逻辑,希望把 IsInvalid 这个函数永远返回true 就可以了。 


我们首先拿到中间代码:为了让大家读懂il,我把源代码作为注释放在il 种了 

运行 

ildasm /source DemoCrack.exe /out:crack.il 

crack.il 就是我们的中间代码了,hoho。 接下来我们对他做稍微的修改 

文件中 关于IsInvalid 的大概逻辑是: 

None.gif  .method  public hidebysig  static  bool  IsValid(int32 i) cil managed 
ExpandedBlockStart.gif   { 
InBlock.gif    // Code size       15 (0xf) 
InBlock.gif
    .maxstack  2 
InBlock.gif    .locals init ([0] bool CS$00000003$00000000) 
InBlock.gif//000019:  
InBlock.gif
//000020:     public static  bool IsValid(int i) 
InBlock.gif
//000021:     { 
InBlock.gif
//000022:         if(i>100) 
InBlock.gif
    IL_0000:  ldarg.0 
InBlock.gif    IL_0001:  ldc.i4.s   100 
InBlock.gif    IL_0003:  ble.s      IL_0009 
InBlock.gif 
InBlock.gif//000023:             { 
InBlock.gif
//000024:                 return true; 
InBlock.gif
    IL_0005:  ldc.i4.1 
InBlock.gif    IL_0006:  stloc.0 
InBlock.gif    IL_0007:  br.s       IL_000d 
InBlock.gif 
InBlock.gif//000025:             } 
InBlock.gif
//000026:         else 
InBlock.gif
//000027:             { 
InBlock.gif
//000028:                 return false; 
InBlock.gif
    IL_0009:  ldc.i4.0 
InBlock.gif    IL_000a:  stloc.0 
InBlock.gif    IL_000b:  br.s       IL_000d 
InBlock.gif 
InBlock.gif//000029:             } 
InBlock.gif
//000030:     } 
InBlock.gif
    IL_000d:  ldloc.0 
InBlock.gif    IL_000e:  ret 
ExpandedBlockEnd.gif  }  //  end of method DemoCrack::IsValid


这几个指令足够简单了吧,我把他替换为 
None.gif  .method  public hidebysig  static  bool  IsValid(int32 i) cil managed 
ExpandedBlockStart.gif   { 
InBlock.gif    // Code size       15 (0xf) 
InBlock.gif
    .maxstack  2 
InBlock.gif    .locals init ([0] bool CS$00000003$00000000) 
InBlock.gif//000019:  
InBlock.gif
//000020:     public static  bool IsValid(int i) 
InBlock.gif
//000021:     { 
InBlock.gif
//                return true; 
InBlock.gif
    IL_0000:  ldc.i4.1 
InBlock.gif    IL_0001:  stloc.0 
InBlock.gif  
InBlock.gif 
InBlock.gif    IL_0002:  ldloc.0 
InBlock.gif    IL_0003:  ret 
ExpandedBlockEnd.gif  }  //  end of method DemoCrack::IsValid

然后保存一下这个文件。 

接下来就是编译成exe 
运行 

Ilasm crack.il 为了演示,我就不修改其图标等其他设资了。 

然后确认一下我们改的 il 没有问题 
调用 

PEVerify Crack.exe 

一切OK 的话,就大功告成了。 

接下来运行 Crack.exe 
Enter your ID 
12 
You are valid User 

PS. 简单的一个 Demo,不用用于非法用途。 

接下来你可以考虑一下,如何不让别人来Crack 自己的应用程序,如果是你,你会增么做。 
不要仅仅是代码搅乱之类的,hoho 





分类:  .NET 企业应用

转载于:https://my.oschina.net/u/233641/blog/71021

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值