The Computer Oracle

Is there any way to copy null bytes (ASCII 0x00) to the clipboard on Windows?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Luau

--

Chapters
00:00 Is There Any Way To Copy Null Bytes (Ascii 0x00) To The Clipboard On Windows?
00:55 Accepted Answer Score 16
01:57 Thank you

--

Full question
https://superuser.com/questions/946533/i...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #copypaste #clipboard

#avk47



ACCEPTED ANSWER

Score 16


No, you cannot put text with embedded null characters on the clipboard. Let's look at the list of standard Windows clipboard formats. There are a few formats that hold things generally understood as text:

  • CF_TEXT (1)
  • CF_OEMTEXT (7)
  • CF_UNICODETEXT (13)

Every single one of those has this sentence in its definition:

A null character signals the end of the data.

Now, CF_UNICODETEXT keeps its data as UTF-16LE, so it will more than likely have some null bytes, but null characters (two null bytes in a row, basically) will still end the string.

We can only speculate about why null characters aren't allowed in clipboard text, but more than likely it's just because the most commonly-used string processing functions in Windows assume a null character signals the end. The only other way to know where a string stops would be to prefix it with its length.

You can hold graphics on the clipboard even though they likely have null bytes because they get passed around in different clipboard formats (e.g. CF_BITMAP), which have to be understood differently by programs.