You can use WinDivert (LGPL) for this purpose (disclaimer: WinDivert is my project). WinDivert is a user-mode API that raises the functionality of the WFP kernel call driver in user mode.
The pseudocode will look something like this:
HANDLE handle = DivertOpen( "inbound && " // Inbound packets "tcp.SrcPort == 80 && " // HTTP "tcp.PayloadLength > 0", // Data 0, 0, 0); while (TRUE) { // Capture a packet. DivertRecv(handle, buf, size, &addr, &len); // Modify the packet. ... // Re-inject modified packet. DivertSend(handle, buf, len, &addr, NULL); }
Note that WinDivert is a packet level, so the HTTP stream can be split into several packets, which can complicate the situation.
Basil source share