• <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>

            meet-dream

            a simple template hook class for function and member functions

            Some times,we need too hook some function to do something that's not so easy to do with normally add somecode.A solution is to hook focused functions and interface.Here is a template hook class maybe help your work easier,which complie with vs2005.It midify the jmp table to replace the function,maybe not?properly? for other compliers.

            class HookPfn
            {
            ?struct make_writeable
            ?{
            ??void* p;
            ??MEMORY_BASIC_INFORMATION mbi_thunk;
            ??make_writeable(void* _p):p(_p)
            ??{
            ???VirtualQuery(p, &mbi_thunk, sizeof(MEMORY_BASIC_INFORMATION));
            ???VirtualProtect(mbi_thunk.BaseAddress, mbi_thunk.RegionSize, PAGE_READWRITE, &mbi_thunk.Protect);
            ??
            ??}
            ??~make_writeable()
            ??{
            ???VirtualProtect(mbi_thunk.BaseAddress, mbi_thunk.RegionSize, mbi_thunk.Protect,&mbi_thunk.Protect);
            ??}
            ?};
            public:
            ?template<class F>
            ?void restore(F pfn,unsigned long handle)
            ?{
            ??
            ??void* p;
            ??__asm mov eax,[pfn]
            ??__asm mov dword ptr[p],eax
            ??make_writeable write(p);
            ??__asm push ecx
            ??__asm mov eax,pfn
            ??__asm inc eax
            ??__asm mov ecx,handle
            ??__asm mov dword ptr[eax],ecx
            ??__asm pop ecx
            ?}
            ?template<class F1,class F2>
            ?unsigned long redirect(F1 pfn1,F2 pfn2)
            ?{
            ???//should use restrict object prevent?F1 and F2 's arguments and type not same
            ??void* p;
            ??__asm mov eax,[pfn1]
            ??__asm mov dword ptr[p],eax
            ??make_writeable write(p);

            ??unsigned long bas1,bas2,of1,of2,of;
            ??__asm push ecx
            ??__asm mov eax,pfn1
            ??__asm mov bas1,eax
            ??__asm inc eax
            ??__asm mov ecx,dword ptr[eax]
            ??__asm mov of1,ecx

            ??__asm mov eax,pfn2
            ??__asm mov bas2,eax
            ??__asm inc eax
            ??__asm mov ecx,dword ptr[eax]
            ??__asm mov of2,ecx

            ??of=(bas2-bas1+of2-of1)+of1;

            ??__asm mov eax,pfn1
            ??__asm inc eax
            ??__asm mov ecx,of
            ??__asm mov dword ptr[eax],ecx
            ??__asm pop ecx
            ??return of1;
            ?}
            ?
            };

            class mmt
            {
            public:
            ?void donothing()
            {
            }
            ?void donothing(int)
            {
            }
            ??void dosomething()
            {
            }
            };

            void fastcall(int a,int b)
            {
            }
            void askcall(int,int)
            {
            }


            It can be used as example:
            int main()
            {
            ?HookMemberFunction sh;
            ?unsigned long hd=sh.redirect(&fastcall,&askcall);//test api
            ?fastcall(0,0);//two?function
            ?askcall(0,0);
            ?sh.restore(&fastcall,hd);
            ?askcall(0,0);
            ?fastcall(0,0);
            //test overlay functions(donothing)
            ?typedef void (mmt::*sp)(void);
            ?sp p1=&mmt::dosomething;
            ?sp p2=&mmt::donothing;
            ?hd=sh.redirect(p1,p2);
            ?mmt mt;//a class
            ?mt.donothing();
            ?mt.dosomething();
            ?sh.restore(p1,hd);
            ?mt.donothing();
            ?mt.dosomething();

            }
            Although it can be work right,addtionly we may be use it not properly.Youcan add some strict class to prevent bad use of it by check if the argument and return type is strictly same.,if you need it.

            posted on 2007-03-05 23:51 meet-dream 閱讀(661) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久大香香蕉国产| 2021最新久久久视精品爱| 国产精品久久波多野结衣| 久久精品国产久精国产| 国产香蕉97碰碰久久人人| 精品国产日韩久久亚洲| 久久国产精品无码HDAV| 久久艹国产| 精品国产乱码久久久久软件| 精品999久久久久久中文字幕| 久久人人爽人人爽AV片| 亚洲AV无码久久精品色欲| 久久亚洲中文字幕精品一区| 亚洲精品tv久久久久久久久| 久久久久亚洲精品无码网址| 日日噜噜夜夜狠狠久久丁香五月| 7国产欧美日韩综合天堂中文久久久久| 亚洲精品WWW久久久久久| 精品久久久久久亚洲| 久久亚洲sm情趣捆绑调教| 99久久人人爽亚洲精品美女| 亚洲精品美女久久久久99| 欧美久久一级内射wwwwww.| 久久亚洲高清观看| 国产美女久久精品香蕉69| 久久经典免费视频| 亚洲国产成人久久笫一页| 韩国三级中文字幕hd久久精品| 国产精品久久午夜夜伦鲁鲁| 一97日本道伊人久久综合影院| 成人a毛片久久免费播放| 狠狠狠色丁香婷婷综合久久俺| 国产成人精品免费久久久久| 一本一本久久A久久综合精品 | 久久久久久久国产免费看| 日韩人妻无码精品久久久不卡| 狠狠色狠狠色综合久久| 欧美精品九九99久久在观看| 久久久这里只有精品加勒比| 色99久久久久高潮综合影院 | 国产精品久久久久天天影视|