void license_write_binary_blob(wStream* s, LICENSE_BLOB* blob) { Stream_EnsureRemainingCapacity(s, blob->length + 4); Stream_Write_UINT16(s, blob->type); /* wBlobType (2 bytes) */ Stream_Write_UINT16(s, blob->length); /* wBlobLen (2 bytes) */ if (blob->length > 0) Stream_Write(s, blob->data, blob->length); /* blobData */ }
int cliprdr_client_format_data_response(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse) { wStream* s; cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle; formatDataResponse->msgType = CB_FORMAT_DATA_RESPONSE; s = cliprdr_packet_new(formatDataResponse->msgType, formatDataResponse->msgFlags, formatDataResponse->dataLen); Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->dataLen); cliprdr_packet_send(cliprdr, s); return 0; }
void rail_send_channel_data(void* rail_object, void* data, size_t length) { wStream* s = NULL; railPlugin* plugin = (railPlugin*) rail_object; s = Stream_New(NULL, length); Stream_Write(s, data, length); svc_plugin_send((rdpSvcPlugin*) plugin, s); }
void rdp_write_client_auto_reconnect_cookie(wStream* s, rdpSettings* settings) { ARC_CS_PRIVATE_PACKET* autoReconnectCookie; autoReconnectCookie = settings->ClientAutoReconnectCookie; Stream_Write_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */ Stream_Write_UINT32(s, autoReconnectCookie->version); /* version (4 bytes) */ Stream_Write_UINT32(s, autoReconnectCookie->logonId); /* LogonId (4 bytes) */ Stream_Write(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */ }
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 rail_virtual_channel_event_data_received(railPlugin* rail, void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) { wStream* data_in; if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) { return CHANNEL_RC_OK; } if (dataFlags & CHANNEL_FLAG_FIRST) { if (rail->data_in) Stream_Free(rail->data_in, TRUE); rail->data_in = Stream_New(NULL, totalLength); if (!rail->data_in) { WLog_ERR(TAG, "Stream_New failed!"); return CHANNEL_RC_NO_MEMORY; } } data_in = rail->data_in; if (!Stream_EnsureRemainingCapacity(data_in, (int) dataLength)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write(data_in, pData, dataLength); if (dataFlags & CHANNEL_FLAG_LAST) { if (Stream_Capacity(data_in) != Stream_GetPosition(data_in)) { WLog_ERR(TAG, "rail_plugin_process_received: read error"); return ERROR_INTERNAL_ERROR; } rail->data_in = NULL; Stream_SealLength(data_in); Stream_SetPosition(data_in, 0); if (!MessageQueue_Post(rail->queue, NULL, 0, (void*) data_in, NULL)) { WLog_ERR(TAG, "MessageQueue_Post failed!"); return ERROR_INTERNAL_ERROR; } } return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drdynvc_virtual_channel_event_data_received(drdynvcPlugin* drdynvc, void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) { wStream* data_in; if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) { return CHANNEL_RC_OK; } if (dataFlags & CHANNEL_FLAG_FIRST) { if (drdynvc->data_in) Stream_Free(drdynvc->data_in, TRUE); drdynvc->data_in = Stream_New(NULL, totalLength); } if (!(data_in = drdynvc->data_in)) { WLog_Print(drdynvc->log, WLOG_ERROR, "Stream_New failed!"); return CHANNEL_RC_NO_MEMORY; } if (!Stream_EnsureRemainingCapacity(data_in, dataLength)) { WLog_Print(drdynvc->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!"); Stream_Free(drdynvc->data_in, TRUE); drdynvc->data_in = NULL; return ERROR_INTERNAL_ERROR; } Stream_Write(data_in, pData, dataLength); if (dataFlags & CHANNEL_FLAG_LAST) { if (Stream_Capacity(data_in) != Stream_GetPosition(data_in)) { WLog_Print(drdynvc->log, WLOG_ERROR, "drdynvc_plugin_process_received: read error"); return ERROR_INVALID_DATA; } drdynvc->data_in = NULL; Stream_SealLength(data_in); Stream_SetPosition(data_in, 0); if (!MessageQueue_Post(drdynvc->queue, NULL, 0, (void*) data_in, NULL)) { WLog_Print(drdynvc->log, WLOG_ERROR, "MessageQueue_Post failed!"); return ERROR_INTERNAL_ERROR; } } return CHANNEL_RC_OK; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else { buffer = (BYTE*) malloc(Length); if (!buffer) { WLog_ERR(TAG, "malloc failed!"); return CHANNEL_RC_OK; } if (!drive_file_read(file, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; } } Stream_Write_UINT32(irp->output, Length); if (Length > 0) { if (!Stream_EnsureRemainingCapacity(irp->output, (int) Length)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); return ERROR_INTERNAL_ERROR; } Stream_Write(irp->output, buffer, Length); } free(buffer); return irp->Complete(irp); }
static BOOL wts_write_drdynvc_create_request(wStream *s, UINT32 ChannelId, const char *ChannelName) { UINT32 len; wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId); len = strlen(ChannelName) + 1; if (!Stream_EnsureRemainingCapacity(s, (int) len)) return FALSE; Stream_Write(s, ChannelName, len); return TRUE; }
static BOOL rail_write_unicode_string_value(wStream* s, RAIL_UNICODE_STRING* unicode_string) { if (unicode_string->length > 0) { if (!Stream_EnsureRemainingCapacity(s, unicode_string->length)) return FALSE; Stream_Write(s, unicode_string->string, unicode_string->length); /* string */ } return TRUE; }
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 void update_send_surface_command(rdpContext* context, wStream* s) { wStream* update; rdpRdp* rdp = context->rdp; update = fastpath_update_pdu_init(rdp->fastpath); Stream_EnsureRemainingCapacity(update, Stream_GetPosition(s)); Stream_Write(update, Stream_Buffer(s), Stream_GetPosition(s)); fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, update); Stream_Release(update); }
static void FDSAPI_EncodeString(wStream* s, const char* stringValue) { UINT16 stringSize = (stringValue ? strlen(stringValue) : 0); Stream_Write_UINT16(s, stringSize); if (stringSize > 0) { Stream_Write(s, stringValue, stringSize); } }
BOOL rdp_write_client_time_zone(wStream* s, rdpSettings* settings) { LPTIME_ZONE_INFORMATION tz; DWORD rc; tz = settings->ClientTimeZone; if (!tz) return FALSE; rc = GetTimeZoneInformation(tz); /* Bias */ Stream_Write_UINT32(s, tz->Bias); /* standardName (64 bytes) */ Stream_Write(s, tz->StandardName, sizeof(tz->StandardName)); /* StandardDate */ rdp_write_system_time(s, &tz->StandardDate); DEBUG_TIMEZONE("bias=%d stdName='%s' dlName='%s'", tz->Bias, tz->StandardName, tz->DaylightName); /* Note that StandardBias is ignored if no valid standardDate is provided. */ /* StandardBias */ Stream_Write_UINT32(s, tz->StandardBias); DEBUG_TIMEZONE("StandardBias=%d", tz->StandardBias); /* daylightName (64 bytes) */ Stream_Write(s, tz->DaylightName, sizeof(tz->DaylightName)); /* DaylightDate */ rdp_write_system_time(s, &tz->DaylightDate); /* Note that DaylightBias is ignored if no valid daylightDate is provided. */ /* DaylightBias */ Stream_Write_UINT32(s, tz->DaylightBias); DEBUG_TIMEZONE("DaylightBias=%d", tz->DaylightBias); return TRUE; }
static void update_send_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_command) { wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) surface_bits_command->bitmapDataLength); update_write_surfcmd_surface_bits_header(s, surface_bits_command); Stream_Write(s, surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength); fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s); Stream_Release(s); }
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); if (!s) { free(wszPCB); WLog_ERR(TAG, "Stream_New failed!"); return FALSE; } 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; }
static BOOL autodetect_send_bandwidth_measure_stop(rdpContext* context, UINT16 payloadLength, UINT16 sequenceNumber, UINT16 requestType) { wStream* s; UCHAR *buffer = NULL; BOOL bResult = FALSE; s = rdp_message_channel_pdu_init(context->rdp); if (!s) return FALSE; WLog_VRB(AUTODETECT_TAG, "sending Bandwidth Measure Stop PDU -> payloadLength=%u", payloadLength); /* 4-bytes aligned */ payloadLength &= ~3; Stream_Write_UINT8(s, requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME ? 0x08 : 0x06); /* headerLength (1 byte) */ Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */ Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */ Stream_Write_UINT16(s, requestType); /* requestType (2 bytes) */ if (requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME) { Stream_Write_UINT16(s, payloadLength); /* payloadLength (2 bytes) */ if (payloadLength > 0) { if (!Stream_EnsureRemainingCapacity(s, payloadLength)) { Stream_Release(s); return FALSE; } /* Random data (better measurement in case the line is compressed) */ buffer = malloc(payloadLength); if (NULL == buffer) { Stream_Release(s); return FALSE; } winpr_RAND(buffer, payloadLength); Stream_Write(s, buffer, payloadLength); } } bResult = rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ); if (!bResult) { Stream_Release(s); } free(buffer); return bResult; }
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 */ }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT remdesk_send_ctl_verify_password_pdu(remdeskPlugin* remdesk) { int status; UINT error; wStream* s; int cbExpertBlobW = 0; WCHAR* expertBlobW = NULL; REMDESK_CTL_VERIFY_PASSWORD_PDU pdu; if ((error = remdesk_generate_expert_blob(remdesk))) { WLog_ERR(TAG, "remdesk_generate_expert_blob failed with error %lu!", error); return error; } pdu.expertBlob = remdesk->ExpertBlob; status = ConvertToUnicode(CP_UTF8, 0, pdu.expertBlob, -1, &expertBlobW, 0); if (status <= 0) { WLog_ERR(TAG, "ConvertToUnicode failed!"); return ERROR_INTERNAL_ERROR; } cbExpertBlobW = status * 2; remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_VERIFY_PASSWORD, cbExpertBlobW); s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto out; } remdesk_write_ctl_header(s, &(pdu.ctlHeader)); Stream_Write(s, (BYTE*) expertBlobW, cbExpertBlobW); Stream_SealLength(s); if ((error = remdesk_virtual_channel_write(remdesk, s))) WLog_ERR(TAG, "remdesk_virtual_channel_write failed with error %lu!", error); out: free(expertBlobW); if (error != CHANNEL_RC_OK) Stream_Free(s, TRUE); return error; }
BOOL license_write_platform_challenge_response_packet(rdpLicense* license, wStream* s, BYTE* macData) { if (!license_write_binary_blob(s, license->EncryptedPlatformChallenge) || /* EncryptedPlatformChallengeResponse */ !license_write_binary_blob(s, license->EncryptedHardwareId) || /* EncryptedHWID */ !Stream_EnsureRemainingCapacity(s, 16)) { return FALSE; } Stream_Write(s, macData, 16); /* MACData */ return TRUE; }
static void serial_process_irp_read(SERIAL_DEVICE* serial, IRP* irp) { SERIAL_TTY* tty; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); DEBUG_SVC("length %u offset %llu", Length, Offset); tty = serial->tty; if (tty == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("tty not valid."); } else { buffer = (BYTE*) malloc(Length); if (!serial_tty_read(tty, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; DEBUG_WARN("read %s(%d) failed.", serial->path, tty->id); } else { DEBUG_SVC("read %llu-%llu from %d", Offset, Offset + Length, tty->id); } } Stream_Write_UINT32(irp->output, Length); if (Length > 0) { Stream_EnsureRemainingCapacity(irp->output, Length); Stream_Write(irp->output, buffer, Length); } free(buffer); irp->Complete(irp); }
static BOOL rdg_process_keep_alive_packet(rdpRdg* rdg) { int status; wStream* sChunk; int packetSize = 8; char chunkSize[11]; sprintf_s(chunkSize, sizeof(chunkSize), "%X\r\n", packetSize); sChunk = Stream_New(NULL, strlen(chunkSize) + packetSize + 2); if (!sChunk) return FALSE; Stream_Write(sChunk, chunkSize, strlen(chunkSize)); Stream_Write_UINT16(sChunk, PKT_TYPE_KEEPALIVE); /* Type */ Stream_Write_UINT16(sChunk, 0); /* Reserved */ Stream_Write_UINT32(sChunk, packetSize); /* Packet length */ 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); return (status < 0 ? FALSE : TRUE); }
static void drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else { buffer = (BYTE*) malloc(Length); if (!drive_file_read(file, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; } else { } } Stream_Write_UINT32(irp->output, Length); if (Length > 0) { Stream_EnsureRemainingCapacity(irp->output, (int) Length); Stream_Write(irp->output, buffer, Length); } free(buffer); irp->Complete(irp); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT rail_send_channel_data(railPlugin* rail, void* data, size_t length) { wStream* s = NULL; s = Stream_New(NULL, length); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); return CHANNEL_RC_NO_MEMORY; } Stream_Write(s, data, length); return rail_send(rail, s); }
static BOOL rdg_write_packet(rdpRdg* rdg, wStream* sPacket) { int status; wStream* sChunk; char chunkSize[11]; sprintf_s(chunkSize, sizeof(chunkSize), "%"PRIXz"\r\n", Stream_Length(sPacket)); sChunk = Stream_New(NULL, strlen(chunkSize) + Stream_Length(sPacket) + 2); if (!sChunk) return FALSE; Stream_Write(sChunk, chunkSize, strlen(chunkSize)); Stream_Write(sChunk, Stream_Buffer(sPacket), Stream_Length(sPacket)); 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 FALSE; return TRUE; }
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; }
BOOL rdpsnd_server_send_formats(RdpsndServerContext* context, wStream* s) { int pos; UINT16 i; BOOL status; ULONG written; Stream_Write_UINT8(s, SNDC_FORMATS); Stream_Write_UINT8(s, 0); Stream_Seek_UINT16(s); Stream_Write_UINT32(s, 0); /* dwFlags */ Stream_Write_UINT32(s, 0); /* dwVolume */ Stream_Write_UINT32(s, 0); /* dwPitch */ Stream_Write_UINT16(s, 0); /* wDGramPort */ Stream_Write_UINT16(s, context->num_server_formats); /* wNumberOfFormats */ Stream_Write_UINT8(s, context->block_no); /* cLastBlockConfirmed */ Stream_Write_UINT16(s, 0x06); /* wVersion */ Stream_Write_UINT8(s, 0); /* bPad */ for (i = 0; i < context->num_server_formats; i++) { Stream_Write_UINT16(s, context->server_formats[i].wFormatTag); /* wFormatTag (WAVE_FORMAT_PCM) */ Stream_Write_UINT16(s, context->server_formats[i].nChannels); /* nChannels */ Stream_Write_UINT32(s, context->server_formats[i].nSamplesPerSec); /* nSamplesPerSec */ Stream_Write_UINT32(s, context->server_formats[i].nSamplesPerSec * context->server_formats[i].nChannels * context->server_formats[i].wBitsPerSample / 8); /* nAvgBytesPerSec */ Stream_Write_UINT16(s, context->server_formats[i].nBlockAlign); /* nBlockAlign */ Stream_Write_UINT16(s, context->server_formats[i].wBitsPerSample); /* wBitsPerSample */ Stream_Write_UINT16(s, context->server_formats[i].cbSize); /* cbSize */ if (context->server_formats[i].cbSize > 0) { Stream_Write(s, context->server_formats[i].data, context->server_formats[i].cbSize); } } 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; }
static void guac_rdpdr_device_printer_announce_handler(guac_rdpdr_device* device, wStream* output_stream, int device_id) { /* Printer header */ guac_client_log(device->rdpdr->client, GUAC_LOG_INFO, "Sending printer"); Stream_Write_UINT32(output_stream, RDPDR_DTYP_PRINT); Stream_Write_UINT32(output_stream, device_id); Stream_Write(output_stream, "PRN1\0\0\0\0", 8); /* DOS name */ /* Printer data */ Stream_Write_UINT32(output_stream, 24 + GUAC_PRINTER_DRIVER_LENGTH + GUAC_PRINTER_NAME_LENGTH); Stream_Write_UINT32(output_stream, RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER | RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER); Stream_Write_UINT32(output_stream, 0); /* reserved - must be 0 */ Stream_Write_UINT32(output_stream, 0); /* PnPName length (PnPName is ultimately ignored) */ Stream_Write_UINT32(output_stream, GUAC_PRINTER_DRIVER_LENGTH); /* DriverName length */ Stream_Write_UINT32(output_stream, GUAC_PRINTER_NAME_LENGTH); /* PrinterName length */ Stream_Write_UINT32(output_stream, 0); /* CachedFields length */ Stream_Write(output_stream, GUAC_PRINTER_DRIVER, GUAC_PRINTER_DRIVER_LENGTH); Stream_Write(output_stream, GUAC_PRINTER_NAME, GUAC_PRINTER_NAME_LENGTH); }
/** * Function description * Write RFX_AVC420_BITMAP_STREAM structure to stream * * @return 0 on success, otherwise a Win32 error code */ static INLINE UINT rdpgfx_write_h264_avc420(wStream* s, RDPGFX_AVC420_BITMAP_STREAM* havc420) { UINT error = CHANNEL_RC_OK; if ((error = rdpgfx_write_h264_metablock(s, &(havc420->meta)))) { WLog_ERR(TAG, "rdpgfx_write_h264_metablock failed with error %u!", error); return error; } Stream_Write(s, havc420->data, havc420->length); return error; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) { UINT32 Length; UINT64 Offset; ssize_t status; BYTE* buffer = NULL; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); buffer = (BYTE*) malloc(Length); if (!buffer) { WLog_ERR(TAG, "malloc failed!"); return CHANNEL_RC_NO_MEMORY; } status = read(parallel->file, buffer, Length); if (status < 0) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; } else { } Stream_Write_UINT32(irp->output, Length); if (Length > 0) { if (!Stream_EnsureRemainingCapacity(irp->output, Length)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); free(buffer); return CHANNEL_RC_NO_MEMORY; } Stream_Write(irp->output, buffer, Length); } free(buffer); return irp->Complete(irp); }