Below is my BinaryReader loop, I've tried stepping through it to see what's going on, but when it gets back to setting the Position variable, it goes from "433939" to "433941", nothing else is interacting with it, it doesn't change at all going through this loop, but instead of going from 433939 to 433940 it skips over it. Is there something I am missing here?
while (Binary.BaseStream.Position < Binary.BaseStream.Length)
{
CurrentData = Binary.ReadByte().ToString("X2");
Position = Binary.BaseStream.Position;
if (CurrentData == "FF")
{
if (ImageFound == false)
{
if (Binary.ReadByte().ToString("X2") == "D8")
{
Console.WriteLine("Header Found!");
ImageFound = true;
Binary.BaseStream.Position = Position;
continue;
}
}
if (ImageFound == true)
{
if (Binary.ReadByte().ToString("X2") == "D9")
{
Console.WriteLine("Footer Fount!");
ImageFound = false;
Image.Append(Binary.ReadByte().ToString("FFD9"));
File.WriteAllText(new Random().Next().ToString() + ".bin", Image.ToString());
Console.ReadLine();
continue;
}
}
}
if (ImageFound == true)
{
Image.Append(CurrentData);
continue;
}
}
I'm really not seeing where this is going wrong, like I said Step over or break points aren't helping at all, which isn't all to great.
Oh I feel stupid, I must need to take a break or get a coffee. The problem was I was advancing the position for a comparison and not resetting it if it failed.
if (Binary.ReadByte().ToString("X2") == "D9")
Was advancing it the one byte and returning false, so I just needed to add and else saying
Binary.BaseStream.Position--;