From: rossum on
On Sat, 12 Sep 2009 11:57:46 +0200, "Michelle"
<michelle(a)notvalid.nomail> wrote:

>Rossum,
>
>I spend some time reading about the mentioned algorithms.
>The "Boyer-Moore Algorithm" seems to be the most popular and fastest. (Also
>used in several hex editors).
>Unfortunately (so far) I couldn't find a c# example for searching binary
>files.
>Because I've not much experience using C#, it's difficult to translate the
>'theory' to a working example.
>So if you know one, I appreciate a link to it.
>I'd like to read other people's code and figure out how it works to learn
>about. (It's for education only :-)) )
>
>Regards,
>
>Michelle
>
You appear to have two basic problems:
1 Read a binary file.
2 Search the data.

The first problem you should be able to find the answer for yourself
(you did say "education"). Reading files is a basic computer
progeamming skill, separate from string searching. It is useful for
many different problems and there is plenty of help available on the
web (e.g. http://dotnetperls.com/binaryreader) and in books. All you
need to do is to call off the next few bytes, using ReadBytes(), as
needed. The library will tell you when the end of the file is
reached.

For the second problem, there are many implementations of Boyer-Moore
but they all seem use characters and strings instead of bytes and byte
arrays. You will need to change the code yourself. All strings need
to be changed to byte arrays and all characters need to be changed to
bytes. References to a position in a string need to be changed to
references to a position in a byte array.

rossum

From: Michelle on
Tom,

> You need to qualify the method definition with the static keyword:
> static int FindByteString(string strInputFile, byte[] rgbPattern)
>
> Put the keyword 'static' before the 'int', and it should remove that
> error. It's probably best if you know why... so I suggest a bit of
> research on the 'static' keyword and what static members are.

I did some research on that and tried this solution already.
When I Put the keyword 'static' before the 'int' i get more errors (3 times)
"An object reference is required for the non-static field, method, or
property 'binSearch.Program.FRangesEqual(byte[], int, int, byte[])' "

Michelle


From: Tom Spink on
Michelle wrote:

> Tom,
>
>> You need to qualify the method definition with the static keyword:
>> static int FindByteString(string strInputFile, byte[] rgbPattern)
>>
>> Put the keyword 'static' before the 'int', and it should remove that
>> error. It's probably best if you know why... so I suggest a bit of
>> research on the 'static' keyword and what static members are.
>
> I did some research on that and tried this solution already.
> When I Put the keyword 'static' before the 'int' i get more errors (3 times)
> "An object reference is required for the non-static field, method, or
> property 'binSearch.Program.FRangesEqual(byte[], int, int, byte[])' "
>
> Michelle

That's because you've got more methods that you need to qualify with the
static keyword.

So, you've got a method called FRangesEqual - I bet that doesn't have
'static' on it either!

Stick it on, and on any others methods you've defined.

I don't mean to be rude, but if you'd done your research, you'll see why
you need to qualify all these method declarations with 'static'. If a
static method calls another method defined a class - and you don't have
an object reference, then that method must be static.

--
Tom

From: Michelle on
Tom,

Errors fixed.
I become a little bit tirred, so I'm not as sharp longer.
Excuses for that.

Michelle



From: Tom Spink on
Michelle wrote:

> Tom,
>
> Errors fixed.
> I become a little bit tirred, so I'm not as sharp longer.
> Excuses for that.
>
> Michelle

I'm glad you've got it sorted! That makes me smile.

See! :-)

--
Tom