From: Michelle on
I need some help to search through a (sometimes large) binary file.

I'd like to search within this binary file for a pattern containing a
particular hex value (e.g. FF56131A1B087B15610800151E).
When the pattern is found, i need to know the (start) offset, because then I'd
like to read the 4 previous bytes (need the hex values).
I suppose that i need to read the file in blocks (500 kb or 1 mb) because
it's a large file.

I 'am a rookie using C#, so if possible please share a piece of code.

Thanks in advance,

Michelle


From: Fred Mellender on
"read binary file c#" in Google returns many hits, including:
http://www.codersource.net/csharp_read_write_binary_files.html
http://www.yoda.arachsys.com/csharp/readbinary.html
http://dotnetperls.com/binaryreader



"Michelle" <michelle(a)notvalid.nomail> wrote in message
news:OSzELUiMKHA.3672(a)TK2MSFTNGP02.phx.gbl...
>I need some help to search through a (sometimes large) binary file.
>
> I'd like to search within this binary file for a pattern containing a
> particular hex value (e.g. FF56131A1B087B15610800151E).
> When the pattern is found, i need to know the (start) offset, because then
> I'd like to read the 4 previous bytes (need the hex values).
> I suppose that i need to read the file in blocks (500 kb or 1 mb) because
> it's a large file.
>
> I 'am a rookie using C#, so if possible please share a piece of code.
>
> Thanks in advance,
>
> Michelle
>

From: Jeff Johnson on
"Michelle" <michelle(a)notvalid.nomail> wrote in message
news:OSzELUiMKHA.3672(a)TK2MSFTNGP02.phx.gbl...

>I need some help to search through a (sometimes large) binary file.
>
> I'd like to search within this binary file for a pattern containing a
> particular hex value (e.g. FF56131A1B087B15610800151E).
> When the pattern is found, i need to know the (start) offset, because then
> I'd like to read the 4 previous bytes (need the hex values).
> I suppose that i need to read the file in blocks (500 kb or 1 mb) because
> it's a large file.

Define "large," because you'd be better of if you can read the entire thing
into a byte array and then just work off that byte array. Using chunks
forces you to deal with the situation where the data you're searching for is
split across the end of one chunk and the beginning of the next.


From: Michelle on
It's not only reading a binary file, but also searching for a particular hex
value (pattern).
And what about if my pattern is at the block border ?

"Fred Mellender" <nospam_fredm73(a)gmail.com> wrote in message
news:%23Fov8fiMKHA.5072(a)TK2MSFTNGP05.phx.gbl...
> "read binary file c#" in Google returns many hits, including:
> http://www.codersource.net/csharp_read_write_binary_files.html
> http://www.yoda.arachsys.com/csharp/readbinary.html
> http://dotnetperls.com/binaryreader
>
>
>
> "Michelle" <michelle(a)notvalid.nomail> wrote in message
> news:OSzELUiMKHA.3672(a)TK2MSFTNGP02.phx.gbl...
>>I need some help to search through a (sometimes large) binary file.
>>
>> I'd like to search within this binary file for a pattern containing a
>> particular hex value (e.g. FF56131A1B087B15610800151E).
>> When the pattern is found, i need to know the (start) offset, because
>> then I'd like to read the 4 previous bytes (need the hex values).
>> I suppose that i need to read the file in blocks (500 kb or 1 mb) because
>> it's a large file.
>>
>> I 'am a rookie using C#, so if possible please share a piece of code.
>>
>> Thanks in advance,
>>
>> Michelle
>>
>


From: Michelle on
Mostly more then 1 Gb.

"Jeff Johnson" <i.get(a)enough.spam> wrote in message
news:%23BEECKjMKHA.3672(a)TK2MSFTNGP02.phx.gbl...
> "Michelle" <michelle(a)notvalid.nomail> wrote in message
> news:OSzELUiMKHA.3672(a)TK2MSFTNGP02.phx.gbl...
>
>>I need some help to search through a (sometimes large) binary file.
>>
>> I'd like to search within this binary file for a pattern containing a
>> particular hex value (e.g. FF56131A1B087B15610800151E).
>> When the pattern is found, i need to know the (start) offset, because
>> then I'd like to read the 4 previous bytes (need the hex values).
>> I suppose that i need to read the file in blocks (500 kb or 1 mb) because
>> it's a large file.
>
> Define "large," because you'd be better of if you can read the entire
> thing into a byte array and then just work off that byte array. Using
> chunks forces you to deal with the situation where the data you're
> searching for is split across the end of one chunk and the beginning of
> the next.
>