簡單操作IL文件


IL文件修改入門篇

================================== 
Object: 
   掌握簡單的IL文件處理知識 
   能夠熟練運用ildasm,ilasm工具 
================================== 
1.編寫簡單的hello.cs

2.編譯源代碼
csc hello.cs

3.反編譯hello.exe,命令如下: 
ildasm hello.exe /out=hello.il

4.打開hello.il文件,找到下面語句 
IL_0000:  ldstr      "Hello World!" 
修改為 
IL_0000:  ldstr      "Hello World! A Cracked Version." 
保存文件。

5.編譯il文件 
ilasm /res:hello.res hello.il /out:hellocracked.exe 
--------------------------------------------------------

Microsoft (R) .NET Framework IL Assembler.  Version 1.1.4322.573 
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. 
Assembling 'hello.il' , no listing file, to EXE --> 'hellocracked.exe' 
Source file is ANSI

Assembled method HelloWorld::Main 
Assembled method HelloWorld::.ctor 
Creating PE file

Emitting members: 
Global 
Class 1 Methods: 2; 
Writing PE file 
Operation completed successfully

----------------------------------------------------------- 
成功編譯。

5.運行hellocracked.exe,結果如下: 
Hello World! A Cracked Version.


OK。

 

IL文件修改提高篇 
================================== 
Object: 
   熟悉強名字簽名之后的代碼處理 
================================== 
1.修改hello.cs文件,加入強名字屬性代碼 
[assembly:AssemblyKeyFileAttribute("key.snk")] 
[assembly:AssemblyDelaySignAttribute(false)]

2.生成強名字對,這就是一個典型的RSA應用 
sn -k key.snk

3.編譯hello.cs文件 
csc hello.cs

4.反編譯hello.exe,命令如下: 
ildasm hello.exe /out=hello.il

5.打開hello.il文件,找到下面語句 
IL_0000:  ldstr      "Hello World!" 
修改為 
IL_0000:  ldstr      "Hello World! A Cracked Version." 
保存文件。

5.編譯il文件 
ilasm /res:hello.res hello.il /out:hellocracked.exe 
--------------------------------------------------------

Microsoft (R) .NET Framework IL Assembler.  Version 1.1.4322.573 
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. 
Assembling 'hello.il' , no listing file, to EXE --> 'hellocracked.exe' 
Source file is ANSI

Assembled method HelloWorld::Main 
Assembled method HelloWorld::.ctor 
Creating PE file

Emitting members: 
Global 
Class 1 Methods: 2; 
Writing PE file 
Operation completed successfully

----------------------------------------------------------- 
成功編譯。

5.運行hellocracked.exe,結果如下:

Unhandled Exception: System.IO.FileLoadException: Strong name validation failed 
for assembly 'hellocracked.exe'. 
File name: "hellocracked.exe"

出現錯誤,原因是因為簽名的代碼被修改了,這是在破解時通常會遇到的,下面來介紹如何糾正該錯誤。

[方法A] 
6.1.1、重新生成exe文件 
ilasm /res:hello.res hello.il /out:hellocracked_resign.exe

6.1.2、因為我們有RSA keypair,所以可以重新簽名程序,但是在破解時,是不知道簽名的RSA keypair的,而且根據RSA算法,破解的可能性幾乎不可能的。 
sn -R hellocracked_resign.exe key.snk 
----------------------------------------------------------- 
Microsoft (R) .NET Framework 強名稱實用工具版本 1.1.4322.573 
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

成功地對程序集“hellocracked_resign.exe”進行了重新簽名 
----------------------------------------------------------- 
6.1.3、重新運行hellocracked_resign.exe,OK 
Hello World! A Cracked Version.

[方法B] 
6.2.1、刪除IL文件中的如下內容,保存文件 
.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........ 
                3B B2 D0 F9 DA 7E 55 B2 50 40 6B CF EB 20 F6 67   // ;....~U.P@k.. .g 
                E7 D6 AF 65 32 4F 6D 21 5D 91 53 0B 04 C7 E2 15   // ...e2Om!].S..... 
                F0 6A EE 38 F8 74 DB 22 34 F9 A1 B5 16 C1 04 66   // .j.8.t."4......f 
                B7 0B A8 36 49 9E 8A 71 E1 D1 26 AB A2 78 4E 3A   // ...6I..q..&..xN: 
                8B 71 8C 7F 4D 54 22 28 5F 1F 8D DE 6C 96 EC 22   // .q..MT"(_...l.." 
                34 8A 35 3F 95 0A F4 F4 7F B7 8C F5 5D F4 CB 54   // 4.5?........]..T 
                92 94 DD 5E D5 0D 20 12 7F B1 9B 15 7F 0E FB 2A   // ...^.. ........* 
                76 5F 45 3D 20 2C E2 6D FE 55 72 30 49 76 28 FE ) // v_E= ,.m.Ur0Iv(.

6.2.2 重新生成exe文件 
ilasm /res:hello.res hello.il /out:hellocracked_nosign.exe

6.2.3 重新運行hellocracked_nosign.exe,OK 
Hello World! A Cracked Version. 
因為刪除了簽名信息,所以代碼仍然可以正常執行,就這是破解時通常所用的方法。

如果你能夠看懂IL代碼,基本上就可以做你想做的任何修改了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM