Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Reading Binary Code from file  (Read 4250 times)

0 Members and 1 Guest are viewing this topic.

almn

  • Guest
Reading Binary Code from file
« on: December 09, 2006, 04:00:25 PM »
Hello,

I would like to know if anybody could help , I am trying to read the binary content of a file and search for a specific hex code, here is what I have:

        Dim gett As New IO.BinaryReader(IO.File.OpenRead("c:\file.txt"))
        Dim read As String = gett.ReadDouble
        Dim SearchString As String
        MessageBox.Show(read)
        SearchString = ("4D5A50000200000004")
        If read.IndexOf(SearchString) <> -1 Then MessageBox.Show("found") Else MessageBox.Show("no")

Thanks in Advance

Al968

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Reading Binary Code from file
« Reply #1 on: December 09, 2006, 04:25:27 PM »
I'm not sure what the question is. Is this working or not and if not where is the problem?

The ReadDouble method reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes. I may be wrong, but your search argument seems too large and probably shouldn't be dimensioned as a string.

 8-)

PS. I got the definition of ReadDouble direct from the VB.Net help. Marvelous little invention that help thing.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

almn

  • Guest
Re: Reading Binary Code from file
« Reply #2 on: December 09, 2006, 05:25:25 PM »
N/o the code I posted is not working  :P
Yes I do know that "little invention"
Yes the "double" part is a mistake but Then I don't know what to read it as  :-/

Thanks

Al968

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Reading Binary Code from file
« Reply #3 on: December 10, 2006, 05:43:51 AM »
Check out the ReadAllBytes method. I'm still not certain your search argument is defined properly or even that you need a binary reader for a text file.

I'm very confused, your file has a txt extension. Can you not simply use the ReadAllLines method and then use Instr to search for your argument. :-?
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

almn

  • Guest
Re: Reading Binary Code from file
« Reply #4 on: December 10, 2006, 05:41:20 PM »
Actually the file.txt is not the actual file I want to read it from, the file is an exe file, Sorry if I confused you  :-/

Thanks

Al968