Author Topic: Windows Projects  (Read 16255 times)

Vortex

  • Member
  • *****
  • Posts: 2768
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;

}

Vortex

  • Member
  • *****
  • Posts: 2768
Re: Windows Projects
« Reply #31 on: October 15, 2020, 03:39:04 AM »
Quote
splitter.exe splits a large file into megabyte chunks for transmission. It will also recombine them.

https://www.digitalmars.com/splitter.c

Compiling the code :

Code: [Select]
set PATH=%PATH%;\pcc32\bin

pcc32.exe /MM /I\pcc32\include /c splitter.c
link32 /SUBSYSTEM:CONSOLE /LIBPATH:\pcc32\lib /NEV splitter.obj kernel32.lib user32.lib msvcrt.lib