代码之家  ›  专栏  ›  技术社区  ›  kellogs

LSP包修改

  •  1
  • kellogs  · 技术社区  · 16 年前

    有人愿意分享一些关于如何使用LSP修改数据包的见解吗?

    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 回复  |  直到 16 年前
        1
  •  0
  •   kellogs    16 年前

    推荐文章