void rdp_read_surface_commands_capability_set(STREAM* s, rdpSettings* settings) { stream_seek_uint32(s); /* cmdFlags (4 bytes) */ stream_seek_uint32(s); /* reserved (4 bytes) */ settings->surface_commands = True; }
void rts_flow_control_ack_command_read(rdpRpc* rpc, STREAM* s) { /* Ack (24 bytes) */ stream_seek_uint32(s); /* BytesReceived (4 bytes) */ stream_seek_uint32(s); /* AvailableWindow (4 bytes) */ stream_seek(s, 16); /* ChannelCookie (16 bytes) */ }
void rdp_read_order_capability_set(STREAM* s, rdpSettings* settings) { int i; uint16 orderFlags; uint8 orderSupport[32]; uint16 orderSupportExFlags; stream_seek(s, 16); /* terminalDescriptor (16 bytes) */ stream_seek_uint32(s); /* pad4OctetsA (4 bytes) */ stream_seek_uint16(s); /* desktopSaveXGranularity (2 bytes) */ stream_seek_uint16(s); /* desktopSaveYGranularity (2 bytes) */ stream_seek_uint16(s); /* pad2OctetsA (2 bytes) */ stream_seek_uint16(s); /* maximumOrderLevel (2 bytes) */ stream_seek_uint16(s); /* numberFonts (2 bytes) */ stream_read_uint16(s, orderFlags); /* orderFlags (2 bytes) */ stream_read(s, orderSupport, 32); /* orderSupport (32 bytes) */ stream_seek_uint16(s); /* textFlags (2 bytes) */ stream_read_uint16(s, orderSupportExFlags); /* orderSupportExFlags (2 bytes) */ stream_seek_uint32(s); /* pad4OctetsB (4 bytes) */ stream_seek_uint32(s); /* desktopSaveSize (4 bytes) */ stream_seek_uint16(s); /* pad2OctetsC (2 bytes) */ stream_seek_uint16(s); /* pad2OctetsD (2 bytes) */ stream_seek_uint16(s); /* textANSICodePage (2 bytes) */ stream_seek_uint16(s); /* pad2OctetsE (2 bytes) */ for (i = 0; i < 32; i++) { if (orderSupport[i] == False) settings->order_support[i] = False; } }
/* http://msdn.microsoft.com/en-us/library/dd390700.aspx */ static uint32 tsmf_codec_parse_VIDEOINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, STREAM* s) { /* typedef struct tagVIDEOINFOHEADER { RECT rcSource; //16 RECT rcTarget; //16 32 DWORD dwBitRate; //4 36 DWORD dwBitErrorRate; //4 40 REFERENCE_TIME AvgTimePerFrame; //8 48 BITMAPINFOHEADER bmiHeader; } VIDEOINFOHEADER; */ uint64 AvgTimePerFrame; /* VIDEOINFOHEADER.rcSource, RECT(LONG left, LONG top, LONG right, LONG bottom) */ stream_seek_uint32(s); stream_seek_uint32(s); stream_read_uint32(s, mediatype->Width); stream_read_uint32(s, mediatype->Height); /* VIDEOINFOHEADER.rcTarget */ stream_seek(s, 16); /* VIDEOINFOHEADER.dwBitRate */ stream_read_uint32(s, mediatype->BitRate); /* VIDEOINFOHEADER.dwBitErrorRate */ stream_seek_uint32(s); /* VIDEOINFOHEADER.AvgTimePerFrame */ stream_read_uint64(s, AvgTimePerFrame); mediatype->SamplesPerSecond.Numerator = 1000000; mediatype->SamplesPerSecond.Denominator = (int)(AvgTimePerFrame / 10LL); return 48; }
void rdp_recv_logon_info_v2(rdpRdp* rdp, STREAM* s) { uint32 cbDomain; uint32 cbUserName; stream_seek_uint16(s); /* version (2 bytes) */ stream_seek_uint32(s); /* size (4 bytes) */ stream_seek_uint32(s); /* sessionId (4 bytes) */ stream_read_uint32(s, cbDomain); /* cbDomain (4 bytes) */ stream_read_uint32(s, cbUserName); /* cbUserName (4 bytes) */ stream_seek(s, 558); /* pad */ stream_seek(s, cbDomain); /* domain */ stream_seek(s, cbUserName); /* userName */ }
void rdp_read_glyph_cache_capability_set(STREAM* s, rdpSettings* settings) { stream_seek(s, 40); /* glyphCache (40 bytes) */ stream_seek_uint32(s); /* fragCache (4 bytes) */ stream_seek_uint16(s); /* glyphSupportLevel (2 bytes) */ stream_seek_uint16(s); /* pad2Octets (2 bytes) */ }
void cliprdr_process_long_format_names(cliprdrPlugin* cliprdr, STREAM* s, uint32 length, uint16 flags) { int num_formats; uint8* start_mark; uint8* end_mark; CLIPRDR_FORMAT_NAME* format_name; num_formats = 0; stream_get_mark(s, start_mark); stream_get_mark(s, end_mark); end_mark += length; while (s->p < end_mark) { stream_seek_uint32(s); stream_seek(s, 32); num_formats++; } stream_set_mark(s, start_mark); cliprdr->format_names = (CLIPRDR_FORMAT_NAME*) xmalloc(sizeof(CLIPRDR_FORMAT_NAME) * num_formats); cliprdr->num_format_names = num_formats; num_formats = 0; while (s->p < end_mark) { format_name = &cliprdr->format_names[num_formats++]; stream_read_uint32(s, format_name->id); format_name->name = freerdp_uniconv_in(cliprdr->uniconv, s->p, 32); format_name->length = strlen(format_name->name); stream_seek(s, 32); } }
static uint32 handle_EstablishContext(IRP* irp) { uint32 len, rv; uint32 scope; SCARDCONTEXT hContext = -1; stream_seek(irp->input, 8); stream_read_uint32(irp->input, len); if (len != 8) return SCARD_F_INTERNAL_ERROR; stream_seek_uint32(irp->input); stream_read_uint32(irp->input, scope); rv = SCardEstablishContext(scope, NULL, NULL, &hContext); stream_write_uint32(irp->output, 4); // ? stream_write_uint32(irp->output, -1); // ? stream_write_uint32(irp->output, 4); stream_write_uint32(irp->output, hContext); /* TODO: store hContext in allowed context list */ return SCARD_S_SUCCESS; }
static boolean rdpsnd_server_recv_formats(rdpsnd_server* rdpsnd, STREAM* s) { int i; if (stream_get_left(s) < 20) return false; stream_seek_uint32(s); /* dwFlags */ stream_seek_uint32(s); /* dwVolume */ stream_seek_uint32(s); /* dwPitch */ stream_seek_uint16(s); /* wDGramPort */ stream_read_uint16(s, rdpsnd->context.num_client_formats); /* wNumberOfFormats */ stream_seek_uint8(s); /* cLastBlockConfirmed */ stream_seek_uint16(s); /* wVersion */ stream_seek_uint8(s); /* bPad */ if (rdpsnd->context.num_client_formats > 0) { rdpsnd->context.client_formats = xzalloc(rdpsnd->context.num_client_formats * sizeof(rdpsndFormat)); for (i = 0; i < rdpsnd->context.num_client_formats; i++) { if (stream_get_left(s) < 18) { xfree(rdpsnd->context.client_formats); rdpsnd->context.client_formats = NULL; return false; } stream_read_uint16(s, rdpsnd->context.client_formats[i].wFormatTag); stream_read_uint16(s, rdpsnd->context.client_formats[i].nChannels); stream_read_uint32(s, rdpsnd->context.client_formats[i].nSamplesPerSec); stream_seek_uint32(s); /* nAvgBytesPerSec */ stream_read_uint16(s, rdpsnd->context.client_formats[i].nBlockAlign); stream_read_uint16(s, rdpsnd->context.client_formats[i].wBitsPerSample); stream_read_uint16(s, rdpsnd->context.client_formats[i].cbSize); if (rdpsnd->context.client_formats[i].cbSize > 0) { stream_seek(s, rdpsnd->context.client_formats[i].cbSize); } } } return true; }
boolean rdp_recv_control_pdu(STREAM* s, uint16* action) { if (stream_get_left(s) < 8) return false; stream_read_uint16(s, *action); /* action (2 bytes) */ stream_seek_uint16(s); /* grantId (2 bytes) */ stream_seek_uint32(s); /* controlId (4 bytes) */ return true; }
void rdp_recv_logon_info_v1(rdpRdp* rdp, STREAM* s) { uint32 cbDomain; uint32 cbUserName; stream_read_uint32(s, cbDomain); /* cbDomain (4 bytes) */ stream_seek(s, 52); /* domain (52 bytes) */ stream_read_uint32(s, cbUserName); /* cbUserName (4 bytes) */ stream_seek(s, 512); /* userName (512 bytes) */ stream_seek_uint32(s); /* sessionId (4 bytes) */ }
static boolean audin_server_recv_formats(audin_server* audin, STREAM* s, uint32 length) { int i; if (length < 8) return false; stream_read_uint32(s, audin->context.num_client_formats); /* NumFormats (4 bytes) */ stream_seek_uint32(s); /* cbSizeFormatsPacket (4 bytes) */ length -= 8; if (audin->context.num_client_formats <= 0) return false; audin->context.client_formats = xzalloc(audin->context.num_client_formats * sizeof(rdpsndFormat)); for (i = 0; i < audin->context.num_client_formats; i++) { if (length < 18) { xfree(audin->context.client_formats); audin->context.client_formats = NULL; return false; } stream_read_uint16(s, audin->context.client_formats[i].wFormatTag); stream_read_uint16(s, audin->context.client_formats[i].nChannels); stream_read_uint32(s, audin->context.client_formats[i].nSamplesPerSec); stream_seek_uint32(s); /* nAvgBytesPerSec */ stream_read_uint16(s, audin->context.client_formats[i].nBlockAlign); stream_read_uint16(s, audin->context.client_formats[i].wBitsPerSample); stream_read_uint16(s, audin->context.client_formats[i].cbSize); if (audin->context.client_formats[i].cbSize > 0) { stream_seek(s, audin->context.client_formats[i].cbSize); } } IFCALL(audin->context.Opening, &audin->context); return true; }
/* http://msdn.microsoft.com/en-us/library/dd407326.aspx */ static uint32 tsmf_codec_parse_VIDEOINFOHEADER2(TS_AM_MEDIA_TYPE* mediatype, STREAM* s) { uint64 AvgTimePerFrame; /* VIDEOINFOHEADER2.rcSource, RECT(LONG left, LONG top, LONG right, LONG bottom) */ stream_seek_uint32(s); stream_seek_uint32(s); stream_read_uint32(s, mediatype->Width); stream_read_uint32(s, mediatype->Height); /* VIDEOINFOHEADER2.rcTarget */ stream_seek(s, 16); /* VIDEOINFOHEADER2.dwBitRate */ stream_read_uint32(s, mediatype->BitRate); /* VIDEOINFOHEADER2.dwBitErrorRate */ stream_seek_uint32(s); /* VIDEOINFOHEADER2.AvgTimePerFrame */ stream_read_uint64(s, AvgTimePerFrame); mediatype->SamplesPerSecond.Numerator = 1000000; mediatype->SamplesPerSecond.Denominator = (int)(AvgTimePerFrame / 10LL); /* Remaining fields before bmiHeader */ stream_seek(s, 24); return 72; }
void rdp_read_draw_gdiplus_cache_capability_set(STREAM* s, rdpSettings* settings) { uint32 drawGDIPlusSupportLevel; uint32 drawGdiplusCacheLevel; stream_read_uint32(s, drawGDIPlusSupportLevel); /* drawGDIPlusSupportLevel (4 bytes) */ stream_seek_uint32(s); /* GdipVersion (4 bytes) */ stream_read_uint32(s, drawGdiplusCacheLevel); /* drawGdiplusCacheLevel (4 bytes) */ stream_seek(s, 10); /* GdipCacheEntries (10 bytes) */ stream_seek(s, 8); /* GdipCacheChunkSize (8 bytes) */ stream_seek(s, 6); /* GdipImageCacheProperties (6 bytes) */ if (drawGDIPlusSupportLevel & DRAW_GDIPLUS_SUPPORTED) settings->draw_gdi_plus = True; if (drawGdiplusCacheLevel & DRAW_GDIPLUS_CACHE_LEVEL_ONE) settings->draw_gdi_plus_cache = True; }
void rdp_read_bitmap_cache_capability_set(STREAM* s, rdpSettings* settings) { stream_seek_uint32(s); /* pad1 (4 bytes) */ stream_seek_uint32(s); /* pad2 (4 bytes) */ stream_seek_uint32(s); /* pad3 (4 bytes) */ stream_seek_uint32(s); /* pad4 (4 bytes) */ stream_seek_uint32(s); /* pad5 (4 bytes) */ stream_seek_uint32(s); /* pad6 (4 bytes) */ stream_seek_uint16(s); /* Cache0Entries (2 bytes) */ stream_seek_uint16(s); /* Cache0MaximumCellSize (2 bytes) */ stream_seek_uint16(s); /* Cache1Entries (2 bytes) */ stream_seek_uint16(s); /* Cache1MaximumCellSize (2 bytes) */ stream_seek_uint16(s); /* Cache2Entries (2 bytes) */ stream_seek_uint16(s); /* Cache2MaximumCellSize (2 bytes) */ }
static void rfx_compose_message_tile(RFX_CONTEXT* context, STREAM* s, uint8* 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_check_size(s, 19); start_pos = stream_get_pos(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_get_pos(s); stream_set_pos(s, start_pos + 2); stream_write_uint32(s, 19 + YLen + CbLen + CrLen); /* BlockT.blockLen */ stream_set_pos(s, start_pos + 13); stream_write_uint16(s, YLen); stream_write_uint16(s, CbLen); stream_write_uint16(s, CrLen); stream_set_pos(s, end_pos); }
boolean rdp_read_extended_info_packet(STREAM* s, rdpSettings* settings) { uint16 clientAddressFamily; uint16 cbClientAddress; uint16 cbClientDir; uint16 cbAutoReconnectLen; stream_read_uint16(s, clientAddressFamily); /* clientAddressFamily */ stream_read_uint16(s, cbClientAddress); /* cbClientAddress */ settings->ipv6 = (clientAddressFamily == ADDRESS_FAMILY_INET6 ? true : false); if (stream_get_left(s) < cbClientAddress) return false; settings->ip_address = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), cbClientAddress); stream_seek(s, cbClientAddress); stream_read_uint16(s, cbClientDir); /* cbClientDir */ if (stream_get_left(s) < cbClientDir) return false; if (settings->client_dir) xfree(settings->client_dir); settings->client_dir = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), cbClientDir); stream_seek(s, cbClientDir); if (!rdp_read_client_time_zone(s, settings)) return false; stream_seek_uint32(s); /* clientSessionId, should be set to 0 */ stream_read_uint32(s, settings->performance_flags); /* performanceFlags */ stream_read_uint16(s, cbAutoReconnectLen); /* cbAutoReconnectLen */ if (cbAutoReconnectLen > 0) return rdp_read_client_auto_reconnect_cookie(s, settings); /* autoReconnectCookie */ /* reserved1 (2 bytes) */ /* reserved2 (2 bytes) */ return true; }
IRP* irp_new(DEVMAN* devman, STREAM* data_in) { IRP* irp; uint32 DeviceId; DEVICE* device; stream_read_uint32(data_in, DeviceId); device = devman_get_device_by_id(devman, DeviceId); if (device == NULL) { DEBUG_WARN("unknown DeviceId %d", DeviceId); return NULL; } irp = xnew(IRP); irp->device = device; irp->devman = devman; stream_read_uint32(data_in, irp->FileId); stream_read_uint32(data_in, irp->CompletionId); stream_read_uint32(data_in, irp->MajorFunction); stream_read_uint32(data_in, irp->MinorFunction); irp->input = data_in; irp->output = stream_new(256); stream_write_uint16(irp->output, RDPDR_CTYP_CORE); stream_write_uint16(irp->output, PAKID_CORE_DEVICE_IOCOMPLETION); stream_write_uint32(irp->output, DeviceId); stream_write_uint32(irp->output, irp->CompletionId); stream_seek_uint32(irp->output); /* IoStatus */ irp->Complete = irp_complete; irp->Discard = irp_free; DEBUG_SVC("DeviceId %d FileId %d CompletionId %d MajorFunction 0x%X MinorFunction 0x%x", irp->device->id, irp->FileId, irp->CompletionId, irp->MajorFunction, irp->MinorFunction); return irp; }
void update_read_palette(rdpUpdate* update, STREAM* s, PALETTE_UPDATE* palette_update) { int i; uint8 byte; uint32 color; stream_seek_uint16(s); /* pad2Octets (2 bytes) */ stream_seek_uint32(palette_update->number); /* numberColors (4 bytes), must be set to 256 */ if (palette_update->number > 256) palette_update->number = 256; /* paletteEntries */ for (i = 0; i < palette_update->number; i++) { stream_read_uint8(s, byte); color = byte; stream_read_uint8(s, byte); color |= (byte << 8); stream_read_uint8(s, byte); color |= (byte << 16); palette_update->entries[i] = color; } }
static void rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, boolean user_loggedon) { STREAM* data_out; DEVICE* device; LIST_ITEM* item; uint32 count; uint8 c; int data_len; int i; int count_pos; int pos; data_out = stream_new(256); stream_write_uint16(data_out, RDPDR_CTYP_CORE); stream_write_uint16(data_out, PAKID_CORE_DEVICELIST_ANNOUNCE); count_pos = stream_get_pos(data_out); count = 0; stream_seek_uint32(data_out); /* deviceCount */ for (item = rdpdr->devman->devices->head; item; item = item->next) { device = (DEVICE*)item->data; /** * 1. versionMinor 0x0005 doesn't send PAKID_CORE_USER_LOGGEDON * so all devices should be sent regardless of user_loggedon * 2. smartcard devices should be always sent * 3. other devices are sent only after user_loggedon */ if (rdpdr->versionMinor == 0x0005 || device->type == RDPDR_DTYP_SMARTCARD || user_loggedon) { data_len = (device->data == NULL ? 0 : stream_get_length(device->data)); stream_check_size(data_out, 20 + data_len); stream_write_uint32(data_out, device->type); /* deviceType */ stream_write_uint32(data_out, device->id); /* deviceID */ strncpy((char*)stream_get_tail(data_out), device->name, 8); for (i = 0; i < 8; i++) { stream_peek_uint8(data_out, c); if (c > 0x7F) stream_write_uint8(data_out, '_'); else stream_seek_uint8(data_out); } stream_write_uint32(data_out, data_len); if (data_len > 0) stream_write(data_out, stream_get_data(device->data), data_len); count++; printf("registered device #%d: %s (type=%d id=%d)\n", count, device->name, device->type, device->id); } } pos = stream_get_pos(data_out); stream_set_pos(data_out, count_pos); stream_write_uint32(data_out, count); stream_set_pos(data_out, pos); stream_seal(data_out); svc_plugin_send((rdpSvcPlugin*)rdpdr, data_out); }
/* receives a list of server supported formats and returns a list of client supported formats */ static void rdpsnd_process_message_formats(rdpsndPlugin* rdpsnd, STREAM* data_in) { uint16 wNumberOfFormats; uint16 nFormat; uint16 wVersion; STREAM* data_out; rdpsndFormat* out_formats; uint16 n_out_formats; rdpsndFormat* format; uint8* format_mark; uint8* data_mark; int pos; rdpsnd_free_supported_formats(rdpsnd); stream_seek_uint32(data_in); /* dwFlags */ stream_seek_uint32(data_in); /* dwVolume */ stream_seek_uint32(data_in); /* dwPitch */ stream_seek_uint16(data_in); /* wDGramPort */ stream_read_uint16(data_in, wNumberOfFormats); stream_read_uint8(data_in, rdpsnd->cBlockNo); /* cLastBlockConfirmed */ stream_read_uint16(data_in, wVersion); stream_seek_uint8(data_in); /* bPad */ DEBUG_SVC("wNumberOfFormats %d wVersion %d", wNumberOfFormats, wVersion); if (wNumberOfFormats < 1) { DEBUG_WARN("wNumberOfFormats is 0"); return; } out_formats = (rdpsndFormat*)xzalloc(wNumberOfFormats * sizeof(rdpsndFormat)); n_out_formats = 0; data_out = stream_new(24); stream_write_uint8(data_out, SNDC_FORMATS); /* msgType */ stream_write_uint8(data_out, 0); /* bPad */ stream_seek_uint16(data_out); /* BodySize */ stream_write_uint32(data_out, TSSNDCAPS_ALIVE | TSSNDCAPS_VOLUME); /* dwFlags */ stream_write_uint32(data_out, 0xFFFFFFFF); /* dwVolume */ stream_write_uint32(data_out, 0); /* dwPitch */ stream_write_uint16_be(data_out, 0); /* wDGramPort */ stream_seek_uint16(data_out); /* wNumberOfFormats */ stream_write_uint8(data_out, 0); /* cLastBlockConfirmed */ stream_write_uint16(data_out, 6); /* wVersion */ stream_write_uint8(data_out, 0); /* bPad */ for (nFormat = 0; nFormat < wNumberOfFormats; nFormat++) { stream_get_mark(data_in, format_mark); format = &out_formats[n_out_formats]; stream_read_uint16(data_in, format->wFormatTag); stream_read_uint16(data_in, format->nChannels); stream_read_uint32(data_in, format->nSamplesPerSec); stream_seek_uint32(data_in); /* nAvgBytesPerSec */ stream_read_uint16(data_in, format->nBlockAlign); stream_read_uint16(data_in, format->wBitsPerSample); stream_read_uint16(data_in, format->cbSize); stream_get_mark(data_in, data_mark); stream_seek(data_in, format->cbSize); format->data = NULL; DEBUG_SVC("wFormatTag=%d nChannels=%d nSamplesPerSec=%d nBlockAlign=%d wBitsPerSample=%d", format->wFormatTag, format->nChannels, format->nSamplesPerSec, format->nBlockAlign, format->wBitsPerSample); if (rdpsnd->fixed_format > 0 && rdpsnd->fixed_format != format->wFormatTag) continue; if (rdpsnd->fixed_channel > 0 && rdpsnd->fixed_channel != format->nChannels) continue; if (rdpsnd->fixed_rate > 0 && rdpsnd->fixed_rate != format->nSamplesPerSec) continue; if (rdpsnd->device && rdpsnd->device->FormatSupported(rdpsnd->device, format)) { DEBUG_SVC("format supported."); stream_check_size(data_out, 18 + format->cbSize); stream_write(data_out, format_mark, 18 + format->cbSize); if (format->cbSize > 0) { format->data = xmalloc(format->cbSize); memcpy(format->data, data_mark, format->cbSize); } n_out_formats++; } } rdpsnd->n_supported_formats = n_out_formats; if (n_out_formats > 0) { rdpsnd->supported_formats = out_formats; } else { xfree(out_formats); DEBUG_WARN("no formats supported"); } pos = stream_get_pos(data_out); stream_set_pos(data_out, 2); stream_write_uint16(data_out, pos - 4); stream_set_pos(data_out, 18); stream_write_uint16(data_out, n_out_formats); stream_set_pos(data_out, pos); svc_plugin_send((rdpSvcPlugin*)rdpsnd, data_out); if (wVersion >= 6) { data_out = stream_new(8); stream_write_uint8(data_out, SNDC_QUALITYMODE); /* msgType */ stream_write_uint8(data_out, 0); /* bPad */ stream_write_uint16(data_out, 4); /* BodySize */ stream_write_uint16(data_out, HIGH_QUALITY); /* wQualityMode */ stream_write_uint16(data_out, 0); /* Reserved */ svc_plugin_send((rdpSvcPlugin*)rdpsnd, data_out); } }
void rdp_read_server_control_pdu(STREAM* s, uint16* action) { stream_read_uint16(s, *action); /* action (2 bytes) */ stream_seek_uint16(s); /* grantId (2 bytes) */ stream_seek_uint32(s); /* controlId (4 bytes) */ }
boolean gcc_read_client_core_data(STREAM* s, rdpSettings *settings, uint16 blockLength) { uint32 version; uint16 colorDepth = 0; uint16 postBeta2ColorDepth = 0; uint16 highColorDepth = 0; uint16 supportedColorDepths = 0; uint16 earlyCapabilityFlags = 0; uint32 serverSelectedProtocol = 0; char* str; /* Length of all required fields, until imeFileName */ if (blockLength < 128) return false; stream_read_uint32(s, version); /* version */ settings->rdp_version = (version == RDP_VERSION_4 ? 4 : 7); stream_read_uint16(s, settings->width); /* desktopWidth */ stream_read_uint16(s, settings->height); /* desktopHeight */ stream_read_uint16(s, colorDepth); /* colorDepth */ stream_seek_uint16(s); /* SASSequence (Secure Access Sequence) */ stream_read_uint32(s, settings->kbd_layout); /* keyboardLayout */ stream_read_uint32(s, settings->client_build); /* clientBuild */ /* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */ str = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), 32); stream_seek(s, 32); snprintf(settings->client_hostname, sizeof(settings->client_hostname), "%s", str); xfree(str); stream_read_uint32(s, settings->kbd_type); /* keyboardType */ stream_read_uint32(s, settings->kbd_subtype); /* keyboardSubType */ stream_read_uint32(s, settings->kbd_fn_keys); /* keyboardFunctionKey */ stream_seek(s, 64); /* imeFileName */ blockLength -= 128; /** * The following fields are all optional. If one field is present, all of the preceding * fields MUST also be present. If one field is not present, all of the subsequent fields * MUST NOT be present. * We must check the bytes left before reading each field. */ do { if (blockLength < 2) break; stream_read_uint16(s, postBeta2ColorDepth); /* postBeta2ColorDepth */ blockLength -= 2; if (blockLength < 2) break; stream_seek_uint16(s); /* clientProductID */ blockLength -= 2; if (blockLength < 4) break; stream_seek_uint32(s); /* serialNumber */ blockLength -= 4; if (blockLength < 2) break; stream_read_uint16(s, highColorDepth); /* highColorDepth */ blockLength -= 2; if (blockLength < 2) break; stream_read_uint16(s, supportedColorDepths); /* supportedColorDepths */ blockLength -= 2; if (blockLength < 2) break; stream_read_uint16(s, earlyCapabilityFlags); /* earlyCapabilityFlags */ blockLength -= 2; if (blockLength < 64) break; str = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), 64); stream_seek(s, 64); snprintf(settings->client_product_id, sizeof(settings->client_product_id), "%s", str); xfree(str); blockLength -= 64; if (blockLength < 1) break; stream_read_uint8(s, settings->performance_flags); /* connectionType */ blockLength -= 1; if (blockLength < 1) break; stream_seek_uint8(s); /* pad1octet */ blockLength -= 1; if (blockLength < 4) break; stream_read_uint32(s, serverSelectedProtocol); /* serverSelectedProtocol */ blockLength -= 4; if (settings->selected_protocol != serverSelectedProtocol) return false; } while (0); if (highColorDepth > 0) settings->color_depth = highColorDepth; else if (postBeta2ColorDepth > 0) { switch (postBeta2ColorDepth) { case RNS_UD_COLOR_4BPP: settings->color_depth = 4; break; case RNS_UD_COLOR_8BPP: settings->color_depth = 8; break; case RNS_UD_COLOR_16BPP_555: settings->color_depth = 15; break; case RNS_UD_COLOR_16BPP_565: settings->color_depth = 16; break; case RNS_UD_COLOR_24BPP: settings->color_depth = 24; break; default: return false; } } else { switch (colorDepth) { case RNS_UD_COLOR_4BPP: settings->color_depth = 4; break; case RNS_UD_COLOR_8BPP: settings->color_depth = 8; break; default: return false; } } return true; }
boolean rdp_read_info_packet(STREAM* s, rdpSettings* settings) { uint32 flags; uint16 cbDomain; uint16 cbUserName; uint16 cbPassword; uint16 cbAlternateShell; uint16 cbWorkingDir; stream_seek_uint32(s); /* CodePage */ stream_read_uint32(s, flags); /* flags */ settings->autologon = ((flags & INFO_AUTOLOGON) ? true : false); settings->remote_app = ((flags & INFO_RAIL) ? true : false); settings->console_audio = ((flags & INFO_REMOTECONSOLEAUDIO) ? true : false); settings->compression = ((flags & INFO_COMPRESSION) ? true : false); stream_read_uint16(s, cbDomain); /* cbDomain */ stream_read_uint16(s, cbUserName); /* cbUserName */ stream_read_uint16(s, cbPassword); /* cbPassword */ stream_read_uint16(s, cbAlternateShell); /* cbAlternateShell */ stream_read_uint16(s, cbWorkingDir); /* cbWorkingDir */ if (stream_get_left(s) < cbDomain + 2) return false; if (cbDomain > 0) { settings->domain = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), cbDomain); stream_seek(s, cbDomain); } stream_seek(s, 2); if (stream_get_left(s) < cbUserName + 2) return false; if (cbUserName > 0) { settings->username = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), cbUserName); stream_seek(s, cbUserName); } stream_seek(s, 2); if (stream_get_left(s) < cbPassword + 2) return false; if (cbPassword > 0) { settings->password = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), cbPassword); stream_seek(s, cbPassword); } stream_seek(s, 2); if (stream_get_left(s) < cbAlternateShell + 2) return false; if (cbAlternateShell > 0) { settings->shell = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), cbAlternateShell); stream_seek(s, cbAlternateShell); } stream_seek(s, 2); if (stream_get_left(s) < cbWorkingDir + 2) return false; if (cbWorkingDir > 0) { settings->directory = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), cbWorkingDir); stream_seek(s, cbWorkingDir); } stream_seek(s, 2); if (settings->rdp_version >= 5) return rdp_read_extended_info_packet(s, settings); /* extraInfo */ return true; }
void rdp_read_frame_acknowledge_capability_set(STREAM* s, rdpSettings* settings) { stream_seek_uint32(s); /* (4 bytes) */ }
static uint32 handle_ListReaders(IRP* irp, tbool wide) { uint32 len, rv; SCARDCONTEXT hContext; DWORD dwReaders; char *readerList = NULL, *walker; int elemLength, dataLength; int pos, poslen1, poslen2; stream_seek(irp->input, 8); stream_read_uint32(irp->input, len); stream_seek(irp->input, 0x1c); stream_read_uint32(irp->input, len); if (len != 4) return SCARD_F_INTERNAL_ERROR; stream_read_uint32(irp->input, hContext); /* ignore rest of [MS-RDPESC] 2.2.2.4 ListReaders_Call */ rv = SCARD_S_SUCCESS; #ifdef SCARD_AUTOALLOCATE dwReaders = SCARD_AUTOALLOCATE; rv = SCardListReaders(hContext, NULL, (LPSTR) &readerList, &dwReaders); #else rv = SCardListReaders(hContext, NULL, NULL, &dwReaders); readerList = xmalloc(dwReaders); rv = SCardListReaders(hContext, NULL, readerList, &dwReaders); #endif if (rv != SCARD_S_SUCCESS) { DEBUG_SCARD("Failure: %s (0x%08x)", pcsc_stringify_error(rv), (unsigned) rv); return rv; } /* DEBUG_SCARD("Success 0x%08x %d %d", (unsigned) hContext, (unsigned) cchReaders, (int) strlen(readerList));*/ poslen1 = stream_get_pos(irp->output); stream_seek_uint32(irp->output); stream_write_uint32(irp->output, 0x01760650); poslen2 = stream_get_pos(irp->output); stream_seek_uint32(irp->output); walker = readerList; dataLength = 0; while (1) { elemLength = strlen(walker); if (elemLength == 0) break; dataLength += sc_output_string(irp, walker, wide); walker += elemLength + 1; elemLength = strlen(walker); } dataLength += sc_output_string(irp, "\0", wide); pos = stream_get_pos(irp->output); stream_set_pos(irp->output, poslen1); stream_write_uint32(irp->output, dataLength); stream_set_pos(irp->output, poslen2); stream_write_uint32(irp->output, dataLength); stream_set_pos(irp->output, pos); sc_output_repos(irp, dataLength); sc_output_alignment(irp, 8); #ifdef SCARD_AUTOALLOCATE SCardFreeMemory(hContext, readerList); #else xfree(readerList); #endif return rv; }
void rdp_read_virtual_channel_capability_set(STREAM* s, rdpSettings* settings) { stream_seek_uint32(s); /* flags (4 bytes) */ stream_read_uint32(s, settings->vc_chunk_size); /* VCChunkSize (4 bytes) */ }
static void rfx_compose_message_tileset(RFX_CONTEXT* context, STREAM* s, uint8* image_data, int width, int height, int rowstride) { int size; int start_pos, end_pos; int i; int numQuants; const uint32* quantVals; const uint32* quantValsPtr; int quantIdxY; int quantIdxCb; int quantIdxCr; int numTiles; int numTilesX; int numTilesY; int xIdx; int yIdx; int tilesDataSize; if (context->num_quants == 0) { numQuants = 1; quantVals = rfx_default_quantization_values; quantIdxY = 0; quantIdxCb = 0; quantIdxCr = 0; } else { numQuants = context->num_quants; quantVals = context->quants; quantIdxY = context->quant_idx_y; quantIdxCb = context->quant_idx_cb; quantIdxCr = context->quant_idx_cr; } numTilesX = (width + 63) / 64; numTilesY = (height + 63) / 64; numTiles = numTilesX * numTilesY; size = 22 + numQuants * 5; stream_check_size(s, size); start_pos = stream_get_pos(s); stream_write_uint16(s, WBT_EXTENSION); /* CodecChannelT.blockType */ stream_seek_uint32(s); /* set CodecChannelT.blockLen later */ stream_write_uint8(s, 1); /* CodecChannelT.codecId */ stream_write_uint8(s, 0); /* CodecChannelT.channelId */ stream_write_uint16(s, CBT_TILESET); /* subtype */ stream_write_uint16(s, 0); /* idx */ stream_write_uint16(s, context->properties); /* properties */ stream_write_uint8(s, numQuants); /* numQuants */ stream_write_uint8(s, 0x40); /* tileSize */ stream_write_uint16(s, numTiles); /* numTiles */ stream_seek_uint32(s); /* set tilesDataSize later */ quantValsPtr = quantVals; for (i = 0; i < numQuants * 5; i++) { stream_write_uint8(s, quantValsPtr[0] + (quantValsPtr[1] << 4)); quantValsPtr += 2; } DEBUG_RFX("width:%d height:%d rowstride:%d", width, height, rowstride); end_pos = stream_get_pos(s); for (yIdx = 0; yIdx < numTilesY; yIdx++) { for (xIdx = 0; xIdx < numTilesX; xIdx++) { rfx_compose_message_tile(context, s, image_data + yIdx * 64 * rowstride + xIdx * 8 * context->bits_per_pixel, (xIdx < numTilesX - 1) ? 64 : width - xIdx * 64, (yIdx < numTilesY - 1) ? 64 : height - yIdx * 64, rowstride, quantVals, quantIdxY, quantIdxCb, quantIdxCr, xIdx, yIdx); } } tilesDataSize = stream_get_pos(s) - end_pos; size += tilesDataSize; end_pos = stream_get_pos(s); stream_set_pos(s, start_pos + 2); stream_write_uint32(s, size); /* CodecChannelT.blockLen */ stream_set_pos(s, start_pos + 18); stream_write_uint32(s, tilesDataSize); stream_set_pos(s, end_pos); }
static uint32 handle_State(IRP* irp) { LONG rv; SCARDHANDLE hCard; DWORD state = 0, protocol = 0; DWORD readerLen; DWORD atrLen = MAX_ATR_SIZE; char * readerName; BYTE pbAtr[MAX_ATR_SIZE]; #ifdef WITH_DEBUG_SCARD int i; #endif stream_seek(irp->input, 0x24); stream_seek_uint32(irp->input); /* atrLen */ stream_seek(irp->input, 0x0c); stream_read_uint32(irp->input, hCard); stream_seek(irp->input, 0x04); #ifdef SCARD_AUTOALLOCATE readerLen = SCARD_AUTOALLOCATE; rv = SCardStatus(hCard, (LPSTR) &readerName, &readerLen, &state, &protocol, pbAtr, &atrLen); #else readerLen = 256; readerName = xmalloc(readerLen); rv = SCardStatus(hCard, (LPSTR) readerName, &readerLen, &state, &protocol, pbAtr, &atrLen); #endif if (rv != SCARD_S_SUCCESS) { DEBUG_SCARD("Failure: %s (0x%08x)", pcsc_stringify_error(rv), (unsigned) rv); return sc_output_return(irp, rv); } DEBUG_SCARD("Success (hcard: 0x%08x len: %d state: 0x%08x, proto: 0x%08x)", (unsigned) hCard, (int) atrLen, (unsigned) state, (unsigned) protocol); #ifdef WITH_DEBUG_SCARD printf(" ATR: "); for (i = 0; i < atrLen; i++) printf("%02x%c", pbAtr[i], (i == atrLen - 1) ? ' ' : ':'); printf("\n"); #endif state = sc_map_state(state); stream_write_uint32(irp->output, state); stream_write_uint32(irp->output, protocol); stream_write_uint32(irp->output, atrLen); stream_write_uint32(irp->output, 0x00000001); stream_write_uint32(irp->output, atrLen); stream_write(irp->output, pbAtr, atrLen); sc_output_repos(irp, atrLen); sc_output_alignment(irp, 8); #ifdef SCARD_AUTOALLOCATE xfree(readerName); #else xfree(readerName); #endif return rv; }
void rdp_read_brush_capability_set(STREAM* s, rdpSettings* settings) { stream_seek_uint32(s); /* brushSupportLevel (4 bytes) */ }