Blame src/guid/ntapi_tt_guid.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dde53a
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_time.h>
dd89bb
#include <ntapi/nt_guid.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
dd89bb
void __fastcall __ntapi_tt_guid_copy(
dd89bb
	__out	nt_guid *	pguid_dst,
dd89bb
	__in	const nt_guid *	pguid_src)
dd89bb
{
dd89bb
	uint64_t *	dst;
dd89bb
	uint64_t *	src;
dd89bb
dd89bb
	dst = (uint64_t *)pguid_dst;
dd89bb
	src = (uint64_t *)pguid_src;
dd89bb
dd89bb
	*dst = *src;
dd89bb
	src++;	dst++;
dd89bb
	*dst = *src;
dd89bb
}
dd89bb
dd89bb
701eb2
void __fastcall __ntapi_tt_guid_to_string_utf16(
dd89bb
	__in	const nt_guid *		guid,
dd89bb
	__out	nt_guid_str_utf16 *	guid_str)
dd89bb
{
dd89bb
	uint16_t	key;
dd89bb
	wchar16_t *	wch;
dd89bb
dd89bb
	wch = &(guid_str->group5[0]);
dd89bb
dd89bb
	__ntapi_tt_uint32_to_hex_utf16(
dd89bb
		guid->data1,
dd89bb
		&guid_str->group1[0]);
dd89bb
dd89bb
	__ntapi_tt_uint16_to_hex_utf16(
dd89bb
		guid->data2,
dd89bb
		&guid_str->group2[0]);
dd89bb
dd89bb
	__ntapi_tt_uint16_to_hex_utf16(
dd89bb
		guid->data3,
dd89bb
		&guid_str->group3[0]);
dd89bb
dd89bb
	key = guid->data4[0] * 0x100 + guid->data4[1];
dd89bb
dd89bb
	__ntapi_tt_uint16_to_hex_utf16(
dd89bb
		key,
dd89bb
		&guid_str->group4[0]);
dd89bb
dd89bb
	key = guid->data4[2] * 0x100 + guid->data4[3];
dd89bb
dd89bb
	__ntapi_tt_uint16_to_hex_utf16(
dd89bb
		key,
dd89bb
		&guid_str->group5[0]);
dd89bb
dd89bb
	key = guid->data4[4] * 0x100 + guid->data4[5];
dd89bb
dd89bb
	__ntapi_tt_uint16_to_hex_utf16(
dd89bb
		key,
dd89bb
		&(wch[4]));
dd89bb
dd89bb
	key = guid->data4[6] * 0x100 + guid->data4[7];
dd89bb
dd89bb
	__ntapi_tt_uint16_to_hex_utf16(
dd89bb
		key,
dd89bb
		&(wch[8]));
dd89bb
dd89bb
	guid_str->lbrace = '{';
dd89bb
	guid_str->rbrace = '}';
dd89bb
	guid_str->dash1 = '-';
dd89bb
	guid_str->dash2 = '-';
dd89bb
	guid_str->dash3 = '-';
dd89bb
	guid_str->dash4 = '-';
dd89bb
dd89bb
	return;
dd89bb
}
dd89bb
dd89bb
dd89bb
int32_t __fastcall __ntapi_tt_guid_compare(
dd89bb
	__in	const nt_guid *	pguid_dst,
dd89bb
	__in	const nt_guid *	pguid_src)
dd89bb
{
dd89bb
	uint64_t *	dst;
dd89bb
	uint64_t *	src;
dd89bb
dd89bb
	dst = (uint64_t *)pguid_dst;
dd89bb
	src = (uint64_t *)pguid_src;
dd89bb
dd89bb
	if ((*dst != *src) || (*(++dst) != *(++src)))
dd89bb
		return NT_STATUS_OBJECT_TYPE_MISMATCH;
dd89bb
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}
dd89bb
dd89bb
701eb2
int32_t __fastcall __ntapi_tt_string_to_guid_utf16(
dd89bb
	__out	nt_guid_str_utf16 *	guid_str,
dd89bb
	__in	nt_guid *		guid)
dd89bb
{
dd89bb
	int32_t		status;
dd89bb
	wchar16_t *	wch;
dd89bb
	uint16_t	key;
dd89bb
dd89bb
	if ((guid_str->lbrace != '{')
dd89bb
			|| (guid_str->rbrace != '}')
dd89bb
			|| (guid_str->dash1 != '-')
dd89bb
			|| (guid_str->dash2 != '-')
dd89bb
			|| (guid_str->dash3 != '-')
dd89bb
			|| (guid_str->dash4 != '-'))
dd89bb
			return NT_STATUS_INVALID_PARAMETER;
dd89bb
dd89bb
	wch = &(guid_str->group5[0]);
dd89bb
dd89bb
	status = __ntapi_tt_hex_utf16_to_uint32(
dd89bb
		guid_str->group1,
dd89bb
		&guid->data1);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
dd89bb
	status = __ntapi_tt_hex_utf16_to_uint16(
dd89bb
		guid_str->group2,
dd89bb
		&guid->data2);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
dd89bb
	status = __ntapi_tt_hex_utf16_to_uint16(
dd89bb
		guid_str->group3,
dd89bb
		&guid->data3);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
dd89bb
	status = __ntapi_tt_hex_utf16_to_uint16(
dd89bb
		guid_str->group4,
dd89bb
		&key);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
3e609e
	guid->data4[0] = key >> 8;
dd89bb
	guid->data4[1] = key % 0x100;
dd89bb
dd89bb
	status = __ntapi_tt_hex_utf16_to_uint16(
dd89bb
		&(wch[0]),
dd89bb
		&key);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
3e609e
	guid->data4[2] = key >> 8;
dd89bb
	guid->data4[3] = key % 0x100;
dd89bb
dd89bb
	status = __ntapi_tt_hex_utf16_to_uint16(
dd89bb
		&(wch[4]),
dd89bb
		&key);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
3e609e
	guid->data4[4] = key >> 8;
dd89bb
	guid->data4[5] = key % 0x100;
dd89bb
dd89bb
	status = __ntapi_tt_hex_utf16_to_uint16(
dd89bb
		&(wch[8]),
dd89bb
		&key);
dd89bb
dd89bb
	if (status != NT_STATUS_SUCCESS)
dd89bb
		return status;
dd89bb
3e609e
	guid->data4[6] = key >> 8;
dd89bb
	guid->data4[7] = key % 0x100;
dd89bb
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}