.NET uses UTF-16 to represent strings, which is usually 2 bytes per character.
Many debugging tricks (including my own answers) will use the output of !do
to get the address of the first character and then use the string length*2 in order to get the end address of the string.
Some examples where this can be useful:
du
to dump the string, because!do
will not dump the complete string.writemem
to write strings to a file so that it can be processed by other toolss
to search for strings containing specific substrings
However, UTF-16 also has 4 bytes characters (U+10000 to U+10FFFF), which might screw up everything.
- string length is counted in characters and a 4 byte character is probably only counted as 1 character, so any length*2 calculations are incorrect
du
might stop at characters which end on00 00
So, how safe is it to use such scripts debugging .NET applications in WinDbg?