00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#include "nt.h"
00026
#include "ntrtlp.h"
00027
00028
#if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
00029
static
00030
int
00031 __cdecl
00032
ScanHexFormat(
00033 IN
const WCHAR* Buffer,
00034 IN ULONG MaximumLength,
00035 IN
const WCHAR* Format,
00036 ...);
00037
00038
#pragma alloc_text(PAGE, RtlStringFromGUID)
00039
#pragma alloc_text(PAGE, ScanHexFormat)
00040
#pragma alloc_text(PAGE, RtlGUIDFromString)
00041
#endif // ALLOC_PRAGMA && NTOS_KERNEL_RUNTIME
00042
00043 extern const WCHAR
GuidFormat[];
00044
00045 #define GUID_STRING_SIZE 38
00046
00047
00048 NTSYSAPI
00049
NTSTATUS
00050 NTAPI
00051 RtlStringFromGUID(
00052 IN REFGUID Guid,
00053 OUT PUNICODE_STRING GuidString
00054 )
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 {
00079
RTL_PAGED_CODE();
00080 GuidString->Length =
GUID_STRING_SIZE *
sizeof(WCHAR);
00081 GuidString->MaximumLength = GuidString->Length +
sizeof(UNICODE_NULL);
00082
if (!(GuidString->Buffer =
RtlAllocateStringRoutine(GuidString->MaximumLength))) {
00083
return STATUS_NO_MEMORY;
00084 }
00085 swprintf(GuidString->Buffer,
GuidFormat, Guid->Data1, Guid->Data2, Guid->Data3, Guid->Data4[0], Guid->Data4[1], Guid->Data4[2], Guid->Data4[3], Guid->Data4[4], Guid->Data4[5], Guid->Data4[6], Guid->Data4[7]);
00086
return STATUS_SUCCESS;
00087 }
00088
00089
00090
static
00091
int
00092 __cdecl
00093 ScanHexFormat(
00094 IN
const WCHAR* Buffer,
00095 IN ULONG MaximumLength,
00096 IN
const WCHAR* Format,
00097 ...)
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 {
00125 va_list ArgList;
00126
int FormatItems;
00127
00128 va_start(ArgList, Format);
00129
for (FormatItems = 0;;) {
00130
switch (*Format) {
00131
case 0:
00132
return (MaximumLength && *
Buffer) ? -1 : FormatItems;
00133
case '%':
00134 Format++;
00135
if (*Format !=
'%') {
00136 ULONG Number;
00137
int Width;
00138
int Long;
00139 PVOID Pointer;
00140
00141
for (Long = 0, Width = 0;; Format++) {
00142
if ((*Format >=
'0') && (*Format <=
'9')) {
00143 Width = Width * 10 + *Format -
'0';
00144 }
else if (*Format ==
'l') {
00145 Long++;
00146 }
else if ((*Format ==
'X') || (*Format ==
'x')) {
00147
break;
00148 }
00149 }
00150 Format++;
00151
for (Number = 0; Width--;
Buffer++, MaximumLength--) {
00152
if (!MaximumLength)
00153
return -1;
00154 Number *= 16;
00155
if ((*
Buffer >=
'0') && (*
Buffer <=
'9')) {
00156 Number += (*
Buffer -
'0');
00157 }
else if ((*
Buffer >=
'a') && (*
Buffer <=
'f')) {
00158 Number += (*
Buffer -
'a' + 10);
00159 }
else if ((*
Buffer >=
'A') && (*
Buffer <=
'F')) {
00160 Number += (*
Buffer -
'A' + 10);
00161 }
else {
00162
return -1;
00163 }
00164 }
00165 Pointer = va_arg(ArgList, PVOID);
00166
if (Long) {
00167 *(PULONG)Pointer = Number;
00168 }
else {
00169 *(
PUSHORT)Pointer = (
USHORT)Number;
00170 }
00171 FormatItems++;
00172
break;
00173 }
00174
00175
default:
00176
if (!MaximumLength || (*
Buffer != *Format)) {
00177
return -1;
00178 }
00179
Buffer++;
00180 MaximumLength--;
00181 Format++;
00182
break;
00183 }
00184 }
00185 }
00186
00187
00188 NTSYSAPI
00189
NTSTATUS
00190 NTAPI
00191 RtlGUIDFromString(
00192 IN PUNICODE_STRING GuidString,
00193 OUT GUID* Guid
00194 )
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 {
00217
USHORT Data4[8];
00218
int Count;
00219
00220
RTL_PAGED_CODE();
00221
if (
ScanHexFormat(GuidString->Buffer, GuidString->Length /
sizeof(WCHAR),
GuidFormat, &Guid->Data1, &Guid->Data2, &Guid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3], &Data4[4], &Data4[5], &Data4[6], &Data4[7]) == -1) {
00222
return STATUS_INVALID_PARAMETER;
00223 }
00224
for (
Count = 0;
Count <
sizeof(Data4)/
sizeof(Data4[0]);
Count++) {
00225 Guid->Data4[
Count] = (UCHAR)Data4[
Count];
00226 }
00227
return STATUS_SUCCESS;
00228 }