2013-08-29 01:47:37 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* RAIL common functions
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
* Copyright 2011 Roman Barabanov <romanbarabanov@gmail.com>
|
|
|
|
* Copyright 2011 Vic Lee
|
2015-06-08 19:04:05 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2013-08-29 01:47:37 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#include "rail_common.h"
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
|
|
|
const char* const RAIL_ORDER_TYPE_STRINGS[] =
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
"Execute",
|
|
|
|
"Activate",
|
|
|
|
"System Parameters Update",
|
|
|
|
"System Command",
|
|
|
|
"Handshake",
|
|
|
|
"Notify Event",
|
|
|
|
"",
|
|
|
|
"Window Move",
|
|
|
|
"Local Move/Size",
|
|
|
|
"Min Max Info",
|
|
|
|
"Client Status",
|
|
|
|
"System Menu",
|
|
|
|
"Language Bar Info",
|
|
|
|
"Get Application ID Request",
|
|
|
|
"Get Application ID Response",
|
2013-10-12 01:36:34 +04:00
|
|
|
"Execute Result",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
""
|
2013-08-29 01:47:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void rail_string_to_unicode_string(char* string, RAIL_UNICODE_STRING* unicode_string)
|
|
|
|
{
|
|
|
|
WCHAR* buffer = NULL;
|
|
|
|
int length = 0;
|
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(unicode_string->string);
|
2013-08-29 01:47:37 +04:00
|
|
|
|
|
|
|
unicode_string->string = NULL;
|
|
|
|
unicode_string->length = 0;
|
|
|
|
|
2013-10-12 01:36:34 +04:00
|
|
|
if (!string || strlen(string) < 1)
|
2013-08-29 01:47:37 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
length = ConvertToUnicode(CP_UTF8, 0, string, -1, &buffer, 0) * 2;
|
|
|
|
|
|
|
|
unicode_string->string = (BYTE*) buffer;
|
|
|
|
unicode_string->length = (UINT16) length;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rail_read_pdu_header(wStream* s, UINT16* orderType, UINT16* orderLength)
|
2013-08-29 01:47:37 +04:00
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-08 19:04:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2013-10-12 01:36:34 +04:00
|
|
|
|
2013-08-29 01:47:37 +04:00
|
|
|
Stream_Read_UINT16(s, *orderType); /* orderType (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, *orderLength); /* orderLength (2 bytes) */
|
2013-10-12 01:36:34 +04:00
|
|
|
|
2015-06-08 19:04:05 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-29 01:47:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void rail_write_pdu_header(wStream* s, UINT16 orderType, UINT16 orderLength)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT16(s, orderType); /* orderType (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */
|
|
|
|
}
|
|
|
|
|
2015-06-08 19:04:05 +03:00
|
|
|
wStream* rail_pdu_init(size_t length)
|
2013-08-29 01:47:37 +04:00
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
s = Stream_New(NULL, length + RAIL_PDU_HEADER_LENGTH);
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
2013-08-29 01:47:37 +04:00
|
|
|
Stream_Seek(s, RAIL_PDU_HEADER_LENGTH);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rail_read_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake)
|
2013-08-29 01:47:37 +04:00
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-08 19:04:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2013-10-12 01:36:34 +04:00
|
|
|
|
2013-08-29 01:47:37 +04:00
|
|
|
Stream_Read_UINT32(s, handshake->buildNumber); /* buildNumber (4 bytes) */
|
2013-10-12 01:36:34 +04:00
|
|
|
|
2015-06-08 19:04:05 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-29 01:47:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void rail_write_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, handshake->buildNumber); /* buildNumber (4 bytes) */
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT rail_read_handshake_ex_order(wStream* s, RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
|
2013-10-12 01:36:34 +04:00
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2015-06-08 19:04:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2013-10-12 01:36:34 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, handshakeEx->buildNumber); /* buildNumber (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, handshakeEx->railHandshakeFlags); /* railHandshakeFlags (4 bytes) */
|
|
|
|
|
2015-06-08 19:04:05 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-10-12 01:36:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void rail_write_handshake_ex_order(wStream* s, RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT32(s, handshakeEx->buildNumber); /* buildNumber (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, handshakeEx->railHandshakeFlags); /* railHandshakeFlags (4 bytes) */
|
|
|
|
}
|