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.

420 lines
9.2 KiB

  1. #ifndef _VREGISTRY_H_
  2. #define _VREGISTRY_H_
  3. #include "precomp.h"
  4. #define SUCCESS(x) ((x) == ERROR_SUCCESS)
  5. #define FAILURE(x) (!SUCCESS(x))
  6. #define szOutOfMemory "ERROR OUT OF MEMORY"
  7. struct VIRTUALKEY;
  8. struct VIRTUALVAL;
  9. struct ENUMENTRY;
  10. struct OPENKEY;
  11. //
  12. // Callback for QueryValue
  13. //
  14. typedef LONG (WINAPI *_pfn_QueryValue)(
  15. OPENKEY *key,
  16. VIRTUALKEY *vkey,
  17. VIRTUALVAL *vvalue);
  18. //
  19. // Callback for SetValue
  20. //
  21. typedef LONG (WINAPI *_pfn_SetValue)(
  22. OPENKEY *key,
  23. VIRTUALKEY *vkey,
  24. VIRTUALVAL *vvalue,
  25. DWORD dwType,
  26. const BYTE* pbData,
  27. DWORD cbData);
  28. //
  29. // Callback for OpenKey, called before virtual keys are searched.
  30. //
  31. typedef LONG (WINAPI *_pfn_OpenKeyTrigger)(WCHAR* wszKey);
  32. //
  33. // A generic prototype for RegEnumValue and RegEnumKeyEx.
  34. // This is used to simplify the enumeration code.
  35. // When using this function pointer, the last four parameters
  36. // must be NULL.
  37. //
  38. typedef LONG (WINAPI *_pfn_EnumFunction)(HKEY hKey, DWORD dwIndex, LPWSTR lpName,
  39. LPDWORD lpcName, void*, void*, void*, void*);
  40. //
  41. // Redirector: maps a key from one location to another
  42. //
  43. struct REDIRECTOR
  44. {
  45. REDIRECTOR *next;
  46. LPWSTR wzPath;
  47. LPWSTR wzPathNew;
  48. };
  49. //
  50. // Protector: Prevents the key in the path from being deleted or modified.
  51. //
  52. struct PROTECTOR
  53. {
  54. PROTECTOR *next;
  55. LPWSTR wzPath;
  56. };
  57. //
  58. // Open registry key as opened with RegCreateKey/Ex or RegOpenKey/Ex
  59. //
  60. struct OPENKEY
  61. {
  62. OPENKEY *next;
  63. HKEY hkOpen;
  64. BOOL bVirtual;
  65. BOOL bRedirected;
  66. VIRTUALKEY *vkey;
  67. LPWSTR wzPath;
  68. ENUMENTRY* enumKeys;
  69. ENUMENTRY* enumValues;
  70. template<class T>
  71. ENUMENTRY* AddEnumEntries(T* entryHead, _pfn_EnumFunction enumFunc);
  72. VOID BuildEnumList();
  73. VOID FlushEnumList();
  74. };
  75. //
  76. // Virtual value: holds virtual registry value, owned by VIRTUALKEY
  77. //
  78. struct VIRTUALVAL
  79. {
  80. VIRTUALVAL *next;
  81. WCHAR wName[MAX_PATH];
  82. DWORD dwType;
  83. BYTE *lpData;
  84. DWORD cbData;
  85. _pfn_QueryValue pfnQueryValue;
  86. _pfn_SetValue pfnSetValue;
  87. };
  88. //
  89. // Virtual key: holds virtual key and values, owned by other virtualkeys
  90. //
  91. struct VIRTUALKEY
  92. {
  93. VIRTUALKEY *next;
  94. VIRTUALKEY *keys;
  95. VIRTUALVAL *values;
  96. WCHAR wName[MAX_PATH];
  97. VIRTUALKEY *AddKey(
  98. LPCWSTR lpPath
  99. );
  100. VIRTUALVAL *AddValue(
  101. LPCWSTR lpValueName,
  102. DWORD dwType,
  103. BYTE *lpData,
  104. DWORD cbData = 0
  105. );
  106. VIRTUALVAL *AddValueDWORD(
  107. LPCWSTR lpValueName,
  108. DWORD dwValue
  109. );
  110. VIRTUALVAL *AddExpander(LPCWSTR lpValueName);
  111. VIRTUALVAL *AddProtector(LPCWSTR lpValueName);
  112. VIRTUALVAL *AddCustom(
  113. LPCWSTR lpValueName,
  114. _pfn_QueryValue pfnQueryValue
  115. );
  116. VIRTUALVAL *AddCustomSet(
  117. LPCWSTR lpValueName,
  118. _pfn_SetValue pfnSetValue
  119. );
  120. VIRTUALKEY *FindKey(LPCWSTR lpKeyName);
  121. VIRTUALVAL *FindValue(
  122. LPCWSTR lpValueName
  123. );
  124. VOID Free();
  125. };
  126. //
  127. // Enum entry: An entry in a list of all enumerated items belonging to a key.
  128. //
  129. struct ENUMENTRY
  130. {
  131. ENUMENTRY* next;
  132. LPWSTR wzName;
  133. };
  134. //
  135. // Open Key Trigger: Describes a function to be called when a key is opened.
  136. //
  137. struct OPENKEYTRIGGER
  138. {
  139. OPENKEYTRIGGER* next;
  140. LPWSTR wzPath;
  141. _pfn_OpenKeyTrigger pfnTrigger;
  142. };
  143. // Class to wrap the virtual registry functionality
  144. class CVirtualRegistry
  145. {
  146. private:
  147. OPENKEY *OpenKeys;
  148. VIRTUALKEY *Root;
  149. REDIRECTOR *Redirectors;
  150. PROTECTOR *KeyProtectors;
  151. OPENKEYTRIGGER *OpenKeyTriggers;
  152. HKEY CreateDummyKey();
  153. OPENKEY *FindOpenKey(HKEY hKey);
  154. BOOL CheckRedirect(
  155. LPWSTR *lpPath
  156. );
  157. BOOL CheckProtected(
  158. LPWSTR lpPath
  159. );
  160. VOID CheckTriggers(
  161. LPWSTR lpPath
  162. );
  163. VOID FlushEnumLists();
  164. public:
  165. BOOL Init();
  166. VOID Free();
  167. REDIRECTOR *AddRedirect(
  168. LPCWSTR lpPath,
  169. LPCWSTR lpPathNew);
  170. PROTECTOR *AddKeyProtector(
  171. LPCWSTR lpPath);
  172. OPENKEYTRIGGER* AddOpenKeyTrigger(
  173. LPCWSTR lpPath,
  174. _pfn_OpenKeyTrigger pfnOpenKey);
  175. VIRTUALKEY *AddKey(LPCWSTR lpPath);
  176. LONG OpenKeyA(
  177. HKEY hKey,
  178. LPCSTR lpSubKey,
  179. LPSTR lpClass,
  180. DWORD dwOptions,
  181. REGSAM samDesired,
  182. LPSECURITY_ATTRIBUTES pSecurityAttributes,
  183. HKEY *phkResult,
  184. LPDWORD lpdwDisposition,
  185. BOOL bCreate
  186. );
  187. LONG OpenKeyW(
  188. HKEY hKey,
  189. LPCWSTR lpSubKey,
  190. LPWSTR lpClass,
  191. DWORD dwOptions,
  192. REGSAM samDesired,
  193. LPSECURITY_ATTRIBUTES pSecurityAttributes,
  194. HKEY *phkResult,
  195. LPDWORD lpdwDisposition,
  196. BOOL bCreate,
  197. BOOL bRemote = FALSE,
  198. LPCWSTR lpMachineName = NULL
  199. );
  200. LONG QueryValueA(
  201. HKEY hKey,
  202. LPSTR lpValueName,
  203. LPDWORD lpType,
  204. LPBYTE lpData,
  205. LPDWORD lpcbData
  206. );
  207. LONG QueryValueW(
  208. HKEY hKey,
  209. LPWSTR lpValueName,
  210. LPDWORD lpType,
  211. LPBYTE lpData,
  212. LPDWORD lpcbData
  213. );
  214. LONG EnumKeyA(
  215. HKEY hKey,
  216. DWORD dwIndex,
  217. LPSTR lpName,
  218. LPDWORD lpcbName
  219. );
  220. LONG EnumKeyW(
  221. HKEY hKey,
  222. DWORD dwIndex,
  223. LPWSTR lpName,
  224. LPDWORD lpcbName
  225. );
  226. LONG EnumValueA(
  227. HKEY hKey,
  228. DWORD dwIndex,
  229. LPSTR lpValueName,
  230. LPDWORD lpcbValueName,
  231. LPDWORD lpType,
  232. LPBYTE lpData,
  233. LPDWORD lpcbData
  234. );
  235. LONG EnumValueW(
  236. HKEY hKey,
  237. DWORD dwIndex,
  238. LPWSTR lpValueName,
  239. LPDWORD lpcbValueName,
  240. LPDWORD lpType,
  241. LPBYTE lpData,
  242. LPDWORD lpcbData
  243. );
  244. LONG QueryInfoA(
  245. HKEY hKey,
  246. LPSTR lpClass,
  247. LPDWORD lpcbClass,
  248. LPDWORD lpReserved,
  249. LPDWORD lpcSubKeys,
  250. LPDWORD lpcbMaxSubKeyLen,
  251. LPDWORD lpcbMaxClassLen,
  252. LPDWORD lpcValues,
  253. LPDWORD lpcbMaxValueNameLen,
  254. LPDWORD lpcbMaxValueLen,
  255. LPDWORD lpcbSecurityDescriptor,
  256. PFILETIME lpftLastWriteTime
  257. );
  258. LONG QueryInfoW(
  259. HKEY hKey,
  260. LPWSTR lpClass,
  261. LPDWORD lpcbClass,
  262. LPDWORD lpReserved,
  263. LPDWORD lpcSubKeys,
  264. LPDWORD lpcbMaxSubKeyLen,
  265. LPDWORD lpcbMaxClassLen,
  266. LPDWORD lpcValues,
  267. LPDWORD lpcbMaxValueNameLen,
  268. LPDWORD lpcbMaxValueLen,
  269. LPDWORD lpcbSecurityDescriptor,
  270. PFILETIME lpftLastWriteTime
  271. );
  272. LONG SetValueA(
  273. HKEY hKey,
  274. LPCSTR lpValueName,
  275. DWORD dwType,
  276. CONST BYTE* lpData,
  277. DWORD cbData
  278. );
  279. LONG SetValueW(
  280. HKEY hKey,
  281. LPCWSTR lpValueName,
  282. DWORD dwType,
  283. CONST BYTE* lpData,
  284. DWORD cbData
  285. );
  286. LONG DeleteKeyA(
  287. HKEY hKey,
  288. LPCSTR lpSubKey
  289. );
  290. LONG DeleteKeyW(
  291. HKEY hKey,
  292. LPCWSTR lpSubKey
  293. );
  294. LONG CloseKey(HKEY hKey);
  295. };
  296. APIHOOK_ENUM_BEGIN
  297. APIHOOK_ENUM_ENTRY(RegConnectRegistryA)
  298. APIHOOK_ENUM_ENTRY(RegConnectRegistryW)
  299. APIHOOK_ENUM_ENTRY(RegOpenKeyExA)
  300. APIHOOK_ENUM_ENTRY(RegOpenKeyExW)
  301. APIHOOK_ENUM_ENTRY(RegQueryValueExA)
  302. APIHOOK_ENUM_ENTRY(RegQueryValueExW)
  303. APIHOOK_ENUM_ENTRY(RegCloseKey)
  304. APIHOOK_ENUM_ENTRY(RegOpenKeyA)
  305. APIHOOK_ENUM_ENTRY(RegOpenKeyW)
  306. APIHOOK_ENUM_ENTRY(RegQueryValueA)
  307. APIHOOK_ENUM_ENTRY(RegQueryValueW)
  308. APIHOOK_ENUM_ENTRY(RegCreateKeyA)
  309. APIHOOK_ENUM_ENTRY(RegCreateKeyW)
  310. APIHOOK_ENUM_ENTRY(RegCreateKeyExA)
  311. APIHOOK_ENUM_ENTRY(RegCreateKeyExW)
  312. APIHOOK_ENUM_ENTRY(RegEnumValueA)
  313. APIHOOK_ENUM_ENTRY(RegEnumValueW)
  314. APIHOOK_ENUM_ENTRY(RegEnumKeyA)
  315. APIHOOK_ENUM_ENTRY(RegEnumKeyW)
  316. APIHOOK_ENUM_ENTRY(RegEnumKeyExA)
  317. APIHOOK_ENUM_ENTRY(RegEnumKeyExW)
  318. APIHOOK_ENUM_ENTRY(RegQueryInfoKeyA)
  319. APIHOOK_ENUM_ENTRY(RegQueryInfoKeyW)
  320. APIHOOK_ENUM_ENTRY(RegSetValueExA)
  321. APIHOOK_ENUM_ENTRY(RegSetValueExW)
  322. APIHOOK_ENUM_ENTRY(RegDeleteKeyA)
  323. APIHOOK_ENUM_ENTRY(RegDeleteKeyW)
  324. APIHOOK_ENUM_END
  325. extern CVirtualRegistry VRegistry;
  326. extern LPWSTR MakePath(HKEY hkBase, LPCWSTR lpKey, LPCWSTR lpSubKey);
  327. extern LPWSTR SplitPath(LPCWSTR lpPath, HKEY *hkBase);
  328. // Type for the functions that build the keys
  329. typedef VOID (*_pfn_Builder)(char* szParam);
  330. enum PURPOSE {eWin9x, eWinNT, eWin2K, eWinXP, eCustom};
  331. // Entry in the table of custom registry settings
  332. struct VENTRY
  333. {
  334. WCHAR cName[64];
  335. _pfn_Builder pfnBuilder;
  336. PURPOSE ePurpose;
  337. // Indicates if this entry should be called as part of VRegistry initialization
  338. BOOL bShouldCall;
  339. // Parameter
  340. char* szParam;
  341. };
  342. extern VENTRY *g_pVList;
  343. #endif //_VREGISTRY_H_