2011-08-10 10:24:06 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-10 10:24:06 +04:00
|
|
|
* Remote Applications Integrated Locally (RAIL) Utils
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-11-22 06:22:06 +04:00
|
|
|
#include <winpr/crt.h>
|
2011-08-10 10:24:06 +04:00
|
|
|
|
2012-11-22 06:22:06 +04:00
|
|
|
#include <freerdp/types.h>
|
2011-08-10 10:24:06 +04:00
|
|
|
#include <freerdp/utils/rail.h>
|
2012-10-09 07:21:26 +04:00
|
|
|
|
2011-08-22 03:04:21 +04:00
|
|
|
#include <freerdp/rail.h>
|
2011-08-10 10:24:06 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void rail_unicode_string_alloc(RAIL_UNICODE_STRING* unicode_string, UINT16 cbString)
|
2011-08-10 10:24:06 +04:00
|
|
|
{
|
2011-08-11 00:33:15 +04:00
|
|
|
unicode_string->length = cbString;
|
2012-10-09 07:21:26 +04:00
|
|
|
unicode_string->string = malloc(cbString);
|
|
|
|
memset(unicode_string->string, 0, cbString);
|
2011-08-10 10:24:06 +04:00
|
|
|
}
|
|
|
|
|
2012-06-20 01:26:37 +04:00
|
|
|
void rail_unicode_string_free(RAIL_UNICODE_STRING* unicode_string)
|
2011-08-10 10:24:06 +04:00
|
|
|
{
|
2011-08-11 00:33:15 +04:00
|
|
|
unicode_string->length = 0;
|
2011-08-10 10:24:06 +04:00
|
|
|
|
|
|
|
if (unicode_string->string != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(unicode_string->string);
|
2011-08-10 10:24:06 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rail_read_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string)
|
2011-08-10 10:24:06 +04:00
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 2)
|
2013-01-11 04:29:34 +04:00
|
|
|
return FALSE;
|
2013-03-29 04:23:16 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, unicode_string->length); /* cbString (2 bytes) */
|
2013-03-29 04:23:16 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < unicode_string->length)
|
2013-01-11 04:29:34 +04:00
|
|
|
return FALSE;
|
2011-08-10 10:24:06 +04:00
|
|
|
|
|
|
|
if (unicode_string->string == NULL)
|
2012-10-09 11:01:37 +04:00
|
|
|
unicode_string->string = (BYTE*) malloc(unicode_string->length);
|
2011-08-10 10:24:06 +04:00
|
|
|
else
|
2012-10-09 11:01:37 +04:00
|
|
|
unicode_string->string = (BYTE*) realloc(unicode_string->string, unicode_string->length);
|
2011-08-10 10:24:06 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, unicode_string->string, unicode_string->length);
|
2013-03-29 04:23:16 +04:00
|
|
|
|
2013-01-11 04:29:34 +04:00
|
|
|
return TRUE;
|
2011-08-10 10:24:06 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rail_write_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string)
|
2011-08-10 10:24:06 +04:00
|
|
|
{
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, 2 + unicode_string->length);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, unicode_string->length); /* cbString (2 bytes) */
|
|
|
|
Stream_Write(s, unicode_string->string, unicode_string->length); /* string */
|
2011-08-10 10:24:06 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rail_write_unicode_string_value(wStream* s, RAIL_UNICODE_STRING* unicode_string)
|
2011-08-10 10:24:06 +04:00
|
|
|
{
|
2011-08-11 02:08:44 +04:00
|
|
|
if (unicode_string->length > 0)
|
2011-08-12 12:46:40 +04:00
|
|
|
{
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, unicode_string->length);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, unicode_string->string, unicode_string->length); /* string */
|
2011-08-12 12:46:40 +04:00
|
|
|
}
|
2011-08-10 10:24:06 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rail_read_rectangle_16(wStream* s, RECTANGLE_16* rectangle_16)
|
2011-08-10 10:24:06 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, rectangle_16->left); /* left (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, rectangle_16->top); /* top (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, rectangle_16->right); /* right (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, rectangle_16->bottom); /* bottom (2 bytes) */
|
2011-08-10 10:24:06 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rail_write_rectangle_16(wStream* s, RECTANGLE_16* rectangle_16)
|
2011-08-10 10:24:06 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, rectangle_16->left); /* left (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, rectangle_16->top); /* top (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, rectangle_16->right); /* right (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, rectangle_16->bottom); /* bottom (2 bytes) */
|
2011-08-10 10:24:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void* rail_clone_order(UINT32 event_type, void* order)
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 type;
|
|
|
|
UINT32 size;
|
2011-08-22 03:04:21 +04:00
|
|
|
} ordersize_table[] =
|
|
|
|
{
|
2013-03-29 04:23:16 +04:00
|
|
|
{RailChannel_GetSystemParam, sizeof(RAIL_SYSPARAM_ORDER)},
|
|
|
|
{RailChannel_ServerExecuteResult, sizeof(RAIL_EXEC_RESULT_ORDER)},
|
|
|
|
{RailChannel_ServerSystemParam, sizeof(RAIL_SYSPARAM_ORDER)},
|
|
|
|
{RailChannel_ServerMinMaxInfo, sizeof(RAIL_MINMAXINFO_ORDER)},
|
|
|
|
{RailChannel_ServerLocalMoveSize, sizeof(RAIL_LOCALMOVESIZE_ORDER)},
|
|
|
|
{RailChannel_ServerGetAppIdResponse, sizeof(RAIL_GET_APPID_RESP_ORDER)},
|
|
|
|
{RailChannel_ServerLanguageBarInfo, sizeof(RAIL_LANGBAR_INFO_ORDER)},
|
|
|
|
{RailChannel_ClientSystemParam, sizeof(RAIL_SYSPARAM_ORDER)},
|
|
|
|
{RailChannel_ClientExecute, sizeof(RDP_PLUGIN_DATA)},
|
|
|
|
{RailChannel_ClientActivate, sizeof(RAIL_ACTIVATE_ORDER)},
|
|
|
|
{RailChannel_ClientSystemMenu, sizeof(RAIL_SYSMENU_ORDER)},
|
|
|
|
{RailChannel_ClientSystemCommand, sizeof(RAIL_SYSCOMMAND_ORDER)},
|
|
|
|
{RailChannel_ClientNotifyEvent, sizeof(RAIL_NOTIFY_EVENT_ORDER)},
|
|
|
|
{RailChannel_ClientWindowMove, sizeof(RAIL_WINDOW_MOVE_ORDER)},
|
|
|
|
{RailChannel_ClientGetAppIdRequest, sizeof(RAIL_GET_APPID_REQ_ORDER)},
|
|
|
|
{RailChannel_ClientLanguageBarInfo, sizeof(RAIL_LANGBAR_INFO_ORDER)},
|
2011-08-22 03:04:21 +04:00
|
|
|
};
|
|
|
|
size_t i = 0;
|
|
|
|
size_t order_size = 0;
|
|
|
|
void* new_order = NULL;
|
|
|
|
|
2012-11-22 05:50:28 +04:00
|
|
|
for (i = 0; i < ARRAYSIZE(ordersize_table); i++)
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
|
|
|
if (event_type == ordersize_table[i].type)
|
|
|
|
{
|
|
|
|
order_size = ordersize_table[i].size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Event type not found.
|
2013-03-29 04:23:16 +04:00
|
|
|
if (order_size == 0)
|
|
|
|
return NULL;
|
2011-08-22 03:04:21 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
new_order = malloc(order_size);
|
2013-03-29 04:23:16 +04:00
|
|
|
CopyMemory(new_order, order, order_size);
|
2011-08-22 03:04:21 +04:00
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
//fprintf(stderr, "rail_clone_order: type=%d order=%p\n", event_type, new_order);
|
2011-08-22 03:04:21 +04:00
|
|
|
|
|
|
|
// Create copy of variable data for some orders
|
2013-03-29 04:23:16 +04:00
|
|
|
if ((event_type == RailChannel_GetSystemParam) ||
|
|
|
|
(event_type == RailChannel_ClientSystemParam))
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
2013-03-29 04:23:16 +04:00
|
|
|
RAIL_SYSPARAM_ORDER* new_sysparam = (RAIL_SYSPARAM_ORDER*) new_order;
|
|
|
|
RAIL_SYSPARAM_ORDER* old_sysparam = (RAIL_SYSPARAM_ORDER*) order;
|
2011-08-22 03:04:21 +04:00
|
|
|
|
|
|
|
rail_unicode_string_alloc(&new_sysparam->highContrast.colorScheme,
|
|
|
|
old_sysparam->highContrast.colorScheme.length);
|
|
|
|
|
2013-03-29 04:23:16 +04:00
|
|
|
CopyMemory(new_sysparam->highContrast.colorScheme.string,
|
2011-08-22 03:04:21 +04:00
|
|
|
old_sysparam->highContrast.colorScheme.string,
|
|
|
|
old_sysparam->highContrast.colorScheme.length);
|
|
|
|
}
|
|
|
|
|
2013-03-29 04:23:16 +04:00
|
|
|
if (event_type == RailChannel_ServerExecuteResult)
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
2013-03-29 04:23:16 +04:00
|
|
|
RAIL_EXEC_RESULT_ORDER* new_exec_result = (RAIL_EXEC_RESULT_ORDER*) new_order;
|
|
|
|
RAIL_EXEC_RESULT_ORDER* old_exec_result = (RAIL_EXEC_RESULT_ORDER*) order;
|
2011-08-22 03:04:21 +04:00
|
|
|
|
|
|
|
rail_unicode_string_alloc(&new_exec_result->exeOrFile,
|
|
|
|
old_exec_result->exeOrFile.length);
|
|
|
|
|
2013-03-29 04:23:16 +04:00
|
|
|
CopyMemory(new_exec_result->exeOrFile.string,
|
2011-08-22 03:04:21 +04:00
|
|
|
old_exec_result->exeOrFile.string,
|
|
|
|
old_exec_result->exeOrFile.length);
|
|
|
|
}
|
|
|
|
|
2013-03-29 04:23:16 +04:00
|
|
|
if (event_type == RailChannel_ServerGetAppIdResponse)
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
|
|
|
RAIL_GET_APPID_RESP_ORDER* new_app_resp = (RAIL_GET_APPID_RESP_ORDER*)new_order;
|
|
|
|
|
|
|
|
new_app_resp->applicationId.string = &new_app_resp->applicationIdBuffer[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_order;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void rail_free_cloned_order(UINT32 event_type, void* order)
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
//fprintf(stderr, "rail_free_cloned_order: type=%d order=%p\n", event_type, order);
|
2013-03-29 04:23:16 +04:00
|
|
|
if ((event_type == RailChannel_GetSystemParam) ||
|
|
|
|
(event_type == RailChannel_ClientSystemParam))
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
2013-03-29 04:23:16 +04:00
|
|
|
RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) order;
|
2011-08-22 03:04:21 +04:00
|
|
|
rail_unicode_string_free(&sysparam->highContrast.colorScheme);
|
|
|
|
}
|
|
|
|
|
2013-03-29 04:23:16 +04:00
|
|
|
if (event_type == RailChannel_ServerExecuteResult)
|
2011-08-22 03:04:21 +04:00
|
|
|
{
|
2013-03-29 04:23:16 +04:00
|
|
|
RAIL_EXEC_RESULT_ORDER* exec_result = (RAIL_EXEC_RESULT_ORDER*) order;
|
2011-08-22 03:04:21 +04:00
|
|
|
rail_unicode_string_free(&exec_result->exeOrFile);
|
|
|
|
}
|
2013-03-29 04:23:16 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(order);
|
2011-08-22 03:04:21 +04:00
|
|
|
}
|