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

            久久精品国产精品亜洲毛片| 久久免费的精品国产V∧| 青青青青久久精品国产 | 国产激情久久久久影院小草| 久久国产精品一区| 日韩一区二区三区视频久久| 亚洲∧v久久久无码精品| 日本免费久久久久久久网站| 婷婷久久精品国产| 久久精品国产亚洲AV无码娇色 | 国产精品无码久久久久 | 粉嫩小泬无遮挡久久久久久| 久久久久18| 久久se精品一区二区| 亚洲婷婷国产精品电影人久久| 久久99精品国产麻豆 | 亚洲成色www久久网站夜月| 久久久精品一区二区三区| 久久亚洲精品无码VA大香大香| 国产精品99久久免费观看| 亚洲欧洲中文日韩久久AV乱码| 中文字幕一区二区三区久久网站| 久久强奷乱码老熟女网站| 久久se精品一区精品二区| 久久久噜噜噜www成人网| 国内精品伊人久久久久777| 精品久久久久久无码中文野结衣| 久久天天躁狠狠躁夜夜躁2O2O | 成人久久免费网站| 亚洲精品第一综合99久久| 久久久青草青青国产亚洲免观| 久久91综合国产91久久精品| 久久婷婷五月综合97色一本一本| 久久亚洲中文字幕精品一区| 亚洲伊人久久综合影院| 亚洲国产成人精品女人久久久 | 99久久香蕉国产线看观香| 久久伊人五月天论坛| 久久99久久成人免费播放| 91久久成人免费| 久久国产乱子伦精品免费午夜|