天天看點

IL檔案修改提高篇 IL檔案修改提高篇

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   // ;[email protected] .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代碼,基本上就可以做你想做的任何修改了。

相關源代碼:

http://files.cnblogs.com/midea0978/dotnet-IL-guide.rar