http://research.microsoft.com/sn/detours/
Detours is a library for instrumenting arbitrary Win32 functions on x86 machines. Detours intercepts Win32 functions by re-writing target function images.
Well, my bet is that there are no hooks to enable you to do this.
Yes, you should be able to use Delphi.
Actually, your best bet would be the network card, I think. I know
some network cards can be placed into permiscous mode so that they see
every packet on the network. I have used this to develop a simple
network analyzer in the past. I don't remember exactly what I did but
there is a hook that you can grab that will call you for every packet.
Keep in mind I did this with Delphi 1, however, so it may have been a
hardware interrupt or such. But that may help.
As for writing a replacement winsock dll, it should be possible. I
know there are 3rd party winsock implementations you can buy. There
may even be one out there that supports what you are looking for.
Actually, depending on your exact needs you may be able to use the new
Microsoft V-LAN software to estabulish encrypted links. But that
would probably only work if all your clients are remote and not on the
same physical network. But if I was you I'd look check to see if
there were hooks in winsock 2 or if there was a 3rd party winsock
vendor who supplied hooks.
Bingo. I just remembered that the hook I was using was supplied by
Trumpet winsock. I don't know if it is still around but you may be
able to get a copy of it. Don't know if they ever made a winsock 2
version though.
Your best bet is to see if someone has created a public
domain/shareware winsock implementation that you can somehow get
source code to.
As for creating a layered service provider where they call your
winsock dll and then you call the real winsock I believe you will have
problems with that one. Just a gut feeling really, but you would have
to rename the real winsock dll and it may have other dlls that it uses
or who knows what. But I think you would have more trouble with that
then just creating your own winsock dll.
Good luck. Oh, and if you do happen to find source to a winsock
implementation could you post that information on here. I'm sure
people would be interested.