I need to read a binary file made by c++.
ReadStream.littleEndian = true
This works ok, but then I need to read several CStrings:
s = ReadStream.ReadPString
This doesn’t work
I tried Will Sank suggestion:
But it doesn’t work either
How to read CStrings?
With the debugger the read string using any of the preceding looks like
The real string should be:
This looks like an UTF16 string with byte marks at the beginning.
If you have any control over the program that writes the file it might be worthwhile seeing if it can generate something a bit easier to deal with.
CStrings are null terminated so you are possibly going to have to read a byte at a time, append to your string if it is not 0 and exit if it is. If the data is wide (UTF16/32) then you might have to read more than one byte at a time. Remember to set the text encoding correctly as well.
Reading one byte at a time from disk might be slow so an alternative could be to read it all into a memoryblock, attach another binarystream to the memoryblock and then read the memoryblock as described above. If you have the MBS plugins you might find functions that help speed up finding bytes in memoryblocks.
Download M_String from here: http://www.mactechnologies.com/index.php?page=downloads
This has a nice method DefineEncodingByAnalysis_MTC, which should set the encoding after examining the byte mark.
[quote=347260:@Beatrix Willius]Download M_String from here: http://www.mactechnologies.com/index.php?page=downloads
This has a nice method DefineEncodingByAnalysis_MTC, which should set the encoding after examining the byte mark.[/quote]
Is there a newer version, I tried to test the M_String Harness but doesn’t run, it gives error:
M_String.SqueezeB_MTC, line 30
Can’t find a type with this name
dim rx as RegExMBS = NewRegExMBS
This comes from the MBS plugin. Comment the code out if you don’t use this plugin.