• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            xiaoguozi's Blog
            Pay it forword - 我并不覺的自豪,我所嘗試的事情都失敗了······習(xí)慣原本生活的人不容易改變,就算現(xiàn)狀很糟,他們也很難改變,在過程中,他們還是放棄了······他們一放棄,大家就都是輸家······讓愛傳出去,很困難,也無法預(yù)料,人們需要更細心的觀察別人,要隨時注意才能保護別人,因為他們未必知道自己要什么·····
            這兩天主要看了flex的cairngorm框架,順便寫了個用flex獲取flickr網(wǎng)站的圖片,其中不乏艱難的過程,第一個就是flickr庫api和實際編譯出來的有出入,其中Photo.as缺少farm就是一個明顯,所以只能自己手工修改源碼重新編譯,網(wǎng)上討論這個問題的比較少,不知道為什么,我找了好久才找到一篇關(guān)于這個的。還有一個問題就是大墻,其中網(wǎng)上有段這么描述:
            最 近打開Flickr發(fā)現(xiàn)有些圖片總是顯示小紅叉,開始以為是網(wǎng)速問題沒有在意,昨天有個朋友說他存在Flickr上的圖片都不能顯示了,發(fā)覺情況不對勁 了。
            今天看到了這篇帖子:
            http://www.flickr.com/help/forum/zh-hk/117995/
            原來又是偉大的墻在作怪,這次的癥狀是所有的網(wǎng)通線路都無法 訪問farm3.static.flickr.com和farm5.static.flickr.com這兩個服務(wù)器,由于這次只是讓域名無法解析,所以 最簡單的解決辦法是修改host文件,方法如下:
            用記事本打開C:\Windows\System32\drivers\etc\hosts 這個文件,然后在文件最后追加兩行:

            然 后重啟一下瀏覽器,我們親愛的Flickr又復(fù)活了  : )

            由于自己是網(wǎng)通的,圖片是farm5服務(wù)器的,所以圖片也顯示不了,不過修改下host表就OK了

            寫這個的主要目的還是學(xué)習(xí)下cairgorm框架,學(xué)習(xí)他的MVC思想,目的算基本達到,flickr的問題實在有點煩,不過還是走過來了,下面是運行效果:


            有用的幾個網(wǎng)址:
            http://code.google.com/p/as3flickrlib/issues/detail?id=14#makechanges
            http://www.flickr.com/services/api/
            http://naramiki.blogbus.com/logs/57133710.html

            最后附上flickr自己編譯的庫
            http://m.shnenglu.com/Files/guojingjia2006/flickr087.swc.rar

            posted @ 2010-07-20 22:10 小果子 閱讀(549) | 評論 (0)編輯 收藏

             

            左通過棧傳遞,被調(diào)用的函數(shù)在返回前清理傳送參數(shù)的內(nèi)存棧,但不同的 是函數(shù)名的修飾部分(關(guān)于函數(shù)名的修飾部分在后面將詳細說明)。

            _stdcall
            Pascal程序的缺省調(diào)用方式,通常用于Win32 Api中,函數(shù)采用從右到左 的壓棧方式,自己在退出時清空堆棧。VC將函數(shù)編譯后會在函數(shù)名前面加上下劃線前綴,在函數(shù)名后加上"@"和參數(shù)的字節(jié)數(shù)。


            2
            C調(diào) 用約定(即用__cdecl關(guān)鍵字說明)按從右至左的順序壓參數(shù)入棧,由調(diào)用者把參數(shù)彈出棧。對于傳送參數(shù)的內(nèi)存棧是由調(diào)用者來維護的(正因為如此,實現(xiàn)可變參數(shù)的函數(shù)只 能使用該調(diào)用約定)。另外,在函數(shù)名修飾約定方面也有所不同。


            _cdecl
            CC++程序的缺省調(diào)用方式。每一個調(diào)用它的函數(shù)都包含清空堆棧的代碼,所 以產(chǎn)生的可執(zhí)行文件大小會比調(diào)用_stdcall函數(shù)的大。函數(shù)采用從右到左的壓棧方式。VC將函數(shù)編譯后會在函數(shù)名前面加上下劃線前綴。是MFC缺省調(diào)用約定。


            3
            __fastcall調(diào)用約定是“人”如其名,它的主要特點就是快,因為它是通過寄存器來傳送參數(shù)的(實際上,它用ECXEDX傳送前兩個雙字(DWORD)或更小的參數(shù),剩下的參數(shù)仍舊自右向左壓棧傳送,被調(diào)用的函數(shù)在返 回前清理傳送參數(shù)的內(nèi)存棧),在函數(shù)名修飾約定方面,它和前兩者均不同。


            _fastcall
            方式的函數(shù)采用寄存器傳遞參數(shù),VC將函數(shù)編譯后會在函數(shù)名前面加上"@"前綴,在函數(shù)名后加上"@"和參數(shù)的字節(jié)數(shù)。


            4
            thiscall僅僅應(yīng)用于“C++”成員函數(shù)。this指針存放于CX寄存器,參數(shù)從右到左壓。thiscall不是關(guān)鍵詞,因此不能被程序員指定。


            5
            naked call采用1-4的調(diào)用約定時,如果必要的話,進入函數(shù)時編譯器會產(chǎn)生代碼來保存ESIEDIEBXEBP寄存器,退出函數(shù)時則產(chǎn)生代碼恢復(fù)這些寄存器的內(nèi)容。naked call不產(chǎn)生這樣的代碼。naked call不是類型修飾符,故 必須和_declspec共同使用。


            關(guān)鍵字 __stdcall__cdecl__fastcall可以直接加在要輸出的函數(shù)前,也可以在編譯環(huán)境的Setting...\C/C++ \Code Generation項選擇。當(dāng)加在輸出函數(shù)前的關(guān)鍵字與編譯環(huán)境中的選擇不同時,直接加在輸出函數(shù)前的關(guān)鍵字有效。它們對應(yīng)的命令行參數(shù)分別為/Gz/Gd/Gr。缺省狀態(tài)為/Gd,即__cdecl


            要完全模仿PASCAL調(diào)用約定首先必須使用__stdcall調(diào)用約定,至于函數(shù)名修飾約定,可以通過其它方法模仿。還有一個值得 一提的是WINAPI宏,Windows.h支持該宏,它可以將出函數(shù)翻譯成適當(dāng)?shù)恼{(diào)用約定,在WIN32中,它被定義為__stdcall。使用WINAPI宏可以創(chuàng)建自己的APIs


            2)
            名字修飾約定


            1
            、修飾名
            (Decoration name)

            C”或者“C++”函數(shù)在內(nèi)部(編譯和鏈接)通過修飾名識別。修飾名是編譯器在編譯函 數(shù)定義或者原型時生成的字符串。有些情況下使用函數(shù)的修飾名是必要的,如在模塊定義文件里頭指定輸出“C++”重載函數(shù)、構(gòu)造函數(shù)、析構(gòu)函數(shù),又如在匯編代碼里調(diào)用“C””或“C++”函數(shù)等。


            修飾名由函數(shù)名、類名、調(diào)用約定、返回類型、參數(shù)等共同決定。


            2
            、名字修飾約定隨調(diào)用約定和編譯種類(CC++)的不同而變化。函數(shù)名修飾約定隨編譯種類和調(diào)用約定的不同而不同,下 面分別說明。


            a
            C編譯時函數(shù)名修飾約定規(guī)則:


            __stdcall
            調(diào)用約定在輸出函數(shù)名前加上一個下劃線前綴,后面加上一個“@”符號和其參數(shù)的字節(jié)數(shù),格式為_functionname@number


            __cdecl
            調(diào)用約定僅在輸出函數(shù)名前加上一個下劃線前綴,格式為_functionname


            __fastcall
            調(diào)用約定在輸出函數(shù)名前加上一個“@”符號,后面也是一個“@”符號和其參數(shù)的字節(jié)數(shù),格式為@functionname@number


            它們均不改變輸出函數(shù)名中的字符大小寫,這和PASCAL調(diào)用約定不同,PASCAL約定輸出的函數(shù)名無任何修飾且全部大寫。


            b
            C++編 譯時函數(shù)名修飾約定規(guī)則:


            __stdcall
            調(diào)用約定:

            1
            、 以“?”標(biāo)識函數(shù) 名的開始,后跟函數(shù)名;

            2
            、函數(shù)名后面以“@@YG”標(biāo)識參數(shù)表的開始,后跟參數(shù)表;

            3
            、 參數(shù)表以代號表示:

            X--void

            D--char

            E--unsigned char

            F--short

            H--int

            I--unsigned int

            J--long

            K--unsigned long

            M--float

            N--double

            _N--bool

            ....
            PA--
            表示指 針,后面的代號表明指針類型,如果相同類型的指針連續(xù)出現(xiàn),以“0”代替,一個“0”代表一次重復(fù);

            4
            、 參數(shù)表的第一項為該函數(shù)的返回值類型,其后依次為參數(shù)的數(shù)據(jù)類型,指針標(biāo)識在其所指數(shù)據(jù)類型前;

            5
            、 參數(shù)表后以“@Z” 標(biāo)識整個名字的結(jié)束,如果該函數(shù)無參數(shù),則以“Z”標(biāo)識結(jié)束。


            其格式為“?functionname@@YG*****@Z”或“?functionname@@YG*XZ”,例如

            int Test1
            char *var1,unsigned long-----?Test1@@YGHPADK@Z

            void Test2
            () -----?Test2@@YGXXZ


            __cdecl
            調(diào)用約定:

            規(guī) 則同上面的_stdcall調(diào)用約定,只是參數(shù)表的開始標(biāo)識由上面的“@@YG”變?yōu)?#8220;@@YA”。


            __fastcall
            調(diào)用約定:

            規(guī) 則同上面的_stdcall調(diào)用約定,只是參數(shù)表的開始標(biāo)識由上面的“@@YG”變?yōu)?#8220;@@YI”。


            VC++
            對函數(shù)的省缺聲明是"__cedcl",將只能被C/C++調(diào)用
            .

            CB
            在輸出函數(shù)聲明時使用4種修飾符號

            //__cdecl
            cb
            的默認(rèn)值,它會在輸出函數(shù)名前加_,并保留此函數(shù)名不變,參數(shù)按照從右到左的順序依次傳遞給棧,也可以寫 成_cdeclcdecl形式。

            //__fastcall
            她修飾的函數(shù)的參 數(shù)將盡肯呢感地使用寄存器來處理,其函數(shù)名前加@,參數(shù)按照從左到右的順序壓棧;

            //__pascal
            它說明的函數(shù)名使 用Pascal格 式的命名約定。這時函數(shù)名全部大寫。參數(shù)按照從左到右的順序壓棧;

            //__stdcall
            使用標(biāo)準(zhǔn)約定的函 數(shù)名。函數(shù)名不會改變。使用__stdcall修飾時。參數(shù)按照由右到左的順序壓棧,也可以是_stdcall


            TITLE  : __stdcall與__cdecl的區(qū)別
            AUTHOR : lionel@nkbbs.org
            DATE   : 
            01/10/2005

            CONTENT:

                Visual C
            ++ Compiler Options可以指定的Calling Convention有 3種:
               
                
            /Gd /Gr /Gz
               
                這三個參數(shù)決定了:
               
                
            1.函數(shù)參數(shù)以何種順序入棧,右到左還是左到右。
                
            2.在函數(shù)運行完后,是調(diào)用函數(shù)還是被調(diào)用函數(shù)清理入棧的參數(shù)。
                
            3.在編譯時函數(shù)名字是如何轉(zhuǎn)換的。
               
                下面我們分別詳細介紹:
               
                
            1./Gd
                    這是編譯器默認(rèn)的轉(zhuǎn)換模式,對一般函數(shù)使用 C的函數(shù)調(diào)用轉(zhuǎn)換方式__cdecl,
                    但是對于C
            ++ 成員函數(shù)和前面修飾了__stdcall __fastcall的函數(shù)除外。
                   
                
            2./Gr
                    對于一般函數(shù)使用__fastcall函數(shù)調(diào)用轉(zhuǎn)換方式,所有使用__fastcall的函數(shù)
                    必須要有函數(shù)原形。但對于C
            ++ 成員函數(shù)和前面修飾了__cdecl __stdcall 的
                    函數(shù)除外。
                   
                
            3./Gz
                    對于所有 C函數(shù)使用__stdcall函數(shù)調(diào)用轉(zhuǎn)換方式,但對于可變參數(shù)的 C函數(shù)以
                    及用__cdecl __fastcall修飾過的函數(shù)和C
            ++ 成員函數(shù)除外。所有用__stdcall
                    修飾的函數(shù)必須有函數(shù)原形。
                   
                    事實上,對于x86系統(tǒng),C
            ++ 成員函數(shù)的調(diào)用方式有點特別,將成員函數(shù)的this
                    指針放入ECX,所有函數(shù)參數(shù)從右向左入棧,被調(diào)用的成員函數(shù)負責(zé)清理入棧的
                    參數(shù)。對于可變參數(shù)的成員函數(shù),始終使用__cdecl的轉(zhuǎn)換方式。
                   
                下面該進入主題,分別講一下這三種函數(shù)調(diào)用轉(zhuǎn)換方式有什么區(qū)別:
               
                
            1.__cdecl
                    這是編譯器默認(rèn)的函數(shù)調(diào)用轉(zhuǎn)換方式,它可以處理可變參數(shù)的函數(shù)調(diào)用。參數(shù)
                    的入棧順序是從右向左。在函數(shù)運行結(jié)束后,由調(diào)用函數(shù)負責(zé)清理入棧的參數(shù)。
                    在編譯時,在每個函數(shù)前面加上下劃線(_),沒有函數(shù)名大小寫的轉(zhuǎn)換。即
                   
                      _functionname
                   
                
            2.__fastcall
                    有一些函數(shù)調(diào)用的參數(shù)被放入ECX,EDX中,而其它參數(shù)從右向左入棧。被調(diào)用
                    函數(shù)在它將要返回時負責(zé)清理入棧的參數(shù)。在內(nèi)嵌匯編語言的時候,需要注意
                    寄存器的使用,以免與編譯器使用的產(chǎn)生沖突。函數(shù)名字的轉(zhuǎn)換是:
                   
                      @functionname@number
                   
                    沒有函數(shù)名大小寫的轉(zhuǎn)換,number表示函數(shù)參數(shù)的字節(jié)數(shù)。由于有一些參數(shù)不
                    需要入棧,所以這種轉(zhuǎn)換方式會在一定程度上提高函數(shù)調(diào)用的速度。
                   
                
            3.__stdcall
                  函數(shù)參數(shù)從右向左入棧,被調(diào)用函數(shù)負責(zé)入棧參數(shù)的清理工作。函數(shù)名轉(zhuǎn)換格
                  式如下:
               
                    _functionname@number
               
                下面我們親自寫一個程序,看看各種不同的調(diào)用在編譯后有什么區(qū)別,我們的被調(diào)
                用函數(shù)如下:
               
                
            int function(int a, int b)
                {
                    
            return a + b;
                }
               
                
            void main()
                {
                    function(
            1020);
                }
               
                
            1.__cdecl
                   
                    _function

                             push    ebp
                             mov     ebp, esp
                             mov     eax, [ebp
            +8]       ;參數(shù)1
                             add     eax, [ebp
            +C]       ;加上參數(shù)2
                             pop     ebp
                             retn

                    _main
                             push    ebp
                             mov     ebp, esp
                             push    14h                ;參數(shù) 2入棧
                             push    0Ah                ;參數(shù) 1入棧
                             call    _function          ;調(diào)用函數(shù)
                             add     esp, 
            8             ;修正棧
                             xor     eax, eax
                             pop     ebp
                             retn
                            
                
            2.__fastcall
               
                    @function@
            8
                             push    ebp
                             mov     ebp, esp           ;保存棧指針
                             sub     esp, 
            8             ;多了兩個局部變量
                             mov     [ebp
            -8], edx       ;保存參數(shù) 2
                             mov     [ebp
            -4], ecx       ;保存參數(shù) 1
                             mov     eax, [ebp
            -4]       ;參數(shù) 1
                             add     eax, [ebp
            -8]       ;加上參數(shù) 2
                             mov     esp, ebp           ;修正棧
                             pop     ebp
                             retn

                    _main
                             push    ebp
                             mov     ebp, esp
                             mov     edx, 14h           ;參數(shù) 2給EDX
                             mov     ecx, 0Ah           ;參數(shù) 1給ECX
                             call    @function@
            8        ;調(diào)用函數(shù)
                             xor     eax, eax
                             pop     ebp
                             retn
             
                
            3.__stdcall
               
                    _function@
            8

                             push    ebp
                             mov     ebp, esp
                             mov     eax, [ebp]         ;參數(shù) 
            1
                             add     eax, [ebp
            +C]       ;加上參數(shù) 2
                             pop     ebp
                             retn    
            8                  ;修復(fù)棧

                    _main
                             push    ebp
                             mov     ebp, esp
                             push    14h                ;參數(shù) 2入棧
                             push    0Ah                ;參數(shù) 1入棧 
                             call    _function@
            8    ;函數(shù)調(diào)用
                             xor     eax, eax
                             pop     ebp
                             retn

                可見上述三種方法各有各的特點,而且_main必須是__cdecl,一般WIN32的函數(shù)都是
                __stdcall。而且在Windef.h中有如下的定義:
               
                
            #define CALLBACK __stdcall
                
            #define WINAPI  __stdcall

            posted @ 2010-07-01 09:27 小果子 閱讀(272) | 評論 (0)編輯 收藏
            當(dāng)調(diào)用(call)一個函數(shù)時,主調(diào)函數(shù)將聲明中的參數(shù)表以逆序壓棧,然后將當(dāng)前的代碼執(zhí)行指針(eip)壓棧,跳轉(zhuǎn)到被調(diào)函數(shù)的入口點。
                    進入被調(diào)函數(shù)時,函數(shù)將esp減去相應(yīng)字節(jié)數(shù)獲取局部變量存儲空間。被調(diào)函數(shù)返回(ret)時,將esp加上相應(yīng)字節(jié)數(shù),歸還棧空間,彈出主調(diào)函數(shù) 壓在棧中的代碼執(zhí)行指針(eip),跳回主調(diào)函數(shù)。再由主調(diào)函數(shù)恢復(fù)到調(diào)用前的棧。
                  
            為了訪問函數(shù)局部變量,必須有方法定位每一個變量。變量相對于棧頂esp的位置在進入函數(shù)體時就已確定,但是由于esp會在函數(shù)執(zhí)行期變動,所以將esp
            的值保存在ebp中,并事先將原ebp的值壓棧保存,以聲明中的順序(即壓棧的相反順序)來確定偏移量。
            訪問函數(shù)的局部變量和訪問函數(shù)參數(shù)的區(qū)別:
            局部變量總是通過將ebp減去偏移量來訪問,函數(shù)參數(shù)總是通過將ebp加上偏移量來訪問。對于32位 變量而言,第一個局部變量位于ebp-4,第二個位于ebp-8,以此類推,32位局部變量在棧中形成一個逆序數(shù)組;第一個函數(shù)參數(shù)位于ebp+8,第二 個位于ebp+12,以此類推,32位函數(shù)參數(shù)在棧中形成一個正序數(shù)組。

                  
            函數(shù)的返回值不同于函數(shù)參數(shù),可以通過寄存器傳遞。如果返回值類型可以放入32位變量,比如int、short、char、指針等類型,將通過eax寄存
            器傳遞。如果返回值類型是64位變量,如_int64,則通過edx+eax傳遞,edx存儲高32位,eax存儲低32位。如果返回值是浮點類型,如
            float和double,通過專用的浮點數(shù)寄存器棧的棧頂返回。如果返回值類型是struct或class類型,編譯器將通過隱式修改函數(shù)的簽名,以引
            用型參數(shù)的形式傳回。由于函數(shù)返回值通過寄存器返回,不需要空間分配等操作,所以返回值的代價很低。基于這個原因,C89規(guī)范中約定,不寫明返回值類型的
            函數(shù),返回值類型默認(rèn)為int。這一規(guī)則與現(xiàn)行的C++語法相違背,因為C++中,不寫明返回值類型的函數(shù)返回值類型為void,表示不返回值。這種語法
            不兼容性是為了加強C++的類型安全,但同時也帶來了一些代碼兼容性問題。
            代碼示例
            VarType Func (Arg1, Arg2, Arg3, ... ArgN)
            {
                VarType Var1, Var2, Var3, ...VarN;
                //...
                return VarN;
            }
            假設(shè)sizeof(VarType) = 4(DWORD), 則一次函數(shù)調(diào)用匯編代碼示例為:
            調(diào)用方代碼:

            push ArgN ; 依次逆序壓入調(diào)用參數(shù)
            push ...
            push Arg1
            call Func_Address ; 壓入當(dāng)前EIP后跳轉(zhuǎn)
            跳轉(zhuǎn)至被調(diào)方代碼:
            push ebp ; 備份調(diào)用方EBP指針
            mov ebp, esp ; 建立被調(diào)方棧底
            sub esp, N * 4; 為局部變量分配空間
            mov dword ptr[esp- 4 * 1 ], 0 ; 初始化各個局部變量 = 0 這里假定VarType不是類
            mov dword ptr[esp - 4 * ... ], 0
            mov dword ptr[esp - 4 * N ], 0
            . . . . . . ; 這里執(zhí)行一些函數(shù)功能語句(比如將第N個參數(shù)[ebp + N * 4]存入局部變量), 功能完成后將函數(shù)返回值存至eax
            add esp, N * 4 ; 銷毀局部變量
            mov esp, ebp ; 恢復(fù)主調(diào)方棧頂
            pop ebp ; 恢復(fù)主調(diào)方棧底
            ret ; 彈出EIP 返回主調(diào)方代碼
            接上面調(diào)用方代碼:
            add esp, N * 4 ; 釋放參數(shù)空間, 恢復(fù)調(diào)用前的棧
            mov dword ptr[ebp - 4], eax ; 將返回值保存進調(diào)用方的某個VarType型局部變量
            進入函數(shù)時堆棧分配示意圖
            內(nèi)存低地址 | ESP - - - - - - - - - - - - - - - - EBP - - - - - - - - - - - - - - - - - - - - - >| 內(nèi)存高地址
            Stack State: VarN . . . Var3 Var2 Var1 SFP EIP Arg1 Arg2 Arg3 . . . ArgN
            //資料
            區(qū)...............................................................................................................................
            SFP 解釋:      
            除了堆棧指針(ESP指向堆棧頂部的的低地址)之外,
            為了使用方便還有指向幀內(nèi)固定地址的指針叫做幀指針(FP)。有些文章把它叫做局部基指針(LB-local base
            pointer)。從理論上來說, 局部變量可以用SP加偏移量來引用。 然而, 當(dāng)有字被壓棧和出棧后, 這些偏移量就變了。
            盡管在某些情況下編譯器能夠跟蹤棧中的字操作, 由此可以修正偏移量, 但是在某些情況下不能。而且在所有情況下, 要引入可觀的管理開銷。
            而且在有些機器上, 比如Intel處理器, 由SP加偏移量訪問一個變量需要多條指令才能實現(xiàn)。
                    因此,
            許多編譯器使用第二個寄存器, FP, 對于局部變量和函數(shù)參數(shù)都可以引用, 因為它們到FP的距離不會受到PUSH和POP操作的影響。
            在Intel CPU中, BP(EBP)用于這個目的。 在Motorola CPU中,
            除了A7(堆棧指針SP)之外的任何地址寄存器都可以做FP。考慮到我們堆棧的增長方向, 從FP的位置開始計算, 函數(shù)參數(shù)的偏移量是正值,
            而局部變量的偏移量是負值。
                  
            當(dāng)一個例程被調(diào)用時所必須做的第一件事是保存前一個FP(這樣當(dāng)例程退出時就可以恢復(fù)這個被保存的FP稱為SFP)。 然后它把SP復(fù)制到FP,
            創(chuàng)建新的FP, 把SP向前移動為局部變量保留空間。 這稱為例程的序幕(prolog)工作。當(dāng)例程退出時, 堆棧必須被清除干凈,
            這稱為例程的收尾(epilog)工作。 Intel的ENTER和LEAVE指令, Motorola的LINK和UNLINK指令,
            都可以用于有效地序幕和收尾工作。
                     所有局部變量都在棧中由函數(shù)統(tǒng)一分配,形成了類似逆序數(shù)組的結(jié)構(gòu),可以通過指針逐一訪問。這一特點具有很多有趣性質(zhì),比如,考慮如下函數(shù),找出其中的錯 誤及其造成的結(jié)果:
            void f()
            {
            int i,a[10];
            for(i=0;i}
                    這個函數(shù)中包含的錯誤,即使是C++新手也很容易發(fā)現(xiàn),這是老生常談的越界訪問問
            題。但是這個錯誤造成的結(jié)果,是很多人沒有想到的。這次的越界訪問,并不會像很多新手預(yù)料的那樣造成一個“非法操作”消息,也不會像很多老手估計的那樣會
            默不作聲,而是導(dǎo)致一個死循環(huán)。
                    錯誤的本質(zhì)顯而易見,我們訪問了a[10],但是a[10]并不存在。C++標(biāo)準(zhǔn)對于越界訪問只是說“未定義操作”。我們知道,a[10]是數(shù)組a 所在位置之后的一個位置,但問題是,是誰在這個位置上。是i!
                  
            根據(jù)前面的討論,i在數(shù)組a之前被聲明,所以在a之前分配在棧上。但是,I386上棧是向下增長的,所以,a的地址低于i的地址。其結(jié)果是在循環(huán)的最后,


            ---------------------------------------------
            原文的紅色esp感覺應(yīng)該是ebp..
            posted @ 2010-07-01 09:07 小果子 閱讀(429) | 評論 (0)編輯 收藏
            這幾天對匯編來了興趣~,同時對setWindowsHook感興趣,所以研究了下掃雷程序用OD,參考了網(wǎng)上的分析和自己的實踐,寫了個掃雷輔助~,用setWindowsHook ,附上學(xué)習(xí)成果~
            dll.cpp

            #include 
            "saoleiDll.h"

            #pragma   data_seg("Shared")
            HINSTANCE g_hInstance = NULL;
            HHOOK       g_hHook = NULL;
            HWND         g_hWnd = NULL;
            #pragma   data_seg()
            #pragma   comment(linker,"/SECTION:Shared,RWS")   

            LRESULT WINAPI MouseProc(
            int nCode,WPARAM wParam,LPARAM lParam){
                
            //MessageBox(g_hWnd,L"DD",L"DD",MB_OK);
                DWORD x = 0x10056A8;
                DWORD y = 0x10056AC;
                DWORD addr = 0x1005361;

                wchar_t d[100];
                
            int ny=*((wchar_t*)x);
                
            int nx=*((wchar_t*)y);

                DWORD pFunc = 0x01003512 ; 

                
            for(int i=0;i<ny;i++){
                    
            for(int j=0;j<nx;j++){
                        
            int tmp=*((char*)(addr+32*i+j));
                        
            if(tmp==0x8E){
                        }
            else if(tmp==0x0F){
                            {
                                
            int xi=i+1;
                                
            int yi=j+1;
                                __asm{
                                    push xi
                                    push yi
                                    call pFunc
                                }
                            }
                        }
                    }
                }

                
            //wsprintf(d,L"%d %d",ny,nx);
                //MessageBox(g_hWnd,d,L"DD",MB_OK);
                return  CallNextHookEx(g_hHook,nCode,wParam,lParam);
            };
            HHOOK InstallHook (HWND hWnd,DWORD dwThreadId)
            {
                
            if(dwThreadId!=0){
                    g_hWnd = hWnd;
                    g_hHook = SetWindowsHookEx(WH_KEYBOARD,MouseProc,g_hInstance,dwThreadId);
                    
            return g_hHook;
                }
            else{
                    
            return NULL;
                }
            }
            void UninstallHook()
            {
                UnhookWindowsHookEx(g_hHook);
            }
            BOOL APIENTRY DllMain( HMODULE hModule,
                                   DWORD  ul_reason_for_call,
                                   LPVOID lpReserved
                                 )
            {
                
            switch (ul_reason_for_call)
                {
                
            case DLL_PROCESS_ATTACH:
                    g_hInstance=(HINSTANCE)hModule;
                    
            break;
                
            case DLL_THREAD_ATTACH:
                
            case DLL_THREAD_DETACH:
                
            case DLL_PROCESS_DETACH:
                    
            break;
                }
                
            return TRUE;
            }

            engine.h

            #ifndef __engine_h__
            #define __engine_h__
            #include "..\saoleiDll\saoleiDll.h"

            #pragma comment(lib,"..\\Debug\\saoleiDll.lib")
            DWORD dwThreadId;
            HWND hhWnd;
            extern HWND hWnd;
            void process(){
                DWORD x = 0x10056A8;
                DWORD y = 0x10056AC;
                DWORD addr = 0x1005361;

                hhWnd=FindWindow(NULL,L"掃雷");
                DWORD hProcessId;
                dwThreadId=GetWindowThreadProcessId(hhWnd, &hProcessId);
                HANDLE Process = OpenProcess(PROCESS_VM_OPERATION| PROCESS_VM_WRITE|PROCESS_VM_READ, 
            false, hProcessId);

                
            if(Process==NULL){
                
            //MessageBox(-1,GetLastError(),"D",MB_OK);
                    DWORD sd=GetLastError();
                }


                unsigned 
            short int nx=0,ny=0;
                ReadProcessMemory(Process,(LPCVOID)x,&ny,2,NULL);
                ReadProcessMemory(Process,(LPCVOID)y,&nx,2,NULL);

                unsigned 
            short int s=0,b=0;
                
            int test=0;
                
            int cnt=0;
                
            for(int i = 0; i < ny; i ++){
                    
            for(int j = 0; j < nx; j++){
                        ::ReadProcessMemory(Process, (LPCVOID)(addr + 32*i+j), &b, 1, NULL);
                        
            if (b == 0x8F) 
                        {
                            cnt++;
                            s = 0x8E; 
                            ::WriteProcessMemory(Process, (LPVOID)(addr + (nx+2)*i+j), &s, 1, NULL);
                            ReadProcessMemory(Process, (LPCVOID)(addr + (nx+2)*i+j), &test, 1, NULL);
                        }
                    }
                }
                ::InvalidateRect(hhWnd, NULL, 
            true);
                ::CloseHandle(Process);
            }

            #endif


            posted @ 2010-06-30 20:42 小果子 閱讀(154) | 評論 (0)編輯 收藏
            方法14 :MessageProc Function

            The MessageProc hook procedure 
            is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function after an input event occurs in a dialog box, message box, menu, or scroll bar, but before the message generated by the input event is processed. The hook procedure can monitor messages for a dialog box, message box, menu, or scroll bar created by a particular application or all applications. MessageProc鉤子子程是同SetWindowsHookEx方法一起使用的、應(yīng)用程序或者庫定義的回調(diào)方法。在對話框,消息框,菜單,滾動條的輸入事件發(fā)生后、在這些輸入事件生成的消息被處理之前,系統(tǒng)調(diào)用該方法。鉤子子程可以監(jiān)視特定的程序或者所有程序生成的對話框,消息框,菜單或者滾動條的消息。

            The HOOKPROC type defines a pointer to 
            this callback function. MessageProc is a placeholder for the application-defined or library-defined function name. HOOKPROC類型定義了指向該回調(diào)函數(shù)的指針。MessageProc是程序定義的或者庫定義的方法名字。

            Syntax語法

            LRESULT CALLBACK MessageProc(      

                    
            int code,

                WPARAM wParam,

                LPARAM lParam

            );

            Parameters參數(shù)

            code :[
            in] Specifies the type of input event that generated the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and return the value returned by CallNextHookEx. This parameter can be one of the following values. 指定生成消息的輸入事件的類型。如果code小于0,鉤子子程必須將消息傳遞給CallNextHookEx方法,自己不進行任何進一步處理,并且要返回由方法CallNextHookEx返回的返回值。該參數(shù)可以時下列方法之一。

            1.MSGF_DDEMGR :The input event occurred while the Dynamic Data Exchange Management Library (DDEML) was waiting for a synchronous transaction to finish. 當(dāng)DDEML正在等待同步傳輸結(jié)束時,該輸入事件發(fā)生。

            2.MSGF_DIALOGBOX :The input event occurred in a message box or dialog box. 輸入事件在消息框或者對話框中發(fā)生。

            3.MSGF_MENU :The input event occurred in a menu. 輸入事件在菜單中發(fā)生。

            4.MSGF_SCROLLBAR :The input event occurred in a scroll bar.輸入事件在滾動條中發(fā)生。

            wParam :This parameter 
            is not used. 該參數(shù)未被使用。

            lParam :[
            in] Pointer to an MSG structure. 指向MSG結(jié)構(gòu)的指針。

            Return Value返回值

            If code 
            is less than zero, the hook procedure must return the value returned by CallNextHookEx.

            If code 
            is greater than or equal to zero, and the hook procedure did not process the message, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_MSGFILTER hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure.

            如果code小于0,鉤子子程必須返回由方法CallNextHookEx返回的返回值。如果code大于等于0,而且鉤子子程還沒有處理該消息,強烈要求調(diào)用CallNextHookEx方法并返回由它返回的返回值;否則,其它已經(jīng)安裝了WH_MSGFILTER鉤子的應(yīng)用程序?qū)⑹詹坏姐^子通知,可能導(dǎo)致行為的錯誤。如果鉤子子程已經(jīng)處理了該消息,應(yīng)該返回非0值,以組織系統(tǒng)將消息傳遞給鉤子鏈表中剩下的鉤子或者目標(biāo)窗口子程。

            Remarks備注

            An application installs the hook procedure by specifying the WH_MSGFILTER hook type and a pointer to the hook procedure 
            in a call to the SetWindowsHookEx function.

            If an application that uses the DDEML and performs synchronous transactions must process messages before they are dispatched, it must use the WH_MSGFILTER hook.

            應(yīng)用程序通過下面方法來安裝鉤子:指定WH_MSGFILTER鉤子類型;指定在調(diào)用SetWindowsHookEx的方法中指向鉤子子程的指針。

            使用DDEML、執(zhí)行同步傳遞的應(yīng)用程序應(yīng)該在消息被分發(fā)前進行處理,必須使用WH_MSGFILTER鉤子。

             

            方法15 :MouseProc Function

            The MouseProc hook procedure 
            is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a mouse message to be processed. MouseProc鉤子子程是同SetWindowsHookEx方法一起使用的、應(yīng)用程序定義的或者庫定義的回調(diào)函數(shù)。無論什么時候,當(dāng)應(yīng)用程序一調(diào)用GetMessage 或者 PeekMessage方法,有鼠標(biāo)消息即將被處理時,系統(tǒng)調(diào)用該方法。

            The HOOKPROC type defines a pointer to 
            this callback function. MouseProc is a placeholder for the application-defined or library-defined function name.  HOOKPROC類型定義了指向回調(diào)函數(shù)的指針。MouseProc是應(yīng)用程序定義的或者庫定義的方法名稱。

            Syntax:語法

            LRESULT CALLBACK MouseProc(      

                     
            int nCode,

                WPARAM wParam,

                LPARAM lParam

            );

            Parameters 參數(shù)

            nCode :[
            in] Specifies a code the hook procedure uses to determine how to process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. This parameter can be one of the following values. 指定鉤子子程使用的用來決定如何處理消息的碼值。如果nCode小于0,鉤子子程必須將消息傳遞給CallNextHookEx方法,自己不進行進一步的處理,并且要返回由CallNextHookEx方法返回的返回值。該參數(shù)可以是下列值之一:

            1.HC_ACTION :The wParam and lParam parameters contain information about a mouse message. 參數(shù)wParam 和 lParam包含和鼠標(biāo)消息相關(guān)的信息。

            2.HC_NOREMOVE :The wParam and lParam parameters contain information about a mouse message, and the mouse message has not been removed from the message queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)

            參數(shù)wParam 和 lParam包含和鼠標(biāo)消息相關(guān)的信息,鼠標(biāo)消息還沒有從消息隊列中移除。

            wParam :[
            in] Specifies the identifier of the mouse message. 指定鼠標(biāo)消息的標(biāo)識符。

            lParam:[
            in] Pointer to a MOUSEHOOKSTRUCT structure. 指向MOUSEHOOKSTRUCT結(jié)構(gòu)的指針。

            Return Value 返回值

            If nCode 
            is less than zero, the hook procedure must return the value returned by CallNextHookEx. If nCode is greater than or equal to zero, and the hook procedure did not process the message, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_MOUSE hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the target window procedure.

            如果code小于0,鉤子子程必須返回由CallNextHookEx方法返回的返回值。如果code大于等于0,鉤子子程還沒有處理該消息,強烈要求調(diào)用CallNextHookEx方法并返回由它返回的返回值;否則,其它已經(jīng)安裝了WH_MOUSE鉤子的應(yīng)用程序?qū)⑹詹坏姐^子通知,可能導(dǎo)致行為的錯誤。如果鉤子子程已經(jīng)處理了該消息,應(yīng)該返回非0值,以阻止系統(tǒng)將消息傳遞給鉤子鏈表中剩余的鉤子或者目標(biāo)窗體程序。

            Remarks備注

            An application installs the hook procedure by specifying the WH_MOUSE hook type and a pointer to the hook procedure 
            in a call to the SetWindowsHookEx function. The hook procedure must not install a WH_JOURNALPLAYBACK Hook callback function.

            應(yīng)用程序通過下面方法來安裝鉤子:指定WH_MOUSE鉤子類型;指定在調(diào)用SetWindowsHookEx的方法中指向鉤子子程的指針。該鉤子子程不應(yīng)安裝WH_JOURNALPLAYBACK鉤子的回調(diào)函數(shù)。

             

            方法15 :MouseProc Function

            The MouseProc hook procedure 
            is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a mouse message to be processed. MouseProc鉤子子程是同SetWindowsHookEx方法一起使用的、應(yīng)用程序定義的或者庫定義的回調(diào)函數(shù)。無論什么時候,當(dāng)應(yīng)用程序一調(diào)用GetMessage 或者 PeekMessage方法,有鼠標(biāo)消息即將被處理時,系統(tǒng)調(diào)用該方法。

            The HOOKPROC type defines a pointer to 
            this callback function. MouseProc is a placeholder for the application-defined or library-defined function name.  HOOKPROC類型定義了指向回調(diào)函數(shù)的指針。MouseProc是應(yīng)用程序定義的或者庫定義的方法名稱。

            Syntax:語法

            LRESULT CALLBACK MouseProc(      

                     
            int nCode,

                WPARAM wParam,

                LPARAM lParam

            );

            Parameters 參數(shù)

            nCode :[
            in] Specifies a code the hook procedure uses to determine how to process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. This parameter can be one of the following values. 指定鉤子子程使用的用來決定如何處理消息的碼值。如果nCode小于0,鉤子子程必須將消息傳遞給CallNextHookEx方法,自己不進行進一步的處理,并且要返回由CallNextHookEx方法返回的返回值。該參數(shù)可以是下列值之一:

            1.HC_ACTION :The wParam and lParam parameters contain information about a mouse message. 參數(shù)wParam 和 lParam包含和鼠標(biāo)消息相關(guān)的信息。

            2.HC_NOREMOVE :The wParam and lParam parameters contain information about a mouse message, and the mouse message has not been removed from the message queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)

            參數(shù)wParam 和 lParam包含和鼠標(biāo)消息相關(guān)的信息,鼠標(biāo)消息還沒有從消息隊列中移除。

            wParam :[
            in] Specifies the identifier of the mouse message. 指定鼠標(biāo)消息的標(biāo)識符。

            lParam:[
            in] Pointer to a MOUSEHOOKSTRUCT structure. 指向MOUSEHOOKSTRUCT結(jié)構(gòu)的指針。

            Return Value 返回值

            If nCode 
            is less than zero, the hook procedure must return the value returned by CallNextHookEx. If nCode is greater than or equal to zero, and the hook procedure did not process the message, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_MOUSE hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the target window procedure.

            如果code小于0,鉤子子程必須返回由CallNextHookEx方法返回的返回值。如果code大于等于0,鉤子子程還沒有處理該消息,強烈要求調(diào)用CallNextHookEx方法并返回由它返回的返回值;否則,其它已經(jīng)安裝了WH_MOUSE鉤子的應(yīng)用程序?qū)⑹詹坏姐^子通知,可能導(dǎo)致行為的錯誤。如果鉤子子程已經(jīng)處理了該消息,應(yīng)該返回非0值,以阻止系統(tǒng)將消息傳遞給鉤子鏈表中剩余的鉤子或者目標(biāo)窗體程序。

            Remarks備注

            An application installs the hook procedure by specifying the WH_MOUSE hook type and a pointer to the hook procedure 
            in a call to the SetWindowsHookEx function. The hook procedure must not install a WH_JOURNALPLAYBACK Hook callback function.

            應(yīng)用程序通過下面方法來安裝鉤子:指定WH_MOUSE鉤子類型;指定在調(diào)用SetWindowsHookEx的方法中指向鉤子子程的指針。該鉤子子程不應(yīng)安裝WH_JOURNALPLAYBACK鉤子的回調(diào)函數(shù)。

             

             

            方法16 :SetWindowsHookEx Function

            The SetWindowsHookEx function installs an application
            -defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.

            SetWindowsHookEx方法安裝一個應(yīng)用程序定義的鉤子子程到鉤子鏈表中。你可能安裝鉤子子程來監(jiān)視系統(tǒng)的一些類型的事件。這些事件可以同下面的線程一起使用:指定的線程或者同一桌面下做為調(diào)用線程的所有線程。

            Syntax 語法

            HHOOK SetWindowsHookEx(      

                
            int idHook,

                HOOKPROC lpfn,

                HINSTANCE hMod,

                DWORD dwThreadId

            );

            Parameters參數(shù)

            idHook :[
            in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values. 指定即將被安裝的鉤子子程的類型。該參數(shù)可以是下列值之一:

            1.WH_CALLWNDPROC :Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. 安裝一個鉤子子程,用來在系統(tǒng)將消息發(fā)送給目的窗體程序之前監(jiān)視消息。

            2. WH_CALLWNDPROCRET :Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. 安裝一個鉤子子程,用來在消息被目標(biāo)窗體程序處理之后來監(jiān)視消息。

            3.WH_CBT :Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application.安裝一個鉤子子程,用來接收對CBT程序有用的通知。

            4.WH_DEBUG :Installs a hook procedure useful for debugging other hook procedures.安裝一個對調(diào)試其它鉤子子程有用的鉤子子程。

            5.WH_FOREGROUNDIDLE :Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time.安裝一個鉤子子程,當(dāng)應(yīng)用程序的前臺線程即將空閑時,該子程被調(diào)用。該鉤子在空閑時間里來執(zhí)行低權(quán)限任務(wù)時很有用。

            5.WH_GETMESSAGE :Installs a hook procedure that monitors messages posted to a message queue.安裝一個鉤子子程用來監(jiān)視傳遞給消息隊列的消息。

            6.WH_JOURNALPLAYBACK :Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure.安裝一個鉤子子程用來傳遞前期由WH_JOURNALRECORD鉤子子程記錄的消息。

            7.WH_JOURNALRECORD :Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. 安裝一個鉤子子程來記錄傳遞給系統(tǒng)消息隊列的輸入消息。該鉤子對記錄宏很有用。

            8.WH_KEYBOARD :Installs a hook procedure that monitors keystroke messages.安裝一個鉤子子程用來監(jiān)視鍵盤消息。

            9.WH_KEYBOARD_LL  :Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events.在Windows NT/2000/XP環(huán)境下:安裝一個鉤子子程用來監(jiān)視低層鍵盤輸入事件。

            10.WH_MOUSE :Installs a hook procedure that monitors mouse messages.安裝一個鉤子子程用來監(jiān)視鼠標(biāo)消息。

            11.WH_MOUSE_LL :: Installs a hook procedure that monitors low-level mouse input events. 在 Windows NT/2000/XP環(huán)境下,安裝一個鉤子子程用來監(jiān)視低層鼠標(biāo)輸入事件。

            12.WH_MSGFILTER :Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar.安裝一個鉤子子程用來監(jiān)視下列對象的輸入事件產(chǎn)生的消息:對話框、消息框、菜單、滾動條。

            13.WH_SHELL :Installs a hook procedure that receives notifications useful to shell applications.安裝一個鉤子子程用來接收對加殼程序有用的通知。

            14.WH_SYSMSGFILTER :Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread.安裝一個鉤子子程用來監(jiān)視下列對象的輸入事件產(chǎn)生的消息:對話框、消息框、菜單、滾動條。鉤子子程為同一桌面下做為調(diào)用線程的所有線程監(jiān)視這些消息。

            lpfn :[
            in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.

            鉤子子程的指針。如果參數(shù)dwThreadId為0或者指定由不同進程創(chuàng)建的線程的標(biāo)識符,lpfn參數(shù)必須指向動態(tài)鏈接庫里的鉤子子程。否則,lpfn可以指向與當(dāng)前進程相關(guān)的代碼中的鉤子子程。

            hMod :[
            in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.

            由lpfn參數(shù)指向的含有鉤子子程的DLL的句柄。如果參數(shù)dwThreadId指定了由當(dāng)前進程創(chuàng)建的線程,或者如果鉤子子程處在與當(dāng)前進程相關(guān)的代碼中,hMod參數(shù)必須設(shè)置為Null。

            dwThreadId :[
            in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread. 指定鉤子子程即將關(guān)聯(lián)的線程的標(biāo)識符。如果該參數(shù)是0,鉤子子程與在同一桌面環(huán)境下運行的做為調(diào)用線程的所有存在的線程相關(guān)聯(lián)。

            Return Value返回值

            If the function succeeds, the 
            return value is the handle to the hook procedure. If the function fails, the return value is NULL.

            如果方法執(zhí)行成功,返回鉤子子程的句柄。如果失敗,返回空。

            Remarks備注

            SetWindowsHookEx can be used to inject a DLL into another process. A 
            32-bit DLL cannot be injected into a 64-bit process, and a 64-bit DLL cannot be injected into a 32-bit process. If an application requires the use of hooks in other processes, it is required that a 32-bit application call SetWindowsHookEx to inject a 32-bit DLL into 32-bit processes, and a 64-bit application call SetWindowsHookEx to inject a 64-bit DLL into 64-bit processes. The 32-bit and 64-bit DLLs must have different names.

            SetWindowsHookEx可以被注入到DLL中,進而被映射到另外進程中。32位的DLL不能被注入到64位的進程中,同樣,64位的DLL也不能被注入到32位的進程中。如果應(yīng)用程序請求在其它的進程中使用鉤子,要求,32位的應(yīng)用程序調(diào)用SetWindowsHookEx將32位的DLL注入到32位的進程中,64位的應(yīng)用程序調(diào)用SetWindowsHookEx將64位的DLL注入到64位的進程中。32位的DLL和64位的DLL必須具有不同的名稱。

            An error may occur 
            if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process. 如果參數(shù)hMod為空,參數(shù)dwThreadId為0,或者指定了由另外進程創(chuàng)建的線程的標(biāo)識符,會產(chǎn)生錯誤。

            Calling the CallNextHookEx function to chain to the next hook procedure 
            is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications. 雖然調(diào)用CallNextHookEx方法鏈接到下一個鉤子子程是可選的,但是強烈建議使用;否則,其它已經(jīng)安裝了鉤子的應(yīng)用程序?qū)⒉唤邮浙^子通知,可能導(dǎo)致行為錯誤。除非絕對需要阻止通知被其它應(yīng)用程序看見,其他時候都應(yīng)該調(diào)用CallNextHookEx方法。

            Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook. 在結(jié)束前,應(yīng)用程序必須調(diào)用UnhookWindowsHookEx方法來釋放與該鉤子相關(guān)的系統(tǒng)資源。

            The scope of a hook depends on the hook type. Some hooks can be 
            set only with global scope; others can also be set for only a specific thread, as shown in the following table. 鉤子的作用域取決于鉤子的類型。一些鉤子只能在全局范圍使用,其它一些僅僅能在指定的線程中使用。如下表所示:

            Hook
                

            Scope

            WH_CALLWNDPROC
                

            Thread or global線程
            /全局

            WH_CALLWNDPROCRET
                

            Thread or global線程
            /全局

            WH_CBT
                

            Thread or global線程
            /全局

            WH_DEBUG
                

            Thread or global線程
            /全局

            WH_FOREGROUNDIDLE
                

            Thread or global線程
            /全局

            WH_GETMESSAGE
                

            Thread or global線程
            /全局

            WH_JOURNALPLAYBACK
                

            Global only全局

            WH_JOURNALRECORD
                

            Global only全局

            WH_KEYBOARD
                

            Thread or global線程
            /全局

            WH_KEYBOARD_LL
                

            Global only全局

            WH_MOUSE
                

            Thread or global線程
            /全局

            WH_MOUSE_LL
                

            Global only全局

            WH_MSGFILTER
                

            Thread or global線程
            /全局

            WH_SHELL
                

            Thread or global線程
            /全局

            WH_SYSMSGFILTER
                

            Global only全局

            For a specified hook type, thread hooks are called first, then global hooks.

            對于指定的鉤子類型,線程鉤子先被調(diào)用,然后是全局鉤子。

            The global hooks are a shared resource, and installing one affects all applications 
            in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.

             全局鉤子是共享資源,安裝一個鉤子會影響同一桌面環(huán)境下做為調(diào)用線程的所有應(yīng)用程序。所有的全局鉤子函數(shù)都應(yīng)該在庫中。全局鉤子應(yīng)該被分發(fā)到特定目的的應(yīng)用程序中,或者在程序調(diào)試中間,來輔助開發(fā)。不再需要鉤子的庫應(yīng)該移除鉤子子程。

            posted @ 2010-06-26 20:38 小果子 閱讀(451) | 評論 (0)編輯 收藏
            僅列出標(biāo)題
            共58頁: First 35 36 37 38 39 40 41 42 43 Last 
            久久婷婷色香五月综合激情| 久久国产精品无| 精品久久久久久中文字幕人妻最新| 亚洲香蕉网久久综合影视| 97久久超碰国产精品2021| 韩国三级中文字幕hd久久精品 | 久久久久久久久66精品片| 伊人久久综合精品无码AV专区| 99久久免费国产精品热| 亚洲国产精品综合久久网络| 久久精品国产亚洲av影院| 精品无码人妻久久久久久| 久久久老熟女一区二区三区| 免费精品久久久久久中文字幕| 国产精品免费福利久久| 久久亚洲AV无码精品色午夜| 久久国产热这里只有精品| 久久精品国产亚洲精品2020| 国产精品久久新婚兰兰| 久久精品国产WWW456C0M| 久久精品国产一区| 蜜臀久久99精品久久久久久小说| 无码国内精品久久人妻麻豆按摩| 国产精品欧美亚洲韩国日本久久 | 亚洲综合久久综合激情久久| 国内精品九九久久精品| 亚洲伊人久久成综合人影院| 久久精品成人免费观看97| 久久久久国产精品| 国产午夜福利精品久久2021| 热re99久久精品国99热| 亚洲精品无码专区久久久| 97久久国产综合精品女不卡| 国产精品久久久久蜜芽| 精品多毛少妇人妻AV免费久久| 欧美一级久久久久久久大| 午夜精品久久久久久影视777| 久久国产视频99电影| 午夜精品久久久久久| 久久婷婷色综合一区二区 | 国产91久久综合|