Use ntdll functions instead of MultiByteToWideChar/WideCharToMultiByte
to avoid corrupting the last error code.
This commit is contained in:
parent
996c0bff59
commit
60fd03d248
|
@ -345,12 +345,11 @@ DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len
|
||||||
|
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
DWORD len, cls_len;
|
||||||
NULL, 0, NULL, NULL );
|
|
||||||
DWORD cls_len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
|
|
||||||
info->ClassLength / sizeof(WCHAR),
|
|
||||||
NULL, 0, NULL, NULL );
|
|
||||||
|
|
||||||
|
RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
|
||||||
|
RtlUnicodeToMultiByteSize( &cls_len, (WCHAR *)(buf_ptr + info->ClassOffset),
|
||||||
|
info->ClassLength );
|
||||||
if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
|
if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
|
||||||
|
|
||||||
if (len >= *name_len || (class_len && (cls_len >= *class_len)))
|
if (len >= *name_len || (class_len && (cls_len >= *class_len)))
|
||||||
|
@ -358,17 +357,16 @@ DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*name_len = len;
|
*name_len = len;
|
||||||
WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
|
||||||
name, len, NULL, NULL );
|
|
||||||
name[len] = 0;
|
name[len] = 0;
|
||||||
if (class_len)
|
if (class_len)
|
||||||
{
|
{
|
||||||
*class_len = cls_len;
|
*class_len = cls_len;
|
||||||
if (class)
|
if (class)
|
||||||
{
|
{
|
||||||
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
|
RtlUnicodeToMultiByteN( class, cls_len, NULL,
|
||||||
info->ClassLength / sizeof(WCHAR),
|
(WCHAR *)(buf_ptr + info->ClassOffset),
|
||||||
class, cls_len, NULL, NULL );
|
info->ClassLength );
|
||||||
class[cls_len] = 0;
|
class[cls_len] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -516,10 +514,7 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
|
||||||
|
|
||||||
if (status) goto done;
|
if (status) goto done;
|
||||||
|
|
||||||
len = WideCharToMultiByte( CP_ACP, 0,
|
RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->ClassOffset), info->ClassLength);
|
||||||
(WCHAR *)(buf_ptr + info->ClassOffset),
|
|
||||||
info->ClassLength/sizeof(WCHAR),
|
|
||||||
NULL, 0, NULL, NULL );
|
|
||||||
if (class_len)
|
if (class_len)
|
||||||
{
|
{
|
||||||
if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
|
if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
|
||||||
|
@ -527,10 +522,8 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
|
||||||
}
|
}
|
||||||
if (class && !status)
|
if (class && !status)
|
||||||
{
|
{
|
||||||
WideCharToMultiByte( CP_ACP, 0,
|
RtlUnicodeToMultiByteN( class, len, NULL, (WCHAR *)(buf_ptr + info->ClassOffset),
|
||||||
(WCHAR *)(buf_ptr + info->ClassOffset),
|
info->ClassLength );
|
||||||
info->ClassLength/sizeof(WCHAR),
|
|
||||||
class, len, NULL, NULL );
|
|
||||||
class[len] = 0;
|
class[len] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -679,11 +672,11 @@ DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
|
||||||
|
|
||||||
if (is_string( type )) /* need to convert to Unicode */
|
if (is_string( type )) /* need to convert to Unicode */
|
||||||
{
|
{
|
||||||
DWORD lenW = MultiByteToWideChar( CP_ACP, 0, data, count, NULL, 0 );
|
DWORD lenW;
|
||||||
if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW*sizeof(WCHAR) )))
|
RtlMultiByteToUnicodeSize( &lenW, data, count );
|
||||||
return ERROR_OUTOFMEMORY;
|
if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
|
||||||
MultiByteToWideChar( CP_ACP, 0, data, count, dataW, lenW );
|
RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
|
||||||
count = lenW * sizeof(WCHAR);
|
count = lenW;
|
||||||
data = (BYTE *)dataW;
|
data = (BYTE *)dataW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,17 +871,17 @@ DWORD WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD
|
||||||
|
|
||||||
if (is_string(info->Type))
|
if (is_string(info->Type))
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
|
DWORD len;
|
||||||
(total_size - info_size) /sizeof(WCHAR),
|
|
||||||
NULL, 0, NULL, NULL );
|
RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info_size),
|
||||||
|
total_size - info_size );
|
||||||
if (data && len)
|
if (data && len)
|
||||||
{
|
{
|
||||||
if (len > *count) status = STATUS_BUFFER_OVERFLOW;
|
if (len > *count) status = STATUS_BUFFER_OVERFLOW;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
|
RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info_size),
|
||||||
(total_size - info_size) /sizeof(WCHAR),
|
total_size - info_size );
|
||||||
data, len, NULL, NULL );
|
|
||||||
/* if the type is REG_SZ and data is not 0-terminated
|
/* if the type is REG_SZ and data is not 0-terminated
|
||||||
* and there is enough space in the buffer NT appends a \0 */
|
* and there is enough space in the buffer NT appends a \0 */
|
||||||
if (len < *count && data[len-1]) data[len] = 0;
|
if (len < *count && data[len-1]) data[len] = 0;
|
||||||
|
@ -1104,24 +1097,24 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
DWORD len;
|
||||||
NULL, 0, NULL, NULL );
|
|
||||||
|
RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
|
||||||
if (len >= *val_count)
|
if (len >= *val_count)
|
||||||
{
|
{
|
||||||
status = STATUS_BUFFER_OVERFLOW;
|
status = STATUS_BUFFER_OVERFLOW;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
|
||||||
value, len, NULL, NULL );
|
|
||||||
value[len] = 0;
|
value[len] = 0;
|
||||||
*val_count = len;
|
*val_count = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string(info->Type))
|
if (is_string(info->Type))
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
|
DWORD len;
|
||||||
(total_size - info->DataOffset) / sizeof(WCHAR),
|
RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
|
||||||
NULL, 0, NULL, NULL );
|
total_size - info->DataOffset );
|
||||||
if (data && len)
|
if (data && len)
|
||||||
{
|
{
|
||||||
if (len > *count)
|
if (len > *count)
|
||||||
|
@ -1129,9 +1122,8 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
|
||||||
status = STATUS_BUFFER_OVERFLOW;
|
status = STATUS_BUFFER_OVERFLOW;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
|
RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
|
||||||
(total_size - info->DataOffset) / sizeof(WCHAR),
|
total_size - info->DataOffset );
|
||||||
data, len, NULL, NULL );
|
|
||||||
/* if the type is REG_SZ and data is not 0-terminated
|
/* if the type is REG_SZ and data is not 0-terminated
|
||||||
* and there is enough space in the buffer NT appends a \0 */
|
* and there is enough space in the buffer NT appends a \0 */
|
||||||
if (len < *count && data[len-1]) data[len] = 0;
|
if (len < *count && data[len-1]) data[len] = 0;
|
||||||
|
|
|
@ -152,12 +152,11 @@ DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len
|
||||||
|
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
DWORD len, cls_len;
|
||||||
NULL, 0, NULL, NULL );
|
|
||||||
DWORD cls_len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
|
|
||||||
info->ClassLength / sizeof(WCHAR),
|
|
||||||
NULL, 0, NULL, NULL );
|
|
||||||
|
|
||||||
|
RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
|
||||||
|
RtlUnicodeToMultiByteSize( &cls_len, (WCHAR *)(buf_ptr + info->ClassOffset),
|
||||||
|
info->ClassLength );
|
||||||
if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
|
if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
|
||||||
|
|
||||||
if (len >= *name_len || (class_len && (cls_len >= *class_len)))
|
if (len >= *name_len || (class_len && (cls_len >= *class_len)))
|
||||||
|
@ -165,17 +164,16 @@ DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*name_len = len;
|
*name_len = len;
|
||||||
WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
|
||||||
name, len, NULL, NULL );
|
|
||||||
name[len] = 0;
|
name[len] = 0;
|
||||||
if (class_len)
|
if (class_len)
|
||||||
{
|
{
|
||||||
*class_len = cls_len;
|
*class_len = cls_len;
|
||||||
if (class)
|
if (class)
|
||||||
{
|
{
|
||||||
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
|
RtlUnicodeToMultiByteN( class, cls_len, NULL,
|
||||||
info->ClassLength / sizeof(WCHAR),
|
(WCHAR *)(buf_ptr + info->ClassOffset),
|
||||||
class, cls_len, NULL, NULL );
|
info->ClassLength );
|
||||||
class[cls_len] = 0;
|
class[cls_len] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +205,7 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
char buffer[256], *buf_ptr = buffer;
|
char buffer[256], *buf_ptr = buffer;
|
||||||
KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
|
KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
|
||||||
DWORD total_size;
|
DWORD total_size, len;
|
||||||
|
|
||||||
TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
|
TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
|
||||||
reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
|
reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
|
||||||
|
@ -216,6 +214,7 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
|
||||||
return ERROR_INVALID_PARAMETER;
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
|
||||||
status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
|
status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
|
||||||
|
if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
|
||||||
|
|
||||||
if (class || class_len)
|
if (class || class_len)
|
||||||
{
|
{
|
||||||
|
@ -229,39 +228,32 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
|
||||||
status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
|
status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!status)
|
if (status) goto done;
|
||||||
|
|
||||||
|
RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->ClassOffset), info->ClassLength);
|
||||||
|
if (class_len)
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0,
|
if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
|
||||||
(WCHAR *)(buf_ptr + info->ClassOffset),
|
*class_len = len;
|
||||||
info->ClassLength/sizeof(WCHAR),
|
}
|
||||||
NULL, 0, NULL, NULL );
|
if (class && !status)
|
||||||
if (class_len)
|
{
|
||||||
{
|
RtlUnicodeToMultiByteN( class, len, NULL, (WCHAR *)(buf_ptr + info->ClassOffset),
|
||||||
if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
|
info->ClassLength );
|
||||||
*class_len = len;
|
class[len] = 0;
|
||||||
}
|
|
||||||
if (class && !status)
|
|
||||||
{
|
|
||||||
WideCharToMultiByte( CP_ACP, 0,
|
|
||||||
(WCHAR *)(buf_ptr + info->ClassOffset),
|
|
||||||
info->ClassLength/sizeof(WCHAR),
|
|
||||||
class, len, NULL, NULL );
|
|
||||||
class[len] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else status = STATUS_SUCCESS;
|
||||||
|
|
||||||
if (!status || status == STATUS_BUFFER_OVERFLOW)
|
if (subkeys) *subkeys = info->SubKeys;
|
||||||
{
|
if (max_subkey) *max_subkey = info->MaxNameLen;
|
||||||
if (subkeys) *subkeys = info->SubKeys;
|
if (max_class) *max_class = info->MaxClassLen;
|
||||||
if (max_subkey) *max_subkey = info->MaxNameLen;
|
if (values) *values = info->Values;
|
||||||
if (max_class) *max_class = info->MaxClassLen;
|
if (max_value) *max_value = info->MaxValueNameLen;
|
||||||
if (values) *values = info->Values;
|
if (max_data) *max_data = info->MaxValueDataLen;
|
||||||
if (max_value) *max_value = info->MaxValueNameLen;
|
if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
|
||||||
if (max_data) *max_data = info->MaxValueDataLen;
|
|
||||||
if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
done:
|
||||||
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
|
||||||
return RtlNtStatusToDosError( status );
|
return RtlNtStatusToDosError( status );
|
||||||
}
|
}
|
||||||
|
@ -324,11 +316,11 @@ DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
|
||||||
|
|
||||||
if (is_string( type )) /* need to convert to Unicode */
|
if (is_string( type )) /* need to convert to Unicode */
|
||||||
{
|
{
|
||||||
DWORD lenW = MultiByteToWideChar( CP_ACP, 0, data, count, NULL, 0 );
|
DWORD lenW;
|
||||||
if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW*sizeof(WCHAR) )))
|
RtlMultiByteToUnicodeSize( &lenW, data, count );
|
||||||
return ERROR_OUTOFMEMORY;
|
if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
|
||||||
MultiByteToWideChar( CP_ACP, 0, data, count, dataW, lenW );
|
RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
|
||||||
count = lenW * sizeof(WCHAR);
|
count = lenW;
|
||||||
data = (BYTE *)dataW;
|
data = (BYTE *)dataW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,24 +521,24 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
DWORD len;
|
||||||
NULL, 0, NULL, NULL );
|
|
||||||
|
RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
|
||||||
if (len >= *val_count)
|
if (len >= *val_count)
|
||||||
{
|
{
|
||||||
status = STATUS_BUFFER_OVERFLOW;
|
status = STATUS_BUFFER_OVERFLOW;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
|
RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
|
||||||
value, len, NULL, NULL );
|
|
||||||
value[len] = 0;
|
value[len] = 0;
|
||||||
*val_count = len;
|
*val_count = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string(info->Type))
|
if (is_string(info->Type))
|
||||||
{
|
{
|
||||||
DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
|
DWORD len;
|
||||||
(total_size - info->DataOffset) / sizeof(WCHAR),
|
RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
|
||||||
NULL, 0, NULL, NULL );
|
total_size - info->DataOffset );
|
||||||
if (data && len)
|
if (data && len)
|
||||||
{
|
{
|
||||||
if (len > *count)
|
if (len > *count)
|
||||||
|
@ -554,9 +546,8 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
|
||||||
status = STATUS_BUFFER_OVERFLOW;
|
status = STATUS_BUFFER_OVERFLOW;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
|
RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
|
||||||
(total_size - info->DataOffset) / sizeof(WCHAR),
|
total_size - info->DataOffset );
|
||||||
data, len, NULL, NULL );
|
|
||||||
/* if the type is REG_SZ and data is not 0-terminated
|
/* if the type is REG_SZ and data is not 0-terminated
|
||||||
* and there is enough space in the buffer NT appends a \0 */
|
* and there is enough space in the buffer NT appends a \0 */
|
||||||
if (len < *count && data[len-1]) data[len] = 0;
|
if (len < *count && data[len-1]) data[len] = 0;
|
||||||
|
@ -569,6 +560,7 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
|
||||||
else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
|
else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else status = STATUS_SUCCESS;
|
||||||
|
|
||||||
if (type) *type = info->Type;
|
if (type) *type = info->Type;
|
||||||
if (count) *count = info->DataLength;
|
if (count) *count = info->DataLength;
|
||||||
|
|
Loading…
Reference in New Issue