Not an universal method but it's possible to search for the RET instruction in the epilogue code of a function. 32-bit code demo :
#include <stdio.h>
int testfunc(int x,int y,int *pSize)
{
int temp;
int result;
__asm{
mov edx,OFFSET label1
dec edx
l1:
inc edx
// Search for the RET ( 0xC3 ) instruction
cmp BYTE PTR [edx],0xC3
jne l1
mov temp,edx
}
result=x;
result+=y;
*pSize=1+(int)temp-(int)testfunc;
label1:
return result;
}
int main(void)
{
int fSize;
testfunc(10,20,&fSize);
printf("Size of the function testfunc = %d bytes\n",fSize);
return 0;
}