protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { if (regionLength <= 4) { WriteLine(LogLevel.WARN, "CyclicalActivityRegion is empty!"); return; } uint oldest = reader.ReadSInt16(); uint newest = reader.ReadSInt16(); // length is length of region minus the bytes we've just read long effectiveLength = regionLength - 4; long position = reader.BaseStream.Position; if (position + effectiveLength > reader.BaseStream.Length) { WriteLine(LogLevel.WARN, "CyclicalActivityRegion position=0x{0:X4} + effectiveLength=0x{1:X4} > length=0x{2:X4} !", position, effectiveLength, reader.BaseStream.Length); return; } WriteLine(LogLevel.INFO, "Oldest 0x{0:X4} (offset 0x{2:X4}), newest 0x{1:X4} (offset 0x{3:X4})", position + oldest, position + newest, oldest, newest); if (oldest == newest && oldest == 0) { // no data in file return; } if (newest >= effectiveLength || oldest >= effectiveLength) { throw new IndexOutOfRangeException("Invalid pointer to CyclicalActivity Record"); } CyclicStream cyclicStream = new CyclicStream(reader.BaseStream, reader.BaseStream.Position, effectiveLength); CustomBinaryReader cyclicReader = new CustomBinaryReader(cyclicStream); reader.BaseStream.Seek(oldest, SeekOrigin.Current); bool last = false; while (!last) { long pos = cyclicStream.Position; if (pos == newest) { last = true; } base.ProcessInternal(cyclicReader, writer); if (cyclicStream.Wrapped) { last = true; } } writer.WriteElementString("DataBufferIsWrapped", cyclicStream.Wrapped.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // read the type byte type = reader.ReadByte(); regionLength = reader.ReadSInt16(); long fileLength = regionLength; if (type == 0x01) { // this is just the signature } else { long start = reader.BaseStream.Position; base.ProcessInternal(reader, writer); long amountProcessed = reader.BaseStream.Position - start; fileLength -= amountProcessed; } if (fileLength > 0) { // deal with a remaining fileLength that is greater than int while (fileLength > int.MaxValue) { reader.ReadBytes(int.MaxValue); fileLength -= int.MaxValue; } reader.ReadBytes((int)fileLength); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { uint oldest = reader.ReadSInt16(); uint newest = reader.ReadSInt16(); // length is length of region minus the bytes we've just read long effectiveLength = regionLength - 4; long position = reader.BaseStream.Position; WriteLine(LogLevel.INFO, "Oldest {0:X4} (offset {2:X4}), newest {1:X4} (offset {3:X4})", position + oldest, position + newest, oldest, newest); if (oldest == newest && oldest == 0) { // no data in file return; } CyclicStream cyclicStream = new CyclicStream(reader.BaseStream, reader.BaseStream.Position, effectiveLength); CustomBinaryReader cyclicReader = new CustomBinaryReader(cyclicStream); reader.BaseStream.Seek(oldest, SeekOrigin.Current); bool last = false; while (!last) { long pos = cyclicStream.Position; if (pos == newest) { last = true; } base.ProcessInternal(cyclicReader, writer); } writer.WriteElementString("DataBufferIsWrapped", cyclicStream.Wrapped.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader) { // read the type byte type = reader.ReadByte(); regionLength = reader.ReadSInt16(); long fileLength = regionLength; if (type == 0x01) { // this is just the signature this.signature = reader.ReadBytes((int)fileLength); fileLength = 0; long currentOffset = reader.BaseStream.Position; reader.BaseStream.Position = SignatureRegion.signedDataOffsetBegin; Validator.ValidateDelayedGen1(reader.ReadBytes(SignatureRegion.GetSignedDataLength()), this.signature); reader.BaseStream.Position = currentOffset; } else { long start = reader.BaseStream.Position; base.ProcessInternal(reader); long amountProcessed = reader.BaseStream.Position - start; fileLength -= amountProcessed; if (this.Name == "CardCertificate") { Validator.SetCertificate(this); } else if (this.Name == "CACertificate") { Validator.SetCACertificate(this); } ; } if (fileLength > 0) { // deal with a remaining fileLength that is greater than int while (fileLength > int.MaxValue) { reader.ReadBytes(int.MaxValue); fileLength -= int.MaxValue; } reader.ReadBytes((int)fileLength); } }
protected override void ProcessInternal(CustomBinaryReader reader) { previousRecordLength = reader.ReadSInt16(); currentRecordLength = reader.ReadSInt16(); recordDate = reader.ReadTimeReal(); dailyPresenceCounter = reader.ReadBCDString(2); distance = reader.ReadSInt16(); uint recordCount = (currentRecordLength - 12) / 2; this.ProcessedRegions.Capacity = (int)recordCount; WriteLine(LogLevel.DEBUG, "Reading {0} activity records", recordCount); while (recordCount > 0) { ActivityChangeRegion acr = new ActivityChangeRegion(); acr.Name = "ActivityChangeInfo"; acr.Process(reader); this.ProcessedRegions.Add(acr); recordCount--; } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { previousRecordLength = reader.ReadSInt16(); currentRecordLength = reader.ReadSInt16(); recordDate = reader.ReadTimeReal(); dailyPresenceCounter = reader.ReadBCDString(2); distance = reader.ReadSInt16(); writer.WriteAttributeString("DateTime", recordDate.ToString("u")); writer.WriteAttributeString("DailyPresenceCounter", dailyPresenceCounter.ToString()); writer.WriteAttributeString("Distance", distance.ToString()); uint recordCount = (currentRecordLength - 12) / 2; WriteLine(LogLevel.DEBUG, "Reading {0} activity records", recordCount); while (recordCount > 0) { ActivityChangeRegion acr = new ActivityChangeRegion(); acr.Name = "ActivityChangeInfo"; acr.Process(reader, writer); recordCount--; } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // get the count according to allocation size uint count; switch (SizeAlloc) { case SizeAllocation.BYTE: count = reader.ReadByte(); break; case SizeAllocation.WORD: count = reader.ReadSInt16(); break; default: throw new InvalidOperationException("Bad size allocation"); } ProcessItems(reader, writer, count); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { uintValue = reader.ReadSInt16(); writer.WriteString(uintValue.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader) { uintValue = reader.ReadSInt16(); }
protected override void ProcessInternal(CustomBinaryReader reader) { // read the type byte type = reader.ReadByte(); regionLength = reader.ReadSInt16(); long fileLength = regionLength; long start = reader.BaseStream.Position; if (DataFile.StrictProcessing && start + regionLength > reader.BaseStream.Length) { throw new InvalidOperationException(string.Format("{0}: Would try to read more than length of stream! Position 0x{1:X4} + RegionLength 0x{2:X4} > Length 0x{3:X4}", Name, start, regionLength, reader.BaseStream.Length)); } if (type == 0x01) { // this is just the signature this.signature = reader.ReadBytes((int)fileLength); fileLength = 0; long currentOffset = reader.BaseStream.Position; reader.BaseStream.Position = SignatureRegion.signedDataOffsetBegin; Validator.ValidateDelayedGen1(reader.ReadBytes(SignatureRegion.GetSignedDataLength()), this.signature, () => { return(SignatureRegion.newestDateTime); }); reader.BaseStream.Position = currentOffset; } else { base.ProcessInternal(reader); long amountProcessed = reader.BaseStream.Position - start; fileLength -= amountProcessed; if (this.Name == "CardCertificate") { Validator.SetCertificate(this); } else if (this.Name == "CACertificate") { Validator.SetCACertificate(this); } ; } if (DataFile.StrictProcessing && fileLength != 0) { throw new InvalidOperationException(string.Format("{0}: Read wrong number of bytes! Position 0x{1:X4} and end of region 0x{2:X4} but bytes left 0x{3:X4}", Name, reader.BaseStream.Position, start + regionLength, fileLength)); } if (DataFile.StrictProcessing && reader.BaseStream.Position > start + regionLength) { throw new InvalidOperationException(string.Format("{0}: Read past end of region! Position 0x{1:X4} > end of region 0x{2:X4}", Name, reader.BaseStream.Position, start + regionLength)); } if (fileLength > 0) { // deal with a remaining fileLength that is greater than int while (fileLength > int.MaxValue) { reader.ReadBytes(int.MaxValue); fileLength -= int.MaxValue; } reader.ReadBytes((int)fileLength); } }
protected override void ProcessInternal(CustomBinaryReader reader) { if (regionLength <= 4) { WriteLine(LogLevel.WARN, "CyclicalActivityRegion is empty!"); return; } uint oldest = reader.ReadSInt16(); uint newest = reader.ReadSInt16(); // length is length of region minus the bytes we've just read long effectiveLength = regionLength - 4; long position = reader.BaseStream.Position; if (position + effectiveLength > reader.BaseStream.Length) { WriteLine(LogLevel.WARN, "CyclicalActivityRegion position=0x{0:X4} + effectiveLength=0x{1:X4} > length=0x{2:X4} !", position, effectiveLength, reader.BaseStream.Length); return; } WriteLine(LogLevel.DEBUG, "Oldest 0x{0:X4} (offset 0x{2:X4}), newest 0x{1:X4} (offset 0x{3:X4})", position + oldest, position + newest, oldest, newest); if (oldest == newest && oldest == 0) { // no data in file return; } if (newest >= effectiveLength || oldest >= effectiveLength) { throw new IndexOutOfRangeException("Invalid pointer to CyclicalActivity Record"); } CyclicStream cyclicStream = new CyclicStream(reader.BaseStream, reader.BaseStream.Position, effectiveLength); CustomBinaryReader cyclicReader = new CustomBinaryReader(cyclicStream); reader.BaseStream.Seek(oldest, SeekOrigin.Current); bool last = false; while (!last) { long pos = cyclicStream.Position; if (pos == newest) { last = true; } foreach (Region r in regions) { var newRegion = r.Copy(); newRegion.RegionLength = regionLength; newRegion.Process(cyclicReader); this.ProcessedRegions.Add(newRegion); } this.DataBufferIsWrapped = cyclicStream.Wrapped; // commenting @davispuh mod because it can cause premature termination // see https://github.com/jugglingcats/tachograph-reader/issues/28 // if (cyclicStream.Wrapped) // { // last = true; // } } reader.BaseStream.Position = position + effectiveLength; }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { uintValue=reader.ReadSInt16(); writer.WriteString(uintValue.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // read the type byte type=reader.ReadByte(); regionLength=reader.ReadSInt16(); long fileLength=regionLength; if ( type == 0x01 ) { // this is just the signature } else { long start=reader.BaseStream.Position; base.ProcessInternal(reader, writer); long amountProcessed=reader.BaseStream.Position-start; fileLength -= amountProcessed; } if ( fileLength > 0 ) { // deal with a remaining fileLength that is greater than int while ( fileLength > int.MaxValue ) { reader.ReadBytes(int.MaxValue); fileLength-=int.MaxValue; } reader.ReadBytes((int) fileLength); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { previousRecordLength=reader.ReadSInt16(); currentRecordLength=reader.ReadSInt16(); recordDate=reader.ReadTimeReal(); dailyPresenceCounter=reader.ReadSInt16(); distance=reader.ReadSInt16(); writer.WriteAttributeString("DateTime", recordDate.ToString()); writer.WriteAttributeString("DailyPresenceCounter", dailyPresenceCounter.ToString()); writer.WriteAttributeString("Distance", distance.ToString()); uint recordCount=(currentRecordLength-12)/2; WriteLine(LogLevel.DEBUG, "Reading {0} activity records", recordCount); while (recordCount > 0) { ActivityChangeRegion acr=new ActivityChangeRegion(); acr.Name="ActivityChangeInfo"; acr.Process(reader, writer); recordCount--; } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { uint oldest=reader.ReadSInt16(); uint newest=reader.ReadSInt16(); // length is length of region minus the bytes we've just read long effectiveLength=regionLength - 4; long position=reader.BaseStream.Position; WriteLine(LogLevel.INFO, "Oldest {0:X4} (offset {2:X4}), newest {1:X4} (offset {3:X4})", position+oldest, position+newest, oldest, newest); if ( oldest == newest && oldest == 0 ) // no data in file return; CyclicStream cyclicStream=new CyclicStream(reader.BaseStream, reader.BaseStream.Position, effectiveLength); CustomBinaryReader cyclicReader=new CustomBinaryReader(cyclicStream); reader.BaseStream.Seek(oldest, SeekOrigin.Current); bool last=false; while ( !last ) { long pos=cyclicStream.Position; if ( pos == newest ) last=true; base.ProcessInternal(cyclicReader, writer); } writer.WriteElementString("DataBufferIsWrapped", cyclicStream.Wrapped.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // get the count according to allocation size uint count; switch (SizeAlloc) { case SizeAllocation.BYTE: count=reader.ReadByte(); break; case SizeAllocation.WORD: count=reader.ReadSInt16(); break; default: throw new InvalidOperationException("Bad size allocation"); } ProcessItems(reader, writer, count); }