private static IvffResult CheckBlockNext( Stream stream, ref IvCommonCheckWork checkWork, ref IvCommonBlockHeader common) { int val2 = Math.Min(checkWork.DivideSize, checkWork.RemainSize); checkWork.RemainSize -= val2; ++checkWork.NowCount; int size; for (; 0 < val2; val2 -= size) { size = Math.Min(16777216, val2); byte[] bytes = new byte[size]; int readSize; if (Ivff.IsResultError(Ivff.ReadNext(stream, bytes, size, out readSize)) || size != readSize) { return(IvffResult.READ_ERROR); } checkWork.CurSum = IvaUtils.CalcSum32(checkWork.CurSum, bytes, size); } if (0 < checkWork.RemainSize) { return(IvffResult.CONTINUE); } return((int)common.BlockDataSum == (int)checkWork.CurSum ? IvffResult.OK : IvffResult.INVALID); }
public static IvffResult IvaLoadSystemSetting( Stream stream, ref IvCommonBlockHeader systemHeader, ref VisionSensorSystemSetting systemSetting) { return(Ivff.LoadBlock <VisionSensorSystemSetting>(stream, ref systemSetting, (long)(systemHeader.FilePosition + (int)systemHeader.BlockHeaderSize))); }
private static IvffResult CheckBlockFirst( Stream stream, ref IvCommonCheckWork checkWork, int divideSize, ref IvCommonBlockHeader workHeader, uint blockID) { return(Ivff.CheckBlockFirst <IvCommonBlockHeader>(stream, out checkWork, divideSize, ref workHeader, ref workHeader, blockID)); }
private static IvffResult CheckFileBlockFirst( Stream stream, ref IvaFileHandler ivaHandler, BlockOffsetIndex index, int divideSize, ref IvCommonBlockHeader blockHeader) { uint blockID = Ivff.BLOCK_ID_TABLE[index]; uint num = ivaHandler.CommonHandler.BlockOffsetTable[(int)index]; stream.Seek((long)num, SeekOrigin.Begin); return(Ivff.CheckBlockFirst <IvCommonBlockHeader>(stream, out ivaHandler.CommonHandler.CheckerWork, divideSize, ref blockHeader, ref blockHeader, blockID)); }
private static IvffResult CheckIvCommonBlockHeader(ref IvCommonBlockHeader common) { if (Ivff.IsResultError(Ivff.CheckIvBlockId(common.BlockID)) || (int)common.BlockHeaderSize < Marshal.SizeOf(typeof(IvCommonBlockHeader)) || (common.BlockSize < (int)common.BlockHeaderSize || common.BlockSize > int.MaxValue)) { return(IvffResult.INVALID); } ushort commonHeaderSum = common.CommonHeaderSum; common.CommonHeaderSum = (ushort)0; ushort num = IvaUtils.CalcSum <IvCommonBlockHeader>((ushort)0, ref common); common.CommonHeaderSum = commonHeaderSum; return((int)commonHeaderSum != (int)num ? IvffResult.INVALID : IvffResult.OK); }
private static IvffResult SeekCommonBlockDataTop( Stream stream, ref IvCommonBlockHeader workHeader) { try { stream.Seek((long)(workHeader.FilePosition + Marshal.SizeOf(typeof(IvCommonBlockHeader))), SeekOrigin.Begin); } catch (Exception ex) { return(IvffResult.ACCESS_ERROR); } return(IvffResult.OK); }
private static IvffResult CheckBlockFirst <T>( Stream stream, out IvCommonCheckWork checkWork, int divideSize, ref T header, ref IvCommonBlockHeader workHeader, uint blockID) where T : struct { checkWork = new IvCommonCheckWork(); IvffResult result1 = Ivff.LoadBlockHeader <T>(stream, ref header); if (Ivff.IsResultError(result1)) { return(result1); } if ((int)workHeader.BlockHeaderSize != Marshal.SizeOf(typeof(IvCommonBlockHeader))) { IvffResult result2 = Ivff.SeekCommonBlockDataTop(stream, ref workHeader); if (Ivff.IsResultError(result2)) { return(result2); } } if (blockID != 0U && (int)workHeader.BlockID != (int)blockID) { return(IvffResult.UNMACH_BLOCK); } checkWork.RemainSize = checkWork.TotalSize = workHeader.BlockSize - Marshal.SizeOf(typeof(IvCommonBlockHeader)); if (divideSize == 0) { checkWork.DivideSize = checkWork.TotalSize; checkWork.DivideCount = 1U; IvffResult ivffResult = Ivff.CheckBlockNext(stream, ref checkWork, ref workHeader); while (ivffResult == IvffResult.CONTINUE) { ivffResult = Ivff.CheckBlockNext(stream, ref checkWork, ref workHeader); } return(ivffResult); } checkWork.DivideSize = divideSize; checkWork.DivideCount = (uint)((workHeader.BlockSize - Marshal.SizeOf(typeof(IvCommonBlockHeader))) / checkWork.DivideSize); return(IvffResult.CONTINUE); }
private static IvffResult LoadBlockHeader <T>(Stream stream, ref T structure) where T : struct { int length = Marshal.SizeOf(typeof(T)); int num1 = Marshal.SizeOf(typeof(IvCommonBlockHeader)); byte[] bytes1 = new byte[length]; int readSize; if (Ivff.IsResultError(Ivff.ReadNext(stream, bytes1, num1, out readSize)) || num1 != readSize) { return(IvffResult.READ_ERROR); } IvCommonBlockHeader commonBlockHeader = new IvCommonBlockHeader(); IvaUtils.BytesToStructure <IvCommonBlockHeader>(ref commonBlockHeader, bytes1); IvffResult result = Ivff.CheckIvCommonBlockHeader(ref commonBlockHeader); if (Ivff.IsResultError(result)) { return(result); } if ((int)commonBlockHeader.BlockHeaderSize > num1) { ushort num2 = Math.Min((ushort)((uint)commonBlockHeader.BlockHeaderSize - (uint)num1), (ushort)(length - num1)); if ((ushort)0 < num2) { byte[] bytes2 = new byte[(int)num2]; if (Ivff.IsResultError(Ivff.ReadNext(stream, bytes2, (int)num2, out readSize)) || (int)num2 != readSize) { return(IvffResult.READ_ERROR); } bytes2.CopyTo((Array)bytes1, num1); } } IvaUtils.BytesToStructure <T>(ref structure, bytes1); return(IvffResult.OK); }
private static IvffResult LoadIvCommonFilehandler( Stream stream, ref IvCommonFileHandler commonHandler) { IvffResult result = IvffResult.OK; int num = 0; bool flag = true; IvCommonBlockHeader workHeader = new IvCommonBlockHeader(); while (flag) { result = Ivff.CheckBlockFirst(stream, ref commonHandler.CheckerWork, 0, ref workHeader, 0U); if (!Ivff.IsResultError(result)) { switch (workHeader.BlockID) { case 4281929: if (num != 0) { return(IvffResult.INVALID); } commonHandler.VersionInfofHeader = workHeader; result = Ivff.LoadBlock <IvVersionInfoData>(stream, ref commonHandler.VersionInfo, (long)(commonHandler.VersionInfofHeader.FilePosition + (int)commonHandler.VersionInfofHeader.BlockHeaderSize)); if (!Ivff.IsResultError(result)) { if (!IvaUtils.IsCompatibleSettingVersion(Ivff.CURRENT_FILE_VERSION, commonHandler.VersionInfo.MinFileVersion)) { result = IvffResult.UNCOMPATIBLE; break; } if (commonHandler.VersionInfo.FileSize < 0U || commonHandler.VersionInfo.FileSize > (uint)int.MaxValue) { result = IvffResult.INVALID; break; } if ((long)commonHandler.VersionInfo.FileSize != stream.Length) { result = IvffResult.INVALID; break; } break; } break; case 5264969: case 5527113: return(IvffResult.INVALID); case 5656141: case 1196379203: case 1196379216: case 1230195795: case 1279480653: case 1279611725: case 1280003650: case 1280529238: case 1296520008: case 1314144592: case 1347699024: case 1396855638: case 1397642070: case 1397969750: case 1414547283: case 1414550593: case 1498565971: result = IvffResult.INVALID; break; case 5657430: if (num == 0) { return(IvffResult.INVALID); } commonHandler.CameraInfofHeader = workHeader; result = Ivff.LoadBlock <VisionSensorVersion>(stream, ref commonHandler.CameraVersion, (long)(commonHandler.CameraInfofHeader.FilePosition + (int)commonHandler.CameraInfofHeader.BlockHeaderSize)); break; case 1397116738: if (num == 0) { return(IvffResult.INVALID); } commonHandler.BlockOffsetHeader = workHeader; result = Ivff.LoadBlock <uint>(stream, ref commonHandler.BlockOffsetTable, (long)(commonHandler.BlockOffsetHeader.FilePosition + (int)commonHandler.BlockOffsetHeader.BlockHeaderSize)); flag = false; break; default: result = IvffResult.OK; break; } if (!Ivff.IsResultError(result)) { try { stream.Seek((long)(workHeader.FilePosition + workHeader.BlockSize), SeekOrigin.Begin); } catch (Exception ex) { break; } ++num; } else { break; } } else { break; } } if (Ivff.IsResultError(result)) { return(IvffResult.FATAL_ERROR); } return(result); }