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) { // get the codepage codepage = reader.ReadByte(); // codePage specifies the part of the ISO/IEC 8859 used to code this string Encoding enc = Encoding.ASCII; if (codepage > 0 && codepage <= 16) { try { // when codepage=1 it is ISO-8859-1 enc = Encoding.GetEncoding("ISO-8859-" + codepage.ToString()); } catch (Exception e) { WriteLine(LogLevel.WARN, "Failed to work with codepage {0}, '{1}'", codepage, e.Message); } } else if (codepage != 0) // 0 means no codepage since value isn't set { WriteLine(LogLevel.WARN, "Unknown codepage {0}", codepage); } // read string using encoding base.ProcessInternal(reader, enc); writer.WriteString(text); }
protected override void ProcessInternal(CustomBinaryReader reader) { type = (EquipmentType)reader.ReadByte(); issuingMemberState = reader.ReadByte(); base.ProcessInternal(reader); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // format: scpaattt tttttttt (16 bits) // s = slot, c = crew status, p = card inserted, a = activity, t = time byte b1 = reader.ReadByte(); byte b2 = reader.ReadByte(); slot = (byte)((b1 >> 7) & 0x01); // 7th bit status = (byte)((b1 >> 6) & 0x01); // 6th bit inserted = ((b1 >> 5) & 0x01) == 0; // 5th bit activity = (Activity)((b1 >> 3) & 0x03); // 4th and 3rd bits time = (((uint)b1 & 0x07) << 8) | b2; // 0th, 1st, 2nd bits from b1 if (this.LogLevel == LogLevel.DEBUG || this.LogLevel == LogLevel.INFO) { long position = reader.BaseStream.Position; if (reader.BaseStream is CyclicStream) { position = ((CyclicStream)reader.BaseStream).ActualPosition; } writer.WriteAttributeString("FileOffset", string.Format("0x{0:X4}", position)); } writer.WriteAttributeString("Slot", slot.ToString()); writer.WriteAttributeString("Status", status.ToString()); writer.WriteAttributeString("Inserted", inserted.ToString()); writer.WriteAttributeString("Activity", activity.ToString()); writer.WriteAttributeString("Time", string.Format("{0:d2}:{1:d2}", time / 60, time % 60)); }
public void Process(CustomBinaryReader reader) { // Store start of region (for logging only) byteOffset = reader.BaseStream.Position; this.ShouldSuppressElement = SuppressElement(reader); // Call subclass process method ProcessInternal(reader); if (this.Name == "MemberStateCertificate") { Validator.SetCACertificate(this); } else if (this.Name == "VuCertificate") { Validator.SetCertificate(this); } ; long endPosition = reader.BaseStream.Position; if (reader.BaseStream is CyclicStream) { endPosition = ((CyclicStream)reader.BaseStream).ActualPosition; } WriteLine(LogLevel.DEBUG, "{0} [0x{1:X4}-0x{2:X4}/0x{3:X4}] {4}", Name, byteOffset, endPosition, endPosition - byteOffset, ToString()); if (GlobalValue) { globalValues[Name] = 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) { byte b1 = reader.ReadByte(); byte b2 = reader.ReadByte(); slot = (byte)((b1 & 0x80) >> 7); // TODO: H: not sure why this is always returning zero (simple logic bug?) status = (byte)((b1 & 0x40)); inserted = (b1 & 0x20) == 0; activity = (Activity)((b1 & 0x18) >> 3); time = (uint)(((b1 & 0x07) << 8) | b2); if (this.LogLevel == LogLevel.DEBUG || this.LogLevel == LogLevel.INFO) { long position = reader.BaseStream.Position; if (reader.BaseStream is CyclicStream) { position = ((CyclicStream)reader.BaseStream).ActualPosition; } writer.WriteAttributeString("FileOffset", string.Format("0x{0:X4}", position)); } writer.WriteAttributeString("Slot", slot.ToString()); writer.WriteAttributeString("Status", status.ToString()); writer.WriteAttributeString("Inserted", inserted.ToString()); writer.WriteAttributeString("Activity", activity.ToString()); writer.WriteAttributeString("Time", string.Format("{0:d2}:{1:d2}", time / 60, time % 60)); }
protected void ProcessItems(CustomBinaryReader reader, uint count) { WriteLine(LogLevel.DEBUG, "Processing repeating {0}, count={1}, offset=0x{2:X4}", Name, count, reader.BaseStream.Position); // repeat processing of child objects uint maxCount = count; this.ProcessedRegions.Capacity = (int)maxCount; while (count > 0) { try { foreach (Region r in regions) { var newRegion = r.Copy(); newRegion.RegionLength = regionLength; newRegion.Process(reader); this.ProcessedRegions.Add(newRegion); } count--; } catch (EndOfStreamException ex) { WriteLine(LogLevel.ERROR, "Repeating {0}, count={1}/{2}: {3}", Name, count, maxCount, ex); break; } } }
protected override void ProcessInternal(CustomBinaryReader reader) { // get the codepage var codepage = reader.ReadByte(); // codePage specifies the part of the ISO/IEC 8859 used to code this string string encodingName = "UNKNOWN"; if (charsetMapping.ContainsKey(codepage)) { encodingName = charsetMapping[codepage]; } Encoding enc = null; if (encodingCache.ContainsKey(encodingName)) { enc = encodingCache[encodingName]; } if (enc == null) { // we want to warn if we didn't recognize codepage because using wrong codepage will cause use of wrong codepoints and thus incorrect data WriteLine(LogLevel.WARN, "Unknown codepage {0}", codepage); enc = Encoding.ASCII; } // read string using encoding base.ProcessInternal(reader, enc); }
/// This is the core method overridden by all subclasses of Region // TODO: M: very inefficient if no matches found - will iterate over WORDs to end of file protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { WriteLine(LogLevel.DEBUG, "Processing..."); // in this case we read a magic and try to process it while (true) { byte[] magic = new byte[2]; int bytesRead = reader.BaseStream.Read(magic, 0, 2); if (bytesRead == 0) { // end of file - nothing more to read break; } if (bytesRead == 1) { // this can happen if zipping over unmatched bytes at end of file - should handle better // throw new InvalidOperationException("Could only read one byte of identifier at end of stream"); break; } // test whether the magic matches one of our child objects string magicString = string.Format("0x{0:X2}{1:X2}", magic[0], magic[1]); foreach (IdentifiedObjectRegion r in regions) { if (r.Matches(magicString)) { r.Process(reader, writer); break; } } } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { byte byteValue = reader.ReadByte(); if (byteValue < countries.Length) { countryName = countries[byteValue]; } else if (byteValue == 0xFD) { countryName = "European Community"; } else if (byteValue == 0xFE) { countryName = "Europe"; } else if (byteValue == 0xFF) { countryName = "World"; } else { countryName = "UNKNOWN"; } writer.WriteAttributeString("Name", countryName); writer.WriteString(byteValue.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { byte b1=reader.ReadByte(); byte b2=reader.ReadByte(); slot=(byte) ((b1 & 0x80) >> 7); // TODO: H: not sure why this is always returning zero (simple logic bug?) status=(byte) ((b1 & 0x40)); inserted=(b1 & 0x20) == 0; activity=(Activity) ((b1 & 0x18) >> 3); time=(uint) (((b1 & 0x07) << 8) | b2); if ( this.LogLevel == LogLevel.DEBUG || this.LogLevel == LogLevel.INFO ) { long position=reader.BaseStream.Position; if ( reader.BaseStream is CyclicStream ) position=((CyclicStream) reader.BaseStream).ActualPosition; writer.WriteAttributeString("FileOffset", string.Format("0x{0:X4}", position)); } writer.WriteAttributeString("Slot", slot.ToString()); writer.WriteAttributeString("Status", status.ToString()); writer.WriteAttributeString("Inserted", inserted.ToString()); writer.WriteAttributeString("Activity", activity.ToString()); writer.WriteAttributeString("Time", string.Format("{0:d2}:{1:d2}", time / 60, time % 60)); }
protected virtual bool SuppressElement(CustomBinaryReader reader) { // derived classes can override this to suppress the writing of // a wrapper element. Used by the ElementaryFileRegion to suppress // altogether the signature blocks that occur for some regions return(false); }
protected override void ProcessInternal(CustomBinaryReader reader) { SignatureRegion.signedDataOffsetBegin = reader.BaseStream.Position; base.ProcessInternal(reader); SignatureRegion.signedDataOffsetEnd = reader.BaseStream.Position; }
protected override void ProcessInternal(CustomBinaryReader reader) { values = new byte[Length]; for (int n = 0; n < Length; n++) { values[n] = reader.ReadByte(); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { if (Count == 0 && CountRef != null) { string refName = CountRef.Substring(1); Count = uint.Parse((string)globalValues[refName]); } ProcessItems(reader, writer, Count); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // iterate over all child regions and process them foreach (Region r in regions) { r.RegionLength = regionLength; r.Process(reader, writer); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { type = (EquipmentType)reader.ReadByte(); issuingMemberState = reader.ReadByte(); writer.WriteAttributeString("Type", type.ToString()); writer.WriteAttributeString("IssuingMemberState", issuingMemberState.ToString()); base.ProcessInternal(reader, writer); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { byte[] buf = new byte[Size]; int amountRead = reader.Read(buf, 0, Size); if (amountRead != Size) { throw new InvalidOperationException("End of file reading padding (size " + Size + ")"); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { driverIdentification = reader.ReadString(14); replacementIndex = reader.ReadByte(); renewalIndex = reader.ReadByte(); writer.WriteAttributeString("ReplacementIndex", replacementIndex.ToString()); writer.WriteAttributeString("RenewalIndex", renewalIndex.ToString()); writer.WriteString(driverIdentification); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { values = new byte[Length]; for (int n = 0; n < Length; n++) { values[n] = reader.ReadByte(); } writer.WriteAttributeString("Value", this.ToString()); }
protected void ProcessItems(CustomBinaryReader reader, XmlWriter writer, uint count) { WriteLine(LogLevel.DEBUG, "Processing repeating {0}, count={1}", Name, count); // repeat processing of child objects while (count > 0) { base.ProcessInternal(reader, writer); count--; } }
protected override void ProcessInternal(CustomBinaryReader reader) { serialNumber = reader.ReadSInt32(); // BCD coding of Month (two digits) and Year (two last digits) uint monthYear = reader.ReadBCDString(2); type = reader.ReadByte(); manufacturerCode = reader.ReadByte(); month = (byte)(monthYear / 100); year = (byte)(monthYear % 100); }
protected override void ProcessInternal(CustomBinaryReader reader) { uint year = reader.ReadBCDString(2); uint month = reader.ReadBCDString(1); uint day = reader.ReadBCDString(1); // year 0, month 0, day 0 means date isn't set if (year > 0 || month > 0 || day > 0) { dateTime = new DateTime((int)year, (int)month, (int)day); } }
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) { SignatureRegion.signedDataOffsetEnd = reader.BaseStream.Position; base.ProcessInternal(reader); long currentOffset = reader.BaseStream.Position; reader.BaseStream.Position = SignatureRegion.signedDataOffsetBegin; Validator.ValidateGen1(reader.ReadBytes(SignatureRegion.GetSignedDataLength()), this.ToBytes(), SignatureRegion.newestDateTime); reader.BaseStream.Position = currentOffset; }
public void Process(Stream s, XmlWriter writer) { CustomBinaryReader r = new CustomBinaryReader(s); try { Process(r, writer); } finally { s.Close(); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { type = (EquipmentType)reader.ReadByte(); issuingMemberState = reader.ReadByte(); driverIdentification = reader.ReadString(14); replacementIndex = reader.ReadByte(); renewalIndex = reader.ReadByte(); writer.WriteAttributeString("Type", type.ToString()); writer.WriteAttributeString("IssuingMemberState", issuingMemberState.ToString()); writer.WriteAttributeString("ReplacementIndex", replacementIndex.ToString()); writer.WriteAttributeString("RenewalIndex", renewalIndex.ToString()); writer.WriteString(driverIdentification); }
protected override void ProcessInternal(CustomBinaryReader reader) { // iterate over all child regions and process them foreach (Region r in regions) { r.RegionLength = regionLength; r.Process(reader); this.ProcessedRegions.Add(r.Name, r); } if (this.Name == "VuCertificate") { SignatureRegion.signedDataOffsetBegin = reader.BaseStream.Position; } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { byte yy1 = reader.ReadByte(); byte yy2 = reader.ReadByte(); byte mm = reader.ReadByte(); byte dd = reader.ReadByte(); int year = ((yy1 & 0xF0) >> 4) * 1000 + (yy1 & 0xF) * 100 + ((yy2 & 0xF0) >> 4) * 10 + (yy2 & 0xF); int month = ((mm & 0xF0) >> 4) * 10 + (mm & 0xF); int day = ((dd & 0xF0) >> 4) * 10 + (dd & 0xF); dateTime = new DateTime(year, month, day); writer.WriteAttributeString("Datef", dateTime.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { serialNumber = reader.ReadSInt32(); month = reader.ReadByte(); year = reader.ReadByte(); type = reader.ReadByte(); manufacturerCode = reader.ReadByte(); writer.WriteAttributeString("Month", month.ToString()); writer.WriteAttributeString("Year", year.ToString()); writer.WriteAttributeString("Type", type.ToString()); writer.WriteAttributeString("ManufacturerCode", manufacturerCode.ToString()); writer.WriteString(serialNumber.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { serialNumber=reader.ReadSInt32(); month=reader.ReadByte(); year=reader.ReadByte(); type=reader.ReadByte(); manufacturerCode=reader.ReadByte(); writer.WriteAttributeString("Month", month.ToString()); writer.WriteAttributeString("Year", year.ToString()); writer.WriteAttributeString("Type", type.ToString()); writer.WriteAttributeString("ManufacturerCode", manufacturerCode.ToString()); writer.WriteString(serialNumber.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { byte byteValue=reader.ReadByte(); if ( byteValue < countries.Length ) countryName=countries[byteValue]; else countryName="UNKNOWN"; writer.WriteAttributeString("Code", HexValueRegion.ToHexString(new byte[] {byteValue})); writer.WriteAttributeString("Name", countryName); }
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) { if ( Count == 0 && CountRef != null ) { string refName=CountRef.Substring(1); Count=uint.Parse((string) globalValues[refName]); } ProcessItems(reader, writer, Count); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { boolValue=reader.ReadByte() > 0; writer.WriteString(boolValue.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // get the codepage codepage=reader.ReadByte(); Encoding enc=Encoding.Default; try { // try to get the encoding enc=Encoding.GetEncoding(codepage); } catch ( Exception ) { // TODO: H: work out what the code page should be // Console.WriteLine("WARN: Failed to work with codepage {0}, '{1}'", codepage, e.Message); } // read string using encoding base.ProcessInternal(reader, enc); writer.WriteString(text); }
protected void ProcessItems(CustomBinaryReader reader, XmlWriter writer, uint count) { WriteLine(LogLevel.DEBUG, "Processing repeating {0}, count={1}", Name, count); // repeat processing of child objects while ( count > 0 ) { base.ProcessInternal(reader, writer); count--; } }
protected override bool SuppressElement(CustomBinaryReader reader) { int type=reader.PeekChar(); return type == 0x01; }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { uintValue=reader.ReadSInt24(); writer.WriteString(uintValue.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { dateTime=reader.ReadTimeReal(); writer.WriteAttributeString("DateTime", dateTime.ToString()); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // we just use the default encoding in the default case this.ProcessInternal(reader, Encoding.Default); writer.WriteString(text); }
// method that will read string from file in specified encoding protected void ProcessInternal(CustomBinaryReader s, Encoding enc) { text=s.ReadString(Length, enc).Trim(); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { byte[] buf=new byte[Size]; int amountRead=reader.Read(buf, 0, Size); if ( amountRead != Size ) throw new InvalidOperationException("End of file reading padding (size "+Size+")"); }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // iterate over all child regions and process them foreach ( Region r in regions ) { r.RegionLength=regionLength; r.Process(reader, writer); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { values=new byte[Length]; for ( int n=0; n< Length; n++ ) values[n]=reader.ReadByte(); writer.WriteAttributeString("Value", this.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); }
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--; } }
/// This is the core method overridden by all subclasses of Region // TODO: M: very inefficient if no matches found - will iterate over WORDs to end of file protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { WriteLine(LogLevel.DEBUG, "Processing..."); // in this case we read a magic and try to process it while ( true ) { byte[] magic=new byte[2]; int bytesRead=reader.BaseStream.Read(magic, 0, 2); if ( bytesRead == 0 ) // end of file - nothing more to read break; if ( bytesRead == 1 ) // this can happen if zipping over unmatched bytes at end of file - should handle better // throw new InvalidOperationException("Could only read one byte of identifier at end of stream"); break; // test whether the magic matches one of our child objects string magicString=string.Format("0x{0:X2}{1:X2}", magic[0], magic[1]); foreach ( IdentifiedObjectRegion r in regions ) { if ( r.Matches(magicString) ) { r.Process(reader, writer); break; } } } }
public void Process(Stream s, XmlWriter writer) { CustomBinaryReader r = new CustomBinaryReader(s); try { Process(r, writer); } finally { s.Close(); } }
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { type=(EquipmentType) reader.ReadByte(); issuingMemberState=reader.ReadByte(); driverIdentification=reader.ReadString(14); replacementIndex=reader.ReadByte(); renewalIndex=reader.ReadByte(); writer.WriteAttributeString("Type", type.ToString()); writer.WriteAttributeString("IssuingMemberState", issuingMemberState.ToString()); writer.WriteAttributeString("ReplacementIndex", replacementIndex.ToString()); writer.WriteAttributeString("RenewalIndex", renewalIndex.ToString()); writer.WriteString(driverIdentification); }
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); } }
public void Process(CustomBinaryReader reader, XmlWriter writer) { // Store start of region (for logging only) byteOffset=reader.BaseStream.Position; bool suppress=SuppressElement(reader); // Write a new output element if ( !suppress ) writer.WriteStartElement(Name); // Call subclass process method ProcessInternal(reader, writer); // End the element if ( !suppress ) writer.WriteEndElement(); long endPosition=reader.BaseStream.Position; if ( reader.BaseStream is CyclicStream ) endPosition=((CyclicStream) reader.BaseStream).ActualPosition; WriteLine(LogLevel.DEBUG, "{0} [0x{1:X4}-0x{2:X4}/0x{3:X4}] {4}", Name, byteOffset, endPosition, endPosition-byteOffset, ToString()); if ( GlobalValue ) { globalValues[Name] = ToString(); } }
protected virtual bool SuppressElement(CustomBinaryReader reader) { // derived classes can override this to suppress the writing of // a wrapper element. Used by the ElementaryFileRegion to suppress // altogether the signature blocks that occur for some regions return false; }
protected abstract void ProcessInternal(CustomBinaryReader reader, XmlWriter writer);
protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer) { // we just use the default encoding in the default case this.ProcessInternal(reader, Encoding.Default); writer.WriteString(Regex.Replace(text, @"[^\u0020-\u007E]", string.Empty)); }