예제 #1
0
파일: tunnel.cpp 프로젝트: sucof/qb-sync
HRESULT TunnelClose()
{
    HRESULT hRes=S_OK;
    int iResult;

    if(SUCCEEDED(TunnelIsUp()))
    {
        hRes=TunnelSend("[notice]{\"type\":\"dbg_quit\",\"msg\":\"dbg disconnected\"}\n");
        if(FAILED(hRes))
            return hRes;
    }
    
    if(!(g_Sock == INVALID_SOCKET)){
        iResult = closesocket(g_Sock);
        g_Sock = INVALID_SOCKET;

        if (iResult == SOCKET_ERROR)
            dprintf("[sync] closesocket failed with error %d\n", WSAGetLastError());
    }

    dprintf("[sync] sync is off\n");
    g_Synchronized=FALSE;
    WSACleanup();
    return hRes;
}
예제 #2
0
파일: tunnel.c 프로젝트: aguinet/ret-sync
HRESULT TunnelReceive(int *lpNbBytesRecvd, LPSTR *lpBuffer)
{
    HRESULT hRes=S_OK;
    int iResult;
    errno_t err;
    *lpNbBytesRecvd = 0;

    if(FAILED(hRes=TunnelIsUp()))
    {
        dbgout("[sync] TunnelReceive: tunnel is not available\n");
        return hRes;
    }

    iResult = recv(g_Sock, RecvBuffer, MAX_SEND, 0);
    if ( iResult == SOCKET_ERROR )
    {
        iResult =  WSAGetLastError();
        if (iResult == WSAEWOULDBLOCK)
        {
            return hRes;
        }
        else
        {
            dbgout("[sync] recv failed with error: %d, 0x%x\n", iResult, g_Sock);
            WsaErrMsg(iResult);
            goto error_close;
        }
    }
    else if ( iResult == 0 ) {
        dbgout("[sync] recv: connection closed\n");
        goto error_close;
    }

    *lpBuffer = (LPSTR) calloc(iResult+1, sizeof(CHAR));
    if (lpBuffer == NULL) {
        dbgout("[sync] failed at allocate buffer: %d\n", GetLastError());
        return E_FAIL;
    }

    err = memcpy_s(*lpBuffer, iResult+1, RecvBuffer, iResult);
    if (err) {
        dbgout("[sync] memcpy_s failed to copy received buffer\n");
        free(*lpBuffer);
        *lpBuffer = NULL;
        hRes = E_FAIL;
    } else {
        *lpNbBytesRecvd = iResult;
    }

    return hRes;

error_close:
    g_Synchronized = FALSE;
    TunnelClose();
    return E_FAIL;
}
예제 #3
0
파일: sync.cpp 프로젝트: sucof/qb-sync
void
CALLBACK
DebugExtensionNotify(ULONG Notify, ULONG64 Argument)
{
    UNREFERENCED_PARAMETER(Argument);
    HRESULT hRes=S_OK;
    BOOL bIgnoreEvent = false;

    switch(Notify){
        case DEBUG_NOTIFY_SESSION_ACTIVE:
            #if VERBOSE >= 2
            dprintf("[sync] DebugExtensionNotify: A debugging session is active. The session may not necessarily be suspended.\n");
            #endif
            break;

        case DEBUG_NOTIFY_SESSION_INACTIVE:
            #if VERBOSE >= 2
            dprintf("[sync] DebugExtensionNotify: No debugging session is active.\n");
            #endif
            break;

        case DEBUG_NOTIFY_SESSION_ACCESSIBLE:
            #if VERBOSE >= 2
            dprintf("[sync] DebugExtensionNotify: The debugging session has suspended and is now accessible.\n");
            #endif
            if(SUCCEEDED(TunnelIsUp()))
            {
                hRes = EventFilterCb(&bIgnoreEvent);
                if(SUCCEEDED(hRes) && bIgnoreEvent)
                    break;

                UpdateState();
                CreatePollTimer();
            }
            break;

        case DEBUG_NOTIFY_SESSION_INACCESSIBLE:
            #if VERBOSE >= 2
            dprintf("[sync] DebugExtensionNotify: The debugging session has started running and is now inaccessible.\n");
            #endif
            ReleasePollTimer();
            break;

        default:
            #if VERBOSE >= 2
            dprintf("[sync] DebugExtensionNotify: Unknown Notify reason (%x).\n", Notify);
            #endif
            break;
    }

    return;
}
예제 #4
0
파일: core.cpp 프로젝트: aguinet/ret-sync
extern "C" __declspec(dllexport) void CBPAUSEDEBUG(CBTYPE cbType, PLUG_CB_PAUSEDEBUG* info)
{
#if VERBOSE >= 2
	_plugin_logputs("[sync] debugging paused!");
#endif

	if (SUCCEEDED(TunnelIsUp()))
	{
		UpdateState();
		CreatePollTimer();
	}

}
예제 #5
0
파일: tunnel.cpp 프로젝트: tandasat/qb-sync
HRESULT TunnelSend(PCSTR Format, ...)
{
    HRESULT hRes=S_OK;
    va_list Args;
    int iResult;
    size_t cbRemaining;

    if (FAILED(hRes=TunnelIsUp()))
    {
        dprintf("[sync] TunnelSend: tunnel is unavailable\n");
        return hRes;
    }

    va_start(Args, Format);
    hRes = StringCbVPrintfEx(SendBuffer, MAX_SEND, NULL, &cbRemaining, STRSAFE_NULL_ON_FAILURE, Format, Args);
    va_end(Args);

    if (FAILED(hRes)){
        return hRes;
    }

    #if VERBOSE >= 2
    dprintf("[sync] send 0x%x bytes, %s\n", MAX_SEND-cbRemaining, SendBuffer);
    #endif

    iResult = send(g_Sock, (const char *)SendBuffer, MAX_SEND-((unsigned int)cbRemaining), 0);
    if (iResult == SOCKET_ERROR)
    {
        iResult = WSAGetLastError();
        dprintf("[sync] send failed with error %d, 0x%x\n", iResult, g_Sock);
        WsaErrMsg(iResult);
        g_Synchronized = FALSE;
        TunnelClose();
        hRes=E_FAIL;
    }

    return hRes;
}