Leaked source code of windows server 2003
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.

230 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Crtools.h
  5. Abstract:
  6. This module is the master header file for the Configuration Registry
  7. Tools (CRTools) library.
  8. Author:
  9. David J. Gilman (davegi) 02-Jan-1992
  10. Environment:
  11. Windows, Crt - User Mode
  12. --*/
  13. #include <windows.h>
  14. #include <winreg.h>
  15. //
  16. // Additional type to declare string arrays.
  17. //
  18. //
  19. // Assertion/debug macros/functions.
  20. //
  21. #ifdef UNICODE
  22. #define NUL_SIZE ( 2 )
  23. typedef WCHAR TSTR;
  24. #else
  25. #define NUL_SIZE ( 1 )
  26. typedef char TSTR;
  27. #endif // UNICODE
  28. #if DBG
  29. VOID
  30. CrAssert(
  31. IN PSTR FailedAssertion,
  32. IN PSTR FileName,
  33. IN DWORD LineNumber,
  34. IN PSTR Message OPTIONAL
  35. );
  36. #define ASSERT( exp ) \
  37. if( !( exp )) \
  38. CrAssert( #exp, __FILE__, __LINE__, NULL )
  39. #define ASSERT_MESSAGE( exp, msg ) \
  40. if( !( exp )) \
  41. CrAssert( #exp, __FILE__, __LINE__, msg )
  42. #define ASSERT_IS_KEY( Key ) \
  43. ASSERT( ARGUMENT_PRESENT( Key )); \
  44. ASSERT( Key->Signature == KEY_SIGNATURE );
  45. #else
  46. #define ASSERT( exp )
  47. #define ASSERT_MESSAGE( msg, exp )
  48. #define ASSERT_IS_KEY( Key )
  49. #endif // DBG
  50. //
  51. // Macro to check for a switch character.
  52. //
  53. #define isswitch( s ) \
  54. ((( s ) == '-' ) || (( s ) == '/' ))
  55. //
  56. // Macro to check if an argument is present (i.e. non-NULL).
  57. //
  58. #define ARGUMENT_PRESENT( arg ) \
  59. ((( PVOID ) arg ) != (( PVOID ) NULL ))
  60. //
  61. // Compare two blocks of memory for equality.
  62. //
  63. // BOOL
  64. // Compare(
  65. // IN PVOID Block1,
  66. // IN PVOID Block2,
  67. // IN DWORD NumberOfBytes
  68. // );
  69. //
  70. #define Compare( s1, s2, c ) \
  71. ( memcmp(( PVOID )( s1 ), ( PVOID )( s2 ), ( size_t )( c )) == 0 )
  72. //
  73. // Compute the length (in bytes) of a Unicode string w/o the trailing NUL.
  74. //
  75. #define LENGTH( str ) ( sizeof( str ) - NUL_SIZE )
  76. //
  77. // Check the success of a Win32 Registry API.
  78. //
  79. #define REG_API_SUCCESS( api ) \
  80. ASSERT_MESSAGE( Error == ERROR_SUCCESS, #api )
  81. //
  82. //
  83. // A KEY structure is used to hold information about a Registry Key.
  84. //
  85. typedef struct _KEY
  86. KEY,
  87. *PKEY;
  88. struct _KEY {
  89. PKEY Parent;
  90. HKEY KeyHandle;
  91. PSTR SubKeyName;
  92. PSTR SubKeyFullName;
  93. PSTR ClassName;
  94. DWORD ClassLength;
  95. DWORD TitleIndex;
  96. DWORD NumberOfSubKeys;
  97. DWORD MaxSubKeyNameLength;
  98. DWORD MaxSubKeyClassLength;
  99. DWORD NumberOfValues;
  100. DWORD MaxValueNameLength;
  101. DWORD MaxValueDataLength;
  102. DWORD SecurityDescriptorLength;
  103. FILETIME LastWriteTime;
  104. #if DBG
  105. DWORD Signature;
  106. #endif
  107. };
  108. #define FILE_TIME_STRING_LENGTH ( 25 * sizeof( TCHAR ))
  109. #define KEY_SIGNATURE ( 0xABBABAAB )
  110. #define HKEY_CLASSES_ROOT_STRING "HKEY_CLASSES_ROOT"
  111. #define HKEY_CURRENT_USER_STRING "HKEY_CURRENT_USER"
  112. #define HKEY_LOCAL_MACHINE_STRING "HKEY_LOCAL_MACHINE"
  113. #define HKEY_USERS_STRING "HKEY_USERS"
  114. extern KEY KeyClassesRoot;
  115. extern KEY KeyCurrentUser;
  116. extern KEY KeyLocalMachine;
  117. extern KEY KeyUsers;
  118. PKEY
  119. AllocateKey(
  120. IN PSTR MachineName,
  121. IN PKEY Parent,
  122. IN PSTR SubKeyName
  123. );
  124. VOID
  125. DisplayData(
  126. IN PBYTE ValueData,
  127. IN DWORD ValueDataLength
  128. );
  129. VOID
  130. DisplayKey(
  131. IN PKEY Key,
  132. IN BOOL Values,
  133. IN BOOL Data
  134. );
  135. VOID
  136. DisplayKeys(
  137. IN PKEY Key,
  138. IN BOOL Values,
  139. IN BOOL Data,
  140. IN BOOL Recurse
  141. );
  142. VOID
  143. DisplayKeyInformation(
  144. IN PKEY Key
  145. );
  146. VOID
  147. DisplayMessage(
  148. IN BOOL Terminate,
  149. IN PSTR Format,
  150. IN ...
  151. );
  152. VOID
  153. DisplayValues(
  154. IN PKEY Key,
  155. IN BOOL Data
  156. );
  157. PSTR
  158. FormatFileTime(
  159. IN PFILETIME FileTime OPTIONAL,
  160. IN PSTR Buffer OPTIONAL
  161. );
  162. VOID
  163. FreeKey(
  164. IN PKEY Key
  165. );
  166. PKEY
  167. ParseKey(
  168. IN PSTR SubKeyName
  169. );