boolean gcc_read_server_core_data(STREAM* s, rdpSettings* settings) { uint32 version; uint32 clientRequestedProtocols; stream_read_uint32(s, version); /* version */ stream_read_uint32(s, clientRequestedProtocols); /* clientRequestedProtocols */ if (version == RDP_VERSION_4 && settings->rdp_version > 4) settings->rdp_version = 4; else if (version == RDP_VERSION_5_PLUS && settings->rdp_version < 5) settings->rdp_version = 7; return true; }
void rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, STREAM* s) { stream_read_uint32(s, rdp->errorInfo); /* errorInfo (4 bytes) */ if (rdp->errorInfo != ERRINFO_SUCCESS) rdp_print_errinfo(rdp->errorInfo); }
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 void printer_process_irp_write(PRINTER_DEVICE* printer_dev, IRP* irp) { rdpPrintJob* printjob = NULL; uint32 Length; uint64 Offset; stream_read_uint32(irp->input, Length); stream_read_uint64(irp->input, Offset); (void) Offset; stream_seek(irp->input, 20); /* Padding */ if (printer_dev->printer != NULL) printjob = printer_dev->printer->FindPrintJob(printer_dev->printer, irp->FileId); if (printjob == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; log_warning("printjob id %d not found.", irp->FileId); } else { printjob->Write(printjob, stream_get_tail(irp->input), Length); log_debug("printjob id %d written %d bytes.", irp->FileId, Length); } stream_write_uint32(irp->output, Length); stream_write_uint8(irp->output, 0); /* Padding */ irp->Complete(irp); }
void test_stream(void) { STREAM * stream; int pos; uint32 n; uint64 n64; stream = stream_new(1); pos = stream_get_pos(stream); stream_write_uint8(stream, 0xFE); stream_check_size(stream, 14); stream_write_uint16(stream, 0x0102); stream_write_uint32(stream, 0x03040506); stream_write_uint64(stream, 0x0708091011121314LL); /* freerdp_hexdump(stream->buffer, 15); */ stream_set_pos(stream, pos); stream_seek(stream, 3); stream_read_uint32(stream, n); stream_read_uint64(stream, n64); CU_ASSERT(n == 0x03040506); CU_ASSERT(n64 == 0x0708091011121314LL); stream_free(stream); }
boolean certificate_read_server_certificate(rdpCertificate* certificate, uint8* server_cert, int length) { STREAM* s; uint32 dwVersion; s = stream_new(0); s->p = s->data = server_cert; if (length < 1) { printf("null server certificate\n"); return false; } stream_read_uint32(s, dwVersion); /* dwVersion (4 bytes) */ switch (dwVersion & CERT_CHAIN_VERSION_MASK) { case CERT_CHAIN_VERSION_1: certificate_read_server_proprietary_certificate(certificate, s); break; case CERT_CHAIN_VERSION_2: certificate_read_server_x509_certificate_chain(certificate, s); break; default: printf("invalid certificate chain version:%d\n", dwVersion & CERT_CHAIN_VERSION_MASK); break; } xfree(s); return true; }
void rts_padding_command_read(rdpRpc* rpc, STREAM* s) { uint32 ConformanceCount; stream_read_uint32(s, ConformanceCount); /* ConformanceCount (4 bytes) */ stream_seek(s, ConformanceCount); /* Padding (variable) */ }
boolean rdp_recv_save_session_info(rdpRdp* rdp, STREAM* s) { uint32 infoType; stream_read_uint32(s, infoType); /* infoType (4 bytes) */ //printf("%s\n", INFO_TYPE_LOGON_STRINGS[infoType]); switch (infoType) { case INFO_TYPE_LOGON: rdp_recv_logon_info_v1(rdp, s); break; case INFO_TYPE_LOGON_LONG: rdp_recv_logon_info_v2(rdp, s); break; case INFO_TYPE_LOGON_PLAIN_NOTIFY: rdp_recv_logon_plain_notify(rdp, s); break; case INFO_TYPE_LOGON_EXTENDED_INF: rdp_recv_logon_info_extended(rdp, s); break; default: break; } return true; }
boolean rdp_recv_deactivate_all(rdpRdp* rdp, STREAM* s) { uint16 lengthSourceDescriptor; /* * Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain * the following fields. */ if (stream_get_left(s) > 0) { stream_read_uint32(s, rdp->settings->share_id); /* shareId (4 bytes) */ stream_read_uint16(s, lengthSourceDescriptor); /* lengthSourceDescriptor (2 bytes) */ stream_seek(s, lengthSourceDescriptor); /* sourceDescriptor (should be 0x00) */ } rdp->state = CONNECTION_STATE_CAPABILITY; while (rdp->state != CONNECTION_STATE_ACTIVE) { if (rdp_check_fds(rdp) < 0) return false; if (rdp->disconnect) break; } return true; }
void rdp_read_window_list_capability_set(STREAM* s, rdpSettings* settings) { // TODO: // 2011-07-27: In current time icon cache is not supported by any // Microsoft implementation of server or client. // // But we must process this values according to 3.2.5.1.4 // uint8 numIconCaches; uint16 numIconCacheEntries; uint32 wndSupportLevel; stream_read_uint32(s, wndSupportLevel); /* wndSupportLevel (4 bytes) */ stream_read_uint8(s, numIconCaches); /* numIconCaches (1 byte) */ stream_read_uint16(s, numIconCacheEntries); /* numIconCacheEntries (2 bytes) */ settings->rail_window_supported = False; settings->rail_icon_cache_number = MIN(3, numIconCaches); settings->rail_icon_cache_entries_number = MIN(12, numIconCacheEntries); if ( (wndSupportLevel == WINDOW_LEVEL_SUPPORTED) || (wndSupportLevel == WINDOW_LEVEL_SUPPORTED_EX) ) { settings->rail_window_supported = True; } }
void update_recv_window_info_order(rdpUpdate* update, STREAM* s, WINDOW_ORDER_INFO* orderInfo) { stream_read_uint32(s, orderInfo->windowId); /* windowId (4 bytes) */ if (orderInfo->fieldFlags & WINDOW_ORDER_ICON) { DEBUG_WND("Window Icon Order"); update_read_window_icon_order(s, orderInfo, &update->window_icon); IFCALL(update->WindowIcon, update, orderInfo, &update->window_icon); } else if (orderInfo->fieldFlags & WINDOW_ORDER_CACHED_ICON) { DEBUG_WND("Window Cached Icon Order"); update_read_window_cached_icon_order(s, orderInfo, &update->window_cached_icon); IFCALL(update->WindowCachedIcon, update, orderInfo, &update->window_cached_icon); } else if (orderInfo->fieldFlags & WINDOW_ORDER_STATE_DELETED) { DEBUG_WND("Window Deleted Order"); update_read_window_delete_order(s, orderInfo); IFCALL(update->WindowDelete, update, orderInfo); } else { DEBUG_WND("Window State Order"); update_read_window_state_order(s, orderInfo, &update->window_state); if (orderInfo->fieldFlags & WINDOW_ORDER_STATE_NEW) IFCALL(update->WindowCreate, update, orderInfo, &update->window_state); else IFCALL(update->WindowUpdate, update, orderInfo, &update->window_state); } }
void freerdp_string_read_length32(STREAM* s, rdpString* string, UNICONV* uniconv) { stream_read_uint32(s, string->length); string->unicode = (char*) xmalloc(string->length); stream_read(s, string->unicode, string->length); string->ascii = freerdp_uniconv_in(uniconv, (uint8*) string->unicode, string->length); }
boolean rdp_read_share_data_header(STREAM* s, uint16* length, uint8* type, uint32* share_id, uint8 *compressed_type, uint16 *compressed_len) { if (stream_get_left(s) < 12) return false; /* Share Data Header */ stream_read_uint32(s, *share_id); /* shareId (4 bytes) */ stream_seek_uint8(s); /* pad1 (1 byte) */ stream_seek_uint8(s); /* streamId (1 byte) */ stream_read_uint16(s, *length); /* uncompressedLength (2 bytes) */ stream_read_uint8(s, *type); /* pduType2, Data PDU Type (1 byte) */ if (*type & 0x80) { stream_read_uint8(s, *compressed_type); /* compressedType (1 byte) */ stream_read_uint16(s, *compressed_len); /* compressedLength (2 bytes) */ } else { stream_seek(s, 3); *compressed_type = 0; *compressed_len = 0; } return true; }
void cliprdr_process_format_list(cliprdrPlugin* cliprdr, STREAM* data_in, uint32 dataLen) { FRDP_CB_FORMAT_LIST_EVENT* cb_event; uint32 format; int num_formats; int supported; int i; cb_event = (FRDP_CB_FORMAT_LIST_EVENT*)freerdp_event_new(FRDP_EVENT_CLASS_CLIPRDR, FRDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); num_formats = dataLen / 36; cb_event->formats = (uint32*)xmalloc(sizeof(uint32) * num_formats); cb_event->num_formats = 0; if (num_formats * 36 != dataLen) DEBUG_WARN("dataLen %d not devided by 36!", dataLen); for (i = 0; i < num_formats; i++) { stream_read_uint32(data_in, format); supported = 1; switch (format) { case CB_FORMAT_TEXT: case CB_FORMAT_DIB: case CB_FORMAT_UNICODETEXT: break; default: if (memcmp(stream_get_tail(data_in), CFSTR_HTML, sizeof(CFSTR_HTML)) == 0) { format = CB_FORMAT_HTML; break; } if (memcmp(stream_get_tail(data_in), CFSTR_PNG, sizeof(CFSTR_PNG)) == 0) { format = CB_FORMAT_PNG; break; } if (memcmp(stream_get_tail(data_in), CFSTR_JPEG, sizeof(CFSTR_JPEG)) == 0) { format = CB_FORMAT_JPEG; break; } if (memcmp(stream_get_tail(data_in), CFSTR_GIF, sizeof(CFSTR_GIF)) == 0) { format = CB_FORMAT_GIF; break; } supported = 0; break; } stream_seek(data_in, 32); if (supported) cb_event->formats[cb_event->num_formats++] = format; } svc_plugin_send_event((rdpSvcPlugin*)cliprdr, (FRDP_EVENT*)cb_event); cliprdr_send_format_list_response(cliprdr); }
void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, STREAM* data_in) { FRDP_CB_DATA_REQUEST_EVENT* cb_event; cb_event = (FRDP_CB_DATA_REQUEST_EVENT*)freerdp_event_new(FRDP_EVENT_TYPE_CB_DATA_REQUEST, NULL, NULL); stream_read_uint32(data_in, cb_event->format); svc_plugin_send_event((rdpSvcPlugin*)cliprdr, (FRDP_EVENT*)cb_event); }
void rail_read_server_get_appid_resp_order(STREAM* s, RAIL_GET_APPID_RESP_ORDER* get_appid_resp) { stream_read_uint32(s, get_appid_resp->windowId); /* windowId (4 bytes) */ stream_read(s, &get_appid_resp->applicationIdBuffer[0], 512); /* applicationId (256 UNICODE chars) */ get_appid_resp->applicationId.length = 512; get_appid_resp->applicationId.string = &get_appid_resp->applicationIdBuffer[0]; }
void rail_read_server_exec_result_order(STREAM* s, RAIL_EXEC_RESULT_ORDER* exec_result) { stream_read_uint16(s, exec_result->flags); /* flags (2 bytes) */ stream_read_uint16(s, exec_result->execResult); /* execResult (2 bytes) */ stream_read_uint32(s, exec_result->rawResult); /* rawResult (4 bytes) */ stream_seek_uint16(s); /* padding (2 bytes) */ rail_read_unicode_string(s, &exec_result->exeOrFile); /* exeOrFile */ }
boolean gcc_read_client_security_data(STREAM* s, rdpSettings* settings, uint16 blockLength) { if (blockLength < 8) return false; if (settings->encryption) { stream_read_uint32(s, settings->encryption_method); /* encryptionMethods */ if (settings->encryption_method == 0) stream_read_uint32(s, settings->encryption_method); /* extEncryptionMethods */ } else { stream_seek(s, 8); } return true; }
static void rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, STREAM* data_in) { stream_read_uint16(data_in, rdpdr->versionMajor); stream_read_uint16(data_in, rdpdr->versionMinor); stream_read_uint32(data_in, rdpdr->clientID); DEBUG_SVC("version %d.%d clientID %d", rdpdr->versionMajor, rdpdr->versionMinor, rdpdr->clientID); }
void rdp_read_set_error_info_data_pdu(STREAM* s) { uint32 errorInfo; stream_read_uint32(s, errorInfo); /* errorInfo (4 bytes) */ printf("Error Info: 0x%08X\n", errorInfo); }
static uint32 handle_Connect(IRP* irp, tbool wide) { LONG rv; SCARDCONTEXT hContext; char *readerName = NULL; DWORD dwShareMode = 0; DWORD dwPreferredProtocol = 0; DWORD dwActiveProtocol = 0; SCARDHANDLE hCard; stream_seek(irp->input, 0x1c); stream_read_uint32(irp->input, dwShareMode); stream_read_uint32(irp->input, dwPreferredProtocol); sc_input_reader_name(irp, &readerName, wide); stream_seek(irp->input, 4); stream_read_uint32(irp->input, hContext); DEBUG_SCARD("(context: 0x%08x, share: 0x%08x, proto: 0x%08x, reader: \"%s\")", (unsigned) hContext, (unsigned) dwShareMode, (unsigned) dwPreferredProtocol, readerName ? readerName : "NULL"); rv = SCardConnect(hContext, readerName, (DWORD) dwShareMode, (DWORD) dwPreferredProtocol, &hCard, (DWORD *) &dwActiveProtocol); if (rv != SCARD_S_SUCCESS) DEBUG_SCARD("Failure: %s 0x%08x", pcsc_stringify_error(rv), (unsigned) rv); else DEBUG_SCARD("Success 0x%08x", (unsigned) hCard); stream_write_uint32(irp->output, 0x00000000); stream_write_uint32(irp->output, 0x00000000); stream_write_uint32(irp->output, 0x00000004); stream_write_uint32(irp->output, 0x016Cff34); stream_write_uint32(irp->output, dwActiveProtocol); stream_write_uint32(irp->output, 0x00000004); stream_write_uint32(irp->output, hCard); stream_seek(irp->output, 28); sc_output_alignment(irp, 8); xfree(readerName); return rv; }
boolean certificate_read_server_proprietary_certificate(rdpCertificate* certificate, STREAM* s) { uint32 dwSigAlgId; uint32 dwKeyAlgId; uint32 wPublicKeyBlobType; uint32 wPublicKeyBlobLen; uint32 wSignatureBlobType; uint32 wSignatureBlobLen; printf("Server Proprietary Certificate\n"); stream_read_uint32(s, dwSigAlgId); stream_read_uint32(s, dwKeyAlgId); if (!(dwSigAlgId == 1 && dwKeyAlgId == 1)) { printf("certificate_read_server_proprietary_certificate: parse error 1\n"); return False; } stream_read_uint16(s, wPublicKeyBlobType); if (wPublicKeyBlobType != BB_RSA_KEY_BLOB) { printf("certificate_read_server_proprietary_certificate: parse error 2\n"); return False; } stream_read_uint16(s, wPublicKeyBlobLen); if (!certificate_process_server_public_key(certificate, s, wPublicKeyBlobLen)) { printf("certificate_read_server_proprietary_certificate: parse error 3\n"); return False; } stream_read_uint16(s, wSignatureBlobType); if (wSignatureBlobType != BB_RSA_SIGNATURE_BLOB) { printf("certificate_read_server_proprietary_certificate: parse error 4\n"); return False; } stream_read_uint16(s, wSignatureBlobLen); if (!certificate_process_server_public_signature(certificate, s, wSignatureBlobLen)) { printf("certificate_read_server_proprietary_certificate: parse error 5\n"); return False; } return True; }
static void rdpsnd_process_message_setvolume(rdpsndPlugin* rdpsnd, STREAM* data_in) { uint32 dwVolume; stream_read_uint32(data_in, dwVolume); DEBUG_SVC("dwVolume 0x%X", dwVolume); if (rdpsnd->device) IFCALL(rdpsnd->device->SetVolume, rdpsnd->device, dwVolume); }
void rdp_recv_set_error_info_data_pdu(STREAM* s) { uint32 errorInfo; stream_read_uint32(s, errorInfo); /* errorInfo (4 bytes) */ if (errorInfo != ERRINFO_SUCCESS) rdp_print_errinfo(errorInfo); }
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_input_capability_set(STREAM* s, rdpSettings* settings) { uint16 inputFlags; stream_read_uint16(s, inputFlags); /* inputFlags (2 bytes) */ stream_seek_uint16(s); /* pad2OctetsA (2 bytes) */ stream_read_uint32(s, settings->kbd_layout); /* keyboardLayout (4 bytes) */ stream_read_uint32(s, settings->kbd_type); /* keyboardType (4 bytes) */ stream_read_uint32(s, settings->kbd_subtype); /* keyboardSubType (4 bytes) */ stream_read_uint32(s, settings->kbd_fn_keys); /* keyboardFunctionKeys (4 bytes) */ stream_seek(s, 64); /* imeFileName (64 bytes) */ if ((inputFlags & INPUT_FLAG_FASTPATH_INPUT) || (inputFlags & INPUT_FLAG_FASTPATH_INPUT2)) { if (settings->fast_path_input != False) settings->fast_path_input = True; } }
static uint32 handle_ReleaseContext(IRP* irp) { uint32 len, rv; SCARDCONTEXT hContext = -1; stream_seek(irp->input, 8); stream_read_uint32(irp->input, len); stream_seek(irp->input, 0x10); stream_read_uint32(irp->input, hContext); rv = SCardReleaseContext(hContext); if (rv) DEBUG_SCARD("%s (0x%08x)", pcsc_stringify_error(rv), (unsigned) rv); else DEBUG_SCARD("success 0x%08lx", hContext); return rv; }
static void sc_input_reader_name(IRP* irp, char **dest, tbool wide) { uint32 dataLength; stream_seek(irp->input, 8); stream_read_uint32(irp->input, dataLength); DEBUG_SCARD("datalength %d", dataLength); sc_input_repos(irp, sc_input_string(irp, dest, dataLength, wide)); }
void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, STREAM* s, uint32 dataLen, uint16 msgFlags) { RDP_CB_DATA_REQUEST_EVENT* cb_event; cb_event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_DATA_REQUEST, NULL, NULL); stream_read_uint32(s, cb_event->format); svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (RDP_EVENT*) cb_event); }
static void rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* message, STREAM* s) { uint32 frameIdx; uint16 numRegions; stream_read_uint32(s, frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */ stream_read_uint16(s, numRegions); /* numRegions (2 bytes) */ DEBUG_RFX("RFX_FRAME_BEGIN: frameIdx:%d numRegions:%d", frameIdx, numRegions); }