Author Topic: Windows Projects  (Read 4190 times)

Vortex

  • Member
  • *****
  • Posts: 2206
Re: Windows Projects
« Reply #30 on: January 29, 2020, 05:56:14 AM »
With thanks to Manos helping me to understand the Nasm style inline assembly, here is a quick example to calculate the size of a function :

Code: [Select]
#include <stdio.h>
 
int testfunc(int x,int y,int *pSize)
{
    int result;
    int temp;
 
    asm
    {
        mov     edx,label1
        dec     edx
l1:
        inc     edx
           
// Search for the RET ( 0xC3 ) instruction
 
        cmp     byte [edx], 0xC3
        jne     l1
 
        mov     dword [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;

}