cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

registry.h (13773B)


      1/**
      2 * WinPR: Windows Portable Runtime
      3 * Windows Registry
      4 *
      5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *     http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 */
     19
     20#ifndef WINPR_REGISTRY_H
     21#define WINPR_REGISTRY_H
     22
     23#include <winpr/windows.h>
     24
     25#if defined(_WIN32) && !defined(_UWP)
     26
     27#include <winreg.h>
     28
     29#else
     30
     31#ifdef __cplusplus
     32extern "C"
     33{
     34#endif
     35
     36#include <winpr/winpr.h>
     37#include <winpr/wtypes.h>
     38
     39#include <winpr/nt.h>
     40#include <winpr/io.h>
     41#include <winpr/error.h>
     42
     43#ifndef _WIN32
     44
     45#define OWNER_SECURITY_INFORMATION 0x00000001
     46#define GROUP_SECURITY_INFORMATION 0x00000002
     47#define DACL_SECURITY_INFORMATION 0x00000004
     48#define SACL_SECURITY_INFORMATION 0x00000008
     49
     50#define REG_OPTION_RESERVED 0x00000000
     51#define REG_OPTION_NON_VOLATILE 0x00000000
     52#define REG_OPTION_VOLATILE 0x00000001
     53#define REG_OPTION_CREATE_LINK 0x00000002
     54#define REG_OPTION_BACKUP_RESTORE 0x00000004
     55#define REG_OPTION_OPEN_LINK 0x00000008
     56
     57#define REG_CREATED_NEW_KEY 0x00000001
     58#define REG_OPENED_EXISTING_KEY 0x00000002
     59
     60#define REG_NOTIFY_CHANGE_NAME 0x01
     61#define REG_NOTIFY_CHANGE_ATTRIBUTES 0x02
     62#define REG_NOTIFY_CHANGE_LAST_SET 0x04
     63#define REG_NOTIFY_CHANGE_SECURITY 0x08
     64
     65#define KEY_QUERY_VALUE 0x00000001
     66#define KEY_SET_VALUE 0x00000002
     67#define KEY_CREATE_SUB_KEY 0x00000004
     68#define KEY_ENUMERATE_SUB_KEYS 0x00000008
     69#define KEY_NOTIFY 0x00000010
     70#define KEY_CREATE_LINK 0x00000020
     71#define KEY_WOW64_64KEY 0x00000100
     72#define KEY_WOW64_32KEY 0x00000200
     73#define KEY_WOW64_RES 0x00000300
     74
     75#define REG_WHOLE_HIVE_VOLATILE 0x00000001
     76#define REG_REFRESH_HIVE 0x00000002
     77#define REG_NO_LAZY_FLUSH 0x00000004
     78#define REG_FORCE_RESTORE 0x00000008
     79
     80#define KEY_READ                                                                      \
     81	((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & \
     82	 (~SYNCHRONIZE))
     83
     84#define KEY_WRITE ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE))
     85
     86#define KEY_EXECUTE ((KEY_READ) & (~SYNCHRONIZE))
     87
     88#define KEY_ALL_ACCESS                                                             \
     89	((STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY | \
     90	  KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY | KEY_CREATE_LINK) &                     \
     91	 (~SYNCHRONIZE))
     92
     93#define REG_NONE 0
     94#define REG_SZ 1
     95#define REG_EXPAND_SZ 2
     96#define REG_BINARY 3
     97#define REG_DWORD 4
     98#define REG_DWORD_LITTLE_ENDIAN 4
     99#define REG_DWORD_BIG_ENDIAN 5
    100#define REG_LINK 6
    101#define REG_MULTI_SZ 7
    102#define REG_RESOURCE_LIST 8
    103#define REG_FULL_RESOURCE_DESCRIPTOR 9
    104#define REG_RESOURCE_REQUIREMENTS_LIST 10
    105#define REG_QWORD 11
    106#define REG_QWORD_LITTLE_ENDIAN 11
    107
    108	typedef HANDLE HKEY;
    109	typedef HANDLE* PHKEY;
    110
    111#endif
    112
    113	typedef ACCESS_MASK REGSAM;
    114
    115#define HKEY_CLASSES_ROOT ((HKEY)(LONG_PTR)(LONG)0x80000000)
    116#define HKEY_CURRENT_USER ((HKEY)(LONG_PTR)(LONG)0x80000001)
    117#define HKEY_LOCAL_MACHINE ((HKEY)(LONG_PTR)(LONG)0x80000002)
    118#define HKEY_USERS ((HKEY)(LONG_PTR)(LONG)0x80000003)
    119#define HKEY_PERFORMANCE_DATA ((HKEY)(LONG_PTR)(LONG)0x80000004)
    120#define HKEY_PERFORMANCE_TEXT ((HKEY)(LONG_PTR)(LONG)0x80000050)
    121#define HKEY_PERFORMANCE_NLSTEXT ((HKEY)(LONG_PTR)(LONG)0x80000060)
    122#define HKEY_CURRENT_CONFIG ((HKEY)(LONG_PTR)(LONG)0x80000005)
    123#define HKEY_DYN_DATA ((HKEY)(LONG_PTR)(LONG)0x80000006)
    124#define HKEY_CURRENT_USER_LOCAL_SETTINGS ((HKEY)(LONG_PTR)(LONG)0x80000007)
    125
    126#define RRF_RT_REG_NONE 0x00000001
    127#define RRF_RT_REG_SZ 0x00000002
    128#define RRF_RT_REG_EXPAND_SZ 0x00000004
    129#define RRF_RT_REG_BINARY 0x00000008
    130#define RRF_RT_REG_DWORD 0x00000010
    131#define RRF_RT_REG_MULTI_SZ 0x00000020
    132#define RRF_RT_REG_QWORD 0x00000040
    133
    134#define RRF_RT_DWORD (RRF_RT_REG_BINARY | RRF_RT_REG_DWORD)
    135#define RRF_RT_QWORD (RRF_RT_REG_BINARY | RRF_RT_REG_QWORD)
    136#define RRF_RT_ANY 0x0000FFFF
    137
    138#define RRF_NOEXPAND 0x10000000
    139#define RRF_ZEROONFAILURE 0x20000000
    140
    141	struct val_context
    142	{
    143		int valuelen;
    144		LPVOID value_context;
    145		LPVOID val_buff_ptr;
    146	};
    147
    148	typedef struct val_context* PVALCONTEXT;
    149
    150	typedef struct pvalueA
    151	{
    152		LPSTR pv_valuename;
    153		int pv_valuelen;
    154		LPVOID pv_value_context;
    155		DWORD pv_type;
    156	} PVALUEA, *PPVALUEA;
    157
    158	typedef struct pvalueW
    159	{
    160		LPWSTR pv_valuename;
    161		int pv_valuelen;
    162		LPVOID pv_value_context;
    163		DWORD pv_type;
    164	} PVALUEW, *PPVALUEW;
    165
    166#ifdef UNICODE
    167	typedef PVALUEW PVALUE;
    168	typedef PPVALUEW PPVALUE;
    169#else
    170typedef PVALUEA PVALUE;
    171typedef PPVALUEA PPVALUE;
    172#endif
    173
    174	typedef struct value_entA
    175	{
    176		LPSTR ve_valuename;
    177		DWORD ve_valuelen;
    178		DWORD_PTR ve_valueptr;
    179		DWORD ve_type;
    180	} VALENTA, *PVALENTA;
    181
    182	typedef struct value_entW
    183	{
    184		LPWSTR ve_valuename;
    185		DWORD ve_valuelen;
    186		DWORD_PTR ve_valueptr;
    187		DWORD ve_type;
    188	} VALENTW, *PVALENTW;
    189
    190#ifdef UNICODE
    191	typedef VALENTW VALENT;
    192	typedef PVALENTW PVALENT;
    193#else
    194typedef VALENTA VALENT;
    195typedef PVALENTA PVALENT;
    196#endif
    197
    198	WINPR_API LONG RegCloseKey(HKEY hKey);
    199
    200	WINPR_API LONG RegCopyTreeW(HKEY hKeySrc, LPCWSTR lpSubKey, HKEY hKeyDest);
    201	WINPR_API LONG RegCopyTreeA(HKEY hKeySrc, LPCSTR lpSubKey, HKEY hKeyDest);
    202
    203#ifdef UNICODE
    204#define RegCopyTree RegCopyTreeW
    205#else
    206#define RegCopyTree RegCopyTreeA
    207#endif
    208
    209	WINPR_API LONG RegCreateKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass,
    210	                               DWORD dwOptions, REGSAM samDesired,
    211	                               LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult,
    212	                               LPDWORD lpdwDisposition);
    213	WINPR_API LONG RegCreateKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass,
    214	                               DWORD dwOptions, REGSAM samDesired,
    215	                               LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult,
    216	                               LPDWORD lpdwDisposition);
    217
    218#ifdef UNICODE
    219#define RegCreateKeyEx RegCreateKeyExW
    220#else
    221#define RegCreateKeyEx RegCreateKeyExA
    222#endif
    223
    224	WINPR_API LONG RegDeleteKeyExW(HKEY hKey, LPCWSTR lpSubKey, REGSAM samDesired, DWORD Reserved);
    225	WINPR_API LONG RegDeleteKeyExA(HKEY hKey, LPCSTR lpSubKey, REGSAM samDesired, DWORD Reserved);
    226
    227#ifdef UNICODE
    228#define RegDeleteKeyEx RegDeleteKeyExW
    229#else
    230#define RegDeleteKeyEx RegDeleteKeyExA
    231#endif
    232
    233	WINPR_API LONG RegDeleteTreeW(HKEY hKey, LPCWSTR lpSubKey);
    234	WINPR_API LONG RegDeleteTreeA(HKEY hKey, LPCSTR lpSubKey);
    235
    236#ifdef UNICODE
    237#define RegDeleteTree RegDeleteTreeW
    238#else
    239#define RegDeleteTree RegDeleteTreeA
    240#endif
    241
    242	WINPR_API LONG RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName);
    243	WINPR_API LONG RegDeleteValueA(HKEY hKey, LPCSTR lpValueName);
    244
    245#ifdef UNICODE
    246#define RegDeleteValue RegDeleteValueW
    247#else
    248#define RegDeleteValue RegDeleteValueA
    249#endif
    250
    251	WINPR_API LONG RegDisablePredefinedCacheEx(void);
    252
    253	WINPR_API LONG RegEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD lpcName,
    254	                             LPDWORD lpReserved, LPWSTR lpClass, LPDWORD lpcClass,
    255	                             PFILETIME lpftLastWriteTime);
    256	WINPR_API LONG RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcName,
    257	                             LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcClass,
    258	                             PFILETIME lpftLastWriteTime);
    259
    260#ifdef UNICODE
    261#define RegEnumKeyEx RegEnumKeyExW
    262#else
    263#define RegEnumKeyEx RegEnumKeyExA
    264#endif
    265
    266	WINPR_API LONG RegEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpValueName,
    267	                             LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType,
    268	                             LPBYTE lpData, LPDWORD lpcbData);
    269	WINPR_API LONG RegEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpValueName,
    270	                             LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType,
    271	                             LPBYTE lpData, LPDWORD lpcbData);
    272
    273#ifdef UNICODE
    274#define RegEnumValue RegEnumValueW
    275#else
    276#define RegEnumValue RegEnumValueA
    277#endif
    278
    279	WINPR_API LONG RegFlushKey(HKEY hKey);
    280
    281	WINPR_API LONG RegGetKeySecurity(HKEY hKey, SECURITY_INFORMATION SecurityInformation,
    282	                                 PSECURITY_DESCRIPTOR pSecurityDescriptor,
    283	                                 LPDWORD lpcbSecurityDescriptor);
    284
    285	WINPR_API LONG RegGetValueW(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags,
    286	                            LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
    287	WINPR_API LONG RegGetValueA(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags,
    288	                            LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
    289
    290#ifdef UNICODE
    291#define RegGetValue RegGetValueW
    292#else
    293#define RegGetValue RegGetValueA
    294#endif
    295
    296	WINPR_API LONG RegLoadAppKeyW(LPCWSTR lpFile, PHKEY phkResult, REGSAM samDesired,
    297	                              DWORD dwOptions, DWORD Reserved);
    298	WINPR_API LONG RegLoadAppKeyA(LPCSTR lpFile, PHKEY phkResult, REGSAM samDesired,
    299	                              DWORD dwOptions, DWORD Reserved);
    300
    301#ifdef UNICODE
    302#define RegLoadAppKey RegLoadAppKeyW
    303#else
    304#define RegLoadAppKey RegLoadAppKeyA
    305#endif
    306
    307	WINPR_API LONG RegLoadKeyW(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpFile);
    308	WINPR_API LONG RegLoadKeyA(HKEY hKey, LPCSTR lpSubKey, LPCSTR lpFile);
    309
    310#ifdef UNICODE
    311#define RegLoadKey RegLoadKeyW
    312#else
    313#define RegLoadKey RegLoadKeyA
    314#endif
    315
    316	WINPR_API LONG RegLoadMUIStringW(HKEY hKey, LPCWSTR pszValue, LPWSTR pszOutBuf, DWORD cbOutBuf,
    317	                                 LPDWORD pcbData, DWORD Flags, LPCWSTR pszDirectory);
    318	WINPR_API LONG RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, LPSTR pszOutBuf, DWORD cbOutBuf,
    319	                                 LPDWORD pcbData, DWORD Flags, LPCSTR pszDirectory);
    320
    321#ifdef UNICODE
    322#define RegLoadMUIString RegLoadMUIStringW
    323#else
    324#define RegLoadMUIString RegLoadMUIStringA
    325#endif
    326
    327	WINPR_API LONG RegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, DWORD dwNotifyFilter,
    328	                                       HANDLE hEvent, BOOL fAsynchronous);
    329
    330	WINPR_API LONG RegOpenCurrentUser(REGSAM samDesired, PHKEY phkResult);
    331
    332	WINPR_API LONG RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired,
    333	                             PHKEY phkResult);
    334	WINPR_API LONG RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired,
    335	                             PHKEY phkResult);
    336
    337#ifdef UNICODE
    338#define RegOpenKeyEx RegOpenKeyExW
    339#else
    340#define RegOpenKeyEx RegOpenKeyExA
    341#endif
    342
    343	WINPR_API LONG RegOpenUserClassesRoot(HANDLE hToken, DWORD dwOptions, REGSAM samDesired,
    344	                                      PHKEY phkResult);
    345
    346	WINPR_API LONG RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved,
    347	                                LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen,
    348	                                LPDWORD lpcMaxClassLen, LPDWORD lpcValues,
    349	                                LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen,
    350	                                LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime);
    351	WINPR_API LONG RegQueryInfoKeyA(HKEY hKey, LPSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved,
    352	                                LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen,
    353	                                LPDWORD lpcMaxClassLen, LPDWORD lpcValues,
    354	                                LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen,
    355	                                LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime);
    356
    357#ifdef UNICODE
    358#define RegQueryInfoKey RegQueryInfoKeyW
    359#else
    360#define RegQueryInfoKey RegQueryInfoKeyA
    361#endif
    362
    363	WINPR_API LONG RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved,
    364	                                LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
    365	WINPR_API LONG RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved,
    366	                                LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
    367
    368#ifdef UNICODE
    369#define RegQueryValueEx RegQueryValueExW
    370#else
    371#define RegQueryValueEx RegQueryValueExA
    372#endif
    373
    374	WINPR_API LONG RegRestoreKeyW(HKEY hKey, LPCWSTR lpFile, DWORD dwFlags);
    375	WINPR_API LONG RegRestoreKeyA(HKEY hKey, LPCSTR lpFile, DWORD dwFlags);
    376
    377#ifdef UNICODE
    378#define RegRestoreKey RegRestoreKeyW
    379#else
    380#define RegRestoreKey RegRestoreKeyA
    381#endif
    382
    383	WINPR_API LONG RegSaveKeyExW(HKEY hKey, LPCWSTR lpFile,
    384	                             LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD Flags);
    385	WINPR_API LONG RegSaveKeyExA(HKEY hKey, LPCSTR lpFile,
    386	                             LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD Flags);
    387
    388#ifdef UNICODE
    389#define RegSaveKeyEx RegSaveKeyExW
    390#else
    391#define RegSaveKeyEx RegSaveKeyExA
    392#endif
    393
    394	WINPR_API LONG RegSetKeySecurity(HKEY hKey, SECURITY_INFORMATION SecurityInformation,
    395	                                 PSECURITY_DESCRIPTOR pSecurityDescriptor);
    396
    397	WINPR_API LONG RegSetValueExW(HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, DWORD dwType,
    398	                              const BYTE* lpData, DWORD cbData);
    399	WINPR_API LONG RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType,
    400	                              const BYTE* lpData, DWORD cbData);
    401
    402#ifdef UNICODE
    403#define RegSetValueEx RegSetValueExW
    404#else
    405#define RegSetValueEx RegSetValueExA
    406#endif
    407
    408	WINPR_API LONG RegUnLoadKeyW(HKEY hKey, LPCWSTR lpSubKey);
    409	WINPR_API LONG RegUnLoadKeyA(HKEY hKey, LPCSTR lpSubKey);
    410
    411#ifdef UNICODE
    412#define RegUnLoadKey RegUnLoadKeyW
    413#else
    414#define RegUnLoadKey RegUnLoadKeyA
    415#endif
    416
    417#ifdef __cplusplus
    418}
    419#endif
    420
    421#endif
    422
    423#endif /* WINPR_REGISTRY_H */