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.

261 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. wow64reg.c
  5. Abstract:
  6. This module define some APIs a client can use to access the registry in the mix mode.
  7. The possible scenario is
  8. 1. 32 bit Apps need to access 64 bit registry key.
  9. 2. 64 bit Apps need to access 32-bit registry key.
  10. 3. The actual redirected path from a given path.
  11. Author:
  12. ATM Shafiqul Khalid (askhalid) 10-Nov-1999
  13. Revision History:
  14. --*/
  15. #ifndef __WOW64REG_H__
  16. #define __WOW64REG_H__
  17. //#define LOG_REGISTRY //define this to turn on logging for registry
  18. #define WOW64_REGISTRY_SETUP_KEY_NAME L"\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\WOW64\\ISN Nodes"
  19. #define WOW64_REGISTRY_SETUP_KEY_NAME_REL_PARENT L"SOFTWARE\\Microsoft\\WOW64"
  20. #define WOW64_REGISTRY_SETUP_KEY_NAME_REL L"SOFTWARE\\Microsoft\\WOW64\\ISN Nodes"
  21. #define MACHINE_CLASSES_ROOT L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes"
  22. #define WOW64_REGISTRY_ISN_NODE_NAME L"ISN Nodes"
  23. #define WOW64_RUNONCE_SUBSTR L"\\REGISTRY\\MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"
  24. #define WOW64_32BIT_MACHINE_CLASSES_ROOT L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\Wow6432Node"
  25. #define WOW64_SYSTEM_DIRECTORY_NAME L"SysWow64"
  26. #define NODE_NAME_32BIT L"Wow6432Node"
  27. #define NODE_NAME_32BIT_LEN ((sizeof (NODE_NAME_32BIT)-sizeof(UNICODE_NULL))/sizeof (WCHAR))
  28. #define WOW6432_VALUE_KEY_NAME L"Wow6432KeyValue"
  29. #define ISN_NODE_MAX_LEN 256
  30. #define ISN_NODE_MAX_NUM 30
  31. #define SHRED_MEMORY_NAME L"Wow64svc Shared Memory" // different process can open this for possible interaction
  32. #define WOW64_SVC_REFLECTOR_EVENT_NAME L"Wow64svc reflector Event" // different process can use this to ping wow64svc
  33. #define WOW64_SVC_REFLECTOR_MUTEX_NAME L"Wow64svc reflector Mutex" // different process can use this to synchronize
  34. #define TAG_KEY_ATTRIBUTE_32BIT_WRITE 0x00000001 //written by 32bit apps
  35. #define TAG_KEY_ATTRIBUTE_REFLECTOR_WRITE 0x00000002 //written by reflector
  36. #define WOW64_REFLECTOR_DISABLE 0x00000001
  37. #define WOW64_REFLECTOR_ENABLE 0x00000002
  38. typedef struct _IsnNode {
  39. WCHAR NodeName [ISN_NODE_MAX_LEN];
  40. WCHAR NodeValue [ISN_NODE_MAX_LEN];
  41. DWORD Flag;
  42. HKEY hKey;
  43. }ISN_NODE_TYPE;
  44. typedef enum _WOW6432VALUEKEY_TYPE {
  45. None=0,
  46. Copy, // it's a copy
  47. Reflected, // if it's not a cpoy then it has been reflected on the otherside
  48. NonMergeable // This key should not be merged.
  49. }WOW6432_VALUEKEY_TYPE;
  50. typedef struct _WOW6432VALUEKEY {
  51. WOW6432_VALUEKEY_TYPE ValueType; //define if it's a copy from the other side
  52. SIZE_T Reserve;
  53. ULONGLONG TimeStamp; // time() stamp to track time when it was copied etc.
  54. }WOW6432_VALUEKEY;
  55. typedef WCHAR NODETYPE[ISN_NODE_MAX_LEN];
  56. #define REG_OPTION_OPEN_32BITKEY KEY_WOW64_32KEY
  57. #define REG_OPTION_OPEN_64BITKEY KEY_WOW64_64KEY
  58. #define KEY_WOW64_OPEN KEY_WOW64_64KEY
  59. // This bit is set to make
  60. // special meaning to Wow64
  61. #ifndef KEY_WOW64_RES
  62. #define KEY_WOW64_RES (KEY_WOW64_64KEY | KEY_WOW64_32KEY)
  63. #endif
  64. #define WOW64_MAX_PATH 2048
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. LONG
  69. Wow64RegOpenKeyEx(
  70. IN HKEY hKey, // handle to open key
  71. IN LPCWSTR lpSubKey, // address of name of subkey to open
  72. IN DWORD ulOptions, // reserved current implementation is zero means default.
  73. IN REGSAM samDesired, // security access mask
  74. OUT PHKEY phkResult // address of handle to open key
  75. );
  76. LONG
  77. Wow64RegCreateKeyEx(
  78. HKEY hKey, // handle to an open key
  79. LPCWSTR lpSubKey, // address of subkey name
  80. DWORD Reserved, // reserved
  81. LPWSTR lpClass, // address of class string
  82. DWORD dwOptions, // special options flag
  83. REGSAM samDesired, // desired security access
  84. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  85. // address of key security structure
  86. PHKEY phkResult, // address of buffer for opened handle
  87. LPDWORD lpdwDisposition // address of disposition value buffer
  88. );
  89. BOOL
  90. HandleToKeyName (
  91. IN HANDLE Key,
  92. IN PWCHAR KeyName,
  93. IN OUT DWORD * dwSize
  94. );
  95. BOOL
  96. CreateNode (
  97. PWCHAR Path
  98. );
  99. HKEY
  100. OpenNode (
  101. IN PWCHAR NodeName
  102. );
  103. BOOL
  104. CheckAndCreateNode (
  105. IN PWCHAR Name
  106. );
  107. LONG
  108. RegReflectKey (
  109. HKEY hKey, // handle to open key
  110. LPCTSTR lpSubKey, // subkey name
  111. DWORD dwOption // option flag
  112. );
  113. BOOL
  114. Map64bitTo32bitKeyName (
  115. IN PWCHAR Name64Key,
  116. OUT PWCHAR Name32Key
  117. );
  118. BOOL
  119. Map32bitTo64bitKeyName (
  120. IN PWCHAR Name32Key,
  121. OUT PWCHAR Name64Key
  122. );
  123. // API called from wow64services
  124. BOOL
  125. InitReflector ();
  126. BOOL
  127. StartReflector ();
  128. BOOL
  129. StopReflector ();
  130. BOOL
  131. Wow64RegNotifyLoadHive (
  132. PWCHAR Name
  133. );
  134. BOOL
  135. Wow64RegNotifyUnloadHive (
  136. PWCHAR Name
  137. );
  138. BOOL
  139. Wow64RegNotifyLoadHiveByHandle (
  140. HKEY hKey
  141. );
  142. BOOL
  143. Wow64RegNotifyUnloadHiveByHandle (
  144. HKEY hKey
  145. );
  146. BOOL
  147. Wow64RegNotifyLoadHiveUserSid (
  148. PWCHAR lpwUserSid
  149. );
  150. BOOL
  151. Wow64RegNotifyUnloadHiveUserSid (
  152. PWCHAR lpwUserSid
  153. );
  154. //Called from advapi32 to set a key dirty or need cleanup.
  155. BOOL
  156. Wow64RegSetKeyDirty (
  157. HANDLE hKeyBase
  158. );
  159. //Called from advapi32 to sync a key in case that need synchronization.
  160. BOOL
  161. Wow64RegCloseKey (
  162. HANDLE hKeyBase
  163. );
  164. //Called from advapi32 to delete a key on the mirror side.
  165. BOOL
  166. Wow64RegDeleteKey (
  167. HKEY hBase,
  168. WCHAR *SubKey
  169. );
  170. //Called from advapi to get an handle to remapped key that is on reflection list.
  171. HKEY
  172. Wow64OpenRemappedKeyOnReflection (
  173. HKEY hKey
  174. );
  175. void
  176. InitializeWow64OnBoot(
  177. DWORD dwFlag
  178. );
  179. BOOL
  180. QueryKeyTag (
  181. HKEY hBase,
  182. DWORD *dwAttribute
  183. );
  184. BOOL
  185. Wow64SyncCLSID();
  186. BOOL
  187. IsExemptRedirectedKey (
  188. IN PWCHAR SrcKey,
  189. OUT PWCHAR DestKey
  190. );
  191. BOOL
  192. IsOnReflectionByHandle (
  193. HKEY KeyHandle
  194. );
  195. #ifdef __cplusplus
  196. }
  197. #endif
  198. #endif //__WOW64REG_H__