I notice that GtkTextBuffer will show nothing while assign a binary buffer, because it will call the function g_utf8_validate to make a valid UTF-8 string, so how to show the binary data like this:
Do you need a kind of hex viewer? I don’t think that the GTK API offers a solution “out of the box”. You can convert the (binary) byte stream into a symbolic representation and then insert the latter into the text buffer. E.g.: 0x45 → 0x34 0x35 (also probably: 0x20).
I think the solution is that GtkTextView(Pango) just shows the buffer data, try best to show the data like binary, do not validate(g_utf8_validate) the data or stop at middle position.
No, that’s not a “solution” at all, and it won’t happen.
GTK requires everywhere that text is encoded in UTF-8; that has been a requirement since GTK 2.0, and it won’t change.
If you want to display binary data, you’ll have to find a way to encode it in such a way that it validates as ASCII or UTF-8; the recommendation to convert each byte it to hexadecimal, octal, or decimal representation is a well-established convention.