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

            无码AV中文字幕久久专区| 日本加勒比久久精品| 久久精品视频网| 亚洲国产天堂久久综合| 久久久久久国产精品无码超碰| 人妻精品久久久久中文字幕69| 超级碰久久免费公开视频| 久久久久久国产a免费观看黄色大片| 91精品国产综合久久久久久| 久久99精品久久久久久野外| 99久久国产精品免费一区二区| 日本福利片国产午夜久久| 久久久国产打桩机| 久久99精品免费一区二区| 国内精品伊人久久久久AV影院| 午夜精品久久久久9999高清| 久久99国产精品久久99果冻传媒| 2021国内久久精品| 久久久久久亚洲精品不卡| 久久福利青草精品资源站| 亚洲国产精品成人久久| 亚洲国产精品综合久久网络 | 精品久久久久久| 亚洲精品国产字幕久久不卡 | 无码精品久久久天天影视| 亚洲国产成人精品久久久国产成人一区二区三区综 | 浪潮AV色综合久久天堂| 模特私拍国产精品久久| 国产精品一区二区久久精品无码| 久久青青草原精品影院| 精品久久久久久亚洲| 久久精品一区二区国产| 91精品免费久久久久久久久| 日本道色综合久久影院| 精品久久人人做人人爽综合| 天天综合久久久网| 国产成人久久精品麻豆一区| 久久精品夜色噜噜亚洲A∨| 久久精品国产黑森林| 伊人精品久久久久7777| 久久精品成人欧美大片|