News for hackers. Stuff that matters.
Re:Why the Windows Registry sucks technically (2010) by Someone on Friday July 29, 2022 @08:06AM (#32275877)
> and there's no format agnostic API to access that information (you can open it, but can you understand it?).

One of the critiques in this article is that, because you have to know/guess/assume what encoding is used for various strings, there isn’t one for the registry, either.

If so, both approaches suffer from that (but Unix a bit more because it tends to store multiple items under a file system ‘key’, while Windows programs rarely store multiple items under a single registry key)

I do wonder what RegEdit.exe does here. Does it infer encoding, have a long list of key-to-encoding mappings, or a combination of the two?

Re:Why the Windows Registry sucks technically (2010) by rwmj on Friday July 29, 2022 @08:50AM (#32276200)
I do wonder what RegEdit.exe does here. Does it infer encoding, have a long list of key-to-encoding mappings, or a combination of the two?

I did a bit of experimentation on this too and we think it has a heuristic to guess encodings of strings. (Which to be fair isn't a terrible idea - it's very easy and almost entirely reliable to determine if a string is ASCII/UTF-8 or UTF-16LE which are the major encodings found.)

Re:Why the Windows Registry sucks technically (2010) by magicalhippo on Friday July 29, 2022 @09:25AM (#32276529)
Based on the documentation[1], it seems clear that strings are stored in Unicode (which should be UTF-16LE).

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, and the ANSI version of this function is used (either by explicitly calling RegGetValueA or by not defining UNICODE before including the Windows.h file), this function converts the stored Unicode string to an ANSI string before copying it to the buffer pointed to by pvData.

[1]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf...

Re:Why the Windows Registry sucks technically (2010) by rwmj on Friday July 29, 2022 @09:55AM (#32276908)
The first thing to know about Microsoft documentation is it's almost always wrong.
Re:Why the Windows Registry sucks technically (2010) by magicalhippo on Friday July 29, 2022 @04:59PM (#32281706)
I've been coding against the Win32 API since Windows 95. While I won't argue it's perfect, it's certainly nowhere near "almost always wrong".

Anyway, where in the hivex code do you handle these non-Unicode encoded REG_SZ values?

Btw, the comment for hivex_value_multiple_strings is based on a mistaken interpretation of the documentation. There's nothing contradictory to what MoveFileEx does[1], it simply has a list with a single entry in the case of deletions, and a list with two entries in case of renames.

The REG_MULTI_SZ documentation[2] just points out, correctly, that you can't have a zero-length string within a list of other strings (ie with at least one non-empty string after it). This is of course obvious and hence redundant, but they highlight it for novice programmers.

[1]: https://docs.microsoft.com/en-us/windows/win32/api/winbase/n...

[2]: https://docs.microsoft.com/en-us/windows/win32/sysinfo/regis...

Re:Why the Windows Registry sucks technically (2010) by pie_flavor on Friday July 29, 2022 @02:35PM (#32280337)
This is categorically incorrect. The documentation for the function is entirely accurate. What is true is that the regedit program is more than a featureless wrapper around the API functions (unlike the first thing to know about Linux desktop software). The heuristic is performed for the user who probably doesn't know what they want; the straight exactly-as-you-asked-for-it conversion is performed for the programmer who does. (And it's only a heuristic for values; the encoding for keys is assumed from the file like TFA says, but which one it is is stored in a flag bit.)
Re:Why the Windows Registry sucks technically (2010) by int_19h on Friday July 29, 2022 @08:15PM (#32283129)
To be more precise, like most of Windows, it just stores 16-bit codepoints as such, meaning that it's not necessarily always valid UTF-16LE (in the presence of invalid surrogate pairs).