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.

421 lines
8.8 KiB

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