• <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)  編輯 收藏 引用

            99久久国产热无码精品免费| 久久99久久无码毛片一区二区| 一本大道久久东京热无码AV | 2021少妇久久久久久久久久| 久久久精品人妻一区二区三区四| 国产精品久久国产精麻豆99网站| 日本久久久精品中文字幕| 久久AⅤ人妻少妇嫩草影院| 国产精品乱码久久久久久软件 | 久久久久AV综合网成人| 国产AⅤ精品一区二区三区久久| 2021最新久久久视精品爱 | 久久99国产精品久久99| 三级片免费观看久久| 国产精品视频久久| 久久91精品国产91久| 99久久婷婷国产一区二区| 久久人妻AV中文字幕| 国内精品久久久久久久亚洲| 久久综合亚洲欧美成人| 亚洲精品综合久久| 国产亚州精品女人久久久久久| 一本久久a久久精品vr综合| 欧美粉嫩小泬久久久久久久 | 久久精品国产福利国产秒| 思思久久99热免费精品6| 久久精品一区二区| 97精品伊人久久大香线蕉app| 伊人久久大香线蕉AV一区二区| 丁香久久婷婷国产午夜视频| 久久久噜噜噜久久熟女AA片| 国产aⅴ激情无码久久| 天天做夜夜做久久做狠狠| A级毛片无码久久精品免费| 国产精品一久久香蕉国产线看| 婷婷久久香蕉五月综合加勒比| 性欧美大战久久久久久久| 久久青青草原精品国产不卡| 久久久人妻精品无码一区| 久久精品国产欧美日韩| 久久久久国色AV免费观看|