Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenpnputil.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: BSD - See COPYING.ARM in the top level directory 00004 * FILE: ntoskrnl/io/pnpmgr/pnputil.c 00005 * PURPOSE: PnP Utility Code 00006 * PROGRAMMERS: ReactOS Portable Systems Group 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include <ntoskrnl.h> 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 /* GLOBALS ********************************************************************/ 00016 00017 /* FUNCTIONS ******************************************************************/ 00018 00019 VOID 00020 NTAPI 00021 PnpFreeUnicodeStringList(IN PUNICODE_STRING UnicodeStringList, 00022 IN ULONG StringCount) 00023 { 00024 ULONG i; 00025 00026 /* Go through the list */ 00027 if (UnicodeStringList) 00028 { 00029 /* Go through each string */ 00030 for (i = 0; i < StringCount; i++) 00031 { 00032 /* Check if it exists */ 00033 if (UnicodeStringList[i].Buffer) 00034 { 00035 /* Free it */ 00036 ExFreePool(UnicodeStringList[i].Buffer); 00037 } 00038 } 00039 00040 /* Free the whole list */ 00041 ExFreePool(UnicodeStringList); 00042 } 00043 } 00044 00045 NTSTATUS 00046 NTAPI 00047 PnpRegMultiSzToUnicodeStrings(IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation, 00048 OUT PUNICODE_STRING *UnicodeStringList, 00049 OUT PULONG UnicodeStringCount) 00050 { 00051 PWCHAR p, pp, ps; 00052 ULONG i = 0; 00053 SIZE_T n; 00054 ULONG Count = 0; 00055 00056 /* Validate the key information */ 00057 if (KeyValueInformation->Type != REG_MULTI_SZ) return STATUS_INVALID_PARAMETER; 00058 00059 /* Set the pointers */ 00060 p = (PWCHAR)((ULONG_PTR)KeyValueInformation + 00061 KeyValueInformation->DataOffset); 00062 pp = (PWCHAR)((ULONG_PTR)p + KeyValueInformation->DataLength); 00063 00064 /* Loop the data */ 00065 while (p != pp) 00066 { 00067 /* If we find a NULL, that means one string is done */ 00068 if (!*p) 00069 { 00070 /* Add to our string count */ 00071 Count++; 00072 00073 /* Check for a double-NULL, which means we're done */ 00074 if (((p + 1) == pp) || !(*(p + 1))) break; 00075 } 00076 00077 /* Go to the next character */ 00078 p++; 00079 } 00080 00081 /* If we looped the whole list over, we missed increment a string, do it */ 00082 if (p == pp) Count++; 00083 00084 /* Allocate the list now that we know how big it is */ 00085 *UnicodeStringList = ExAllocatePoolWithTag(PagedPool, 00086 sizeof(UNICODE_STRING) * Count, 00087 'sUpP'); 00088 if (!(*UnicodeStringList)) return STATUS_INSUFFICIENT_RESOURCES; 00089 00090 /* Set pointers for second loop */ 00091 ps = p = (PWCHAR)((ULONG_PTR)KeyValueInformation + 00092 KeyValueInformation->DataOffset); 00093 00094 /* Loop again, to do the copy this time */ 00095 while (p != pp) 00096 { 00097 /* If we find a NULL, that means one string is done */ 00098 if (!*p) 00099 { 00100 /* Check how long this string is */ 00101 n = (ULONG_PTR)p - (ULONG_PTR)ps + sizeof(UNICODE_NULL); 00102 00103 /* Allocate the buffer */ 00104 (*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool, 00105 n, 00106 'sUpP'); 00107 if (!(*UnicodeStringList)[i].Buffer) 00108 { 00109 /* Back out of everything */ 00110 PnpFreeUnicodeStringList(*UnicodeStringList, i); 00111 return STATUS_INSUFFICIENT_RESOURCES; 00112 } 00113 00114 /* Copy the string into the buffer */ 00115 RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n); 00116 00117 /* Set the lengths */ 00118 (*UnicodeStringList)[i].MaximumLength = (USHORT)n; 00119 (*UnicodeStringList)[i].Length = (USHORT)(n - sizeof(UNICODE_NULL)); 00120 00121 /* One more entry done */ 00122 i++; 00123 00124 /* Check for a double-NULL, which means we're done */ 00125 if (((p + 1) == pp) || !(*(p + 1))) break; 00126 00127 /* New string */ 00128 ps = p + 1; 00129 } 00130 00131 /* New string */ 00132 p++; 00133 } 00134 00135 /* Check if we've reached the last string */ 00136 if (p == pp) 00137 { 00138 /* Calculate the string length */ 00139 n = (ULONG_PTR)p - (ULONG_PTR)ps; 00140 00141 /* Allocate the buffer for it */ 00142 (*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool, 00143 n + 00144 sizeof(UNICODE_NULL), 00145 'sUpP'); 00146 if (!(*UnicodeStringList)[i].Buffer) 00147 { 00148 /* Back out of everything */ 00149 PnpFreeUnicodeStringList(*UnicodeStringList, i); 00150 return STATUS_INSUFFICIENT_RESOURCES; 00151 } 00152 00153 /* Make sure there's an actual string here */ 00154 if (n) RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n); 00155 00156 /* Null-terminate the string ourselves */ 00157 (*UnicodeStringList)[i].Buffer[n / sizeof(WCHAR)] = UNICODE_NULL; 00158 00159 /* Set the lenghts */ 00160 (*UnicodeStringList)[i].Length = (USHORT)n; 00161 (*UnicodeStringList)[i].MaximumLength = (USHORT)(n + sizeof(UNICODE_NULL)); 00162 } 00163 00164 /* And we're done */ 00165 *UnicodeStringCount = Count; 00166 return STATUS_SUCCESS; 00167 } 00168 00169 BOOLEAN 00170 NTAPI 00171 PnpRegSzToString(IN PWCHAR RegSzData, 00172 IN ULONG RegSzLength, 00173 OUT PUSHORT StringLength OPTIONAL) 00174 { 00175 PWCHAR p, pp; 00176 00177 /* Find the end */ 00178 pp = RegSzData + RegSzLength; 00179 for (p = RegSzData; p < pp; p++) if (!*p) break; 00180 00181 /* Return it */ 00182 if (StringLength) *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR); 00183 return TRUE; 00184 } 00185 00186 /* EOF */ Generated on Sat May 26 2012 04:36:11 for ReactOS by
1.7.6.1
|