Replace text in Binary files

zakkar

Member
Joined
Oct 2, 2007
Messages
10
Programming Experience
Beginner
Hi ,

I need some help here with reading binary files. I am using VB .NET 2005 and I need to read a binary file , convert it somehow and replace a text value that is stored inside.
For eg. This file has a string value XXXX-XXX/XXX. If I am viewing normally the file and not the binary I am seeing that format. But when it comes to the binary I cannot view it. So. All I need is read the binary , convert it somehow , search inside the binary for the string XXXX-XXX/XXX , replace the string with the value I want and make it binary again.
Does anyone have a working example written in VB .NET which do these things ?
Any sample code ?

I would be mostly appreciated with any help you can give me.

Thank you
zkar
 
Hi ,
I believe so. I don't Know the structure of the file. For eg. Let's say that I have a file , a word document , or an exe or an xls. And I have in there Something written. Let's say it has the format XX/XX. Nowhere else in the document is located this format. It will be unique. So. I want to read this doc file search inside the XX/XX and replace it with another value. All these in a runtime enviroment. Programmatically.
Does anyone have a working example ?

Thank you
zkar
 
Sounds like we have someone wanting to hack....

This might get you started, I havn't tested though. Also Binary is not ascii, so your doc may not transfer 100% if the source is a executable.


dim ifile as filestream = new FileStream("c:\test\binary.dat",FileMode.Open)

dim lengthInBytes as long = iFile.Length

dim bin as BinaryReader = new BinaryReader(iFile)

dim bytearray as byte() = bin.ReadBytes(cint(lengthInBytes))

dim encEncoder as System.Text.Encoding = System.Text.ASCIIEncoding.ASCII

dim str as string = encEncoder.GetString(byteArray);
 
Hi ,
And thank you very much for the code.
It exctracted the file I want but I couldn't find in the created string which I wanted.
I am uploading the file which is in binary format.The zip file contains a pbd . And for this pbd is all about.
Inside this pbd file there is a string variable which has the following format.
XX/XX/XXXX XX:XX
As you can see from the format , It is a datetime field.
So I need to open the pbd file find the XX/XX/XXXX XX:XX inside , replace it with the today's date.
I am attaching also the export of the binary inside the zip.
I have used your code and I just saved it in a txt file.
I cannot find the format I want and I Know it is there. After I replace the format with the today's date how I will change back to binary ? With the changes saved ?

Thank you so far for all your help
zkar
 

Attachments

  • maintainfunctions.zip
    1 KB · Views: 28
  • MAINTAINFUNCTIONS.TXT
    7 KB · Views: 33
I made a mistake. In the files I believe I am able to see the format I want.
Notepad search couldn't find it.
I just saw that in the TXT file I have in readable view the format.
So the last question stays. Ok I am replacing the format with the date. How am I construct again the binary ?

Thank you
zkar
 
Back
Top