2012-05-22 06:34:42 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Windows Registry
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-22 06:34:42 +04:00
|
|
|
#include <winpr/registry.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Windows registry MSDN pages:
|
|
|
|
* Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724880/
|
|
|
|
* Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724875/
|
|
|
|
*/
|
|
|
|
|
2016-03-29 23:03:15 +03:00
|
|
|
#if !defined(_WIN32) || defined(_UWP)
|
2012-05-22 06:34:42 +04:00
|
|
|
|
2012-06-06 05:50:03 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2021-12-22 11:12:49 +03:00
|
|
|
|
2012-07-28 23:49:16 +04:00
|
|
|
#include <winpr/crt.h>
|
2021-12-22 11:12:49 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-06-06 05:50:03 +04:00
|
|
|
|
|
|
|
#include "registry_reg.h"
|
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
#include "../log.h"
|
|
|
|
#define TAG WINPR_TAG("registry")
|
|
|
|
|
2012-06-06 05:50:03 +04:00
|
|
|
static Reg* instance = NULL;
|
|
|
|
|
2022-01-10 17:33:39 +03:00
|
|
|
static Reg* RegGetInstance(void)
|
2012-06-06 05:50:03 +04:00
|
|
|
{
|
|
|
|
if (!instance)
|
|
|
|
instance = reg_open(1);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2012-05-22 06:34:42 +04:00
|
|
|
LONG RegCloseKey(HKEY hKey)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WINPR_UNUSED(hKey);
|
2012-05-22 06:34:42 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegCopyTreeW(HKEY hKeySrc, LPCWSTR lpSubKey, HKEY hKeyDest)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegCopyTreeA(HKEY hKeySrc, LPCSTR lpSubKey, HKEY hKeyDest)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegCreateKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions,
|
2019-11-06 17:24:51 +03:00
|
|
|
REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult,
|
|
|
|
LPDWORD lpdwDisposition)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegCreateKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions,
|
2019-11-06 17:24:51 +03:00
|
|
|
REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult,
|
|
|
|
LPDWORD lpdwDisposition)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegDeleteKeyExW(HKEY hKey, LPCWSTR lpSubKey, REGSAM samDesired, DWORD Reserved)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegDeleteKeyExA(HKEY hKey, LPCSTR lpSubKey, REGSAM samDesired, DWORD Reserved)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegDeleteTreeW(HKEY hKey, LPCWSTR lpSubKey)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegDeleteTreeA(HKEY hKey, LPCSTR lpSubKey)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegDisablePredefinedCacheEx(void)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD lpcName, LPDWORD lpReserved,
|
|
|
|
LPWSTR lpClass, LPDWORD lpcClass, PFILETIME lpftLastWriteTime)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcName, LPDWORD lpReserved,
|
|
|
|
LPSTR lpClass, LPDWORD lpcClass, PFILETIME lpftLastWriteTime)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName,
|
|
|
|
LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpValueName, LPDWORD lpcchValueName,
|
|
|
|
LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegFlushKey(HKEY hKey)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegGetKeySecurity(HKEY hKey, SECURITY_INFORMATION SecurityInformation,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor, LPDWORD lpcbSecurityDescriptor)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegGetValueW(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags, LPDWORD pdwType,
|
|
|
|
PVOID pvData, LPDWORD pcbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegGetValueA(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags, LPDWORD pdwType,
|
|
|
|
PVOID pvData, LPDWORD pcbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegLoadAppKeyW(LPCWSTR lpFile, PHKEY phkResult, REGSAM samDesired, DWORD dwOptions,
|
|
|
|
DWORD Reserved)
|
2012-06-06 03:40:49 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-06-06 03:40:49 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegLoadAppKeyA(LPCSTR lpFile, PHKEY phkResult, REGSAM samDesired, DWORD dwOptions,
|
|
|
|
DWORD Reserved)
|
2012-06-06 03:40:49 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-06-06 03:40:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-22 06:34:42 +04:00
|
|
|
LONG RegLoadKeyW(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpFile)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegLoadKeyA(HKEY hKey, LPCSTR lpSubKey, LPCSTR lpFile)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegLoadMUIStringW(HKEY hKey, LPCWSTR pszValue, LPWSTR pszOutBuf, DWORD cbOutBuf,
|
|
|
|
LPDWORD pcbData, DWORD Flags, LPCWSTR pszDirectory)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, LPSTR pszOutBuf, DWORD cbOutBuf, LPDWORD pcbData,
|
|
|
|
DWORD Flags, LPCSTR pszDirectory)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, DWORD dwNotifyFilter, HANDLE hEvent,
|
|
|
|
BOOL fAsynchronous)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegOpenCurrentUser(REGSAM samDesired, PHKEY phkResult)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
LONG rc;
|
|
|
|
char* str = NULL;
|
|
|
|
int res = ConvertFromUnicode(CP_UTF8, 0, lpSubKey, -1, &str, 0, NULL, NULL);
|
|
|
|
if (res < 0)
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
rc = RegOpenKeyExA(hKey, str, ulOptions, samDesired, phkResult);
|
|
|
|
free(str);
|
|
|
|
return rc;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
|
|
|
|
{
|
2012-06-06 05:50:03 +04:00
|
|
|
RegKey* pKey;
|
2022-01-10 17:33:39 +03:00
|
|
|
Reg* reg = RegGetInstance();
|
2012-06-16 01:06:26 +04:00
|
|
|
|
|
|
|
if (!reg)
|
|
|
|
return -1;
|
|
|
|
|
2022-01-10 17:33:39 +03:00
|
|
|
if (hKey != HKEY_LOCAL_MACHINE)
|
2022-02-15 15:01:52 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Registry emulation only supports HKEY_LOCAL_MACHINE");
|
2022-01-10 17:33:39 +03:00
|
|
|
return ERROR_FILE_NOT_FOUND;
|
2022-02-15 15:01:52 +03:00
|
|
|
}
|
2022-01-10 17:33:39 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(reg->root_key);
|
2012-06-06 05:50:03 +04:00
|
|
|
pKey = reg->root_key->subkeys;
|
|
|
|
|
|
|
|
while (pKey != NULL)
|
|
|
|
{
|
2022-01-10 17:33:39 +03:00
|
|
|
WINPR_ASSERT(lpSubKey);
|
|
|
|
|
|
|
|
if (pKey->subname && (_stricmp(pKey->subname, lpSubKey) == 0))
|
2012-06-06 05:50:03 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
*phkResult = (HKEY)pKey;
|
2012-06-06 05:50:03 +04:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
pKey = pKey->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
*phkResult = NULL;
|
|
|
|
|
2012-07-27 03:43:51 +04:00
|
|
|
return ERROR_FILE_NOT_FOUND;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegOpenUserClassesRoot(HANDLE hToken, DWORD dwOptions, REGSAM samDesired, PHKEY phkResult)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved,
|
2019-11-06 17:24:51 +03:00
|
|
|
LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen,
|
|
|
|
LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen,
|
|
|
|
LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegQueryInfoKeyA(HKEY hKey, LPSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved,
|
2019-11-06 17:24:51 +03:00
|
|
|
LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen,
|
|
|
|
LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen,
|
|
|
|
LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
static LONG reg_read_int(const RegVal* pValue, LPBYTE lpData, LPDWORD lpcbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
const BYTE* ptr = NULL;
|
|
|
|
DWORD required;
|
|
|
|
|
|
|
|
WINPR_ASSERT(pValue);
|
|
|
|
|
|
|
|
switch (pValue->type)
|
|
|
|
{
|
|
|
|
case REG_DWORD:
|
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
|
|
|
required = sizeof(DWORD);
|
|
|
|
ptr = (const BYTE*)&pValue->data.dword;
|
|
|
|
break;
|
|
|
|
case REG_QWORD:
|
|
|
|
required = sizeof(UINT64);
|
|
|
|
ptr = (const BYTE*)&pValue->data.qword;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpcbData)
|
|
|
|
{
|
|
|
|
DWORD size = *lpcbData;
|
|
|
|
*lpcbData = required;
|
|
|
|
if (lpData)
|
|
|
|
{
|
|
|
|
if (size < *lpcbData)
|
|
|
|
return ERROR_MORE_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpData != NULL)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
WINPR_ASSERT(lpcbData);
|
|
|
|
|
|
|
|
size = *lpcbData;
|
|
|
|
*lpcbData = required;
|
|
|
|
if (size < required)
|
|
|
|
return ERROR_MORE_DATA;
|
|
|
|
memcpy(lpData, ptr, required);
|
|
|
|
}
|
|
|
|
else if (lpcbData != NULL)
|
|
|
|
*lpcbData = required;
|
|
|
|
return ERROR_SUCCESS;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
LONG RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType,
|
2019-11-06 17:24:51 +03:00
|
|
|
LPBYTE lpData, LPDWORD lpcbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
LONG status = ERROR_FILE_NOT_FOUND;
|
2012-06-06 05:50:03 +04:00
|
|
|
RegKey* key;
|
|
|
|
RegVal* pValue;
|
2022-02-15 15:01:52 +03:00
|
|
|
char* valueName = NULL;
|
2012-06-06 05:50:03 +04:00
|
|
|
|
2021-12-22 11:12:49 +03:00
|
|
|
WINPR_UNUSED(lpReserved);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
key = (RegKey*)hKey;
|
2021-12-22 11:12:49 +03:00
|
|
|
WINPR_ASSERT(key);
|
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
if (ConvertFromUnicode(CP_UTF8, 0, lpValueName, -1, &valueName, 0, NULL, NULL) <= 0)
|
|
|
|
goto end;
|
|
|
|
|
2012-06-06 05:50:03 +04:00
|
|
|
pValue = key->values;
|
|
|
|
|
|
|
|
while (pValue != NULL)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
if (strcmp(pValue->name, valueName) == 0)
|
2012-06-06 05:50:03 +04:00
|
|
|
{
|
2021-12-22 11:12:49 +03:00
|
|
|
if (lpType)
|
|
|
|
*lpType = pValue->type;
|
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
switch (pValue->type)
|
2012-06-06 05:50:03 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
|
|
|
case REG_QWORD:
|
|
|
|
case REG_DWORD:
|
|
|
|
return reg_read_int(pValue, lpData, lpcbData);
|
|
|
|
case REG_SZ:
|
2012-06-06 05:50:03 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
const size_t length = strnlen(pValue->data.string, UINT32_MAX) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (lpData != NULL)
|
2021-12-22 11:12:49 +03:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
DWORD size;
|
|
|
|
WINPR_ASSERT(lpcbData);
|
|
|
|
|
|
|
|
size = *lpcbData;
|
|
|
|
*lpcbData = (DWORD)length;
|
|
|
|
if (size < length)
|
2021-12-22 11:12:49 +03:00
|
|
|
return ERROR_MORE_DATA;
|
2022-02-15 15:01:52 +03:00
|
|
|
ConvertToUnicode(CP_UTF8, 0, pValue->data.string, length, (WCHAR**)&lpData,
|
|
|
|
length);
|
2021-12-22 11:12:49 +03:00
|
|
|
}
|
2022-02-15 15:01:52 +03:00
|
|
|
else if (lpcbData)
|
|
|
|
*lpcbData = (UINT32)length;
|
2012-06-06 05:50:03 +04:00
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
status = ERROR_SUCCESS;
|
|
|
|
goto end;
|
2021-12-22 11:12:49 +03:00
|
|
|
}
|
2022-02-15 15:01:52 +03:00
|
|
|
default:
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Registry emulation does not support value type %s [0x%08" PRIx32 "]",
|
|
|
|
reg_type_string(pValue->type), pValue->type);
|
|
|
|
break;
|
2012-06-06 05:50:03 +04:00
|
|
|
}
|
2022-02-15 15:01:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pValue = pValue->next;
|
|
|
|
}
|
2012-06-06 05:50:03 +04:00
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
end:
|
|
|
|
free(valueName);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType,
|
|
|
|
LPBYTE lpData, LPDWORD lpcbData)
|
|
|
|
{
|
|
|
|
RegKey* key;
|
|
|
|
RegVal* pValue;
|
2012-06-06 05:50:03 +04:00
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
WINPR_UNUSED(lpReserved);
|
|
|
|
|
|
|
|
key = (RegKey*)hKey;
|
|
|
|
WINPR_ASSERT(key);
|
|
|
|
|
|
|
|
pValue = key->values;
|
|
|
|
|
|
|
|
while (pValue != NULL)
|
|
|
|
{
|
|
|
|
if (strcmp(pValue->name, lpValueName) == 0)
|
|
|
|
{
|
|
|
|
if (lpType)
|
|
|
|
*lpType = pValue->type;
|
|
|
|
|
|
|
|
switch (pValue->type)
|
|
|
|
{
|
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
|
|
|
case REG_QWORD:
|
|
|
|
case REG_DWORD:
|
|
|
|
return reg_read_int(pValue, lpData, lpcbData);
|
|
|
|
case REG_SZ:
|
2012-06-06 05:50:03 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
const size_t length = strnlen(pValue->data.string, UINT32_MAX);
|
|
|
|
char* pData = (char*)lpData;
|
2013-01-31 04:47:27 +04:00
|
|
|
|
2022-02-15 15:01:52 +03:00
|
|
|
if (pData != NULL)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
WINPR_ASSERT(lpcbData);
|
|
|
|
|
|
|
|
size = *lpcbData;
|
|
|
|
*lpcbData = (DWORD)length;
|
|
|
|
if (size < length)
|
|
|
|
return ERROR_MORE_DATA;
|
|
|
|
memcpy(pData, pValue->data.string, length);
|
|
|
|
pData[length] = '\0';
|
|
|
|
}
|
|
|
|
else if (lpcbData)
|
|
|
|
*lpcbData = (UINT32)length;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Registry emulation does not support value type %s [0x%08" PRIx32 "]",
|
|
|
|
reg_type_string(pValue->type), pValue->type);
|
|
|
|
break;
|
2012-06-06 05:50:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pValue = pValue->next;
|
|
|
|
}
|
|
|
|
|
2012-10-11 22:59:01 +04:00
|
|
|
return ERROR_FILE_NOT_FOUND;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegRestoreKeyW(HKEY hKey, LPCWSTR lpFile, DWORD dwFlags)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegRestoreKeyA(HKEY hKey, LPCSTR lpFile, DWORD dwFlags)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegSaveKeyExW(HKEY hKey, LPCWSTR lpFile, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
|
|
|
DWORD Flags)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegSaveKeyExA(HKEY hKey, LPCSTR lpFile, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
|
|
|
DWORD Flags)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegSetKeySecurity(HKEY hKey, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegSetValueExW(HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, DWORD dwType,
|
|
|
|
const BYTE* lpData, DWORD cbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
LONG RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, const BYTE* lpData,
|
|
|
|
DWORD cbData)
|
2012-05-22 06:34:42 +04:00
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegUnLoadKeyW(HKEY hKey, LPCWSTR lpSubKey)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG RegUnLoadKeyA(HKEY hKey, LPCSTR lpSubKey)
|
|
|
|
{
|
2022-02-15 15:01:52 +03:00
|
|
|
WLog_ERR(TAG, "TODO: Implement %s", __FUNCTION__);
|
|
|
|
return -1;
|
2012-05-22 06:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|