P
Peter Duniho
Peter,
Thank you for the explanation. It's more difficult then I thought.
I thought that searching through binary data a common issue was (you can
do
this with every hex editor) and that there were plenty of examples
available.
I don't know about the relative quantity of examples one way or the
other. As far as it being a common feature in hex editors, well...a) not
all hex editors are created equal (any editor that requires the entire
file data to be loaded into memory at once, which is a lot of them, can
trivially search the entire file contents without worrying about the
block-level i/o), and b) for someone with enough programming experience to
be able to write a good hex editor, this really isn't a very difficult
problem.
[...]
To try your example, I created a console application (using Visual
Studio 2008)
Maybe it's a little bit silly, but how can I add my pattern (hex value)
as
an argument to FindByteString -> byte[] rgbPattern?
The same way you'd initialize any array. For example:
byte[] rgbPattern = { 0xff, 0x56, 0x13, 0x1a };
If you want to provide a text string as initialization, that's possible as
well. You'll just have to parse each pair of hex digits in the string as
a byte and add them to an appropriate array. For example:
string strPattern = "ff56131a";
byte[] rgbPattern = RgbFromString(strPattern);
where:
byte[] RgbFromString(string strPattern)
{
byte[] rgbRet = new byte[strPattern.Length / 2];
for (int ib = 0; ib < rgbRet.Length; ib++)
{
rgbRet[ib] = byte.Parse(strPattern.Substring(ib * 2, 2),
NumberStyles.HexNumber);
}
return rgbRet;
}
int FindByteString(string strInputFile, byte[] rgbPattern)
Get an error on this and don't know how to solve it:if (++ibOffset < cbBlockCur.Length)
'int' does not contain a definition for 'Length' and no extension method
'Length' accepting a first argument of type 'int' could be found (are you
missing a using directive or an assembly reference?)
As mentioned before, I'm a rookie using C#, so please be patient.
But I'm willing to learn.
For what it's worth, it's my opinion that one of the best ways to learn
programming is to read other people's code and figure out how it works.
And of course, if you do that, in the process you should be able to figure
out how to fix any parts of the code that might not be exactly correct.
As far as that specific error goes, the purpose of that line of code is
simply to continue the loop if there are still unprocessed bytes left in
the current block (all of the rest of the code in the loop, after that
"if" statement and its block, handles updating the in-memory blocks
holding the data being processed to the next block-size part of the
file). Knowing that, it should be clear that the correct statement is:
if (++ibOffset < cbBlockCur)
That is, just remove the ".Length"...it's superfluous and left over from a
variation of the code I had before I changed it and posted my message.
Hope that helps.
Pete