try
{
byte[] fileBytes = File.ReadAllBytes(dumpFile);
long currentEndFirmware = endFirmware;
int maxIndex = fileBytes.Length - 4;
bool foundFF = false;
for (long i = endFirmware; i <= maxIndex; i++)
{
bool allFF = true;
for (int j = 0; j < 4; j++)
{
if (fileBytes[i + j] != 0xFF)
{
allFF = false;
break;
}
}
if (allFF)
{
actualEndFirmware = i - 4;
foundFF = true;
break;
}
}
if (!foundFF)
{
currentEndFirmware = fileBytes.Length - 4;
}
byte[] dataToCheck = new byte[currentEndFirmware];
Array.Copy(fileBytes, 0, dataToCheck, 0, dataToCheck.Length);
byte[] storedCrcBytes = new byte[4];
Array.Copy(fileBytes, currentEndFirmware, storedCrcBytes, 0, 4);
Array.Reverse(storedCrcBytes);
uint storedCrc = BitConverter.ToUInt32(storedCrcBytes, 0);
uint computedCrc = CRCUtility.CRC32.Compute(dataToCheck, 0, dataToCheck.Length);