summaryrefslogtreecommitdiffhomepage
path: root/src/guid/ntapi_tt_guid.c
blob: 6172214e8592b53b9b4880079fb0230c4207786a (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_time.h>
#include <ntapi/nt_guid.h>
#include "ntapi_impl.h"


void __fastcall __ntapi_tt_guid_copy(
	__out	nt_guid *	pguid_dst,
	__in	const nt_guid *	pguid_src)
{
	uint64_t *	dst;
	uint64_t *	src;

	dst = (uint64_t *)pguid_dst;
	src = (uint64_t *)pguid_src;

	*dst = *src;
	src++;	dst++;
	*dst = *src;
}


void __fastcall __ntapi_tt_guid_to_utf16_string(
	__in	const nt_guid *		guid,
	__out	nt_guid_str_utf16 *	guid_str)
{
	uint16_t	key;
	wchar16_t *	wch;

	wch = &(guid_str->group5[0]);

	__ntapi_tt_uint32_to_hex_utf16(
		guid->data1,
		&guid_str->group1[0]);

	__ntapi_tt_uint16_to_hex_utf16(
		guid->data2,
		&guid_str->group2[0]);

	__ntapi_tt_uint16_to_hex_utf16(
		guid->data3,
		&guid_str->group3[0]);

	key = guid->data4[0] * 0x100 + guid->data4[1];

	__ntapi_tt_uint16_to_hex_utf16(
		key,
		&guid_str->group4[0]);

	key = guid->data4[2] * 0x100 + guid->data4[3];

	__ntapi_tt_uint16_to_hex_utf16(
		key,
		&guid_str->group5[0]);

	key = guid->data4[4] * 0x100 + guid->data4[5];

	__ntapi_tt_uint16_to_hex_utf16(
		key,
		&(wch[4]));

	key = guid->data4[6] * 0x100 + guid->data4[7];

	__ntapi_tt_uint16_to_hex_utf16(
		key,
		&(wch[8]));

	guid_str->lbrace = '{';
	guid_str->rbrace = '}';
	guid_str->dash1 = '-';
	guid_str->dash2 = '-';
	guid_str->dash3 = '-';
	guid_str->dash4 = '-';

	return;
}


int32_t __fastcall __ntapi_tt_guid_compare(
	__in	const nt_guid *	pguid_dst,
	__in	const nt_guid *	pguid_src)
{
	uint64_t *	dst;
	uint64_t *	src;

	dst = (uint64_t *)pguid_dst;
	src = (uint64_t *)pguid_src;

	if ((*dst != *src) || (*(++dst) != *(++src)))
		return NT_STATUS_OBJECT_TYPE_MISMATCH;

	return NT_STATUS_SUCCESS;
}


int32_t __fastcall __ntapi_tt_utf16_string_to_guid(
	__out	nt_guid_str_utf16 *	guid_str,
	__in	nt_guid *		guid)
{
	int32_t		status;
	wchar16_t *	wch;
	uint16_t	key;

	if ((guid_str->lbrace != '{')
			|| (guid_str->rbrace != '}')
			|| (guid_str->dash1 != '-')
			|| (guid_str->dash2 != '-')
			|| (guid_str->dash3 != '-')
			|| (guid_str->dash4 != '-'))
			return NT_STATUS_INVALID_PARAMETER;

	wch = &(guid_str->group5[0]);

	status = __ntapi_tt_hex_utf16_to_uint32(
		guid_str->group1,
		&guid->data1);

	if (status != NT_STATUS_SUCCESS)
		return status;

	status = __ntapi_tt_hex_utf16_to_uint16(
		guid_str->group2,
		&guid->data2);

	if (status != NT_STATUS_SUCCESS)
		return status;

	status = __ntapi_tt_hex_utf16_to_uint16(
		guid_str->group3,
		&guid->data3);

	if (status != NT_STATUS_SUCCESS)
		return status;

	status = __ntapi_tt_hex_utf16_to_uint16(
		guid_str->group4,
		&key);

	if (status != NT_STATUS_SUCCESS)
		return status;

	guid->data4[0] = key / 0x100;
	guid->data4[1] = key % 0x100;

	status = __ntapi_tt_hex_utf16_to_uint16(
		&(wch[0]),
		&key);

	if (status != NT_STATUS_SUCCESS)
		return status;

	guid->data4[2] = key / 0x100;
	guid->data4[3] = key % 0x100;

	status = __ntapi_tt_hex_utf16_to_uint16(
		&(wch[4]),
		&key);

	if (status != NT_STATUS_SUCCESS)
		return status;

	guid->data4[4] = key / 0x100;
	guid->data4[5] = key % 0x100;

	status = __ntapi_tt_hex_utf16_to_uint16(
		&(wch[8]),
		&key);

	if (status != NT_STATUS_SUCCESS)
		return status;

	guid->data4[6] = key / 0x100;
	guid->data4[7] = key % 0x100;

	return NT_STATUS_SUCCESS;
}