예제 #1
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if ((hashFlags & Hashes.Intrinsic) != 0 && Data.BadCrcCount == null)
                {
                    Data.BadCrcCount = 0;
                    var hasher = new Crc32rHasher();
                    int pos    = 12;
                    for (int ix = 0; ix < Data.Chunks.Items.Count; ++ix)
                    {
                        PngChunk chunk = Data.Chunks.Items[ix];
                        hasher.Append(Data.fBuf, pos, (int)chunk.Size + 4);
                        byte[] hash      = hasher.GetHashAndReset();
                        UInt32 actualCRC = BitConverter.ToUInt32(hash, 0);
                        ChunksModel.SetActualCRC(ix, actualCRC);

                        if (actualCRC != chunk.StoredCRC)
                        {
                            ++Data.BadCrcCount;
                        }
                        pos += (int)chunk.Size + 12;
                    }

                    var sb = new StringBuilder();
                    sb.Append(Data.Chunks.Items.Count - Data.BadCrcCount);
                    sb.Append(" of ");
                    sb.Append(Data.Chunks.Items.Count);
                    sb.Append(" CRC checks successful.");
                    IssueModel.Add(sb.ToString(), Data.BadCrcCount == 0? Severity.Noise : Severity.Error);
                }

                base.CalcHashes(hashFlags, validationFlags);
            }
예제 #2
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (Data.Issues.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.Intrinsic) != 0 && Data.History != null && Data.History.ActualCRC == null)
                {
                    var hasher = new Crc32rHasher();
                    hasher.Append(Data.fbs, 0, (int)Data.mediaPosition, (int)Data.mediaPosition + 8, Data.FileSize - Data.mediaPosition - 8);
                    byte[] hash = hasher.GetHashAndReset();
                    HistoryModel.SetActualSelfCRC(BitConverter.ToUInt32(hash, 0));

                    if (Data.History.ActualCRC == Data.History.StoredCRC)
                    {
                        IssueModel.Add("Self-CRC check successful.", Severity.Noise);
                    }
                    else
                    {
                        IssueModel.Add("Self-CRC mismatch, file has been modified.");
                    }
                }

                base.CalcHashes(hashFlags, validationFlags);
            }
예제 #3
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (Data.Issues.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.Intrinsic) != 0)
                {
                    Data.badCrcCount = 0;
                    foreach (var master in Data.layout)
                    {
                        foreach (var cx in master.GetNodeTraces("CRC-32"))
                        {
                            var top  = cx.Peek();
                            var node = top.Node.Nodes[top.Index] as EbmlNodeCRC;
                            if (node.Count > 0)
                            {
                                var hasher = new Crc32rHasher();
                                hasher.Append(Data.fbs, node.Start, node.Count);
                                var hash = hasher.GetHashAndReset();
                                node.ActualCRC32 = BitConverter.ToUInt32(hash, 0);
                                if (node.StoredCRC32 != node.ActualCRC32)
                                {
                                    ++Data.badCrcCount;
                                }
                            }
                        }
                    }
                }

                base.CalcHashes(hashFlags, validationFlags);
            }
예제 #4
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (Data.Issues.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.Intrinsic) != 0 && Data.badCrcCount == null)
                {
                    Data.badCrcCount = 0;
                    foreach (var master in Data.layout)
                    {
                        foreach (var cx in master.GetNodeTraces("CRC-32"))
                        {
                            var top  = cx.Peek();
                            var node = top.Node.Nodes[top.Index] as EbmlNodeCRC;
                            if (node.Count > 0)
                            {
                                var hasher = new Crc32rHasher();
                                hasher.Append(Data.fbs, node.Start, node.Count);
                                var hash = hasher.GetHashAndReset();
                                node.ActualCRC32 = BitConverter.ToUInt32(hash, 0);
                                if (node.StoredCRC32 != node.ActualCRC32)
                                {
                                    ++Data.badCrcCount;
                                }
                            }
                        }
                    }

                    if (Data.CrcCount > 0)
                    {
                        if (Data.badCrcCount == 0)
                        {
                            Data.CdIssue = IssueModel.Add("CRC checks successful.", Severity.Noise, IssueTags.Success);
                        }
                        else
                        {
                            Data.CdIssue = IssueModel.Add("CRC check failure.", Severity.Error, IssueTags.Failure);
                        }
                    }
                }

                base.CalcHashes(hashFlags, validationFlags);
            }
예제 #5
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (IssueModel.Data.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.PcmMD5) != 0 && Data.actualMediaMD5 == null)
                {
                    try
                    {
                        var hasher = new Md5Hasher();
                        hasher.Append(Data.fbs, Data.mediaPosition, Data.MediaCount);
                        Data.actualMediaMD5 = hasher.GetHashAndReset();
                    }
                    catch (EndOfStreamException)
                    {
                        IssueModel.Add("File truncated near audio.", Severity.Fatal);
                    }
                }

                if ((hashFlags & Hashes.PcmCRC32) != 0 && Data.ActualCRC32 == null)
                {
                    try
                    {
                        var hasher = new Crc32rHasher();
                        hasher.Append(Data.fbs, Data.mediaPosition, Data.MediaCount);
                        var hash = hasher.GetHashAndReset();
                        Data.ActualCRC32 = BitConverter.ToUInt32(hash, 0);
                    }
                    catch (EndOfStreamException)
                    {
                        IssueModel.Add("File truncated near audio.", Severity.Fatal);
                    }
                }

                base.CalcHashes(hashFlags, validationFlags);
            }
예제 #6
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (Data.Issues.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.Intrinsic) != 0 && Data.ActualAudioHeaderCRC8 == null)
                {
                    var hasher1 = new Crc8Hasher();
                    hasher1.Append(Data.aHdr);
                    byte[] hash1 = hasher1.GetHashAndReset();
                    Data.ActualAudioHeaderCRC8 = hash1[0];

                    try
                    {
                        var hasher2 = new Crc16nHasher();
                        hasher2.Append(Data.fbs, Data.mediaPosition, Data.FileSize - Data.mediaPosition - 2);
                        byte[] hash2 = hasher2.GetHashAndReset();
                        Data.ActualAudioBlockCRC16 = BitConverter.ToUInt16(hash2, 0);
                    }
                    catch (EndOfStreamException ex)
                    {
                        IssueModel.Add("Read failed while checking audio CRC: " + ex.Message, Severity.Fatal);
                        return;
                    }

                    if (!Data.IsBadDataCRC && !Data.IsBadHeaderCRC)
                    {
                        Data.ChIssue = Data.CdIssue = IssueModel.Add("CRC checks successful on audio header and data.", Severity.Noise, IssueTags.Success);
                    }
                    else
                    {
                        if (Data.IsBadHeaderCRC)
                        {
                            Data.ChIssue = IssueModel.Add("CRC-8 check failed on audio header.", Severity.Error, IssueTags.Failure);
                        }
                        else
                        {
                            Data.ChIssue = IssueModel.Add("CRC-8 check successful on audio header.", Severity.Noise, IssueTags.Success);
                        }

                        if (Data.IsBadDataCRC)
                        {
                            Data.CdIssue = IssueModel.Add("CRC-16 check failed on audio data.", Severity.Error, IssueTags.Failure);
                        }
                        else
                        {
                            Data.CdIssue = IssueModel.Add("CRC-16 check successful on audio data.", Severity.Noise, IssueTags.Success);
                        }
                    }
                }

                if ((hashFlags & Hashes.PcmMD5) != 0 && Data.actualAudioDataMD5 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            try
                            {
                                var hasher = new Md5Hasher();
                                hasher.Append(br);
                                var hash = hasher.GetHashAndReset();
                                Data.actualAudioDataMD5 = hash;
                            }
                            catch (EndOfStreamException ex)
                            { IssueModel.Add("Read failed while verifying audio MD5: " + ex.Message, Severity.Fatal); }

                            if (Data.IsBadDataMD5)
                            {
                                Data.CmIssue = IssueModel.Add("MD5 check failed on audio data.", Severity.Error, IssueTags.Failure);
                            }
                            else
                            {
                                Data.CmIssue = IssueModel.Add("MD5 check successful on audio data.", Severity.Noise, IssueTags.Success);
                            }
                        }
                    }
                }

                if ((hashFlags & (Hashes.PcmCRC32 | Hashes._FlacMatch)) != 0 && Data.ActualPcmCRC32 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            var hasher = new Crc32rHasher();
                            hasher.Append(br);
                            byte[] hash = hasher.GetHashAndReset();
                            Data.ActualPcmCRC32 = BitConverter.ToUInt32(hash, 0);
                        }
                    }
                }

                if ((hashFlags & (Hashes._FlacTags)) != 0)
                {
                    TagCheckNumber("TRACKNUMBER");
                    TagCheckNumber("TRACKTOTAL", optional: true);
                    TagCheckNumber("DISCNUMBER", true);
                    TagCheckNumber("DISCTOTAL", true);
                    TagCheckDate("DATE");
                    TagCheckDate("RELEASE DATE", optional: true);
                    TagCheckDate("ORIGINAL RELEASE DATE", true);
                    TagCheckText("TITLE");
                    TagCheckText("ARTIST");
                    TagCheckText("ALBUM");
                    TagCheckText("ALBUMARTIST", optional: true);
                    TagCheckText("ALBUMARTISTSORTORDER", true);
                    TagCheckText("ORGANIZATION", true);
                    TagCheckText("BARCODE", true);
                    TagCheckText("CATALOGNUMBER", true);
                }

                base.CalcHashes(hashFlags, validationFlags);
            }
예제 #7
0
            public void WriteFile(string generator, Encoding cp)
            {
                using (var ms = new MemoryStream())
                {
                    var bb = cp.GetBytes("; generated by " + generator + Environment.NewLine);
                    ms.Write(bb, 0, bb.Length);

                    var crcPosition = (int)ms.Length + 2;

                    if (HistoryModel != null)
                    {
                        bb = cp.GetBytes("; 00000000 do not modify" + Environment.NewLine);
                        ms.Write(bb, 0, bb.Length);

                        bb = cp.GetBytes(";" + Environment.NewLine);
                        ms.Write(bb, 0, bb.Length);

                        foreach (var historyItem in Data.History.Comment)
                        {
                            var lx = "; " + historyItem + Environment.NewLine;
                            bb = cp.GetBytes(lx);
                            ms.Write(bb, 0, bb.Length);
                        }
                    }

                    bb = cp.GetBytes(";" + Environment.NewLine);
                    ms.Write(bb, 0, bb.Length);

                    foreach (var hashedItem in Data.HashedFiles.Items)
                    {
                        if (hashedItem.ActualHash != null)
                        {
                            bb = cp.GetBytes(hashedItem.ActualHashToHex.ToLower() + ' ' + GetStyleChar(hashedItem.Style) + hashedItem.FileName + Environment.NewLine);
                            ms.Write(bb, 0, bb.Length);
                        }
                    }

                    if (HistoryModel != null)
                    {
                        // Calculate self-CRC.
                        var hasher = new Crc32rHasher();
                        hasher.Append(ms, 0, crcPosition, crcPosition + 8, ms.Length - crcPosition - 8);
                        UInt32 crc = BitConverter.ToUInt32(hasher.GetHashAndReset(), 0);
                        HistoryModel.SetActualSelfCRC(crc);
                        HistoryModel.SetStoredSelfCRC(crc);

                        bb = cp.GetBytes($"{Data.History.ActualCRC:X8}");
                        ms.Seek(crcPosition, SeekOrigin.Begin);
                        ms.Write(bb, 0, bb.Length);
                        HistoryModel.SetIsDirty(false);
                    }

                    Data.fBuf = ms.ToArray();
                    ms.Seek(0, SeekOrigin.Begin);
                    Data.fbs.Position = 0;
                    ms.CopyTo(Data.fbs);
                    Data.fbs.SetLength(Data.fbs.Position);
                    Data.mediaPosition = crcPosition;
                    ResetFile();

                    for (int ix = 0; ix < Data.HashedFiles.Items.Count; ++ix)
                    {
                        HashedModel.SetOldFileName(ix, null);
                    }
                }

                Data.NotifyPropertyChanged(null);
            }
예제 #8
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (Data.Issues.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.Intrinsic) != 0)
                {
                    if (Data.ActualAudioHeaderCRC8 == null)
                    {
                        var hasher = new Crc8Hasher();
                        hasher.Append(Data.aHdr);
                        var hash = hasher.GetHashAndReset();
                        Data.ActualAudioHeaderCRC8 = hash[0];

                        if (Data.IsBadHeader)
                        {
                            IssueModel.Add("CRC-8 check failed on audio header.");
                        }
                    }

                    if (Data.ActualAudioBlockCRC16 == null)
                    {
                        try
                        {
                            var hasher = new Crc16nHasher();
                            hasher.Append(Data.fbs, Data.mediaPosition, Data.FileSize - Data.mediaPosition - 2);
                            var hash = hasher.GetHashAndReset();
                            Data.ActualAudioBlockCRC16 = BitConverter.ToUInt16(hash, 0);
                        }
                        catch (EndOfStreamException ex)
                        {
                            IssueModel.Add("Read failed while verifying audio CRC: " + ex.Message, Severity.Fatal);
                            return;
                        }
                    }

                    if (Data.IsBadDataCRC16)
                    {
                        IssueModel.Add("CRC-16 check failed on audio data.");
                    }
                    else
                    if (Data.IsBadHeader)
                    {
                        IssueModel.Add("CRC-16 check successful.", Severity.Advisory);
                    }
                    else
                    {
                        IssueModel.Add("CRC-8, CRC-16 checks successful.", Severity.Noise);
                    }
                }

#if !NETFX_CORE
                if ((hashFlags & Hashes.PcmMD5) != 0 && Data.actualAudioDataMD5 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            try
                            {
                                var hasher = new Md5Hasher();
                                hasher.Append(br);
                                var hash = hasher.GetHashAndReset();
                                Data.actualAudioDataMD5 = hash;
                            }
                            catch (EndOfStreamException ex)
                            { IssueModel.Add("Read failed while verifying audio MD5: " + ex.Message, Severity.Fatal); }

                            if (Data.IsBadDataMD5)
                            {
                                IssueModel.Add("MD5 check failed on audio data.");
                            }
                            else
                            {
                                IssueModel.Add("MD5 check successful.", Severity.Noise);
                            }
                        }
                    }
                }

                if ((hashFlags & Hashes.PcmCRC32) != 0 && Data.ActualPcmCRC32 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            var hasher = new Crc32rHasher();
                            hasher.Append(br);
                            var hash = hasher.GetHashAndReset();
                            Data.ActualPcmCRC32 = BitConverter.ToUInt32(hash, 0);
                        }
                    }
                }
#endif
                base.CalcHashes(hashFlags, validationFlags);
            }