Пример #1
0
        public bool LoadAICHHashsetFromFile(Mpd.Generic.IO.FileDataIO pFile, bool bVerify)
        {
            m_aAICHPartHashSet.Clear();
            AICHHash masterHash =
                MuleApplication.Instance.AICHObjectManager.CreateAICHHash(pFile);

            if (HasAICHHash && masterHash != AICHHash)
            {
                return(false);
            }
            ushort nCount = pFile.ReadUInt16();

            for (int i = 0; i < nCount; i++)
            {
                m_aAICHPartHashSet.Add(MuleApplication.Instance.AICHObjectManager.CreateAICHHash(pFile));
            }
            if (bVerify)
            {
                return(VerifyAICHHashSet());
            }
            else
            {
                return(true);
            }
        }
Пример #2
0
        public void WriteIdentifier(Mpd.Generic.IO.FileDataIO pFile, bool bKadExcludeMD4)
        {
            uint uIncludesMD4      = bKadExcludeMD4 ? (uint)0 : (uint)1; // This is (currently) mandatory except for Kad
            uint uIncludesSize     = (FileSize != 0) ? (uint)1 : (uint)0;
            uint uIncludesAICH     = HasAICHHash ? (uint)1 : 0;
            uint uMandatoryOptions = 0; // RESERVED - Identifier invalid if we encounter unknown options
            uint uOptions          = 0; // RESERVED

            byte byIdentifierDesc = (byte)
                                    ((uOptions << 5) |
                                     (uMandatoryOptions << 3) |
                                     (uIncludesAICH << 2) |
                                     (uIncludesSize << 1) |
                                     (uIncludesMD4 << 0));

            pFile.WriteUInt8(byIdentifierDesc);
            if (!bKadExcludeMD4)
            {
                pFile.WriteHash16(md4Hash_);
            }
            if (FileSize != (ulong)0)
            {
                pFile.WriteUInt64(FileSize);
            }
            if (HasAICHHash)
            {
                aichHash_.Write(pFile);
            }
        }
Пример #3
0
        public AICHHash CreateAICHHash(Mpd.Generic.IO.FileDataIO fileInput)
        {
            AICHHash hash = CreateAICHHash();

            hash.Read(fileInput);

            return(hash);
        }
Пример #4
0
        public void WriteAICHHashsetToFile(Mpd.Generic.IO.FileDataIO pFile)
        {
            AICHHash.Write(pFile);
            int uParts = m_aAICHPartHashSet.Count;

            pFile.WriteUInt16((ushort)uParts);
            for (int i = 0; i < uParts; i++)
            {
                m_aAICHPartHashSet[i].Write(pFile);
            }
        }
Пример #5
0
        public void WriteMD4HashsetToFile(Mpd.Generic.IO.FileDataIO pFile)
        {
            pFile.WriteHash16(MD4Hash);
            int uParts = m_aMD4HashSet.Count;

            pFile.WriteUInt16((ushort)uParts);
            for (int i = 0; i < uParts; i++)
            {
                pFile.WriteHash16(m_aMD4HashSet[i]);
            }
        }
Пример #6
0
        public void WriteHashSetsToPacket(Mpd.Generic.IO.FileDataIO pFile, bool bMD4, bool bAICH)
        {
            // 6 Options - RESERVED
            // 1 AICH HashSet
            // 1 MD4 HashSet
            byte byOptions = 0;

            if (bMD4)
            {
                if (TheoreticalMD4PartHashCount == 0)
                {
                    bMD4 = false;
                }
                else if (HasExpectedMD4HashCount)
                {
                    byOptions |= 0x01;
                }
                else
                {
                    bMD4 = false;
                }
            }
            if (bAICH)
            {
                if (TheoreticalAICHPartHashCount == 0)
                {
                    bAICH = false;
                }
                else if (HasExpectedAICHHashCount && HasAICHHash)
                {
                    byOptions |= 0x02;
                }
                else
                {
                    bAICH = false;
                }
            }
            pFile.WriteUInt8(byOptions);
            if (bMD4)
            {
                WriteMD4HashsetToFile(pFile);
            }
            if (bAICH)
            {
                WriteAICHHashsetToFile(pFile);
            }
        }
Пример #7
0
        public bool LoadMD4HashsetFromFile(Mpd.Generic.IO.FileDataIO file, bool bVerifyExistingHash)
        {
            byte[] checkid = new byte[16];
            file.ReadHash16(checkid);
            DeleteMD4Hashset();

            uint parts = file.ReadUInt16();

            //TRACE("Nr. hashs: %u\n", (uint)parts);
            if (bVerifyExistingHash &&
                (MpdUtilities.Md4Cmp(MD4Hash, checkid) != 0 ||
                 parts != TheoreticalMD4PartHashCount))
            {
                return(false);
            }
            for (uint i = 0; i < parts; i++)
            {
                byte[] cur_hash = new byte[16];
                file.ReadHash16(cur_hash);
                m_aMD4HashSet.Add(cur_hash);
            }

            if (!bVerifyExistingHash)
            {
                MpdUtilities.Md4Cpy(MD4Hash, checkid);
            }

            // Calculate hash out of hashset and compare to existing filehash
            if (m_aMD4HashSet.Count > 0)
            {
                return(CalculateMD4HashByHashSet(true, true));
            }
            else
            {
                return(true);
            }
        }
Пример #8
0
        public bool ReadHashSetsFromPacket(Mpd.Generic.IO.FileDataIO pFile, ref bool rbMD4, ref bool rbAICH)
        {
            byte byOptions    = pFile.ReadUInt8();
            bool bMD4Present  = (byOptions & 0x01) > 0;
            bool bAICHPresent = (byOptions & 0x02) > 0;

            // We don't abort on unkown option, because even if there is another unknown hashset, there is no data afterwards we
            // try to read on the only occasion this function is used. So we might be able to add optional flags in the future
            // without having to adjust the protocol any further (new additional data/hashs should not be appended without adjustement however)

            if (bMD4Present && !rbMD4)
            {
                // Even if we don't want it, we still have to read the file to skip it
                byte[] tmpHash = new byte[16];
                pFile.ReadHash16(tmpHash);
                uint parts = pFile.ReadUInt16();
                for (uint i = 0; i < parts; i++)
                {
                    pFile.ReadHash16(tmpHash);
                }
            }
            else if (!bMD4Present)
            {
                rbMD4 = false;
            }
            else if (bMD4Present && rbMD4)
            {
                if (!LoadMD4HashsetFromFile(pFile, true))
                {       // corrupt
                    rbMD4  = false;
                    rbAICH = false;
                    return(false);
                }
            }

            if (bAICHPresent && !rbAICH)
            {
                // Even if we don't want it, we still have to read the file to skip it
                AICHHash tmpHash =
                    MuleApplication.Instance.AICHObjectManager.CreateAICHHash(pFile);
                ushort nCount = pFile.ReadUInt16();
                for (int i = 0; i < nCount; i++)
                {
                    tmpHash.Read(pFile);
                }
            }
            else if (!bAICHPresent || !HasAICHHash)
            {
                rbAICH = false;
            }
            else if (bAICHPresent && rbAICH)
            {
                if (!LoadAICHHashsetFromFile(pFile, true))
                {       // corrupt
                    if (rbMD4)
                    {
                        DeleteMD4Hashset();
                        rbMD4 = false;
                    }
                    rbAICH = false;
                    return(false);
                }
            }
            return(true);
        }
Пример #9
0
 public bool LoadAICHHashsetFromFile(Mpd.Generic.IO.FileDataIO pFile)
 {
     return(LoadAICHHashsetFromFile(pFile, true));
 }
Пример #10
0
 public void WriteIdentifier(Mpd.Generic.IO.FileDataIO pFile)
 {
     WriteIdentifier(pFile, false);
 }
Пример #11
0
 public void SetMD4Hash(Mpd.Generic.IO.FileDataIO pFile)
 {
     pFile.ReadHash16(md4Hash_);
 }