I split this since it's a different topic/feature request.
mcb wrote: 09 Mar 2023 16:17
My layperson expectation is that the hex data is "sacred", i.e. the clipboard bytes should go into the Hex view as they are
The clipboard does not contain a sequence of bytes, but various formats, such as CF_TEXT or CF_UNICODETEXT etc. so HxD has to treat it like that (what lands in the clipboard is already converted, not what the source application put into it). One consequence of this is that you can only determine the text length by a terminating #0 character, since the allocated memory in the clipboard can be larger than the text in the clipboard.
Also some formats are autogenerated from other formats, for example CF_TEXT automatically creates CF_UNICODETEXT (with the ANSI encoding CF_TEXT has which is stored in CF_LOCALE) and vice versa.
In other words, conversions automatically happen and there is no raw byte format, which is why you have to define your own "raw" clipboard format, specially for a raw sequence of bytes/hex editors.
To solve this issue HxD does copy something different to the global Windows clipboard depending on the column you are in: in the text column it copies the text as Unicode (using the encoding you selected in HxD to convert it to Unicode), in the hex column it copies it as text too, but this time it's a sequence of hex pairs, as seen in the hex view.
Some other hex editors support this style (bytes represented as hex pairs) as well, which is how data transfers between HxD and other editors is possible, for example the hex editor in Visual Studio.
Additionally HxD internally copies the data as a raw sequence of bytes so you can copy larger amounts of data from one file to another file, within HxD. The Windows clipboard again is limited here regarding the amount of data it can hold, and will get very slow way before hitting this limit.
So, there is no raw byte format that is universally accepted between applications (at most some hex editors invent their own), nor is it clear where the data ends in general (and which bytes are just padding/superfluous). How to determine the exact byte length is specific to every format.
But I made a raw clipboard viewer program once, that shows the raw data (including potential additional data at the end), if you are curious:
https://mh-nexus.de/downloads/RawClipView.exe
In the Text area, I understand that depending on the current character set, some characters may show as garbage or with a replacement character.
So in other words, the data you paste in HxD is always textual data in Unicode (since the Windows clipboard automatically converts it to Unicode in Windows NT+). The original raw bytes are not preserved, and no app besides hex editors have a concept of raw bytes regarding the clipboard. So the only sensible thing to do is to convert this Unicode text (which is UTF-16LE in Windows) to the encoding you selected in HxD.
For example, if you opened a text file in HxD, that is encoded in Windows-1252, it would make no sense to paste the clipboard Unicode text as the "raw" bytes of UTF-16LE into this text file. It would create a text file with a mixed encoding, partly Windows-1252, partly UTF-16LE, and be essentially invalid.
To copy and paste raw data, you have to open a file and copy and paste it within HxD, because HxD uses an internal clipboard that can handle raw data. There is no other way to transfer raw data, since no other apps (besides maybe hex editors) even have a concept of raw data in the clipboard, and therefore wouldn't know how to handle it, nor how to put "raw" data into the clipboard. So the "original" is lost anyways, as they data is converted to one of the standard formats/text encodings by Windows itself.
I hope that makes sense.