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.

942 lines
26 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. reg.h
  5. Abstract:
  6. Implements macros to simplify the registry APIs and to track
  7. the resource allocations.
  8. Author:
  9. Jim Schmidt (jimschm) 24-Mar-1997
  10. Revision History:
  11. jimschm 09-Apr-1997 Expanded Get functionality
  12. --*/
  13. #pragma once
  14. #define HKEY_ROOT ((HKEY) 0X7FFFFFFF)
  15. BOOL
  16. RegInitialize (
  17. VOID
  18. );
  19. VOID
  20. RegTerminate (
  21. VOID
  22. );
  23. VOID
  24. RegInitializeCache (
  25. IN UINT InitialCacheSize
  26. );
  27. VOID
  28. RegTerminateCache (
  29. VOID
  30. );
  31. //
  32. // APIs to set access mode
  33. //
  34. REGSAM
  35. SetRegOpenAccessMode (
  36. REGSAM Mode
  37. );
  38. REGSAM
  39. GetRegOpenAccessMode (
  40. REGSAM Mode
  41. );
  42. REGSAM
  43. SetRegCreateAccessMode (
  44. REGSAM Mode
  45. );
  46. REGSAM
  47. GetRegCreateAccessMode (
  48. REGSAM Mode
  49. );
  50. //
  51. // Tracking of registry calls. These functions are completely
  52. // turned off for non-debug builds and are mapped to the standard
  53. // Win32 APIs via macro definitions.
  54. //
  55. //
  56. // The Track* API take the same params as the Reg* equivalents.
  57. // The Our* API also take the same params as the Reg* equivalents, but
  58. // the debug versions have two extra parameters, File and Line.
  59. //
  60. //
  61. // Use the Track* API set instead of the Reg* API set.
  62. //
  63. #ifndef DEBUG
  64. #define DumpOpenKeys()
  65. #define TrackedRegOpenKey RegOpenKey
  66. #define TrackedRegCreateKey RegCreateKey
  67. #define TrackedRegOpenKeyEx RegOpenKeyEx
  68. #define TrackedRegCreateKeyEx RegCreateKeyEx
  69. #define TrackedRegOpenKeyA RegOpenKeyA
  70. #define TrackedRegCreateKeyA RegCreateKeyA
  71. #define TrackedRegOpenKeyExA RegOpenKeyExA
  72. #define TrackedRegCreateKeyExA RegCreateKeyExA
  73. #define TrackedRegOpenKeyW RegOpenKeyW
  74. #define TrackedRegCreateKeyW RegCreateKeyW
  75. #define TrackedRegOpenKeyExW RegOpenKeyExW
  76. #define TrackedRegCreateKeyExW RegCreateKeyExW
  77. #define OurRegOpenKeyExA RegOpenKeyExA
  78. #define OurRegCreateKeyExA RegCreateKeyExA
  79. #define OurRegOpenRootKeyA(a,b)
  80. #define OurRegOpenRootKeyW(a,b)
  81. #define OurRegOpenKeyExW RegOpenKeyExW
  82. #define OurRegCreateKeyExW RegCreateKeyExW
  83. #define CloseRegKey RealCloseRegKey
  84. #define DEBUG_TRACKING_PARAMS
  85. #define DEBUG_TRACKING_ARGS
  86. #else
  87. extern DWORD g_DontCare;
  88. #define DEBUG_TRACKING_PARAMS ,PCSTR File,DWORD Line
  89. #define DEBUG_TRACKING_ARGS , File, Line
  90. VOID
  91. DumpOpenKeys (
  92. VOID
  93. );
  94. LONG
  95. OurRegOpenKeyExA (
  96. HKEY Key,
  97. PCSTR SubKey,
  98. DWORD Unused,
  99. REGSAM SamMask,
  100. PHKEY ResultPtr,
  101. PCSTR File,
  102. DWORD Line
  103. );
  104. LONG
  105. OurRegOpenKeyExW (
  106. HKEY Key,
  107. PCWSTR SubKey,
  108. DWORD Unused,
  109. REGSAM SamMask,
  110. PHKEY ResultPtr,
  111. PCSTR File,
  112. DWORD Line
  113. );
  114. LONG
  115. OurRegCreateKeyExA (
  116. HKEY Key,
  117. PCSTR SubKey,
  118. DWORD Reserved,
  119. PSTR Class,
  120. DWORD Options,
  121. REGSAM SamMask,
  122. PSECURITY_ATTRIBUTES SecurityAttribs,
  123. PHKEY ResultPtr,
  124. PDWORD DispositionPtr,
  125. PCSTR File,
  126. DWORD Line
  127. );
  128. LONG
  129. OurRegCreateKeyExW (
  130. HKEY Key,
  131. PCWSTR SubKey,
  132. DWORD Reserved,
  133. PWSTR Class,
  134. DWORD Options,
  135. REGSAM SamMask,
  136. PSECURITY_ATTRIBUTES SecurityAttribs,
  137. PHKEY ResultPtr,
  138. PDWORD DispositionPtr,
  139. PCSTR File,
  140. DWORD Line
  141. );
  142. VOID
  143. OurRegOpenRootKeyA (
  144. HKEY Key,
  145. PCSTR SubKey,
  146. PCSTR File,
  147. DWORD Line
  148. );
  149. VOID
  150. OurRegOpenRootKeyW (
  151. HKEY Key,
  152. PCWSTR SubKey,
  153. PCSTR File,
  154. DWORD Line
  155. );
  156. #ifdef UNICODE
  157. #define OurRegOpenRootKey OurRegOpenRootKeyW
  158. #else
  159. #define OurRegOpenRootKey OurRegOpenRootKeyA
  160. #endif
  161. LONG
  162. OurCloseRegKey (
  163. HKEY Key,
  164. PCSTR File,
  165. DWORD Line
  166. );
  167. #define CloseRegKey(k) OurCloseRegKey(k,__FILE__,__LINE__)
  168. #define TrackedRegOpenKeyEx(key,subkey,u,sam,res) OurRegOpenKeyEx(key,subkey,u,sam,res,__FILE__,__LINE__)
  169. #define TrackedRegCreateKeyEx(key,subkey,r,cls,options,sam,security,res,disp) OurRegCreateKeyEx(key,subkey,r,cls,options,sam,security,res,disp,__FILE__,__LINE__)
  170. #define TrackedRegOpenKey(k,sk,rp) OurRegOpenKeyEx(k,sk,0,KEY_ALL_ACCESS,rp,__FILE__,__LINE__)
  171. #define TrackedRegCreateKey(k,sk,rp) OurRegCreateKeyEx(k,sk,0,TEXT(""),0,KEY_ALL_ACCESS,NULL,rp,&g_DontCare,__FILE__,__LINE__)
  172. #define TrackedRegOpenKeyExA(key,subkey,u,sam,res) OurRegOpenKeyExA(key,subkey,u,sam,res,__FILE__,__LINE__)
  173. #define TrackedRegCreateKeyExA(key,subkey,r,cls,options,sam,security,res,disp) OurRegCreateKeyExA(key,subkey,r,cls,options,sam,security,res,disp,__FILE__,__LINE__)
  174. #define TrackedRegOpenKeyA(k,sk,rp) OurRegOpenKeyExA(k,sk,0,KEY_ALL_ACCESS,rp,__FILE__,__LINE__)
  175. #define TrackedRegCreateKeyA(k,sk,rp) OurRegCreateKeyExA(k,sk,0,TEXT(""),0,KEY_ALL_ACCESS,NULL,rp,&g_DontCare,__FILE__,__LINE__)
  176. #define TrackedRegOpenKeyExW(key,subkey,u,sam,res) OurRegOpenKeyExW(key,subkey,u,sam,res,__FILE__,__LINE__)
  177. #define TrackedRegCreateKeyExW(key,subkey,r,cls,options,sam,security,res,disp) OurRegCreateKeyExW(key,subkey,r,cls,options,sam,security,res,disp,__FILE__,__LINE__)
  178. #define TrackedRegOpenKeyW(k,sk,rp) OurRegOpenKeyExW(k,sk,0,KEY_ALL_ACCESS,rp,__FILE__,__LINE__)
  179. #define TrackedRegCreateKeyW(K,sk,rp) OurRegCreateKeyExW(k,sk,0,TEXT(""),0,KEY_ALL_ACCESS,NULL,rp,&g_DontCare,__FILE__,__LINE__)
  180. //
  181. // Undefine the real registry APIs -- using them will throw off the tracking
  182. //
  183. #undef RegOpenKey
  184. #undef RegCreateKey
  185. #undef RegOpenKeyEx
  186. #undef RegCreateKeyEx
  187. #define RegCloseKey USE_CloseRegKey
  188. #define RegOpenKeyA USE_TrackedRegOpenKeyA
  189. #define RegCreateKeyA USE_TrackedRegCreateKeyA
  190. #define RegOpenKeyExA USE_TrackedRegOpenKeyExA
  191. #define RegCreateKeyExA USE_TrackedRegCreateKeyExA
  192. #define RegOpenKeyW USE_TrackedRegOpenKeyw
  193. #define RegCreateKeyW USE_TrackedRegCreateKeyW
  194. #define RegOpenKeyExW USE_TrackedRegOpenKeyExW
  195. #define RegCreateKeyExW USE_TrackedRegCreateKeyExW
  196. #endif
  197. #ifdef UNICODE
  198. #define OurRegOpenKeyEx OurRegOpenKeyExW
  199. #define OurRegCreateKeyEx OurRegCreateKeyExW
  200. #else
  201. #define OurRegOpenKeyEx OurRegOpenKeyExA
  202. #define OurRegCreateKeyEx OurRegCreateKeyExA
  203. #endif
  204. //
  205. // Reg API simplification routines
  206. //
  207. typedef struct {
  208. HKEY KeyHandle;
  209. BOOL OpenedByEnum;
  210. DWORD Index;
  211. CHAR SubKeyName[MAX_REGISTRY_KEYA];
  212. } REGKEY_ENUMA, *PREGKEY_ENUMA;
  213. typedef struct {
  214. HKEY KeyHandle;
  215. BOOL OpenedByEnum;
  216. DWORD Index;
  217. WCHAR SubKeyName[MAX_REGISTRY_KEYW];
  218. } REGKEY_ENUMW, *PREGKEY_ENUMW;
  219. typedef struct {
  220. HKEY KeyHandle;
  221. DWORD Index;
  222. CHAR ValueName[MAX_REGISTRY_VALUE_NAMEA];
  223. DWORD Type;
  224. DWORD DataSize;
  225. } REGVALUE_ENUMA, *PREGVALUE_ENUMA;
  226. typedef struct {
  227. HKEY KeyHandle;
  228. DWORD Index;
  229. WCHAR ValueName[MAX_REGISTRY_VALUE_NAMEW];
  230. DWORD Type;
  231. DWORD DataSize;
  232. } REGVALUE_ENUMW, *PREGVALUE_ENUMW;
  233. typedef struct _tagREGKEYINFOA {
  234. CHAR KeyName[MAX_REGISTRY_KEYA];
  235. HKEY KeyHandle;
  236. REGKEY_ENUMA KeyEnum;
  237. UINT BaseKeyBytes;
  238. struct _tagREGKEYINFOA *Parent, *Child;
  239. } REGKEYINFOA, *PREGKEYINFOA;
  240. typedef struct _tagREGKEYINFOW {
  241. WCHAR KeyName[MAX_REGISTRY_KEYW];
  242. HKEY KeyHandle;
  243. REGKEY_ENUMW KeyEnum;
  244. UINT BaseKeyBytes;
  245. struct _tagREGKEYINFOW *Parent, *Child;
  246. } REGKEYINFOW, *PREGKEYINFOW;
  247. typedef enum {
  248. ENUMERATE_SUBKEY_BEGIN,
  249. ENUMERATE_SUBKEY_RETURN,
  250. ENUMERATE_SUBKEY_NEXT,
  251. ENUMERATE_SUBKEY_DONE,
  252. NO_MORE_ITEMS
  253. } REGTREESTATE;
  254. typedef struct {
  255. CHAR FullKeyName[MAX_REGISTRY_KEYA];
  256. UINT FullKeyNameBytes;
  257. UINT EnumBaseBytes;
  258. PREGKEYINFOA CurrentKey;
  259. POOLHANDLE EnumPool;
  260. REGTREESTATE State;
  261. BOOL FirstEnumerated;
  262. } REGTREE_ENUMA, *PREGTREE_ENUMA;
  263. typedef struct {
  264. WCHAR FullKeyName[MAX_REGISTRY_KEYW];
  265. UINT FullKeyNameBytes;
  266. UINT EnumBaseBytes;
  267. PREGKEYINFOW CurrentKey;
  268. POOLHANDLE EnumPool;
  269. REGTREESTATE State;
  270. BOOL FirstEnumerated;
  271. } REGTREE_ENUMW, *PREGTREE_ENUMW;
  272. //
  273. // Enum functions
  274. //
  275. BOOL
  276. EnumFirstRegKeyA (
  277. OUT PREGKEY_ENUMA EnumPtr,
  278. IN HKEY hKey
  279. );
  280. BOOL
  281. EnumFirstRegKeyW (
  282. OUT PREGKEY_ENUMW EnumPtr,
  283. IN HKEY hKey
  284. );
  285. BOOL
  286. RealEnumFirstRegKeyStrA (
  287. OUT PREGKEY_ENUMA EnumPtr,
  288. IN PCSTR RegKey
  289. DEBUG_TRACKING_PARAMS
  290. );
  291. BOOL
  292. RealEnumFirstRegKeyStrW (
  293. OUT PREGKEY_ENUMW EnumPtr,
  294. IN PCWSTR RegKey
  295. DEBUG_TRACKING_PARAMS
  296. );
  297. #ifdef DEBUG
  298. #define EnumFirstRegKeyStrA(a,b) RealEnumFirstRegKeyStrA(a,b,__FILE__,__LINE__)
  299. #define EnumFirstRegKeyStrW(a,b) RealEnumFirstRegKeyStrW(a,b,__FILE__,__LINE__)
  300. #else
  301. #define EnumFirstRegKeyStrA RealEnumFirstRegKeyStrA
  302. #define EnumFirstRegKeyStrW RealEnumFirstRegKeyStrW
  303. #endif
  304. BOOL
  305. EnumNextRegKeyA (
  306. IN OUT PREGKEY_ENUMA EnumPtr
  307. );
  308. BOOL
  309. EnumNextRegKeyW (
  310. IN OUT PREGKEY_ENUMW EnumPtr
  311. );
  312. VOID
  313. AbortRegKeyEnumA (
  314. IN OUT PREGKEY_ENUMA EnumPtr
  315. );
  316. VOID
  317. AbortRegKeyEnumW (
  318. IN OUT PREGKEY_ENUMW EnumPtr
  319. );
  320. BOOL
  321. RealEnumFirstRegKeyInTreeA (
  322. OUT PREGTREE_ENUMA EnumPtr,
  323. IN PCSTR BaseKeyStr
  324. );
  325. #define EnumFirstRegKeyInTreeA(e,base) SETTRACKCOMMENT(BOOL,"EnumFirstRegKeyInTreeA",__FILE__,__LINE__)\
  326. RealEnumFirstRegKeyInTreeA(e,base)\
  327. CLRTRACKCOMMENT
  328. BOOL
  329. RealEnumFirstRegKeyInTreeW (
  330. OUT PREGTREE_ENUMW EnumPtr,
  331. IN PCWSTR BaseKeyStr
  332. );
  333. #define EnumFirstRegKeyInTreeW(e,base) SETTRACKCOMMENT(BOOL,"EnumFirstRegKeyInTreeW",__FILE__,__LINE__)\
  334. RealEnumFirstRegKeyInTreeW(e,base)\
  335. CLRTRACKCOMMENT
  336. BOOL
  337. RealEnumNextRegKeyInTreeA (
  338. IN OUT PREGTREE_ENUMA EnumPtr
  339. );
  340. #define EnumNextRegKeyInTreeA(e) SETTRACKCOMMENT(BOOL,"EnumNextRegKeyInTreeA",__FILE__,__LINE__)\
  341. RealEnumNextRegKeyInTreeA(e)\
  342. CLRTRACKCOMMENT
  343. BOOL
  344. RealEnumNextRegKeyInTreeW (
  345. IN OUT PREGTREE_ENUMW EnumPtr
  346. );
  347. #define EnumNextRegKeyInTreeW(e) SETTRACKCOMMENT(BOOL,"EnumNextRegKeyInTreeW",__FILE__,__LINE__)\
  348. RealEnumNextRegKeyInTreeW(e)\
  349. CLRTRACKCOMMENT
  350. VOID
  351. AbortRegKeyTreeEnumA (
  352. IN OUT PREGTREE_ENUMA EnumPtr
  353. );
  354. VOID
  355. AbortRegKeyTreeEnumW (
  356. IN OUT PREGTREE_ENUMW EnumPtr
  357. );
  358. BOOL
  359. EnumFirstRegValueA (
  360. OUT PREGVALUE_ENUMA EnumPtr,
  361. IN HKEY hKey
  362. );
  363. BOOL
  364. EnumFirstRegValueW (
  365. OUT PREGVALUE_ENUMW EnumPtr,
  366. IN HKEY hKey
  367. );
  368. BOOL
  369. EnumNextRegValueA (
  370. IN OUT PREGVALUE_ENUMA EnumPtr
  371. );
  372. BOOL
  373. EnumNextRegValueW (
  374. IN OUT PREGVALUE_ENUMW EnumPtr
  375. );
  376. PCSTR
  377. CreateEncodedRegistryStringExA (
  378. IN PCSTR Key,
  379. IN PCSTR Value, OPTIONAL
  380. IN BOOL Tree
  381. );
  382. PCWSTR
  383. CreateEncodedRegistryStringExW (
  384. IN PCWSTR Key,
  385. IN PCWSTR Value, OPTIONAL
  386. IN BOOL Tree
  387. );
  388. #define CreateEncodedRegistryStringA(k,v) CreateEncodedRegistryStringExA(k,v,TRUE)
  389. #define CreateEncodedRegistryStringW(k,v) CreateEncodedRegistryStringExW(k,v,TRUE)
  390. VOID
  391. FreeEncodedRegistryStringA (
  392. IN OUT PCSTR RegString
  393. );
  394. VOID
  395. FreeEncodedRegistryStringW (
  396. IN OUT PCWSTR RegString
  397. );
  398. BOOL
  399. DecodeRegistryStringA (
  400. IN PCSTR RegString,
  401. OUT PSTR KeyBuf, OPTIONAL
  402. OUT PSTR ValueBuf, OPTIONAL
  403. OUT PBOOL TreeFlag OPTIONAL
  404. );
  405. BOOL
  406. DecodeRegistryStringW (
  407. IN PCWSTR RegString,
  408. OUT PWSTR KeyBuf, OPTIONAL
  409. OUT PWSTR ValueBuf, OPTIONAL
  410. OUT PBOOL TreeFlag OPTIONAL
  411. );
  412. //
  413. // Versions that allow caller to specify allocator, and macro that uses
  414. // MemAllocWrapper
  415. //
  416. typedef PVOID (ALLOCATOR_PROTOTYPE)(DWORD Size);
  417. typedef ALLOCATOR_PROTOTYPE * ALLOCATOR;
  418. ALLOCATOR_PROTOTYPE MemAllocWrapper;
  419. typedef VOID (DEALLOCATOR_PROTOTYPE)(PCVOID Mem);
  420. typedef DEALLOCATOR_PROTOTYPE * DEALLOCATOR;
  421. DEALLOCATOR_PROTOTYPE MemFreeWrapper;
  422. BOOL
  423. GetRegValueTypeAndSizeA (
  424. IN HKEY Key,
  425. IN PCSTR ValueName,
  426. OUT PDWORD OutType, OPTIONAL
  427. OUT PDWORD Size OPTIONAL
  428. );
  429. BOOL
  430. GetRegValueTypeAndSizeW (
  431. IN HKEY Key,
  432. IN PCWSTR ValueName,
  433. OUT PDWORD OutType, OPTIONAL
  434. OUT PDWORD Size OPTIONAL
  435. );
  436. PBYTE
  437. GetRegValueData2A (
  438. IN HKEY hKey,
  439. IN PCSTR Value,
  440. IN ALLOCATOR Allocator,
  441. IN DEALLOCATOR Deallocator
  442. );
  443. #define GetRegValueDataA(key,valuename) SETTRACKCOMMENT(PBYTE, "GetRegValueDataA",__FILE__, __LINE__)\
  444. GetRegValueData2A((key),(valuename),MemAllocWrapper,MemFreeWrapper)\
  445. CLRTRACKCOMMENT
  446. PBYTE
  447. GetRegValueData2W (
  448. IN HKEY hKey,
  449. IN PCWSTR Value,
  450. IN ALLOCATOR Allocator,
  451. IN DEALLOCATOR Deallocator
  452. );
  453. #define GetRegValueDataW(key,valuename) SETTRACKCOMMENT(PBYTE, "GetRegValueDataW",__FILE__, __LINE__)\
  454. GetRegValueData2W((key),(valuename),MemAllocWrapper,MemFreeWrapper)\
  455. CLRTRACKCOMMENT
  456. PBYTE
  457. GetRegValueDataOfType2A (
  458. IN HKEY hKey,
  459. IN PCSTR Value,
  460. IN DWORD MustBeType,
  461. IN ALLOCATOR Allocator,
  462. IN DEALLOCATOR Deallocator
  463. );
  464. #define GetRegValueDataOfTypeA(key,valuename,type) SETTRACKCOMMENT(PBYTE, "GetRegValueDataOfTypeA",__FILE__,__LINE__)\
  465. GetRegValueDataOfType2A((key),(valuename),(type),MemAllocWrapper,MemFreeWrapper)\
  466. CLRTRACKCOMMENT
  467. PBYTE
  468. GetRegValueDataOfType2W (
  469. IN HKEY hKey,
  470. IN PCWSTR Value,
  471. IN DWORD MustBeType,
  472. IN ALLOCATOR Allocator,
  473. IN DEALLOCATOR Deallocator
  474. );
  475. #define GetRegValueDataOfTypeW(key,valuename,type) SETTRACKCOMMENT(PBYTE, "GetRegValueDataOfTypeW",__FILE__,__LINE__)\
  476. GetRegValueDataOfType2W((key),(valuename),(type),MemAllocWrapper,MemFreeWrapper)\
  477. CLRTRACKCOMMENT
  478. PBYTE
  479. GetRegKeyData2A (
  480. IN HKEY hKey,
  481. IN PCSTR SubKey,
  482. IN ALLOCATOR Allocator,
  483. IN DEALLOCATOR Deallocator
  484. );
  485. #define GetRegKeyDataA(key,subkey) SETTRACKCOMMENT(PBYTE, "GetRegKeyDataA",__FILE__,__LINE__)\
  486. GetRegKeyData2A((key),(subkey),MemAllocWrapper,MemFreeWrapper)\
  487. CLRTRACKCOMMENT
  488. PBYTE
  489. GetRegKeyData2W (
  490. IN HKEY hKey,
  491. IN PCWSTR SubKey,
  492. IN ALLOCATOR Allocator,
  493. IN DEALLOCATOR Deallocator
  494. );
  495. #define GetRegKeyDataW(key,subkey) SETTRACKCOMMENT(PBYTE, "GetRegKeyDataW",__FILE__,__LINE__)\
  496. GetRegKeyData2W((key),(subkey),MemAllocWrapper,MemFreeWrapper)\
  497. CLRTRACKCOMMENT
  498. PBYTE
  499. GetRegData2A (
  500. IN PCSTR KeyString,
  501. IN PCSTR ValueName,
  502. IN ALLOCATOR Allocator,
  503. IN DEALLOCATOR Deallocator
  504. );
  505. #define GetRegDataA(keystr,value) SETTRACKCOMMENT(PBYTE, "GetRegDataA",__FILE__,__LINE__)\
  506. GetRegData2A((keystr),(value),MemAllocWrapper,MemFreeWrapper)\
  507. CLRTRACKCOMMENT
  508. PBYTE
  509. GetRegData2W (
  510. IN PCWSTR KeyString,
  511. IN PCWSTR ValueName,
  512. IN ALLOCATOR Allocator,
  513. IN DEALLOCATOR Deallocator
  514. );
  515. #define GetRegDataW(keystr,value) SETTRACKCOMMENT(PBYTE, "GetRegDataW",__FILE__,__LINE__)\
  516. GetRegData2W((keystr),(value),MemAllocWrapper,MemFreeWrapper)\
  517. CLRTRACKCOMMENT
  518. BOOL
  519. GetRegSubkeysCount (
  520. IN HKEY ParentKey,
  521. OUT PDWORD SubKeyCount, OPTIONAL
  522. OUT PDWORD MaxSubKeyLen OPTIONAL
  523. );
  524. //
  525. // Reg key create & open
  526. //
  527. HKEY
  528. RealCreateRegKeyA (
  529. IN HKEY ParentKey,
  530. IN PCSTR NewKeyName
  531. DEBUG_TRACKING_PARAMS
  532. );
  533. HKEY
  534. RealCreateRegKeyW (
  535. IN HKEY ParentKey,
  536. IN PCWSTR NewKeyName
  537. DEBUG_TRACKING_PARAMS
  538. );
  539. HKEY
  540. RealCreateRegKeyStrA (
  541. IN PCSTR NewKeyName
  542. DEBUG_TRACKING_PARAMS
  543. );
  544. HKEY
  545. RealCreateRegKeyStrW (
  546. IN PCWSTR NewKeyName
  547. DEBUG_TRACKING_PARAMS
  548. );
  549. HKEY
  550. RealOpenRegKeyStrA (
  551. IN PCSTR RegKey
  552. DEBUG_TRACKING_PARAMS
  553. );
  554. HKEY
  555. RealOpenRegKeyStrW (
  556. IN PCWSTR RegKey
  557. DEBUG_TRACKING_PARAMS
  558. );
  559. HKEY
  560. RealOpenRegKeyA (
  561. IN HKEY ParentKey,
  562. IN PCSTR KeyToOpen
  563. DEBUG_TRACKING_PARAMS
  564. );
  565. HKEY
  566. RealOpenRegKeyW (
  567. IN HKEY ParentKey,
  568. IN PCWSTR KeyToOpen
  569. DEBUG_TRACKING_PARAMS
  570. );
  571. LONG
  572. RealCloseRegKey (
  573. IN HKEY Key
  574. );
  575. BOOL
  576. DeleteRegKeyStrA (
  577. IN PCSTR RegKey
  578. );
  579. BOOL
  580. DeleteRegKeyStrW (
  581. IN PCWSTR RegKey
  582. );
  583. BOOL
  584. DeleteEmptyRegKeyStrA (
  585. IN PCSTR RegKey
  586. );
  587. BOOL
  588. DeleteEmptyRegKeyStrW (
  589. IN PCWSTR RegKey
  590. );
  591. #ifdef DEBUG
  592. #define CreateRegKeyA(a,b) RealCreateRegKeyA(a,b,__FILE__,__LINE__)
  593. #define CreateRegKeyW(a,b) RealCreateRegKeyW(a,b,__FILE__,__LINE__)
  594. #define CreateRegKeyStrA(a) RealCreateRegKeyStrA(a,__FILE__,__LINE__)
  595. #define CreateRegKeyStrW(a) RealCreateRegKeyStrW(a,__FILE__,__LINE__)
  596. #define OpenRegKeyStrA(a) RealOpenRegKeyStrA(a,__FILE__,__LINE__)
  597. #define OpenRegKeyStrW(a) RealOpenRegKeyStrW(a,__FILE__,__LINE__)
  598. #define OpenRegKeyA(a,b) RealOpenRegKeyA(a,b,__FILE__,__LINE__)
  599. #define OpenRegKeyW(a,b) RealOpenRegKeyW(a,b,__FILE__,__LINE__)
  600. #else
  601. #define CreateRegKeyA RealCreateRegKeyA
  602. #define CreateRegKeyW RealCreateRegKeyW
  603. #define CreateRegKeyStrA RealCreateRegKeyStrA
  604. #define CreateRegKeyStrW RealCreateRegKeyStrW
  605. #define OpenRegKeyStrA RealOpenRegKeyStrA
  606. #define OpenRegKeyStrW RealOpenRegKeyStrW
  607. #define OpenRegKeyA RealOpenRegKeyA
  608. #define OpenRegKeyW RealOpenRegKeyW
  609. #endif
  610. //
  611. // Registry root functions
  612. //
  613. VOID
  614. SetRegRoot (
  615. IN HKEY Root
  616. );
  617. HKEY
  618. GetRegRoot (
  619. VOID
  620. );
  621. // Returns non-zero array offset to root, or zero if no root matches
  622. INT GetOffsetOfRootStringA (PCSTR RootString, PDWORD LengthPtr OPTIONAL);
  623. INT GetOffsetOfRootStringW (PCWSTR RootString, PDWORD LengthPtr OPTIONAL);
  624. // Returns non-zero array offset to root, or zero if no root matches
  625. INT GetOffsetOfRootKey (HKEY RootKey);
  626. // Given non-zero array offset to root, returns string or NULL if element
  627. // is out of bounds
  628. PCSTR GetRootStringFromOffsetA (INT i);
  629. PCWSTR GetRootStringFromOffsetW (INT i);
  630. // Given non-zero array offset to root, returns registry handle or NULL if
  631. // element is out of bounds
  632. HKEY GetRootKeyFromOffset (INT i);
  633. // Converts the root at the head of RegPath to an HKEY and gives the number
  634. // of characters occupied by the root string (including optional wack)
  635. HKEY ConvertRootStringToKeyA (PCSTR RegPath, PDWORD LengthPtr OPTIONAL);
  636. HKEY ConvertRootStringToKeyW (PCWSTR RegPath, PDWORD LengthPtr OPTIONAL);
  637. // Returns a pointer to a static string for the matching root, or NULL if
  638. // RegRoot does not point to a valid root
  639. PCSTR ConvertKeyToRootStringA (HKEY RegRoot);
  640. PCWSTR ConvertKeyToRootStringW (HKEY RegRoot);
  641. //
  642. // Macros
  643. //
  644. #define GetRegValueStringA(key,valuename) (PSTR) GetRegValueDataOfTypeA((key),(valuename),REG_SZ)
  645. #define GetRegValueBinaryA(key,valuename) (PBYTE) GetRegValueDataOfTypeA((key),(valuename),REG_BINARY)
  646. #define GetRegValueMultiSzA(key,valuename) (PSTR) GetRegValueDataOfTypeA((key),(valuename),REG_MULTISZ)
  647. #define GetRegValueDwordA(key,valuename) (PDWORD) GetRegValueDataOfTypeA((key),(valuename),REG_DWORD)
  648. #define GetRegValueStringW(key,valuename) (PWSTR) GetRegValueDataOfTypeW((key),(valuename),REG_SZ)
  649. #define GetRegValueBinaryW(key,valuename) (PBYTE) GetRegValueDataOfTypeW((key),(valuename),REG_BINARY)
  650. #define GetRegValueMultiSzW(key,valuename) (PWSTR) GetRegValueDataOfTypeW((key),(valuename),REG_MULTISZ)
  651. #define GetRegValueDwordW(key,valuename) (PDWORD) GetRegValueDataOfTypeW((key),(valuename),REG_DWORD)
  652. #define GetRegValueString2A(key,valuename,alloc,free) GetRegValueDataOfType2A((key),(valuename),REG_SZ,alloc,free)
  653. #define GetRegValueBinary2A(key,valuename,alloc,free) GetRegValueDataOfType2A((key),(valuename),REG_BINARY,alloc,free)
  654. #define GetRegValueMultiSz2A(key,valuename,alloc,free) GetRegValueDataOfType2A((key),(valuename),REG_MULTISZ,alloc,free)
  655. #define GetRegValueDword2A(key,valuename,alloc,free) GetRegValueDataOfType2A((key),(valuename),REG_DWORD,alloc,free)
  656. #define GetRegValueString2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_SZ,alloc,free)
  657. #define GetRegValueBinary2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_BINARY,alloc,free)
  658. #define GetRegValueMultiSz2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_MULTISZ,alloc,free)
  659. #define GetRegValueDword2W(key,valuename,alloc,free) GetRegValueDataOfType2W((key),(valuename),REG_DWORD,alloc,free)
  660. #ifdef UNICODE
  661. #define REGKEY_ENUM REGKEY_ENUMW
  662. #define PREGKEY_ENUM PREGKEY_ENUMW
  663. #define REGVALUE_ENUM REGVALUE_ENUMW
  664. #define PREGVALUE_ENUM PREGVALUE_ENUMW
  665. #define REGTREE_ENUM REGTREE_ENUMW
  666. #define PREGTREE_ENUM PREGTREE_ENUMW
  667. #define EnumFirstRegKey EnumFirstRegKeyW
  668. #define EnumFirstRegKeyStr EnumFirstRegKeyStrW
  669. #define EnumNextRegKey EnumNextRegKeyW
  670. #define AbortRegKeyEnum AbortRegKeyEnumW
  671. #define EnumFirstRegKeyInTree EnumFirstRegKeyInTreeW
  672. #define EnumNextRegKeyInTree EnumNextRegKeyInTreeW
  673. #define AbortRegKeyTreeEnum AbortRegKeyTreeEnumW
  674. #define EnumFirstRegValue EnumFirstRegValueW
  675. #define EnumNextRegValue EnumNextRegValueW
  676. #define GetRegValueTypeAndSize GetRegValueTypeAndSizeW
  677. #define GetRegValueData GetRegValueDataW
  678. #define GetRegValueDataOfType GetRegValueDataOfTypeW
  679. #define GetRegKeyData GetRegKeyDataW
  680. #define GetRegValueData2 GetRegValueData2W
  681. #define GetRegValueDataOfType2 GetRegValueDataOfType2W
  682. #define GetRegKeyData2 GetRegKeyData2W
  683. #define GetRegValueString GetRegValueStringW
  684. #define GetRegValueBinary GetRegValueBinaryW
  685. #define GetRegValueMultiSz GetRegValueMultiSzW
  686. #define GetRegValueDword GetRegValueDwordW
  687. #define GetRegValueString2 GetRegValueString2W
  688. #define GetRegValueBinary2 GetRegValueBinary2W
  689. #define GetRegValueMultiSz2 GetRegValueMultiSz2W
  690. #define GetRegValueDword2 GetRegValueDword2W
  691. #define GetRegData2 GetRegData2W
  692. #define GetRegData GetRegDataW
  693. #define CreateRegKey CreateRegKeyW
  694. #define CreateRegKeyStr CreateRegKeyStrW
  695. #define OpenRegKey OpenRegKeyW
  696. #define OpenRegKeyStr OpenRegKeyStrW
  697. #define DeleteRegKeyStr DeleteRegKeyStrW
  698. #define DeleteEmptyRegKeyStr DeleteEmptyRegKeyStrW
  699. #define GetOffsetOfRootString GetOffsetOfRootStringW
  700. #define GetRootStringFromOffset GetRootStringFromOffsetW
  701. #define ConvertRootStringToKey ConvertRootStringToKeyW
  702. #define ConvertKeyToRootString ConvertKeyToRootStringW
  703. #define CreateEncodedRegistryString CreateEncodedRegistryStringW
  704. #define CreateEncodedRegistryStringEx CreateEncodedRegistryStringExW
  705. #define FreeEncodedRegistryString FreeEncodedRegistryStringW
  706. #define DecodeRegistryString DecodeRegistryStringW
  707. #else
  708. #define REGKEY_ENUM REGKEY_ENUMA
  709. #define PREGKEY_ENUM PREGKEY_ENUMA
  710. #define REGVALUE_ENUM REGVALUE_ENUMA
  711. #define PREGVALUE_ENUM PREGVALUE_ENUMA
  712. #define REGTREE_ENUM REGTREE_ENUMA
  713. #define PREGTREE_ENUM PREGTREE_ENUMA
  714. #define EnumFirstRegKey EnumFirstRegKeyA
  715. #define EnumFirstRegKeyStr EnumFirstRegKeyStrA
  716. #define EnumNextRegKey EnumNextRegKeyA
  717. #define AbortRegKeyEnum AbortRegKeyEnumA
  718. #define EnumFirstRegKeyInTree EnumFirstRegKeyInTreeA
  719. #define EnumNextRegKeyInTree EnumNextRegKeyInTreeA
  720. #define AbortRegKeyTreeEnum AbortRegKeyTreeEnumA
  721. #define EnumFirstRegValue EnumFirstRegValueA
  722. #define EnumNextRegValue EnumNextRegValueA
  723. #define GetRegValueTypeAndSize GetRegValueTypeAndSizeA
  724. #define GetRegValueData GetRegValueDataA
  725. #define GetRegValueDataOfType GetRegValueDataOfTypeA
  726. #define GetRegKeyData GetRegKeyDataA
  727. #define GetRegValueData2 GetRegValueData2A
  728. #define GetRegValueDataOfType2 GetRegValueDataOfType2A
  729. #define GetRegKeyData2 GetRegKeyData2A
  730. #define GetRegValueString GetRegValueStringA
  731. #define GetRegValueBinary GetRegValueBinaryA
  732. #define GetRegValueMultiSz GetRegValueMultiSzA
  733. #define GetRegValueDword GetRegValueDwordA
  734. #define GetRegValueString2 GetRegValueString2A
  735. #define GetRegValueBinary2 GetRegValueBinary2A
  736. #define GetRegValueMultiSz2 GetRegValueMultiSz2A
  737. #define GetRegValueDword2 GetRegValueDword2A
  738. #define GetRegData2 GetRegData2A
  739. #define GetRegData GetRegDataA
  740. #define CreateRegKey CreateRegKeyA
  741. #define CreateRegKeyStr CreateRegKeyStrA
  742. #define OpenRegKey OpenRegKeyA
  743. #define OpenRegKeyStr OpenRegKeyStrA
  744. #define DeleteRegKeyStr DeleteRegKeyStrA
  745. #define DeleteEmptyRegKeyStr DeleteEmptyRegKeyStrA
  746. #define GetOffsetOfRootString GetOffsetOfRootStringA
  747. #define GetRootStringFromOffset GetRootStringFromOffsetA
  748. #define ConvertRootStringToKey ConvertRootStringToKeyA
  749. #define ConvertKeyToRootString ConvertKeyToRootStringA
  750. #define CreateEncodedRegistryString CreateEncodedRegistryStringA
  751. #define CreateEncodedRegistryStringEx CreateEncodedRegistryStringExA
  752. #define FreeEncodedRegistryString FreeEncodedRegistryStringA
  753. #define DecodeRegistryString DecodeRegistryStringA
  754. #endif