Welcome to mirror list, hosted at ThFree Co, Russian Federation.

surface.c « libfreerdp-core - github.com/neutrinolabs/NeutrinoRDP.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 04a6aea43abcfba31e349b7b838fe273880571b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
 * FreeRDP: A Remote Desktop Protocol Client
 * Surface Commands
 *
 * Copyright 2011 Vic Lee
 *
 * 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 <freerdp/utils/pcap.h>

#include "surface.h"

static int update_recv_surfcmd_surface_bits(rdpUpdate* update, STREAM* s)
{
	int pos;
	SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command;

	stream_read_uint16(s, cmd->destLeft);
	stream_read_uint16(s, cmd->destTop);
	stream_read_uint16(s, cmd->destRight);
	stream_read_uint16(s, cmd->destBottom);
	stream_read_uint8(s, cmd->bpp);
	stream_seek(s, 2); /* reserved1, reserved2 */
	stream_read_uint8(s, cmd->codecID);
	stream_read_uint16(s, cmd->width);
	stream_read_uint16(s, cmd->height);
	stream_read_uint32(s, cmd->bitmapDataLength);
	pos = stream_get_pos(s) + cmd->bitmapDataLength;
	cmd->bitmapData = stream_get_tail(s);

	update->SurfaceBits(update->context, cmd);

	stream_set_pos(s, pos);

	return 20 + cmd->bitmapDataLength;
}

static int update_recv_surfcmd_frame_marker(rdpUpdate* update, STREAM* s)
{
	SURFACE_FRAME_MARKER* marker = &update->surface_frame_marker;

	stream_read_uint16(s, marker->frameAction);
	stream_read_uint32(s, marker->frameId);

	update->SurfaceFrameMarker(update->context, marker);

	return 6;
}

tbool update_recv_surfcmds(rdpUpdate* update, uint32 size, STREAM* s)
{
	uint8* mark;
	uint16 cmdType;
	uint32 cmdLength;

	while (size > 2)
	{
		stream_get_mark(s, mark);

		stream_read_uint16(s, cmdType);
		size -= 2;

		switch (cmdType)
		{
			case CMDTYPE_SET_SURFACE_BITS:
			case CMDTYPE_STREAM_SURFACE_BITS:
				cmdLength = update_recv_surfcmd_surface_bits(update, s);
				break;

			case CMDTYPE_FRAME_MARKER:
				cmdLength = update_recv_surfcmd_frame_marker(update, s);
				break;

			default:
				DEBUG_WARN("unknown cmdType 0x%X", cmdType);
				return false;
		}

		size -= cmdLength;

		if (update->dump_rfx)
		{
			pcap_add_record(update->pcap_rfx, mark, cmdLength + 2);
			pcap_flush(update->pcap_rfx);
		}
	}
	return true;
}

void update_write_surfcmd_surface_bits_header(STREAM* s, SURFACE_BITS_COMMAND* cmd)
{
	stream_check_size(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH);

	stream_write_uint16(s, CMDTYPE_STREAM_SURFACE_BITS);

	stream_write_uint16(s, cmd->destLeft);
	stream_write_uint16(s, cmd->destTop);
	stream_write_uint16(s, cmd->destRight);
	stream_write_uint16(s, cmd->destBottom);
	stream_write_uint8(s, cmd->bpp);
	stream_write_uint16(s, 0); /* reserved1, reserved2 */
	stream_write_uint8(s, cmd->codecID);
	stream_write_uint16(s, cmd->width);
	stream_write_uint16(s, cmd->height);
	stream_write_uint32(s, cmd->bitmapDataLength);
}

void update_write_surfcmd_frame_marker(STREAM* s, uint16 frameAction, uint32 frameId)
{
	stream_check_size(s, SURFCMD_FRAME_MARKER_LENGTH);

	stream_write_uint16(s, CMDTYPE_FRAME_MARKER);

	stream_write_uint16(s, frameAction);
	stream_write_uint32(s, frameId);
}