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.

317 lines
7.4 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. // The reg class that does all the real work.
  48. //
  49. class CRegistryChecks
  50. {
  51. public:
  52. LONG OpenKeyExA(
  53. HKEY hKey,
  54. LPCSTR lpSubKey,
  55. LPSTR lpClass,
  56. DWORD dwOptions,
  57. REGSAM samDesired,
  58. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  59. PHKEY phkResult,
  60. LPDWORD lpdwDisposition,
  61. BOOL bCreate
  62. );
  63. LONG OpenKeyExW(
  64. HKEY hKey,
  65. LPCWSTR lpSubKey,
  66. LPWSTR lpClass,
  67. DWORD dwOptions,
  68. REGSAM samDesired,
  69. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  70. PHKEY phkResult,
  71. LPDWORD lpdwDisposition,
  72. BOOL bCreate
  73. );
  74. LONG QueryValueA(
  75. HKEY hKey,
  76. LPCSTR lpSubKey,
  77. LPSTR lpValue,
  78. PLONG lpcbValue
  79. );
  80. LONG QueryValueW(
  81. HKEY hKey,
  82. LPCWSTR lpSubKey,
  83. LPWSTR lpValue,
  84. PLONG lpcbValue
  85. );
  86. LONG QueryValueExA(
  87. HKEY hKey,
  88. LPCSTR lpValueName,
  89. LPDWORD lpReserved,
  90. LPDWORD lpType,
  91. LPBYTE lpData,
  92. LPDWORD lpcbData
  93. );
  94. LONG QueryValueExW(
  95. HKEY hKey,
  96. LPCWSTR lpValueName,
  97. LPDWORD lpReserved,
  98. LPDWORD lpType,
  99. LPBYTE lpData,
  100. LPDWORD lpcbData
  101. );
  102. LONG QueryInfoKeyA(
  103. HKEY hKey,
  104. LPSTR lpClass,
  105. LPDWORD lpcbClass,
  106. LPDWORD lpReserved,
  107. LPDWORD lpcSubKeys,
  108. LPDWORD lpcbMaxSubKeyLen,
  109. LPDWORD lpcbMaxClassLen,
  110. LPDWORD lpcValues,
  111. LPDWORD lpcbMaxValueNameLen,
  112. LPDWORD lpcbMaxValueLen,
  113. LPDWORD lpcbSecurityDescriptor,
  114. PFILETIME lpftLastWriteTime
  115. );
  116. LONG QueryInfoKeyW(
  117. HKEY hKey,
  118. LPWSTR lpClass,
  119. LPDWORD lpcbClass,
  120. LPDWORD lpReserved,
  121. LPDWORD lpcSubKeys,
  122. LPDWORD lpcbMaxSubKeyLen,
  123. LPDWORD lpcbMaxClassLen,
  124. LPDWORD lpcValues,
  125. LPDWORD lpcbMaxValueNameLen,
  126. LPDWORD lpcbMaxValueLen,
  127. LPDWORD lpcbSecurityDescriptor,
  128. PFILETIME lpftLastWriteTime
  129. );
  130. LONG SetValueA(
  131. HKEY hKey,
  132. LPCSTR lpSubKey,
  133. DWORD dwType,
  134. LPCSTR lpData,
  135. DWORD cbData
  136. );
  137. LONG SetValueW(
  138. HKEY hKey,
  139. LPCWSTR lpSubKey,
  140. DWORD dwType,
  141. LPCWSTR lpData,
  142. DWORD cbData
  143. );
  144. LONG SetValueExA(
  145. HKEY hKey,
  146. LPCSTR lpValueName,
  147. DWORD Reserved,
  148. DWORD dwType,
  149. CONST BYTE * lpData,
  150. DWORD cbData
  151. );
  152. LONG SetValueExW(
  153. HKEY hKey,
  154. LPCWSTR lpValueName,
  155. DWORD Reserved,
  156. DWORD dwType,
  157. CONST BYTE * lpData,
  158. DWORD cbData
  159. );
  160. LONG EnumValueA(
  161. HKEY hKey,
  162. DWORD dwIndex,
  163. LPSTR lpValueName,
  164. LPDWORD lpcbValueName,
  165. LPDWORD lpReserved,
  166. LPDWORD lpType,
  167. LPBYTE lpData,
  168. LPDWORD lpcbData
  169. );
  170. LONG EnumValueW(
  171. HKEY hKey,
  172. DWORD dwIndex,
  173. LPWSTR lpValueName,
  174. LPDWORD lpcbValueName,
  175. LPDWORD lpReserved,
  176. LPDWORD lpType,
  177. LPBYTE lpData,
  178. LPDWORD lpcbData
  179. );
  180. LONG EnumKeyExA(
  181. HKEY hKey,
  182. DWORD dwIndex,
  183. LPSTR lpName,
  184. LPDWORD lpcbName,
  185. LPDWORD lpReserved,
  186. LPSTR lpClass,
  187. LPDWORD lpcbClass,
  188. PFILETIME lpftLastWriteTime
  189. );
  190. LONG EnumKeyExW(
  191. HKEY hKey,
  192. DWORD dwIndex,
  193. LPWSTR lpName,
  194. LPDWORD lpcbName,
  195. LPDWORD lpReserved,
  196. LPWSTR lpClass,
  197. LPDWORD lpcbClass,
  198. PFILETIME lpftLastWriteTime
  199. );
  200. LONG CloseKey(
  201. HKEY hKey
  202. );
  203. LONG DeleteKeyA(
  204. HKEY hKey,
  205. LPCSTR lpSubKey
  206. );
  207. LONG DeleteKeyW(
  208. HKEY hKey,
  209. LPCWSTR lpSubKey
  210. );
  211. private:
  212. RCOPENKEY* FindKey(HKEY hKey);
  213. BOOL AddKey(
  214. HKEY hKey,
  215. LPCWSTR pwszPath
  216. );
  217. LONG OpenKeyExOriginalW(
  218. HKEY hKey,
  219. LPCWSTR lpSubKey,
  220. LPWSTR lpClass,
  221. DWORD dwOptions,
  222. REGSAM samDesired,
  223. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  224. PHKEY phkResult,
  225. LPDWORD lpdwDisposition,
  226. BOOL bCreate
  227. );
  228. VOID Check(
  229. HKEY hKey,
  230. LPCSTR lpSubKey,
  231. BOOL fCheckRead,
  232. BOOL fCheckWrite,
  233. REGSAM samDesired = 0
  234. );
  235. VOID Check(
  236. HKEY hKey,
  237. LPCWSTR lpSubKey,
  238. BOOL fCheckRead,
  239. BOOL fCheckWrite,
  240. REGSAM samDesired = 0
  241. );
  242. RCOPENKEY* keys;
  243. };
  244. APIHOOK_ENUM_BEGIN
  245. APIHOOK_ENUM_ENTRY(RegOpenKeyA)
  246. APIHOOK_ENUM_ENTRY(RegOpenKeyW)
  247. APIHOOK_ENUM_ENTRY(RegOpenKeyExA)
  248. APIHOOK_ENUM_ENTRY(RegOpenKeyExW)
  249. APIHOOK_ENUM_ENTRY(RegCreateKeyA)
  250. APIHOOK_ENUM_ENTRY(RegCreateKeyW)
  251. APIHOOK_ENUM_ENTRY(RegCreateKeyExA)
  252. APIHOOK_ENUM_ENTRY(RegCreateKeyExW)
  253. APIHOOK_ENUM_ENTRY(RegCloseKey)
  254. APIHOOK_ENUM_ENTRY(RegQueryValueA)
  255. APIHOOK_ENUM_ENTRY(RegQueryValueW)
  256. APIHOOK_ENUM_ENTRY(RegQueryValueExA)
  257. APIHOOK_ENUM_ENTRY(RegQueryValueExW)
  258. APIHOOK_ENUM_ENTRY(RegQueryInfoKeyA)
  259. APIHOOK_ENUM_ENTRY(RegQueryInfoKeyW)
  260. APIHOOK_ENUM_ENTRY(RegSetValueA)
  261. APIHOOK_ENUM_ENTRY(RegSetValueW)
  262. APIHOOK_ENUM_ENTRY(RegSetValueExA)
  263. APIHOOK_ENUM_ENTRY(RegSetValueExW)
  264. APIHOOK_ENUM_ENTRY(RegEnumValueA)
  265. APIHOOK_ENUM_ENTRY(RegEnumValueW)
  266. APIHOOK_ENUM_ENTRY(RegEnumKeyA)
  267. APIHOOK_ENUM_ENTRY(RegEnumKeyW)
  268. APIHOOK_ENUM_ENTRY(RegEnumKeyExA)
  269. APIHOOK_ENUM_ENTRY(RegEnumKeyExW)
  270. APIHOOK_ENUM_ENTRY(RegDeleteKeyA)
  271. APIHOOK_ENUM_ENTRY(RegDeleteKeyW)
  272. APIHOOK_ENUM_END
  273. #endif // __APPVERIFIER_REGCHK_H_