Merge pull request #2401 from metalefty/codec_guid

Record codec GUID to identify unknown codec
This commit is contained in:
metalefty 2022-11-04 16:13:30 +09:00 committed by GitHub
commit cc43061ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 136 additions and 24 deletions

3
.gitignore vendored
View File

@ -48,7 +48,10 @@ stamp-h1
tap-driver.sh tap-driver.sh
test-driver test-driver
tests/common/test_common tests/common/test_common
tests/libipm/test_libipm
tests/libxrdp/test_libxrdp
tests/memtest/memtest tests/memtest/memtest
tests/xrdp/test_xrdp
tools/devel/tcp_proxy/tcp_proxy tools/devel/tcp_proxy/tcp_proxy
*.trs *.trs
xrdp/xrdp xrdp/xrdp

View File

@ -65,8 +65,20 @@ guid_is_set(const struct guid *guid)
} }
const char *guid_to_str(const struct guid *guid, char *str) const char *guid_to_str(const struct guid *src, char *dest)
{ {
g_bytes_to_hexstr(guid->g, GUID_SIZE, str, GUID_STR_SIZE); const unsigned char *guid = (const unsigned char *)src->g;
return str;
/*
* Flipping integers into little-endian
* See also: https://devblogs.microsoft.com/oldnewthing/20220928-00/?p=107221
*/
g_sprintf(dest, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid[3], guid[2], guid[1], guid[0],
guid[5], guid[4],
guid[7], guid[6],
guid[8], guid[9],
guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);
return dest;
} }

View File

@ -28,7 +28,8 @@
#include "arch.h" #include "arch.h"
#define GUID_SIZE 16 /* bytes */ #define GUID_SIZE 16 /* bytes */
#define GUID_STR_SIZE (GUID_SIZE * 2 + 1) /* Size for string representation */ #define GUID_STR_SIZE (GUID_SIZE * 2 + 4 + 1) /* w/ 4 hyphens + null terminator */
/** /**
* Use a struct for the guid so we can easily copy by assignment * Use a struct for the guid so we can easily copy by assignment
@ -66,10 +67,11 @@ guid_is_set(const struct guid *guid);
* Converts a GUID to a string representation * Converts a GUID to a string representation
* *
* @param guid GUID to represent * @param guid GUID to represent
* @param str pointer to at least GUID_STR_SIZE bytes to store the * @param dest destionation pointer to at least GUID_STR_SIZE
* representation * bytes to store the representation
* @return str is returned for convenience * @return dest is returned for convenience
*/ */
const char *guid_to_str(const struct guid *guid, char *str); const char *guid_to_str(const struct guid *guid, char *dest);
#endif #endif

View File

@ -372,11 +372,11 @@
/* Bitmap Codec: codecGUID (2.2.7.2.10.1.1) */ /* Bitmap Codec: codecGUID (2.2.7.2.10.1.1) */
/* CODEC_GUID_NSCODEC CA8D1BB9-000F-154F-589FAE2D1A87E2D6 */ /* CODEC_GUID_NSCODEC CA8D1BB9-000F-154F-589F-AE2D1A87E2D6 */
#define XR_CODEC_GUID_NSCODEC \ #define XR_CODEC_GUID_NSCODEC \
"\xb9\x1b\x8d\xca\x0f\x00\x4f\x15\x58\x9f\xae\x2d\x1a\x87\xe2\xd6" "\xb9\x1b\x8d\xca\x0f\x00\x4f\x15\x58\x9f\xae\x2d\x1a\x87\xe2\xd6"
/* CODEC_GUID_REMOTEFX 76772F12-BD72-4463-AFB3B73C9C6F7886 */ /* CODEC_GUID_REMOTEFX 76772F12-BD72-4463-AFB3-B73C9C6F7886 */
#define XR_CODEC_GUID_REMOTEFX \ #define XR_CODEC_GUID_REMOTEFX \
"\x12\x2F\x77\x76\x72\xBD\x63\x44\xAF\xB3\xB7\x3C\x9C\x6F\x78\x86" "\x12\x2F\x77\x76\x72\xBD\x63\x44\xAF\xB3\xB7\x3C\x9C\x6F\x78\x86"
@ -384,18 +384,22 @@
#define XR_CODEC_GUID_IMAGE_REMOTEFX \ #define XR_CODEC_GUID_IMAGE_REMOTEFX \
"\xD4\xCC\x44\x27\x8A\x9D\x74\x4E\x80\x3C\x0E\xCB\xEE\xA1\x9C\x54" "\xD4\xCC\x44\x27\x8A\x9D\x74\x4E\x80\x3C\x0E\xCB\xEE\xA1\x9C\x54"
/* MFVideoFormat_H264 0x34363248-0000-0010-800000AA00389B71 */ /* MFVideoFormat_H264 34363248-0000-0010-8000-00AA00389B71 */
#define XR_CODEC_GUID_H264 \ #define XR_CODEC_GUID_H264 \
"\x48\x32\x36\x34\x00\x00\x10\x00\x80\x00\x00\xAA\x00\x38\x9B\x71" "\x48\x32\x36\x34\x00\x00\x10\x00\x80\x00\x00\xAA\x00\x38\x9B\x71"
/* CODEC_GUID_JPEG 1BAF4CE6-9EED-430C-869ACB8B37B66237 */ /* CODEC_GUID_JPEG 1BAF4CE6-9EED-430C-869A-CB8B37B66237 */
#define XR_CODEC_GUID_JPEG \ #define XR_CODEC_GUID_JPEG \
"\xE6\x4C\xAF\x1B\xED\x9E\x0C\x43\x86\x9A\xCB\x8B\x37\xB6\x62\x37" "\xE6\x4C\xAF\x1B\xED\x9E\x0C\x43\x86\x9A\xCB\x8B\x37\xB6\x62\x37"
/* CODEC_GUID_PNG 0E0C858D-28E0-45DB-ADAA0F83E57CC560 */ /* CODEC_GUID_PNG 0E0C858D-28E0-45DB-ADAA-0F83E57CC560 */
#define XR_CODEC_GUID_PNG \ #define XR_CODEC_GUID_PNG \
"\x8D\x85\x0C\x0E\xE0\x28\xDB\x45\xAD\xAA\x0F\x83\xE5\x7C\xC5\x60" "\x8D\x85\x0C\x0E\xE0\x28\xDB\x45\xAD\xAA\x0F\x83\xE5\x7C\xC5\x60"
/* CODEC_GUID_IGNORE 0C4351A6-3535-42AE-910C-CDFCE5760B58 */
#define XR_CODEC_GUID_IGNORE \
"\xA6\x51\x43\x0C\x35\x35\xAE\x42\x91\x0C\xCD\xFC\xE5\x76\x0B\x58"
/* PDU Types (2.2.8.1.1.1.1) */ /* PDU Types (2.2.8.1.1.1.1) */
#define PDUTYPE_DEMANDACTIVEPDU 0x1 #define PDUTYPE_DEMANDACTIVEPDU 0x1
#define PDUTYPE_CONFIRMACTIVEPDU 0x3 #define PDUTYPE_CONFIRMACTIVEPDU 0x3

View File

@ -25,6 +25,7 @@
#include <limits.h> #include <limits.h>
#include "guid.h"
#include "libxrdp.h" #include "libxrdp.h"
#include "ms-rdpbcgr.h" #include "ms-rdpbcgr.h"
#include "ms-rdperp.h" #include "ms-rdperp.h"
@ -521,6 +522,10 @@ xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
int i1; int i1;
char *codec_guid; char *codec_guid;
char *next_guid; char *next_guid;
struct guid guid;
char codec_guid_str[GUID_STR_SIZE];
guid_clear(&guid);
if (len < 1) if (len < 1)
{ {
@ -533,6 +538,10 @@ xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
for (index = 0; index < codec_count; index++) for (index = 0; index < codec_count; index++)
{ {
codec_guid = s->p; codec_guid = s->p;
g_memcpy(guid.g, s->p, GUID_SIZE);
guid_to_str(&guid, codec_guid_str);
if (len < 16 + 1 + 2) if (len < 16 + 1 + 2)
{ {
LOG(LOG_LEVEL_ERROR, "xrdp_caps_process_codecs: error"); LOG(LOG_LEVEL_ERROR, "xrdp_caps_process_codecs: error");
@ -552,8 +561,8 @@ xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
if (g_memcmp(codec_guid, XR_CODEC_GUID_NSCODEC, 16) == 0) if (g_memcmp(codec_guid, XR_CODEC_GUID_NSCODEC, 16) == 0)
{ {
LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: nscodec, codec id %d, properties len %d", LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: NSCodec(%s), codec id [%d], properties len [%d]",
codec_id, codec_properties_length); codec_guid_str, codec_id, codec_properties_length);
self->client_info.ns_codec_id = codec_id; self->client_info.ns_codec_id = codec_id;
i1 = MIN(64, codec_properties_length); i1 = MIN(64, codec_properties_length);
g_memcpy(self->client_info.ns_prop, s->p, i1); g_memcpy(self->client_info.ns_prop, s->p, i1);
@ -561,8 +570,8 @@ xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
} }
else if (g_memcmp(codec_guid, XR_CODEC_GUID_REMOTEFX, 16) == 0) else if (g_memcmp(codec_guid, XR_CODEC_GUID_REMOTEFX, 16) == 0)
{ {
LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: RemoteFX, codec id %d, properties len %d", LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: RemoteFX(%s), codec id [%d], properties len [%d]",
codec_id, codec_properties_length); codec_guid_str, codec_id, codec_properties_length);
self->client_info.rfx_codec_id = codec_id; self->client_info.rfx_codec_id = codec_id;
i1 = MIN(64, codec_properties_length); i1 = MIN(64, codec_properties_length);
g_memcpy(self->client_info.rfx_prop, s->p, i1); g_memcpy(self->client_info.rfx_prop, s->p, i1);
@ -570,8 +579,8 @@ xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
} }
else if (g_memcmp(codec_guid, XR_CODEC_GUID_JPEG, 16) == 0) else if (g_memcmp(codec_guid, XR_CODEC_GUID_JPEG, 16) == 0)
{ {
LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: jpeg, codec id %d, properties len %d", LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: JPEG(%s), codec id [%d], properties len [%d]",
codec_id, codec_properties_length); codec_guid_str, codec_id, codec_properties_length);
self->client_info.jpeg_codec_id = codec_id; self->client_info.jpeg_codec_id = codec_id;
i1 = MIN(64, codec_properties_length); i1 = MIN(64, codec_properties_length);
g_memcpy(self->client_info.jpeg_prop, s->p, i1); g_memcpy(self->client_info.jpeg_prop, s->p, i1);
@ -587,8 +596,8 @@ xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
} }
else if (g_memcmp(codec_guid, XR_CODEC_GUID_H264, 16) == 0) else if (g_memcmp(codec_guid, XR_CODEC_GUID_H264, 16) == 0)
{ {
LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: h264, codec id %d, properties len %d", LOG(LOG_LEVEL_INFO, "xrdp_caps_process_codecs: H264(%s), codec id [%d], properties len [%d]",
codec_id, codec_properties_length); codec_guid_str, codec_id, codec_properties_length);
self->client_info.h264_codec_id = codec_id; self->client_info.h264_codec_id = codec_id;
i1 = MIN(64, codec_properties_length); i1 = MIN(64, codec_properties_length);
g_memcpy(self->client_info.h264_prop, s->p, i1); g_memcpy(self->client_info.h264_prop, s->p, i1);
@ -596,7 +605,8 @@ xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
} }
else else
{ {
LOG(LOG_LEVEL_WARNING, "xrdp_caps_process_codecs: unknown codec id %d", codec_id); LOG(LOG_LEVEL_WARNING, "xrdp_caps_process_codecs: unknown(%s), codec id [%d], properties len [%d]",
codec_guid_str, codec_id, codec_properties_length);
} }
s->p = next_guid; s->p = next_guid;

View File

@ -17,7 +17,8 @@ test_common_SOURCES = \
test_string_calls.c \ test_string_calls.c \
test_os_calls.c \ test_os_calls.c \
test_ssl_calls.c \ test_ssl_calls.c \
test_base64.c test_base64.c \
test_guid.c
test_common_CFLAGS = \ test_common_CFLAGS = \
@CHECK_CFLAGS@ \ @CHECK_CFLAGS@ \

View File

@ -11,5 +11,6 @@ Suite *make_suite_test_string(void);
Suite *make_suite_test_os_calls(void); Suite *make_suite_test_os_calls(void);
Suite *make_suite_test_ssl_calls(void); Suite *make_suite_test_ssl_calls(void);
Suite *make_suite_test_base64(void); Suite *make_suite_test_base64(void);
Suite *make_suite_test_guid(void);
#endif /* TEST_COMMON_H */ #endif /* TEST_COMMON_H */

View File

@ -49,6 +49,7 @@ int main (void)
srunner_add_suite(sr, make_suite_test_os_calls()); srunner_add_suite(sr, make_suite_test_os_calls());
srunner_add_suite(sr, make_suite_test_ssl_calls()); srunner_add_suite(sr, make_suite_test_ssl_calls());
srunner_add_suite(sr, make_suite_test_base64()); srunner_add_suite(sr, make_suite_test_base64());
srunner_add_suite(sr, make_suite_test_guid());
// srunner_add_suite(sr, make_list_suite()); // srunner_add_suite(sr, make_list_suite());
srunner_set_tap(sr, "-"); srunner_set_tap(sr, "-");

77
tests/common/test_guid.c Normal file
View File

@ -0,0 +1,77 @@
#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif
#include "guid.h"
#include "ms-rdpbcgr.h"
#include "os_calls.h"
#include "test_common.h"
/******************************************************************************/
START_TEST(test_guid_to_str_remotefx)
{
/* setup */
char dest[GUID_STR_SIZE];
struct guid guid;
g_memcpy(guid.g, XR_CODEC_GUID_REMOTEFX, GUID_SIZE);
/* test */
guid_to_str(&guid, dest);
/* verify */
ck_assert_str_eq(dest, "76772F12-BD72-4463-AFB3-B73C9C6F7886");
}
END_TEST
START_TEST(test_guid_to_str_nscodec)
{
/* setup */
char dest[GUID_STR_SIZE];
struct guid guid;
g_memcpy(guid.g, XR_CODEC_GUID_NSCODEC, GUID_SIZE);
/* test */
guid_to_str(&guid, dest);
/* verify */
ck_assert_str_eq(dest, "CA8D1BB9-000F-154F-589F-AE2D1A87E2D6");
}
END_TEST
START_TEST(test_guid_to_str_ignore)
{
/* setup */
char dest[GUID_STR_SIZE];
struct guid guid;
g_memcpy(guid.g, XR_CODEC_GUID_IGNORE, GUID_SIZE);
/* test */
guid_to_str(&guid, dest);
/* verify */
ck_assert_str_eq(dest, "0C4351A6-3535-42AE-910C-CDFCE5760B58");
}
END_TEST
/******************************************************************************/
Suite *
make_suite_test_guid(void)
{
Suite *s;
TCase *tc_guid;
s = suite_create("GUID");
tc_guid = tcase_create("guid_to_str");
suite_add_tcase(s, tc_guid);
tcase_add_test(tc_guid, test_guid_to_str_remotefx);
tcase_add_test(tc_guid, test_guid_to_str_nscodec);
tcase_add_test(tc_guid, test_guid_to_str_ignore);
return s;
}

View File

@ -4,6 +4,7 @@
#endif #endif
#include "string_calls.h" #include "string_calls.h"
#include "ms-rdpbcgr.h"
#include "test_common.h" #include "test_common.h"