/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_delete_surface_pdu(RdpgfxServerContext* context, RDPGFX_DELETE_SURFACE_PDU* pdu) { wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_DELETESURFACE, 2); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ return rdpgfx_server_single_packet_send(context, s); }
int cliprdr_client_format_list(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST* formatList) { wStream* s; UINT32 index; int length = 0; int formatNameSize; CLIPRDR_FORMAT* format; cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle; for (index = 0; index < formatList->numFormats; index++) { format = (CLIPRDR_FORMAT*) &(formatList->formats[index]); length += 4; formatNameSize = 2; if (format->formatName) formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, NULL, 0) * 2; length += formatNameSize; } s = cliprdr_packet_new(CB_FORMAT_LIST, 0, length); for (index = 0; index < formatList->numFormats; index++) { format = (CLIPRDR_FORMAT*) &(formatList->formats[index]); Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */ if (format->formatName) { int cchWideChar; LPWSTR lpWideCharStr; lpWideCharStr = (LPWSTR) Stream_Pointer(s); cchWideChar = (Stream_Capacity(s) - Stream_GetPosition(s)) / 2; formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, lpWideCharStr, cchWideChar) * 2; Stream_Seek(s, formatNameSize); } else { Stream_Write_UINT16(s, 0); } } WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatList: numFormats: %d", formatList->numFormats); cliprdr_packet_send(cliprdr, s); return 0; }
static BOOL rdpsnd_server_set_volume(RdpsndServerContext* context, int left, int right) { int pos; BOOL status; ULONG written; wStream* s = context->priv->rdpsnd_pdu; Stream_Write_UINT8(s, SNDC_SETVOLUME); Stream_Write_UINT8(s, 0); Stream_Seek_UINT16(s); Stream_Write_UINT16(s, left); Stream_Write_UINT16(s, right); pos = Stream_GetPosition(s); Stream_SetPosition(s, 2); Stream_Write_UINT16(s, pos - 4); Stream_SetPosition(s, pos); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written); Stream_SetPosition(s, 0); return status; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_evict_cache_entry_pdu(RdpgfxServerContext* context, RDPGFX_EVICT_CACHE_ENTRY_PDU* pdu) { wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_EVICTCACHEENTRY, 2); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, pdu->cacheSlot); /* cacheSlot (2 bytes) */ return rdpgfx_server_single_packet_send(context, s); }
int ntlm_write_ntlm_v2_client_challenge(wStream* s, NTLMv2_CLIENT_CHALLENGE* challenge) { ULONG length; Stream_Write_UINT8(s, challenge->RespType); Stream_Write_UINT8(s, challenge->HiRespType); Stream_Write_UINT16(s, challenge->Reserved1); Stream_Write_UINT32(s, challenge->Reserved2); Stream_Write(s, challenge->Timestamp, 8); Stream_Write(s, challenge->ClientChallenge, 8); Stream_Write_UINT32(s, challenge->Reserved3); length = ntlm_av_pair_list_length(challenge->AvPairs); Stream_Write(s, challenge->AvPairs, length); return 1; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpdr_send_device_list_remove_request(rdpdrPlugin* rdpdr, UINT32 count, UINT32 ids[]) { UINT32 i; wStream* s; s = Stream_New(NULL, count * sizeof(UINT32) + 8); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, RDPDR_CTYP_CORE); Stream_Write_UINT16(s, PAKID_CORE_DEVICELIST_REMOVE); Stream_Write_UINT32(s, count); for (i = 0; i < count; i++) Stream_Write_UINT32(s, ids[i]); Stream_SealLength(s); return rdpdr_send(rdpdr, s); }
static void audin_server_send_formats(audin_server* audin, wStream* s) { int i; UINT32 nAvgBytesPerSec; ULONG written; Stream_SetPosition(s, 0); Stream_Write_UINT8(s, MSG_SNDIN_FORMATS); Stream_Write_UINT32(s, audin->context.num_server_formats); /* NumFormats (4 bytes) */ Stream_Write_UINT32(s, 0); /* cbSizeFormatsPacket (4 bytes), client-to-server only */ for (i = 0; i < audin->context.num_server_formats; i++) { nAvgBytesPerSec = audin->context.server_formats[i].nSamplesPerSec * audin->context.server_formats[i].nChannels * audin->context.server_formats[i].wBitsPerSample / 8; Stream_EnsureRemainingCapacity(s, 18); Stream_Write_UINT16(s, audin->context.server_formats[i].wFormatTag); Stream_Write_UINT16(s, audin->context.server_formats[i].nChannels); Stream_Write_UINT32(s, audin->context.server_formats[i].nSamplesPerSec); Stream_Write_UINT32(s, nAvgBytesPerSec); Stream_Write_UINT16(s, audin->context.server_formats[i].nBlockAlign); Stream_Write_UINT16(s, audin->context.server_formats[i].wBitsPerSample); Stream_Write_UINT16(s, audin->context.server_formats[i].cbSize); if (audin->context.server_formats[i].cbSize) { Stream_EnsureRemainingCapacity(s, audin->context.server_formats[i].cbSize); Stream_Write(s, audin->context.server_formats[i].data, audin->context.server_formats[i].cbSize); } } WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written); }
static int rdpdr_server_send_core_capability_request(RdpdrServerContext* context) { wStream* s; BOOL status; RDPDR_HEADER header; UINT16 numCapabilities; ULONG written; CLOG_DBG("RdpdrServerSendCoreCapabilityRequest\n"); header.Component = RDPDR_CTYP_CORE; header.PacketId = PAKID_CORE_SERVER_CAPABILITY; numCapabilities = 5; s = Stream_New(NULL, RDPDR_HEADER_LENGTH + 512); Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */ Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */ Stream_Write_UINT16(s, numCapabilities); /* numCapabilities (2 bytes) */ Stream_Write_UINT16(s, 0); /* Padding (2 bytes) */ rdpdr_server_write_general_capability_set(context, s); rdpdr_server_write_printer_capability_set(context, s); rdpdr_server_write_port_capability_set(context, s); rdpdr_server_write_drive_capability_set(context, s); rdpdr_server_write_smartcard_capability_set(context, s); Stream_SealLength(s); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written); Stream_Free(s, TRUE); return 0; }
int rdg_write_data_packet(rdpRdg* rdg, BYTE* buf, int size) { int status; wStream* sChunk; int packetSize = size + 10; char chunkSize[11]; if (size < 1) return 0; sprintf_s(chunkSize, sizeof(chunkSize), "%X\r\n", packetSize); sChunk = Stream_New(NULL, strlen(chunkSize) + packetSize + 2); if (!sChunk) return -1; Stream_Write(sChunk, chunkSize, strlen(chunkSize)); Stream_Write_UINT16(sChunk, PKT_TYPE_DATA); /* Type */ Stream_Write_UINT16(sChunk, 0); /* Reserved */ Stream_Write_UINT32(sChunk, packetSize); /* Packet length */ Stream_Write_UINT16(sChunk, size); /* Data size */ Stream_Write(sChunk, buf, size); /* Data */ Stream_Write(sChunk, "\r\n", 2); Stream_SealLength(sChunk); status = tls_write_all(rdg->tlsIn, Stream_Buffer(sChunk), Stream_Length(sChunk)); Stream_Free(sChunk, TRUE); if (status < 0) return -1; return size; }
void update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd) { Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH); Stream_Write_UINT16(s, CMDTYPE_STREAM_SURFACE_BITS); Stream_Write_UINT16(s, cmd->destLeft); Stream_Write_UINT16(s, cmd->destTop); Stream_Write_UINT16(s, cmd->destRight); Stream_Write_UINT16(s, cmd->destBottom); Stream_Write_UINT8(s, cmd->bpp); Stream_Write_UINT16(s, 0); /* reserved1, reserved2 */ Stream_Write_UINT8(s, cmd->codecID); Stream_Write_UINT16(s, cmd->width); Stream_Write_UINT16(s, cmd->height); Stream_Write_UINT32(s, cmd->bitmapDataLength); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_cache_import_reply_pdu(RdpgfxServerContext* context, RDPGFX_CACHE_IMPORT_REPLY_PDU* pdu) { UINT16 index; wStream* s = rdpgfx_server_single_packet_new( RDPGFX_CMDID_CACHEIMPORTREPLY, 2 + 2 * pdu->importedEntriesCount); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } /* importedEntriesCount (2 bytes) */ Stream_Write_UINT16(s, pdu->importedEntriesCount); for (index = 0; index < pdu->importedEntriesCount; index++) { Stream_Write_UINT16(s, pdu->cacheSlots[index]); /* cacheSlot (2 bytes) */ } return rdpgfx_server_single_packet_send(context, s); }
static void update_send_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3) { wStream* s; int bm, em; BYTE orderType; int headerLength; UINT16 extraFlags; INT16 orderLength; rdpUpdate* update = context->update; extraFlags = 0; headerLength = 6; orderType = ORDER_TYPE_BITMAP_COMPRESSED_V3; update_check_flush(context, headerLength + update_approximate_cache_bitmap_v3_order(cache_bitmap_v3, &extraFlags)); s = update->us; bm = Stream_GetPosition(s); Stream_EnsureRemainingCapacity(s, headerLength); Stream_Seek(s, headerLength); update_write_cache_bitmap_v3_order(s, cache_bitmap_v3, &extraFlags); em = Stream_GetPosition(s); orderLength = (em - bm) - 13; Stream_SetPosition(s, bm); Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */ Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */ Stream_Write_UINT16(s, extraFlags); /* extraFlags (2 bytes) */ Stream_Write_UINT8(s, orderType); /* orderType (1 byte) */ Stream_SetPosition(s, em); update->numberOrders++; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_cache_to_surface_pdu(RdpgfxServerContext* context, RDPGFX_CACHE_TO_SURFACE_PDU* pdu) { UINT error = CHANNEL_RC_OK; UINT16 index; RDPGFX_POINT16* destPt; wStream* s = rdpgfx_server_single_packet_new( RDPGFX_CMDID_CACHETOSURFACE, 6 + 4 * pdu->destPtsCount); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, pdu->cacheSlot); /* cacheSlot (2 bytes) */ Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ Stream_Write_UINT16(s, pdu->destPtsCount); /* destPtsCount (2 bytes) */ for (index = 0; index < pdu->destPtsCount; index++) { destPt = &(pdu->destPts[index]); if ((error = rdpgfx_write_point16(s, destPt))) { WLog_ERR(TAG, "rdpgfx_write_point16 failed with error %u", error); goto error; } } return rdpgfx_server_single_packet_send(context, s); error: Stream_Free(s, TRUE); return error; }
BOOL rdp_send_deactivate_all(rdpRdp* rdp) { wStream* s = rdp_send_stream_pdu_init(rdp); BOOL status; if (!s) return FALSE; Stream_Write_UINT32(s, rdp->settings->ShareId); /* shareId (4 bytes) */ Stream_Write_UINT16(s, 1); /* lengthSourceDescriptor (2 bytes) */ Stream_Write_UINT8(s, 0); /* sourceDescriptor (should be 0x00) */ status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId); Stream_Release(s); return status; }
BOOL nego_send_preconnection_pdu(rdpNego* nego) { wStream* s; UINT32 cbSize; UINT16 cchPCB = 0; WCHAR* wszPCB = NULL; WLog_DBG(TAG, "Sending preconnection PDU"); if (!nego_tcp_connect(nego)) return FALSE; /* it's easier to always send the version 2 PDU, and it's just 2 bytes overhead */ cbSize = PRECONNECTION_PDU_V2_MIN_SIZE; if (nego->PreconnectionBlob) { cchPCB = (UINT16) ConvertToUnicode(CP_UTF8, 0, nego->PreconnectionBlob, -1, &wszPCB, 0); cchPCB += 1; /* zero-termination */ cbSize += cchPCB * 2; } s = Stream_New(NULL, cbSize); Stream_Write_UINT32(s, cbSize); /* cbSize */ Stream_Write_UINT32(s, 0); /* Flags */ Stream_Write_UINT32(s, PRECONNECTION_PDU_V2); /* Version */ Stream_Write_UINT32(s, nego->PreconnectionId); /* Id */ Stream_Write_UINT16(s, cchPCB); /* cchPCB */ if (wszPCB) { Stream_Write(s, wszPCB, cchPCB * 2); /* wszPCB */ free(wszPCB); } Stream_SealLength(s); if (transport_write(nego->transport, s) < 0) { Stream_Free(s, TRUE); return FALSE; } Stream_Free(s, TRUE); return TRUE; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT rdpei_send_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s, UINT16 eventId, UINT32 pduLength) { UINT status; Stream_SetPosition(s, 0); Stream_Write_UINT16(s, eventId); /* eventId (2 bytes) */ Stream_Write_UINT32(s, pduLength); /* pduLength (4 bytes) */ Stream_SetPosition(s, Stream_Length(s)); status = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s), Stream_Buffer(s), NULL); #ifdef WITH_DEBUG_RDPEI WLog_DBG(TAG, "rdpei_send_pdu: eventId: %d (%s) length: %d status: %d", eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength, status); #endif return status; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_delete_encoding_context_pdu(RdpgfxServerContext* context, RDPGFX_DELETE_ENCODING_CONTEXT_PDU* pdu) { wStream* s = rdpgfx_server_single_packet_new( RDPGFX_CMDID_DELETEENCODINGCONTEXT, 6); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ Stream_Write_UINT32(s, pdu->codecContextId); /* codecContextId (4 bytes) */ return rdpgfx_server_single_packet_send(context, s); }
static void rdp_write_extended_info_packet(rdpRdp* rdp, wStream* s) { int clientAddressFamily; WCHAR* clientAddress = NULL; int cbClientAddress; WCHAR* clientDir = NULL; int cbClientDir; int cbAutoReconnectCookie; rdpSettings* settings = rdp->settings; clientAddressFamily = settings->IPv6Enabled ? ADDRESS_FAMILY_INET6 : ADDRESS_FAMILY_INET; cbClientAddress = ConvertToUnicode(CP_UTF8, 0, settings->ClientAddress, -1, &clientAddress, 0) * 2; cbClientDir = ConvertToUnicode(CP_UTF8, 0, settings->ClientDir, -1, &clientDir, 0) * 2; cbAutoReconnectCookie = (int) settings->ServerAutoReconnectCookie->cbLen; Stream_Write_UINT16(s, clientAddressFamily); /* clientAddressFamily (2 bytes) */ Stream_Write_UINT16(s, cbClientAddress + 2); /* cbClientAddress (2 bytes) */ if (cbClientAddress > 0) Stream_Write(s, clientAddress, cbClientAddress); /* clientAddress */ Stream_Write_UINT16(s, 0); Stream_Write_UINT16(s, cbClientDir + 2); /* cbClientDir (2 bytes) */ if (cbClientDir > 0) Stream_Write(s, clientDir, cbClientDir); /* clientDir */ Stream_Write_UINT16(s, 0); rdp_write_client_time_zone(s, settings); /* clientTimeZone (172 bytes) */ Stream_Write_UINT32(s, 0); /* clientSessionId (4 bytes), should be set to 0 */ freerdp_performance_flags_make(settings); Stream_Write_UINT32(s, settings->PerformanceFlags); /* performanceFlags (4 bytes) */ Stream_Write_UINT16(s, cbAutoReconnectCookie); /* cbAutoReconnectCookie (2 bytes) */ if (cbAutoReconnectCookie > 0) { rdp_compute_client_auto_reconnect_cookie(rdp); rdp_write_client_auto_reconnect_cookie(rdp, s); /* autoReconnectCookie */ Stream_Write_UINT16(s, 0); /* reserved1 (2 bytes) */ Stream_Write_UINT16(s, 0); /* reserved2 (2 bytes) */ } free(clientAddress); free(clientDir); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_send_map_surface_to_window_pdu(RdpgfxServerContext* context, RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* pdu) { wStream* s = rdpgfx_server_single_packet_new( RDPGFX_CMDID_MAPSURFACETOWINDOW, 18); if (!s) { WLog_ERR(TAG, "rdpgfx_server_single_packet_new failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ Stream_Write_UINT64(s, pdu->windowId); /* windowId (8 bytes) */ Stream_Write_UINT32(s, pdu->mappedWidth); /* mappedWidth (4 bytes) */ Stream_Write_UINT32(s, pdu->mappedHeight); /* mappedHeight (4 bytes) */ return rdpgfx_server_single_packet_send(context, s); }
BOOL input_send_fastpath_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { wStream* s; BYTE eventFlags = 0; rdpRdp* rdp; if (!input || !input->context) return FALSE; rdp = input->context->rdp; eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0; s = fastpath_input_pdu_init(rdp->fastpath, eventFlags, FASTPATH_INPUT_EVENT_UNICODE); if (!s) return FALSE; Stream_Write_UINT16(s, code); /* unicodeCode (2 bytes) */ return fastpath_send_input_pdu(rdp->fastpath, s); }
BOOL rdp_send_deactivate_all(rdpRdp* rdp) { wStream* s; BOOL status; s = Stream_New(NULL, 1024); rdp_init_stream_pdu(rdp, s); Stream_Write_UINT32(s, rdp->settings->ShareId); /* shareId (4 bytes) */ Stream_Write_UINT16(s, 1); /* lengthSourceDescriptor (2 bytes) */ Stream_Write_UINT8(s, 0); /* sourceDescriptor (should be 0x00) */ status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId); Stream_Free(s, TRUE); return status; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpsnd_server_close(RdpsndServerContext* context) { int pos; BOOL status; ULONG written; wStream* s = context->priv->rdpsnd_pdu; UINT error = CHANNEL_RC_OK; EnterCriticalSection(&context->priv->lock); if (context->priv->out_pending_frames > 0) { if (context->selected_client_format < 0) { WLog_ERR(TAG, "Pending audio frame exists while no format selected."); error = ERROR_INVALID_DATA; } else if ((error = rdpsnd_server_send_audio_pdu(context, 0))) { WLog_ERR(TAG, "rdpsnd_server_send_audio_pdu failed with error %lu", error); } } LeaveCriticalSection(&context->priv->lock); if (error) return error; context->selected_client_format = -1; Stream_Write_UINT8(s, SNDC_CLOSE); Stream_Write_UINT8(s, 0); Stream_Seek_UINT16(s); pos = Stream_GetPosition(s); Stream_SetPosition(s, 2); Stream_Write_UINT16(s, pos - 4); Stream_SetPosition(s, pos); status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written); Stream_SetPosition(s, 0); return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; }
void rdp_write_extended_info_packet(wStream* s, rdpSettings* settings) { int clientAddressFamily; WCHAR* clientAddress = NULL; int cbClientAddress; WCHAR* clientDir = NULL; int cbClientDir; int cbAutoReconnectLen; clientAddressFamily = settings->IPv6Enabled ? ADDRESS_FAMILY_INET6 : ADDRESS_FAMILY_INET; cbClientAddress = ConvertToUnicode(CP_UTF8, 0, settings->ClientAddress, -1, &clientAddress, 0) * 2; cbClientDir = ConvertToUnicode(CP_UTF8, 0, settings->ClientDir, -1, &clientDir, 0) * 2; cbAutoReconnectLen = (int) settings->ClientAutoReconnectCookie->cbLen; Stream_Write_UINT16(s, clientAddressFamily); /* clientAddressFamily */ Stream_Write_UINT16(s, cbClientAddress + 2); /* cbClientAddress */ if (cbClientAddress > 0) Stream_Write(s, clientAddress, cbClientAddress); /* clientAddress */ Stream_Write_UINT16(s, 0); Stream_Write_UINT16(s, cbClientDir + 2); /* cbClientDir */ if (cbClientDir > 0) Stream_Write(s, clientDir, cbClientDir); /* clientDir */ Stream_Write_UINT16(s, 0); rdp_write_client_time_zone(s, settings); /* clientTimeZone */ Stream_Write_UINT32(s, 0); /* clientSessionId, should be set to 0 */ Stream_Write_UINT32(s, settings->PerformanceFlags); /* performanceFlags */ Stream_Write_UINT16(s, cbAutoReconnectLen); /* cbAutoReconnectLen */ if (cbAutoReconnectLen > 0) rdp_write_client_auto_reconnect_cookie(s, settings); /* autoReconnectCookie */ /* reserved1 (2 bytes) */ /* reserved2 (2 bytes) */ free(clientAddress); free(clientDir); }
static void update_write_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color) { Stream_EnsureRemainingCapacity(s, 15 + (int) pointer_color->lengthAndMask + (int) pointer_color->lengthXorMask); Stream_Write_UINT16(s, pointer_color->cacheIndex); Stream_Write_UINT16(s, pointer_color->xPos); Stream_Write_UINT16(s, pointer_color->yPos); Stream_Write_UINT16(s, pointer_color->width); Stream_Write_UINT16(s, pointer_color->height); Stream_Write_UINT16(s, pointer_color->lengthAndMask); Stream_Write_UINT16(s, pointer_color->lengthXorMask); if (pointer_color->lengthXorMask > 0) Stream_Write(s, pointer_color->xorMaskData, pointer_color->lengthXorMask); if (pointer_color->lengthAndMask > 0) Stream_Write(s, pointer_color->andMaskData, pointer_color->lengthAndMask); Stream_Write_UINT8(s, 0); /* pad (1 byte) */ }
static int wts_write_variable_uint(wStream* stream, UINT32 val) { int cb; if (val <= 0xFF) { cb = 0; Stream_Write_UINT8(stream, val); } else if (val <= 0xFFFF) { cb = 1; Stream_Write_UINT16(stream, val); } else { cb = 2; Stream_Write_UINT32(stream, val); } return cb; }
static UINT drdynvc_write_variable_uint(wStream* s, UINT32 val) { UINT cb; if (val <= 0xFF) { cb = 0; Stream_Write_UINT8(s, val); } else if (val <= 0xFFFF) { cb = 1; Stream_Write_UINT16(s, val); } else { cb = 2; Stream_Write_UINT32(s, val); } return cb; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT rdpei_server_resume(RdpeiServerContext *context) { ULONG written; RdpeiServerPrivate *priv = context->priv; switch (priv->automataState) { case STATE_WAITING_FRAME: WLog_ERR(TAG, "not suspended"); return CHANNEL_RC_OK; case STATE_SUSPENDED: break; default: WLog_ERR(TAG, "called from unexpected state %d", (int)priv->automataState); return ERROR_INVALID_STATE; } Stream_SetPosition(priv->outputStream, 0); if (!Stream_EnsureCapacity(priv->outputStream, RDPINPUT_HEADER_LENGTH)) { WLog_ERR(TAG, "Stream_EnsureCapacity failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write_UINT16(priv->outputStream, EVENTID_RESUME_TOUCH); Stream_Write_UINT32(priv->outputStream, RDPINPUT_HEADER_LENGTH); if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream), Stream_GetPosition(priv->outputStream), &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); return ERROR_INTERNAL_ERROR; } priv->automataState = STATE_WAITING_FRAME; return CHANNEL_RC_OK; }
BOOL rdg_send_channel_create(rdpRdg* rdg) { int i; wStream* s; BOOL status; char* serverName = rdg->settings->ServerHostname; UINT16 serverNameLen = strlen(serverName) + 1; UINT32 packetSize = 16 + serverNameLen * 2; s = Stream_New(NULL, packetSize); if (!s) return FALSE; Stream_Write_UINT16(s, PKT_TYPE_CHANNEL_CREATE); /* Type (2 bytes) */ Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ Stream_Write_UINT32(s, packetSize); /* PacketLength (4 bytes) */ Stream_Write_UINT8(s, 1); /* Number of resources. (1 byte) */ Stream_Write_UINT8(s, 0); /* Number of alternative resources (1 byte) */ Stream_Write_UINT16(s, rdg->settings->ServerPort); /* Resource port (2 bytes) */ Stream_Write_UINT16(s, 3); /* Protocol number (2 bytes) */ Stream_Write_UINT16(s, serverNameLen * 2); for (i = 0; i < serverNameLen; i++) { Stream_Write_UINT16(s, serverName[i]); } Stream_SealLength(s); status = rdg_write_packet(rdg, s); Stream_Free(s, TRUE); if (status) { rdg->state = RDG_CLIENT_STATE_CHANNEL_CREATE; } return status; }
static void rfx_compose_message_tile(RFX_CONTEXT* context, wStream* s, BYTE* tile_data, int tile_width, int tile_height, int rowstride, const UINT32* quantVals, int quantIdxY, int quantIdxCb, int quantIdxCr, int xIdx, int yIdx) { int YLen = 0; int CbLen = 0; int CrLen = 0; int start_pos, end_pos; Stream_EnsureRemainingCapacity(s, 19); start_pos = Stream_GetPosition(s); Stream_Write_UINT16(s, CBT_TILE); /* BlockT.blockType */ Stream_Seek_UINT32(s); /* set BlockT.blockLen later */ Stream_Write_UINT8(s, quantIdxY); Stream_Write_UINT8(s, quantIdxCb); Stream_Write_UINT8(s, quantIdxCr); Stream_Write_UINT16(s, xIdx); Stream_Write_UINT16(s, yIdx); Stream_Seek(s, 6); /* YLen, CbLen, CrLen */ rfx_encode_rgb(context, tile_data, tile_width, tile_height, rowstride, quantVals + quantIdxY * 10, quantVals + quantIdxCb * 10, quantVals + quantIdxCr * 10, s, &YLen, &CbLen, &CrLen); DEBUG_RFX("xIdx=%d yIdx=%d width=%d height=%d YLen=%d CbLen=%d CrLen=%d", xIdx, yIdx, tile_width, tile_height, YLen, CbLen, CrLen); end_pos = Stream_GetPosition(s); Stream_SetPosition(s, start_pos + 2); Stream_Write_UINT32(s, 19 + YLen + CbLen + CrLen); /* BlockT.blockLen */ Stream_SetPosition(s, start_pos + 13); Stream_Write_UINT16(s, YLen); Stream_Write_UINT16(s, CbLen); Stream_Write_UINT16(s, CrLen); Stream_SetPosition(s, end_pos); }
static void rfx_write_tile(RFX_CONTEXT* context, wStream* s, RFX_TILE* tile) { UINT32 blockLen; blockLen = rfx_tile_length(tile); Stream_EnsureRemainingCapacity(s, blockLen); Stream_Write_UINT16(s, CBT_TILE); /* BlockT.blockType (2 bytes) */ Stream_Write_UINT32(s, blockLen); /* BlockT.blockLen (4 bytes) */ Stream_Write_UINT8(s, tile->quantIdxY); /* quantIdxY (1 byte) */ Stream_Write_UINT8(s, tile->quantIdxCb); /* quantIdxCb (1 byte) */ Stream_Write_UINT8(s, tile->quantIdxCr); /* quantIdxCr (1 byte) */ Stream_Write_UINT16(s, tile->xIdx); /* xIdx (2 bytes) */ Stream_Write_UINT16(s, tile->yIdx); /* yIdx (2 bytes) */ Stream_Write_UINT16(s, tile->YLen); /* YLen (2 bytes) */ Stream_Write_UINT16(s, tile->CbLen); /* CbLen (2 bytes) */ Stream_Write_UINT16(s, tile->CrLen); /* CrLen (2 bytes) */ Stream_Write(s, tile->YData, tile->YLen); /* YData */ Stream_Write(s, tile->CbData, tile->CbLen); /* CbData */ Stream_Write(s, tile->CrData, tile->CrLen); /* CrData */ }