LSP包修改

时间:2010-02-10 22:35:48

标签: winsock packet-mangling

有人关心如何使用LSP进行数据包修改?

我正在使用非IFS子类型,我可以看到(伪?)数据包如何首先进入WSPRecv。但是我该如何修改它们呢?我的询问是关于一个单独的HTTP响应导致WSPRecv被调用3次:((。我需要修改这个响应的几个部分,但由于它有3个切片,因此很难相应地修改它。并且,也许在其他机器上或在不同条件下(例如高流量),只有一个WSPRecv呼叫,或者10个呼叫。这是最好的工作方式(请不要NDIS:D),以及如何正确更改通过增加缓冲区(lpBuffers-> buf)?

int WSPAPI 
WSPRecv(
SOCKET          s,
LPWSABUF        lpBuffers,
DWORD           dwBufferCount,
LPDWORD         lpNumberOfBytesRecvd,
LPDWORD         lpFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
LPWSATHREADID   lpThreadId,
LPINT           lpErrno
)
{
LPWSAOVERLAPPEDPLUS ProviderOverlapped = NULL;
SOCK_INFO          *SocketContext = NULL;
int                 ret = SOCKET_ERROR;


*lpErrno = NO_ERROR;

//
// Find our provider socket corresponding to this one
//
SocketContext = FindAndRefSocketContext(s, lpErrno);
if ( NULL == SocketContext )
{
    dbgprint( "WSPRecv: FindAndRefSocketContext failed!" );
    goto cleanup;
}

//
// Check for overlapped I/O
//
if ( NULL != lpOverlapped )
{
    /*bla bla .. not interesting in my case*/
}
else
{
    ASSERT( SocketContext->Provider->NextProcTable.lpWSPRecv );

    SetBlockingProvider(SocketContext->Provider);
    ret = SocketContext->Provider->NextProcTable.lpWSPRecv(
            SocketContext->ProviderSocket, 
            lpBuffers, 
            dwBufferCount,
            lpNumberOfBytesRecvd, 
            lpFlags, 
            lpOverlapped, 
            lpCompletionRoutine, 
            lpThreadId,
            lpErrno);
    SetBlockingProvider(NULL);

    //is this the place to modify packet length and contents ?

    if (strstr(lpBuffers->buf, "var mapObj = null;"))
    {
        int nLen = strlen(lpBuffers->buf) + 200;
        /*CHAR *szNewBuf = new CHAR[];
        CHAR *pIndex;

        pIndex = strstr(lpBuffers->buf, "var mapObj = null;");
        nLen = strlen(strncpy(szNewBuf, lpBuffers->buf, (pIndex - lpBuffers->buf) * sizeof (CHAR)));
        nLen = strlen(strncpy(szNewBuf + nLen * sizeof(CHAR), "var com = null;\r\n", 17 * sizeof(CHAR)));
        pIndex += 18 * sizeof(CHAR);
        nLen = strlen(strncpy(szNewBuf + nLen * sizeof(CHAR), pIndex, 1330 * sizeof (CHAR)));
        nLen = strlen(strncpy(szNewBuf + nLen * sizeof(CHAR), "if (com == null)\r\n" \
                                           "com = new ActiveXObject(\"InterCommJS.Gateway\");\r\n" \
                                            "com.lat = latitude;\r\n" \
                                            "com.lon = longitude;\r\n}", 111 * sizeof (CHAR)));
        pIndex = strstr(szNewBuf, "Content-Length:");
        pIndex += 16 * sizeof(CHAR);
        strncpy(pIndex, "1465", 4 * sizeof(CHAR));

        lpBuffers->buf = szNewBuf;
        lpBuffers->len += 128;*/
    }

    if ( SOCKET_ERROR != ret )
    {
        SocketContext->BytesRecv += *lpNumberOfBytesRecvd;
    }
}

cleanup:

if ( NULL != SocketContext )
    DerefSocketContext( SocketContext, lpErrno );

return ret;
}

谢谢

1 个答案:

答案 0 :(得分:0)

我的评论得以解决。 http响应标头/请求结果以\ r \ n \ r \ n。

结尾