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.

381 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. RegistryChecks.h
  5. History:
  6. 03/09/2001 maonis Created
  7. --*/
  8. #ifndef __APPVERIFIER_REGCHK_H_
  9. #define __APPVERIFIER_REGCHK_H_
  10. #include "precomp.h"
  11. //
  12. // We keep a list of keys currently open so we know where a key is
  13. // originated from.
  14. //
  15. struct RCOPENKEY
  16. {
  17. RCOPENKEY *next;
  18. HKEY hkBase;
  19. WCHAR wszPath[MAX_PATH];
  20. };
  21. struct RCWARNING
  22. {
  23. WCHAR wszPath[MAX_PATH];
  24. DWORD dwAVStatus;
  25. DWORD cLen;
  26. };
  27. #define HKCU_AppEvents_STR L"HKCU\\AppEvents"
  28. #define HKCU_Console_STR L"HKCU\\Console"
  29. #define HKCU_ControlPanel_STR L"HKCU\\Control Panel"
  30. #define HKCU_Environment_STR L"HKCU\\Environment"
  31. #define HKCU_Identities_STR L"HKCU\\Identities"
  32. #define HKCU_KeyboardLayout_STR L"HKCU\\Keyboard Layout"
  33. #define HKCU_Printers_STR L"HKCU\\Printers"
  34. #define HKCU_RemoteAccess_STR L"HKCU\\RemoteAccess"
  35. #define HKCU_SessionInformation_STR L"HKCU\\SessionInformation"
  36. #define HKCU_UNICODEProgramGroups_STR L"HKCU\\UNICODE Program Groups"
  37. #define HKCU_VolatileEnvironment_STR L"HKCU\\Volatile Environment"
  38. #define HKCU_Windows31MigrationStatus_STR L"HKCU\\Windows 3.1 Migration Status"
  39. #define HKLM_HARDWARE_STR L"HKLM\\HARDWARE"
  40. #define HKLM_SAM_STR L"HKLM\\SAM"
  41. #define HKLM_SECURITY_STR L"HKLM\\SECURITY"
  42. #define HKLM_SYSTEM_STR L"HKLM\\SYSTEM"
  43. #define HKCC_STR L"HKCC"
  44. #define HKUS_STR L"HKUS"
  45. #define NUM_OF_CHAR(x) sizeof(x) / 2 - 1
  46. //
  47. // On Windows 2000, we need to pre-allocate the event
  48. // in RTL_CRITICAL_SECTION. On XP and above, this is
  49. // a no-op.
  50. //
  51. #define PREALLOCATE_EVENT_MASK 0x80000000
  52. //
  53. // Critical section wrapper class.
  54. //
  55. class CCriticalSection
  56. {
  57. private:
  58. CRITICAL_SECTION m_CritSec;
  59. public:
  60. CCriticalSection()
  61. {
  62. InitializeCriticalSectionAndSpinCount(&m_CritSec,
  63. PREALLOCATE_EVENT_MASK | 4000);
  64. }
  65. ~CCriticalSection()
  66. {
  67. DeleteCriticalSection(&m_CritSec);
  68. }
  69. void Lock()
  70. {
  71. EnterCriticalSection(&m_CritSec);
  72. }
  73. BOOL TryLock()
  74. {
  75. return TryEnterCriticalSection(&m_CritSec);
  76. }
  77. void Unlock()
  78. {
  79. LeaveCriticalSection(&m_CritSec);
  80. }
  81. };
  82. //
  83. // Auto-lock class that uses the CCriticalSection class.
  84. //
  85. class CLock
  86. {
  87. private:
  88. CCriticalSection &m_CriticalSection;
  89. public:
  90. CLock(CCriticalSection &CriticalSection)
  91. : m_CriticalSection(CriticalSection)
  92. {
  93. m_CriticalSection.Lock();
  94. }
  95. ~CLock()
  96. {
  97. m_CriticalSection.Unlock();
  98. }
  99. };
  100. //
  101. // The reg class that does all the real work.
  102. //
  103. class CRegistryChecks
  104. {
  105. public:
  106. LONG OpenKeyExA(
  107. HKEY hKey,
  108. LPCSTR lpSubKey,
  109. LPSTR lpClass,
  110. DWORD dwOptions,
  111. REGSAM samDesired,
  112. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  113. PHKEY phkResult,
  114. LPDWORD lpdwDisposition,
  115. BOOL bCreate
  116. );
  117. LONG OpenKeyExW(
  118. HKEY hKey,
  119. LPCWSTR lpSubKey,
  120. LPWSTR lpClass,
  121. DWORD dwOptions,
  122. REGSAM samDesired,
  123. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  124. PHKEY phkResult,
  125. LPDWORD lpdwDisposition,
  126. BOOL bCreate
  127. );
  128. LONG QueryValueA(
  129. HKEY hKey,
  130. LPCSTR lpSubKey,
  131. LPSTR lpValue,
  132. PLONG lpcbValue
  133. );
  134. LONG QueryValueW(
  135. HKEY hKey,
  136. LPCWSTR lpSubKey,
  137. LPWSTR lpValue,
  138. PLONG lpcbValue
  139. );
  140. LONG QueryValueExA(
  141. HKEY hKey,
  142. LPCSTR lpValueName,
  143. LPDWORD lpReserved,
  144. LPDWORD lpType,
  145. LPBYTE lpData,
  146. LPDWORD lpcbData
  147. );
  148. LONG QueryValueExW(
  149. HKEY hKey,
  150. LPCWSTR lpValueName,
  151. LPDWORD lpReserved,
  152. LPDWORD lpType,
  153. LPBYTE lpData,
  154. LPDWORD lpcbData
  155. );
  156. LONG QueryInfoKeyA(
  157. HKEY hKey,
  158. LPSTR lpClass,
  159. LPDWORD lpcbClass,
  160. LPDWORD lpReserved,
  161. LPDWORD lpcSubKeys,
  162. LPDWORD lpcbMaxSubKeyLen,
  163. LPDWORD lpcbMaxClassLen,
  164. LPDWORD lpcValues,
  165. LPDWORD lpcbMaxValueNameLen,
  166. LPDWORD lpcbMaxValueLen,
  167. LPDWORD lpcbSecurityDescriptor,
  168. PFILETIME lpftLastWriteTime
  169. );
  170. LONG QueryInfoKeyW(
  171. HKEY hKey,
  172. LPWSTR lpClass,
  173. LPDWORD lpcbClass,
  174. LPDWORD lpReserved,
  175. LPDWORD lpcSubKeys,
  176. LPDWORD lpcbMaxSubKeyLen,
  177. LPDWORD lpcbMaxClassLen,
  178. LPDWORD lpcValues,
  179. LPDWORD lpcbMaxValueNameLen,
  180. LPDWORD lpcbMaxValueLen,
  181. LPDWORD lpcbSecurityDescriptor,
  182. PFILETIME lpftLastWriteTime
  183. );
  184. LONG SetValueA(
  185. HKEY hKey,
  186. LPCSTR lpSubKey,
  187. DWORD dwType,
  188. LPCSTR lpData,
  189. DWORD cbData
  190. );
  191. LONG SetValueW(
  192. HKEY hKey,
  193. LPCWSTR lpSubKey,
  194. DWORD dwType,
  195. LPCWSTR lpData,
  196. DWORD cbData
  197. );
  198. LONG SetValueExA(
  199. HKEY hKey,
  200. LPCSTR lpValueName,
  201. DWORD Reserved,
  202. DWORD dwType,
  203. CONST BYTE * lpData,
  204. DWORD cbData
  205. );
  206. LONG SetValueExW(
  207. HKEY hKey,
  208. LPCWSTR lpValueName,
  209. DWORD Reserved,
  210. DWORD dwType,
  211. CONST BYTE * lpData,
  212. DWORD cbData
  213. );
  214. LONG EnumValueA(
  215. HKEY hKey,
  216. DWORD dwIndex,
  217. LPSTR lpValueName,
  218. LPDWORD lpcbValueName,
  219. LPDWORD lpReserved,
  220. LPDWORD lpType,
  221. LPBYTE lpData,
  222. LPDWORD lpcbData
  223. );
  224. LONG EnumValueW(
  225. HKEY hKey,
  226. DWORD dwIndex,
  227. LPWSTR lpValueName,
  228. LPDWORD lpcbValueName,
  229. LPDWORD lpReserved,
  230. LPDWORD lpType,
  231. LPBYTE lpData,
  232. LPDWORD lpcbData
  233. );
  234. LONG EnumKeyExA(
  235. HKEY hKey,
  236. DWORD dwIndex,
  237. LPSTR lpName,
  238. LPDWORD lpcbName,
  239. LPDWORD lpReserved,
  240. LPSTR lpClass,
  241. LPDWORD lpcbClass,
  242. PFILETIME lpftLastWriteTime
  243. );
  244. LONG EnumKeyExW(
  245. HKEY hKey,
  246. DWORD dwIndex,
  247. LPWSTR lpName,
  248. LPDWORD lpcbName,
  249. LPDWORD lpReserved,
  250. LPWSTR lpClass,
  251. LPDWORD lpcbClass,
  252. PFILETIME lpftLastWriteTime
  253. );
  254. LONG CloseKey(
  255. HKEY hKey
  256. );
  257. LONG DeleteKeyA(
  258. HKEY hKey,
  259. LPCSTR lpSubKey
  260. );
  261. LONG DeleteKeyW(
  262. HKEY hKey,
  263. LPCWSTR lpSubKey
  264. );
  265. private:
  266. RCOPENKEY* FindKey(HKEY hKey);
  267. BOOL AddKey(
  268. HKEY hKey,
  269. LPCWSTR pwszPath
  270. );
  271. LONG OpenKeyExOriginalW(
  272. HKEY hKey,
  273. LPCWSTR lpSubKey,
  274. LPWSTR lpClass,
  275. DWORD dwOptions,
  276. REGSAM samDesired,
  277. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  278. PHKEY phkResult,
  279. LPDWORD lpdwDisposition,
  280. BOOL bCreate
  281. );
  282. VOID Check(
  283. HKEY hKey,
  284. LPCSTR lpSubKey,
  285. BOOL fCheckRead,
  286. BOOL fCheckWrite,
  287. REGSAM samDesired = 0
  288. );
  289. VOID Check(
  290. HKEY hKey,
  291. LPCWSTR lpSubKey,
  292. BOOL fCheckRead,
  293. BOOL fCheckWrite,
  294. REGSAM samDesired = 0
  295. );
  296. RCOPENKEY* keys;
  297. };
  298. APIHOOK_ENUM_BEGIN
  299. APIHOOK_ENUM_ENTRY(RegOpenKeyA)
  300. APIHOOK_ENUM_ENTRY(RegOpenKeyW)
  301. APIHOOK_ENUM_ENTRY(RegOpenKeyExA)
  302. APIHOOK_ENUM_ENTRY(RegOpenKeyExW)
  303. APIHOOK_ENUM_ENTRY(RegCreateKeyA)
  304. APIHOOK_ENUM_ENTRY(RegCreateKeyW)
  305. APIHOOK_ENUM_ENTRY(RegCreateKeyExA)
  306. APIHOOK_ENUM_ENTRY(RegCreateKeyExW)
  307. APIHOOK_ENUM_ENTRY(RegCloseKey)
  308. APIHOOK_ENUM_ENTRY(RegQueryValueA)
  309. APIHOOK_ENUM_ENTRY(RegQueryValueW)
  310. APIHOOK_ENUM_ENTRY(RegQueryValueExA)
  311. APIHOOK_ENUM_ENTRY(RegQueryValueExW)
  312. APIHOOK_ENUM_ENTRY(RegQueryInfoKeyA)
  313. APIHOOK_ENUM_ENTRY(RegQueryInfoKeyW)
  314. APIHOOK_ENUM_ENTRY(RegSetValueA)
  315. APIHOOK_ENUM_ENTRY(RegSetValueW)
  316. APIHOOK_ENUM_ENTRY(RegSetValueExA)
  317. APIHOOK_ENUM_ENTRY(RegSetValueExW)
  318. APIHOOK_ENUM_ENTRY(RegEnumValueA)
  319. APIHOOK_ENUM_ENTRY(RegEnumValueW)
  320. APIHOOK_ENUM_ENTRY(RegEnumKeyA)
  321. APIHOOK_ENUM_ENTRY(RegEnumKeyW)
  322. APIHOOK_ENUM_ENTRY(RegEnumKeyExA)
  323. APIHOOK_ENUM_ENTRY(RegEnumKeyExW)
  324. APIHOOK_ENUM_ENTRY(RegDeleteKeyA)
  325. APIHOOK_ENUM_ENTRY(RegDeleteKeyW)
  326. APIHOOK_ENUM_END
  327. #endif // __APPVERIFIER_REGCHK_H_