• <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 閱讀(664) 評論(0)  編輯 收藏 引用

            人妻无码αv中文字幕久久| 久久久久亚洲av毛片大| 久久亚洲av无码精品浪潮| 日本国产精品久久| 国产毛片欧美毛片久久久| 精品人妻久久久久久888| 嫩草影院久久99| 久久天天婷婷五月俺也去| 怡红院日本一道日本久久| 国产精品亚洲综合专区片高清久久久 | 久久久久久综合网天天| 久久亚洲AV成人无码国产| 国产69精品久久久久9999| 一本久久a久久精品vr综合| 66精品综合久久久久久久| 亚洲中文字幕久久精品无码APP| 狠狠色丁香久久婷婷综合五月 | 久久久亚洲欧洲日产国码是AV| 国产V综合V亚洲欧美久久| 伊人色综合久久天天人守人婷| 久久成人精品视频| 中文国产成人精品久久不卡 | 精品国产一区二区三区久久| 51久久夜色精品国产| 久久国产精品成人片免费| 亚洲日本久久久午夜精品| 亚洲综合婷婷久久| 久久久久99精品成人片欧美| 欧美精品国产综合久久| 久久久久人妻一区精品| 色综合久久久久网| 国产精品久久网| 国产午夜精品久久久久免费视 | 少妇熟女久久综合网色欲| 国产巨作麻豆欧美亚洲综合久久 | 日日噜噜夜夜狠狠久久丁香五月| 久久久久亚洲AV无码专区网站| 51久久夜色精品国产| 国产午夜精品久久久久九九| 亚洲国产精品久久久久网站 | 2020久久精品国产免费|