Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:04:38+00:00 2026-06-10T17:04:38+00:00

I have hooked a exported MFC DLL function using naked function. the definition of

  • 0

I have hooked a exported MFC DLL function using naked function.

the definition of naked function is as follows :


__declspec(naked)
static void __cdecl GenericHook(void* __this,class CScrollViewAccess* objParam1, class CRect& objParam2,unsigned int iParam1, unsigned long iParam2, char* szParam1,
void* vParam1, class CFont* objParam3,class CFont* objParam4,
                                class CBrush* objParam5)
{       /*function body start*/

    __asm pushad;                   /* first "argument", which is also used to store registers */
    __asm push ecx;                 /* padding so that ebp+8 refers to the first "argument" */

    /* set up standard prologue */
    __asm push ebp;
    __asm mov ebp, esp;
    __asm sub esp, __LOCAL_SIZE;



    if(flg == false)
    {

        //RECT* rct = reinterpret_cast(&objParam2);

        hInst   =   LoadLibrary("C:\\Sample.dll"); /// MFC Dll
        funcPTR =   (CMYCLASS_)(((int)hInst)+((int)0x00001032));
        funcPTR(__this,objParam2);

    /* standard epilogue */
     __asm mov esp, ebp;
     __asm pop ebp;

     __asm pop ecx;                 /* clear padding */
     __asm popad;                   /* clear first "argument" */
     __asm jmp [Trampoline];

}   

    /*function body end*/

The Mfc dll has following function:


    void CMyClass::returnRect(class CRect& objParam)
    {
        int width   = objParam.Width();
        int height  = objParam.Height();
        CPoint pt   = objParam.TopLeft();

        FILE* fp;
        char szEnter[6] = {13,0,10,0,0,0};
        fp = fopen("c:\\LogFolder\\log.txt","ab+");
        fprintf(fp,"Width: %d Height: %d X co-ord: %d Y co-ord: %d\n%s",width,height,pt.x,pt.y,szEnter);
        fclose(fp);
    }

after passing CRect& parameter to the MFC DLL the values logged are wrong.

How to process the reference object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:04:39+00:00Added an answer on June 10, 2026 at 5:04 pm

    I have solved this hooking problem as follows:

    
        extern "C"  __declspec(naked) __declspec(dllexport) void __stdcall GenericHook()
        {        /*function body start*/
            /* set up standard prologue */
            __asm push ebp;
            __asm mov ebp, esp;
            __asm pushad;
    
           // __asm sub esp, __LOCAL_SIZE;            // Grow stack size
            __asm mov eax,[ebp+4];                    //Return Address
            __asm mov objParam1,eax;
            __asm mov eax,DWORD ptr[ebp+8];            //arg1
            __asm mov objParam2,eax;
            __asm mov eax,DWORD ptr[ebp+12];        //arg2
            __asm mov objParam3,eax;
            __asm mov eax,DWORD ptr[ebp+16];        //arg3
            __asm mov objParam4,eax;
            __asm mov eax,DWORD ptr[ebp+20];        //arg4
            __asm mov objParam5,eax;
    
            /*-------------PROCESSING START---------------------*/
            fp = fopen("c:\\LogFolder\\log.txt","ab+");
            fprintf(fp,"arg1: %lu~arg2: %lu~arg3: %lu~arg4: %lu~ar5: %lu\n",objParam1,objParam2,objParam3,objParam4,objParam5);
            fprintf(fp,"==========================================================================\n\n");
            fclose(fp);
            /*-------------PROCESSING END-----------------------*/
    
    
    
    
            /* standard epilogue    
             __asm add esp, __LOCAL_SIZE;*/
             __asm popad;
             __asm mov esp, ebp;   
             __asm pop ebp;
             __asm jmp [Trampoline];   
        }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using EasyHook I have successfully hooked both exported functions and known vtable functions for
I have two functions hooked on the submit event of a form. Each function
I have a function hooked on a $('form').submit() event. This function will fire an
I have a little problem with the CLSID. I have a (hooked) function which
I am using the Windows Forms TreeView control. The way i have it hooked
I'm using the PureMVC framework on a FlexBuilder 3 project. I have already hooked
I have hooked into the ListBoxItems' double-click event using the ff. code in my
I can't run an simple XNA window in fullscreen when I have hooked up
I have 2 keyboards hooked up to my machine (one on PS/2, the other
I have an Ajax site where I have browser navigation hooked up to ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.