Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. wmisecur.c
  5. Abstract:
  6. Wmi security tool
  7. Author:
  8. 16-Jan-1997 AlanWar
  9. Revision History:
  10. --*/
  11. #define INITGUID
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <windows.h>
  16. #include <ole2.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <aclapi.h>
  20. #include "wmium.h"
  21. //
  22. // The routines below were blantenly stolen without remorse from the ole
  23. // sources in \nt\private\ole32\com\class\compapi.cxx. They are copied here
  24. // so that WMI doesn't need to load in ole32 only to convert a guid string
  25. // into its binary representation.
  26. //
  27. //+-------------------------------------------------------------------------
  28. //
  29. // Function: HexStringToDword (private)
  30. //
  31. // Synopsis: scan lpsz for a number of hex digits (at most 8); update lpsz
  32. // return value in Value; check for chDelim;
  33. //
  34. // Arguments: [lpsz] - the hex string to convert
  35. // [Value] - the returned value
  36. // [cDigits] - count of digits
  37. //
  38. // Returns: TRUE for success
  39. //
  40. //--------------------------------------------------------------------------
  41. BOOL HexStringToDword(LPCSTR lpsz, DWORD * RetValue,
  42. int cDigits, WCHAR chDelim)
  43. {
  44. int Count;
  45. DWORD Value;
  46. Value = 0;
  47. for (Count = 0; Count < cDigits; Count++, lpsz++)
  48. {
  49. if (*lpsz >= '0' && *lpsz <= '9')
  50. Value = (Value << 4) + *lpsz - '0';
  51. else if (*lpsz >= 'A' && *lpsz <= 'F')
  52. Value = (Value << 4) + *lpsz - 'A' + 10;
  53. else if (*lpsz >= 'a' && *lpsz <= 'f')
  54. Value = (Value << 4) + *lpsz - 'a' + 10;
  55. else
  56. return(FALSE);
  57. }
  58. *RetValue = Value;
  59. if (chDelim != 0)
  60. return *lpsz++ == chDelim;
  61. else
  62. return TRUE;
  63. }
  64. //+-------------------------------------------------------------------------
  65. //
  66. // Function: wUUIDFromString (internal)
  67. //
  68. // Synopsis: Parse UUID such as 00000000-0000-0000-0000-000000000000
  69. //
  70. // Arguments: [lpsz] - Supplies the UUID string to convert
  71. // [pguid] - Returns the GUID.
  72. //
  73. // Returns: TRUE if successful
  74. //
  75. //--------------------------------------------------------------------------
  76. BOOL wUUIDFromString(LPCSTR lpsz, LPGUID pguid)
  77. {
  78. DWORD dw;
  79. if (!HexStringToDword(lpsz, &pguid->Data1, sizeof(DWORD)*2, '-'))
  80. return FALSE;
  81. lpsz += sizeof(DWORD)*2 + 1;
  82. if (!HexStringToDword(lpsz, &dw, sizeof(WORD)*2, '-'))
  83. return FALSE;
  84. lpsz += sizeof(WORD)*2 + 1;
  85. pguid->Data2 = (WORD)dw;
  86. if (!HexStringToDword(lpsz, &dw, sizeof(WORD)*2, '-'))
  87. return FALSE;
  88. lpsz += sizeof(WORD)*2 + 1;
  89. pguid->Data3 = (WORD)dw;
  90. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, 0))
  91. return FALSE;
  92. lpsz += sizeof(BYTE)*2;
  93. pguid->Data4[0] = (BYTE)dw;
  94. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, '-'))
  95. return FALSE;
  96. lpsz += sizeof(BYTE)*2+1;
  97. pguid->Data4[1] = (BYTE)dw;
  98. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, 0))
  99. return FALSE;
  100. lpsz += sizeof(BYTE)*2;
  101. pguid->Data4[2] = (BYTE)dw;
  102. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, 0))
  103. return FALSE;
  104. lpsz += sizeof(BYTE)*2;
  105. pguid->Data4[3] = (BYTE)dw;
  106. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, 0))
  107. return FALSE;
  108. lpsz += sizeof(BYTE)*2;
  109. pguid->Data4[4] = (BYTE)dw;
  110. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, 0))
  111. return FALSE;
  112. lpsz += sizeof(BYTE)*2;
  113. pguid->Data4[5] = (BYTE)dw;
  114. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, 0))
  115. return FALSE;
  116. lpsz += sizeof(BYTE)*2;
  117. pguid->Data4[6] = (BYTE)dw;
  118. if (!HexStringToDword(lpsz, &dw, sizeof(BYTE)*2, 0))
  119. return FALSE;
  120. lpsz += sizeof(BYTE)*2;
  121. pguid->Data4[7] = (BYTE)dw;
  122. return TRUE;
  123. }
  124. //+-------------------------------------------------------------------------
  125. //
  126. // Function: wGUIDFromString (internal)
  127. //
  128. // Synopsis: Parse GUID such as {00000000-0000-0000-0000-000000000000}
  129. //
  130. // Arguments: [lpsz] - the guid string to convert
  131. // [pguid] - guid to return
  132. //
  133. // Returns: TRUE if successful
  134. //
  135. //--------------------------------------------------------------------------
  136. BOOL wGUIDFromString(LPCSTR lpsz, LPGUID pguid)
  137. {
  138. DWORD dw;
  139. if (*lpsz == '{' )
  140. lpsz++;
  141. if(wUUIDFromString(lpsz, pguid) != TRUE)
  142. return FALSE;
  143. lpsz +=36;
  144. if (*lpsz == '}' )
  145. lpsz++;
  146. if (*lpsz != '\0') // check for zero terminated string - test bug #18307
  147. {
  148. return FALSE;
  149. }
  150. return TRUE;
  151. }
  152. UCHAR Buffer[4096];
  153. int __cdecl main(int argc, char *argv[])
  154. {
  155. WMIHANDLE Handle;
  156. GUID Guid;
  157. ULONG Size;
  158. ULONG Status;
  159. if (wGUIDFromString(argv[1], &Guid))
  160. {
  161. Status = WmiOpenBlock(&Guid, WMIGUID_QUERY, &Handle);
  162. if (Status == ERROR_SUCCESS)
  163. {
  164. Size = sizeof(Buffer);
  165. Status = WmiQueryAllDataMultiple(&Handle,
  166. 1,
  167. &Size,
  168. Buffer);
  169. if (Status == ERROR_SUCCESS)
  170. {
  171. printf("returned %d bytes\n", Size);
  172. }
  173. }
  174. }
  175. }