Display binary file

Topics: Developer Forum, User Forum
May 13, 2012 at 1:08 AM

Hello,

When I try to set the text property to a string i got while reading out a binary file, for example an .exe, scintilla just displays the magic number of it. In this case "MZ". What to I need to change to see the full contence of the string, and not just the first reall characters?

I hope you can understand what I mean, and help me, thanks!

Developer
May 13, 2012 at 2:29 AM

To do this you need to get it to understand that it's not reading a C-Style string (null-terminated), not sure the exact setting needed, but there should be a setting for it somewhere.

May 13, 2012 at 9:47 AM

And what is the name of this setting? Or for what setting should i look?
 

I added some pictures to illustrate what I mean.

This is how it should look like:

And this it how it looks like:

Developer
May 13, 2012 at 5:47 PM
Edited May 13, 2012 at 5:49 PM

I suspect you might prefer the way that Notepad++ renders it, (Notepad++ uses Scintilla at it's core (thus why I know it's possible)) but I suspect that might just be a difference in the font. I'm not sure of the exact setting you need though. Are you sure that the string actually contains all of the data that you read? (also, as a note, the exe you opened was a .net exe, and the "User Strings" are in Unicode, and all other strings are in ASCII)

May 13, 2012 at 6:40 PM

Here I added a picture which shows how the value looks, before I assign it to the text property, and after I assigned it.

Does this help now?

Coordinator
May 15, 2012 at 4:39 AM

I believe blah38621 is correct and your second screenshot proves it.

.NET strings can contain null values because nulls are not used to terminate .NET strings. On the other hand, the underlying Scintilla control wrapped by ScintillaNET uses null terminated strings in many of its APIs. That's why the string seems to get truncated when you assign it to the ScintillaNET control.

You might try to scan the text/binary for null characters and replace them with some other type of representation such as "\0" (a backslash followed by a zero).

 

Jacob

May 15, 2012 at 2:55 PM
Edited May 15, 2012 at 3:13 PM

Okay, if I tried to replace all the null chars with "\0". Now the string is not truncated, but of course the text now contains lots of "\0". When I open the file with SciTe for example, it shows me this "NUL" special chars because SciTe displays all control chars in a special way. But how can I use that,too? Because evertime I replace the null chars with other bytes, I cannot restore them, when I need to get the text back, for saving.

Thanks for your help, and I hope you understand me.

 

EDIT: I solved the problem now: just use the AppendText function instead of the text property because there you can set the textlenght scintilla has to load. Thanks for your help again.