There is an address, I know 100% that a line is stored in it, you need to read characters from the address and then do the operations I need.

I read multibyte encoding:

DWORD addr = 0x112233445566; printf_s("%с\n", *((const char*)addr)); 

The first character was perfectly considered, we try to read the first character from Unicode:

 wprintf_s(L"%с\n", *((const wchar_t*)addr)); 

It gives out some kind of bilberd, I know that in Unicode a character takes 2 bytes, but I don’t understand how to calculate it correctly.

  • and perhaps there is incorrect data. Tried to just print in binary form and see? - KoVadim
  • one
    Begin testing with the hexadecimal printf ("% # x \ n", ((const char ) addr)); printf ("% # x \ n", ((const wchar_t ) addr)); - Yaroslav
  • @Yaroslav - prints bytes in the reverse order, but these bytes correspond to the characters - Duracell
  • @KoVadim - but not true like - Duracell
  • see what's at this address in the debugger - Abyx

1 answer 1

Unicode different, for example, UTF-8, UTF-16LE and UTF-16BE (and their trimmed versions of UCS-2LE and UCS-2BE, respectively). MSVC, by default, works with UCS-2LE.

In general, it would be easier if you brought what you see and what you expect there.

  • Well, for example, the first two characters of MZ, and displays some kind of astrakhan - Duracell
  • Mz? Are you trying to print PE header? - KoVadim
  • @KoVadim - no, but although why not, what difficulties will I have? - Duracell
  • There will be no difficulties. Although the PE header contains lines, it is unlikely that you expect it. - KoVadim 2:58 pm
  • @KoVadim - I just want to do a search for a string in a module, everything worked out with multibyte encoding, but with Unicode, the problem is to count only one character. - Duracell