Displaying file contents of files with Hex 00 values

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
malvern
Newbie
Posts: 3
Joined: Fri Feb 22, 2013 5:54 am

Displaying file contents of files with Hex 00 values

Post by malvern » Fri Feb 22, 2013 6:15 am

I've been "lurking" for quite some time and could usually find most of my answers if I searched the forums hard enough, but this time I'm stumped.

I've written a program that reads an entire file

ReadFile>strFileName,strFileData

and then displays the file contents for the user in a memo window

object DisplayWindow1: tMSMemo
Left = 16
Top = 72
Width = 273
Height = 161
ScrollBars = ssBoth
TabOrder = 10
ReadOnly = True
end

via use of the following command

SetDialogProperty>Dialog1,DisplayWindow1,Text,strFileData

This setup works great, but I ran into a file that is filled with Hex 00 values. When my program tries to display the contents of the file, it displays only the characters up until the first 00 value. This same result is also true if I try to view the contents of the file with a MDL> statement.

Interestingly enough, my program is able to manipulate the file contents and write them back out without any problems, so this appears to be just a display issue.

Can anyone think of a way to force the display of the whole file, regardless of these 00 Hex values?

I would be thankful of any insight you could provide.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Feb 22, 2013 8:55 am

Hi malvern,

You are simply running into the concept of the null-terminated string.

http://en.wikipedia.org/wiki/Null-terminated_string

i.e. the first Null it runs into (hex 00) it thinks it has reached the end of the string and does not display anything beyond that.

The easiest would be just to use a programming editor that can display files in Hex... Notepad++ should allow you to view it all... you may have to put it into Hex Editor mode.

If you want to modify what you are already using to be able to display those pesky Nulls, well... I suppose you could write the equivalent of your own Hex Editor (display only) by examining each and every character in strFileData, storing each char's hex equivalent (Null would translate to 00) to another variable strFileDataHex... then simply view strFileDataHex instead... only then you'd be looking at a lot of hex instead of readable text which is probably not what you want.

So... why don't you use a RegEx> command to replace each and every Null char in strFileData with an often unused char like tilde ~ before you display the whole thing.

Code: Select all

//Replace all Null chars with tilde ~ chars
Let>pattern=\x00
Let>matches_1=
RegEx>pattern,strFileData,0,matches,num,1,~,strFileData
If you give this a try, please let us know how it works out for you.

Take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

malvern
Newbie
Posts: 3
Joined: Fri Feb 22, 2013 5:54 am

Post by malvern » Fri Feb 22, 2013 2:03 pm

jpuziano, thank you for your help. I hadn't run into the RegEx function before, but I certainly won't forget it now!

Here is the code I ended up using to replace the hex "00" nulls with "20" spaces.

Code: Select all


    ReadFile>strFileName,strFileData
    Let>pattern=[\x00]
    RegEx>pattern,strFileData,0,matches,num,1,space,StrFileData
   SetDialogProperty>Dialog1,DisplayWindow1,Text,strFileData


User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Feb 22, 2013 6:34 pm

malvern wrote:jpuziano, thank you for your help. I hadn't run into the RegEx function before, but I certainly won't forget it now!
Well glad I could help! Yes Regular Expressions are quite amazing...

I encourage anyone reading this to experiment with the RegEx> command.

Also, you used this:
  • Let>pattern=[\x00]
The [ square brackets ] don't hurt but they are not required... because you don't really need to define a regular expression character class here... because you are only matching one single character... a Null.

The following line should work just as well for your purposes:
  • Let>pattern=\x00
Here's more info on RegEx Char Classes:
http://www.regular-expressions.info/charclass.html

Take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts