Home All Groups Group Topic Archive Search About

open binary file and search hex string

Author
7 Apr 2005 5:41 PM
Nikos
Hi... I would like to search for a hex string (for example: "E903") inside a
binary file...
Although I open the file correctly, how do I search hex values?
Thanks in advance!
Nikos

Author
7 Apr 2005 6:34 PM
Nicholas Paldino [.NET/C# MVP]
Nikos,

    Are you looking for the character string "E903" or for the two-byte
value 59651?  Either way, once you know what bytes you are looking for, you
need to open the file with a FileStream, and cycle through all of the bytes,
looking one-by-one for a match.

    Hope this helps.


--
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com

Show quoteHide quote
"Nikos" <nkour***@freemail.gr> wrote in message
news:%23zJV0h5OFHA.1528@TK2MSFTNGP09.phx.gbl...
> Hi... I would like to search for a hex string (for example: "E903") inside
> a binary file...
> Although I open the file correctly, how do I search hex values?
> Thanks in advance!
> Nikos
>
>
>
Author
7 Apr 2005 7:04 PM
Nikos
Thanks for the reply... I am actually looking for character string "E903"...
I am stuck with the search routine. How to search hex values?
Should I load all file contents to an array and search? Or,  is it possible
to just read the file byte after byte and examine the offset of the search
string?
Nikos



Show quoteHide quote
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:%23OV9UB6OFHA.1396@TK2MSFTNGP10.phx.gbl...
> Nikos,
>
>    Are you looking for the character string "E903" or for the two-byte
> value 59651?  Either way, once you know what bytes you are looking for,
> you need to open the file with a FileStream, and cycle through all of the
> bytes, looking one-by-one for a match.
>
>    Hope this helps.
>
>
> --
>               - Nicholas Paldino [.NET/C# MVP]
>               - mvp@spam.guard.caspershouse.com
>
> "Nikos" <nkour***@freemail.gr> wrote in message
> news:%23zJV0h5OFHA.1528@TK2MSFTNGP09.phx.gbl...
>> Hi... I would like to search for a hex string (for example: "E903")
>> inside a binary file...
>> Although I open the file correctly, how do I search hex values?
>> Thanks in advance!
>> Nikos
>>
>>
>>
>
>
Author
7 Apr 2005 7:13 PM
Nicholas Paldino [.NET/C# MVP]
Nikos,

    I would just read the file byte by byte, keeping a buffer of the last n
bytes read, where n is the length of the bytes you want to search for.  If
you are looking for that character string, then you should use the GetBytes
method on the AsciiEncoder class in the System.Text namespace to get the
bytes that the string actually is comprised of.


--
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com

Show quoteHide quote
"Nikos" <nkour***@freemail.gr> wrote in message
news:uvJzQQ6OFHA.244@TK2MSFTNGP12.phx.gbl...
> Thanks for the reply... I am actually looking for character string
> "E903"...
> I am stuck with the search routine. How to search hex values?
> Should I load all file contents to an array and search? Or,  is it
> possible to just read the file byte after byte and examine the offset of
> the search string?
> Nikos
>
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote
> in message news:%23OV9UB6OFHA.1396@TK2MSFTNGP10.phx.gbl...
>> Nikos,
>>
>>    Are you looking for the character string "E903" or for the two-byte
>> value 59651?  Either way, once you know what bytes you are looking for,
>> you need to open the file with a FileStream, and cycle through all of the
>> bytes, looking one-by-one for a match.
>>
>>    Hope this helps.
>>
>>
>> --
>>               - Nicholas Paldino [.NET/C# MVP]
>>               - mvp@spam.guard.caspershouse.com
>>
>> "Nikos" <nkour***@freemail.gr> wrote in message
>> news:%23zJV0h5OFHA.1528@TK2MSFTNGP09.phx.gbl...
>>> Hi... I would like to search for a hex string (for example: "E903")
>>> inside a binary file...
>>> Although I open the file correctly, how do I search hex values?
>>> Thanks in advance!
>>> Nikos
>>>
>>>
>>>
>>
>>
>
>
Author
7 Apr 2005 7:32 PM
Nikos
Thanks... I 'll check it now...


Show quoteHide quote
> Nikos,
>
>    I would just read the file byte by byte, keeping a buffer of the last n
> bytes read, where n is the length of the bytes you want to search for.  If
> you are looking for that character string, then you should use the
> GetBytes method on the AsciiEncoder class in the System.Text namespace to
> get the bytes that the string actually is comprised of.
>
>