Re: Search through a (large) binary file.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 10 Sep 2009 16:43:16 +0200, "Michelle"
<michelle@xxxxxxxxxxxxxxx> wrote:

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

This is essentially a string searching problem. Google for the
"Rabin-Karp Algorithm", the "Knuth-Morris-Pratt Algorithm" and the
"Boyer-Moore Algorithm". If there is more than one possible pattern
to search for then Rabin-Karp is the best as it can search for
multiple patterns in a single pass. If there is only a single pattern
to match then use one of the other two as they will be faster at
finding a single target.

Google will find example C# code for all three algorithms.

rossum

.



Relevant Pages

  • Re: memset question!
    ... parameter is also a *byte* fill pattern. ... So, filling an integer with ... 11, like above will fill it with hex 0x0B0B0B0B, or decimal ... For that reason, memset's middle parameter is best passed ...
    (microsoft.public.vc.language)
  • Re: Documentation for Literal Constants
    ... >> The bit pattern described by the constant is created, ... I'm writing my own IntToStr and StrToInt routines and was just trying ... my IntToStr routine will not prepend a negative sign to hex ...
    (microsoft.public.vc.mfc)
  • Re: Hex "generalizations"
    ... It so happens that for the "Hex" pattern (and for the various n-Atoll ... You can't say "In Mind Ninja you can choose to ... Therefore Mind Ninja is a generalization of all of these ...
    (rec.games.abstract)
  • Re: Help me with this!!!
    ... Peter Otten ha scritto: ... It search a text inside that hex value. ... Because the pattern isn't in the file, ... It display the file correcltly but... ...
    (comp.lang.python)
  • Re: Non-printable char in regex
    ... I tried using Hex, ... Octal and Control patterns without success. ... chars in the string the subsequent pattern matching works fine. ...
    (comp.lang.perl.misc)