protected override void ProcessInternal(CustomBinaryReader reader)
        {
            type = (EquipmentType)reader.ReadByte();
            issuingMemberState = reader.ReadByte();

            base.ProcessInternal(reader);
        }
        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));
        }
Exemple #3
0
        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));
        }
        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));
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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)
        {
            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, 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)
        {
            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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
            }
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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)
        {
            values = new byte[Length];

            for (int n = 0; n < Length; n++)
            {
                values[n] = reader.ReadByte();
            }
        }
Exemple #16
0
        protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer)
        {
            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);

            writer.WriteAttributeString("Month", month.ToString());
            writer.WriteAttributeString("Year", year.ToString());
            writer.WriteAttributeString("Type", type.ToString());
            writer.WriteAttributeString("ManufacturerCode", manufacturerCode.ToString());

            writer.WriteString(serialNumber.ToString());
        }
Exemple #17
0
        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());
        }
Exemple #18
0
        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);
            }
        }
Exemple #19
0
        protected override void ProcessInternal(CustomBinaryReader reader)
        {
            // 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)
            {
                this.position = reader.BaseStream.Position;
                if (reader.BaseStream is CyclicStream)
                {
                    this.position = ((CyclicStream)reader.BaseStream).ActualPosition;
                }
            }
        }
        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)
        {
            // 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);
        }
Exemple #22
0
        protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer)
        {
            // get the codepage
            var codepage = reader.ReadByte();
            // codePage specifies the part of the ISO/IEC 8859 used to code this string

            string   encodingName = charsetMapping.GetValueOrDefault(codepage, "UNKNOWN");
            Encoding enc          = encodingCache.GetValueOrDefault(encodingName, null);

            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);
            writer.WriteString(text);
        }
Exemple #23
0
        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);
        }
            public CertificateGen1(byte[] certificateData)
            {
                using (var reader = new CustomBinaryReader(new MemoryStream(certificateData)))
                {
                    this.profileIdentifier = Convert.ToInt32(reader.ReadByte());
                    this.certificationAuthorityReference = new CertificationAuthorityReference(reader);
                    this.holderAuthorisation             = reader.ReadBytes(7);

                    var timestamp = reader.ReadSInt32();
                    if (timestamp != 0xFFFFFFFF)
                    {
                        this.endOfValidity = DateTimeOffset.FromUnixTimeSeconds(timestamp);
                    }
                    else
                    {
                        this.endOfValidity = null;
                    };
                    this.holderReference = reader.ReadBytes(8);
                    this.publicKey       = new RSAPublicKey(reader);
                };
            }
 protected override void ProcessInternal(CustomBinaryReader reader)
 {
     this.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";
     }
 }
        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);
        }
Exemple #27
0
 protected override void ProcessInternal(CustomBinaryReader reader, XmlWriter writer)
 {
     boolValue = reader.ReadByte() > 0;
     writer.WriteString(boolValue.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)
 {
     boolValue=reader.ReadByte() > 0;
     writer.WriteString(boolValue.ToString());
 }
        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)
        {
            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)
 {
     // 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 override void ProcessInternal(CustomBinaryReader reader)
 {
     driverIdentification = reader.ReadString(14);
     replacementIndex     = reader.ReadByte();
     renewalIndex         = reader.ReadByte();
 }
        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)
 {
     byteValue = reader.ReadByte();
 }
Exemple #37
0
        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);
            }
        }