Getting The Size of a C++ Function

后端 未结 16 2150
醉酒成梦
醉酒成梦 2020-12-06 09:37

I was reading this question because I\'m trying to find the size of a function in a C++ program, It is hinted at that there may be a way that is platform specific. My target

16条回答
  •  暖寄归人
    2020-12-06 10:08

    below code the get the accurate function block size, it works fine with my test runtime_checks disable _RTC_CheckEsp in debug mode

        #pragma runtime_checks("", off)
    DWORD __stdcall loadDll(char* pDllFullPath)
    {  
        OutputDebugStringA(pDllFullPath);
        //OutputDebugStringA("loadDll...................\r\n");
        return 0;
        //return test(pDllFullPath);
    }
    #pragma runtime_checks("", restore)
    
    DWORD __stdcall getFuncSize_loadDll()
    {
        DWORD maxSize=(PBYTE)getFuncSize_loadDll-(PBYTE)loadDll;
        PBYTE pTail=(PBYTE)getFuncSize_loadDll-1;
        while(*pTail != 0xC2 && *pTail != 0xC3) --pTail;
        if (*pTail==0xC2)
        {   //0xC3          : ret
            //0xC2 04 00    : ret 4
            pTail +=3;
        }
    
        return pTail-(PBYTE)loadDll;
    };
    

提交回复
热议问题