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.

165 lines
5.1 KiB

  1. /****************************************************************************/
  2. // keynode.h
  3. //
  4. // Copyright (C) 1997-1999 Microsoft Corp.
  5. /****************************************************************************/
  6. #ifndef _TS_APP_CMP_KEY_NODE_H_
  7. #define _TS_APP_CMP_KEY_NODE_H_
  8. #include <nt.h>
  9. #include <ntrtl.h>
  10. #include <nturtl.h>
  11. #include <ntexapi.h>
  12. #include <ntregapi.h>
  13. #include <windows.h>
  14. // some utility macros
  15. #define DELETE_AND_NULL( x ) {if (x) {delete x;} x = NULL;}
  16. // ---------------- KEY BASIC INFO
  17. // Use this object as scratch pad when aquirng basic key information.
  18. class KeyBasicInfo
  19. {
  20. public:
  21. KeyBasicInfo();
  22. ~KeyBasicInfo();
  23. ULONG Size() { return size ; }
  24. KEY_BASIC_INFORMATION *Ptr() { return pInfo; }
  25. KEY_INFORMATION_CLASS Type() { return KeyBasicInformation ; }
  26. NTSTATUS Status() { return status; }
  27. PCWSTR NameSz();// this allocates memory, so it's here for debug only
  28. private:
  29. ULONG size;
  30. KEY_BASIC_INFORMATION *pInfo;
  31. ULONG status;
  32. WCHAR *pNameSz;
  33. };
  34. #if 0 // not used yet!
  35. // ---------------- KEY NODE INFO
  36. class KeyNodeInfo
  37. {
  38. public:
  39. KeyNodeInfo();
  40. ~KeyNodeInfo();
  41. ULONG Size() { return size ; }
  42. KEY_NODE_INFORMATION *Ptr() { return pInfo; }
  43. KEY_INFORMATION_CLASS Type() { return KeyNodeInformation ; }
  44. NTSTATUS Status() { return status; }
  45. private:
  46. ULONG size;
  47. KEY_NODE_INFORMATION *pInfo;
  48. ULONG status;
  49. };
  50. #endif
  51. // ---------------- KEY FULL INFO
  52. // Use this class to create objects that are used as scratch pad when
  53. // acquiring full-key-info.
  54. class KeyFullInfo
  55. {
  56. public:
  57. KeyFullInfo(); // does memory allocation, check status
  58. ~KeyFullInfo();
  59. ULONG Size() { return size ; }
  60. KEY_FULL_INFORMATION *Ptr() { return pInfo; }
  61. KEY_INFORMATION_CLASS Type() { return KeyFullInformation ; }
  62. NTSTATUS Status() { return status; }
  63. private:
  64. ULONG size;
  65. KEY_FULL_INFORMATION *pInfo;
  66. ULONG status;
  67. };
  68. // This class is used to describe a key-node, which is equivalent to a reg-key abstraction.
  69. // All key operation are caried thru this class, with the exception of key-enum, which is still
  70. // handled as a raw NT call.
  71. //
  72. // All Methods set status, which can be acquired by calling Status(), or, in most
  73. // cases, it is returned by the Method called.
  74. class KeyNode
  75. {
  76. public:
  77. KeyNode(HANDLE root, ACCESS_MASK access, PCWSTR name ); // init stuff
  78. KeyNode(KeyNode *parent, KeyBasicInfo *info ); // init stuff
  79. ~KeyNode();
  80. NTSTATUS GetPath( PWCHAR *pwch ); // get the full path to this key
  81. NTSTATUS Open(); // casue the key to be opened, as defined by params passed to the constructorA
  82. NTSTATUS Close(); // will close the key (presumed open)
  83. NTSTATUS Create(UNICODE_STRING *uClass=NULL); // create a single new key under an existing key
  84. NTSTATUS CreateEx( UNICODE_STRING *uClass=NULL); // Create a single branch that potentially has
  85. // a multiple levels of new keys such as
  86. // x1/x2/x3 under an existing key-X.
  87. // Key path specified to the constructire MUST be
  88. // a full path, starting with \Registry\etc
  89. NTSTATUS Delete(); // delete an existing key
  90. NTSTATUS DeleteSubKeys(); // delete the sub tree
  91. NTSTATUS GetFullInfo( KeyFullInfo **p);
  92. NTSTATUS Query( KEY_BASIC_INFORMATION **result , ULONG *resultSize );
  93. NTSTATUS Query( KEY_NODE_INFORMATION **result , ULONG *resultSize );
  94. NTSTATUS Query( KEY_FULL_INFORMATION **result , ULONG *resultSize );
  95. NTSTATUS Status() {return status;}
  96. HANDLE Key() {return hKey; }
  97. WCHAR *Name() {return uniName.Buffer ;}
  98. ACCESS_MASK Masks() {return accessMask ; }
  99. enum DebugType
  100. {
  101. DBG_OPEN,
  102. DBG_OPEN_FAILED,
  103. DBG_DELETE,
  104. DBG_KEY_NAME,
  105. DBG_CREATE
  106. };
  107. void Debug(DebugType );
  108. // if debug=TRUE, then the Debug() func will spit out stuff
  109. static BOOLEAN debug;
  110. private:
  111. NTSTATUS EnumerateAndDeleteSubKeys( KeyNode *, KeyBasicInfo *);
  112. PCWSTR NameSz(); // this allocates memory, so it's here for debug
  113. // since you don't really need this, and it's private
  114. WCHAR *pNameSz;
  115. HANDLE root;
  116. HANDLE hKey;
  117. UNICODE_STRING uniName;
  118. OBJECT_ATTRIBUTES ObjAttr;
  119. ACCESS_MASK accessMask;
  120. NTSTATUS status;
  121. // key infos
  122. KeyBasicInfo *basic;
  123. KeyFullInfo *full;
  124. PVOID pFullPath; // full reg key path, as in \Registr\...blah...blah...\Ts...\blah
  125. };
  126. #endif