.Net環境的下的程式破解(2)

看雪資料發表於2003-06-16

>>>MSIL: 從Hello World開始

.Net下的組合語言(MSIL)看起來要友好的多,學程式設計都從Hello World開始,這裡我們
同樣也從一個小小的Hello World開始來逐步瞭解MSIL,呵呵

所需要的工具僅僅記事本就可以了,開啟Notepad,輸入程式碼:
// file:Hello.il       “//“都是註釋,可省去
// Author:WinHack[CCG]

//定義Assembly(EXE,DLL)
.assembly helloworld      //要產生的Assembly(EXE,DLL)名稱
{
.ver 1:0:0:0    //版本
}

//用.method定義方法(函式)
.method public static void main() il managed  
{
.entrypoint     //這裡定義整個程式的入口點!
.maxstack 1     //函式所保留的棧槽數量

//匯入字串
ldstr "Hello World!!!\n"

//在控制檯(Console)顯示
call void [mscorlib]System.Console::WriteLine(class System.String)

ret //返回
}

將上面的檔案儲存成hello.il檔案,開啟console介面,用ilasm編譯成exe。
D:\>ilasm hello.il
Microsoft (R) .NET Framework IL Assembler.  Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
Assembling 'hello.il' , no listing file, to EXE --> 'hello.EXE'
Source file is ANSI

Assembled global method main
Creating PE file

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

現在就可以執行程式了!
D:\>hello
Hello World!!!

這就是一個簡單得不能在簡單的hello world程式了,但是透過這個程式,我想大家
對MSIL已經有一個大體上的印象了吧,當然.net framework是一個極其龐大的系統,
MSIL裡面包含了很多複雜的元素,後面我會盡力逐個介紹,不過好幾天沒有幹活了,
導師催得緊,過幾天再寫吧。有興趣的發信交流,呵呵^_^


                                                   WinHack    QQ:85436
                                                   屬於[CCG],[OCN],[YCG],[FCG]
                                                   2003-03-14於看雪論壇

相關文章