Discussion:
Hexdump - Display TextElements from binary File
(too old to reply)
Alen Hopek
2006-01-16 17:54:46 UTC
Permalink
Hello,

i need little some help. I try to extract text from a binary file
like a hexdump application.

In fact I try to read out from a Norton Ghost Image the
description entries from this image file. The data i need
starts from a the file position of 250 an has a length
of 200 Bytes.

If i read the file in binary mode from beginning or from
my start pointer i get to my messagebox some readable
characters until there is no zero value. If my application
reads a zero byte i get no more results to my messagebox.

Any Ideas ?

Greetings
Alen Hopek



My Code for this:
--------------------------

OPEN "C:\image.gho" FOR BINARY AS #1
TempStr$ = ""

' Start position
SEEK #1, 250
position = LOC(#1)

' read 200 Bytes from Pointer
FOR a = 1 TO 200
GET$ #1, 1 , Char$
TempStr$ = TempStr$ + CHR$(Char$)
NEXT a

MSGBOX "Position in File: " + STR$(position) + $CRLF + _
"Data from File: " + TempStr$
Michael Mattias
2006-01-16 17:10:01 UTC
Permalink
Post by Alen Hopek
If i read the file in binary mode from beginning or from
my start pointer i get to my messagebox some readable
characters until there is no zero value. If my application
reads a zero byte i get no more results to my messagebox.
That's to be expected. MSGBOX displays all text as 'ASCIIZ' strings,
teminating on a null byte.

What you might want to try is replacing all nulls in your string with a
non-null character before attempting to display that string wiht MSGBOX.

e.g., something like this...
Post by Alen Hopek
' read 200 Bytes from Pointer
FOR a = 1 TO 200
GET$ #1, 1 , Char$
TempStr$ = TempStr$ + CHR$(Char$)
NEXT a
addthisline:
REPLACE CHR$(0) WITH CHR$(32) IN TempStr$ <<< change all nulls to
space for purposes of displaying
Post by Alen Hopek
MSGBOX "Position in File: " + STR$(position) + $CRLF + _
"Data from File: " + TempStr$
Note the TempStr DOES include the null characters, so if you write it to a
file the NUL will be included and if you have a hex editor of some kind you
will see it.

That is, this limitation is specifically a limitation of MSGBOX ( and is
documented: "Strings displayed by the MSGBOX statement are truncated if they
contain embedded $NUL {CHR$(0)} bytes.")

MCM
Peter Manders
2006-01-16 20:19:26 UTC
Permalink
On Mon, 16 Jan 2006 17:10:01 GMT, "Michael Mattias"
Post by Michael Mattias
REPLACE CHR$(0) WITH CHR$(32) IN TempStr$ <<< change all nulls to
space for purposes of displaying
Personally I would prefer:
REPLACE CHR$(0) WITH "!" IN TempStr$

Then add this line:
TempStr$ = TempStr$ + CHR$(0)
Post by Michael Mattias
Post by Alen Hopek
MSGBOX "Position in File: " + STR$(position) + $CRLF + _
"Data from File: " + TempStr$
Note the TempStr DOES include the null characters, so if you write it to a
file the NUL will be included and if you have a hex editor of some kind you
will see it.
Correct Michael, but one should read Char$ where you wrote TempStr$.
You must be working long hours, like most of us.
--
Peter Manders.

Post may contain irony: discontinue use if experiencing mood swings,
nausea or elevated blood pressure.
Michael Mattias
2006-01-16 21:12:40 UTC
Permalink
Post by Peter Manders
Post by Alen Hopek
MSGBOX "Position in File: " + STR$(position) + $CRLF + _
"Data from File: " + TempStr$
[ snipped]
..
Post by Peter Manders
Correct Michael, but one should read Char$ where you wrote TempStr$.
You must be working long hours, like most of us.
Well, I am working long hours, but I did not write that MSGBOX line. That
bug is courtesy original poster.

Help on REPLACE is free, but I bill for bug fixes.

MCM

Loading...