Example #1
0
        /// <summary>
        /// Get the SHA-512 checksum of the input stream.
        /// </summary>
        /// <param name="stream">File Stream for which to generate the checksum.</param>
        /// <returns>String containing the hexidecimal representation of the SHA-512 of the input stream.</returns>
        public static string GetSha512OfFullFile(FileStream stream)
        {
            SHA512CryptoServiceProvider sha512 = new SHA512CryptoServiceProvider();

            stream.Seek(0, SeekOrigin.Begin);
            sha512.ComputeHash(stream);
            return(ParseFile.ByteArrayToString(sha512.Hash));
        }
Example #2
0
        /// <summary>
        /// Get the MD5 checksum of the input stream.
        /// </summary>
        /// <param name="stream">File Stream for which to generate the checksum.</param>
        /// <returns>String containing the hexidecimal representation of the MD5 of the input stream.</returns>
        public static string GetMd5OfFullFile(FileStream stream)
        {
            MD5CryptoServiceProvider hashMd5 = new MD5CryptoServiceProvider();

            stream.Seek(0, SeekOrigin.Begin);
            hashMd5.ComputeHash(stream);
            return(ParseFile.ByteArrayToString(hashMd5.Hash));
        }
        /// <summary>
        /// Get the SHA-512 checksum of the input stream.
        /// </summary>
        /// <param name="stream">File Stream for which to generate the checksum.</param>
        /// <returns>String containing the hexidecimal representation of the SHA-512 of the input stream.</returns>
        public static string GetSha512OfFullFile(FileStream stream)
        {
            var sha512 = SHA512.Create();

            stream.Seek(0, SeekOrigin.Begin);
            sha512.ComputeHash(stream);
            return(ParseFile.ByteArrayToString(sha512.Hash));
        }
        /// <summary>
        /// Get the MD5 checksum of the input stream.
        /// </summary>
        /// <param name="stream">File Stream for which to generate the checksum.</param>
        /// <returns>String containing the hexidecimal representation of the MD5 of the input stream.</returns>
        public static string GetMd5OfFullFile(FileStream stream)
        {
            var hashMd5 = MD5.Create();

            stream.Seek(0, SeekOrigin.Begin);
            hashMd5.ComputeHash(stream);
            return(ParseFile.ByteArrayToString(hashMd5.Hash));
        }
Example #5
0
        private static string GetOutputFileName(ExtractXaStruct pExtractXaStruct, byte[] pTrackId)
        {
            string outputDirectory = Path.Combine(Path.GetDirectoryName(pExtractXaStruct.Path),
                                                  Path.GetFileNameWithoutExtension(pExtractXaStruct.Path));
            string outputFileName = Path.GetFileNameWithoutExtension(pExtractXaStruct.Path) + "_" + ParseFile.ByteArrayToString(pTrackId) + Cdxa.XA_FILE_EXTENSION;

            int fileCount = Directory.GetFiles(outputDirectory, String.Format("{0}*", Path.GetFileNameWithoutExtension(outputFileName)), SearchOption.TopDirectoryOnly).Length;

            outputFileName = String.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(outputFileName), fileCount.ToString("X4"), Cdxa.XA_FILE_EXTENSION);

            //if (outputFileName.Equals("BGM2_01016401_0005.xa"))
            //{
            //    int x = 1;
            //}

            string ret = Path.Combine(outputDirectory, outputFileName);

            return(ret);
        }
Example #6
0
        private void parseExtendedChunk(byte[] pBytes)
        {
            System.Text.Encoding enc = System.Text.Encoding.ASCII;
            // EXID666 - SUBCHUNK
            byte[] exidSubChunkId;
            byte[] exidSubChunkType;
            byte[] exidSubChunkLength;

            string exidSubChunkIntId;
            int    exidSubChunkIntLength;
            // int exidSubChunkRemainder;

            string ostTrackNo;

            int offset = 0;

            while (offset < pBytes.Length)
            {
                exidSubChunkId    = ParseFile.ParseSimpleOffset(pBytes, offset + EX_ID666_SUBCHUNK_ID_OFFSET, EX_ID666_SUBCHUNK_ID_LENGTH);
                exidSubChunkIntId = BitConverter.ToString(exidSubChunkId, 0);

                exidSubChunkType      = ParseFile.ParseSimpleOffset(pBytes, offset + EX_ID666_SUBCHUNK_TYPE_OFFSET, EX_ID666_SUBCHUNK_TYPE_LENGTH);
                exidSubChunkLength    = ParseFile.ParseSimpleOffset(pBytes, offset + EX_ID666_SUBCHUNK_LENGTH_OFFSET, EX_ID666_SUBCHUNK_LENGTH_LENGTH);
                exidSubChunkIntLength = BitConverter.ToInt16(exidSubChunkLength, 0);

                // LENGTH
                if (!exId666Hash.ContainsKey(exidSubChunkIntId))
                {
                    offset += EX_ID666_SUBCHUNK_ID_LENGTH + EX_ID666_SUBCHUNK_TYPE_LENGTH +
                              EX_ID666_SUBCHUNK_LENGTH_LENGTH + (int)exidSubChunkIntLength;
                }
                else if (ParseFile.CompareSegment(exidSubChunkType, 0, EXID666_SUBCHUNK_TYPE_LENGTH))
                {
                    if (tagHash.ContainsKey(exId666Hash[exidSubChunkIntId]))
                    {
                        tagHash.Remove(exId666Hash[exidSubChunkIntId]);
                    }

                    if (exidSubChunkIntId.Equals(EXID666_SUBCHUNK_ID_OST_TRACK))
                    {
                        Array.Reverse(exidSubChunkLength);
                        ostTrackNo = ParseFile.ByteArrayToString(exidSubChunkLength);
                        if (ostTrackNo.Substring(2).Equals("00"))
                        {
                            ostTrackNo = ostTrackNo.Substring(0, 2);
                        }

                        tagHash.Add(exId666Hash[exidSubChunkIntId], ostTrackNo);
                    }
                    else
                    {
                        tagHash.Add(exId666Hash[exidSubChunkIntId], System.BitConverter.ToInt16(exidSubChunkLength, 0).ToString());
                    }

                    offset += EX_ID666_SUBCHUNK_ID_LENGTH + EX_ID666_SUBCHUNK_TYPE_LENGTH +
                              EX_ID666_SUBCHUNK_LENGTH_LENGTH;
                }

                // STRING
                else if (ParseFile.CompareSegment(exidSubChunkType, 0, EXID666_SUBCHUNK_TYPE_STRING))
                {
                    int stringStartOffset = offset + EX_ID666_SUBCHUNK_LENGTH_OFFSET + EX_ID666_SUBCHUNK_LENGTH_LENGTH;

                    // setup for 32-bit align
                    //exidSubChunkRemainder = (EXTENDED_INFO_OFFSET + EX_ID666_CHUNK_DATA_OFFSET + stringStartOffset + exidSubChunkIntLength) % 4;

                    //if (exidSubChunkRemainder != 0)
                    //{
                    //    exidSubChunkIntLength += exidSubChunkRemainder;
                    //}

                    byte[] subChunkData = ParseFile.ParseSimpleOffset(pBytes, stringStartOffset, (int)exidSubChunkIntLength);

                    if (tagHash.ContainsKey(exId666Hash[exidSubChunkIntId]))
                    {
                        tagHash.Remove(exId666Hash[exidSubChunkIntId]);
                    }
                    tagHash.Add(exId666Hash[exidSubChunkIntId], enc.GetString(subChunkData));

                    offset += EX_ID666_SUBCHUNK_ID_LENGTH + EX_ID666_SUBCHUNK_TYPE_LENGTH +
                              EX_ID666_SUBCHUNK_LENGTH_LENGTH + (int)exidSubChunkIntLength;
                }

                // INTEGER
                else if (ParseFile.CompareSegment(exidSubChunkType, 0, EXID666_SUBCHUNK_TYPE_INTEGER))
                {
                    if (exidSubChunkIntId.Equals(EXID666_SUBCHUNK_ID_DUMPDATE))
                    {
                        int    intStartOffset = offset + EX_ID666_SUBCHUNK_LENGTH_OFFSET + EX_ID666_SUBCHUNK_LENGTH_LENGTH;
                        byte[] subChunkData   = ParseFile.ParseSimpleOffset(pBytes, intStartOffset, (int)exidSubChunkIntLength);

                        ostTrackNo = ParseFile.ByteArrayToString(exidSubChunkLength);
                        tagHash.Add(exId666Hash[exidSubChunkIntId], ParseFile.ByteArrayToString(subChunkData));
                    }


                    offset += EX_ID666_SUBCHUNK_ID_LENGTH + EX_ID666_SUBCHUNK_TYPE_LENGTH +
                              EX_ID666_SUBCHUNK_LENGTH_LENGTH + (int)exidSubChunkIntLength;
                }
            } // while (offset < pBytes.GetLength())
        }
Example #7
0
        protected override void DoTaskForFile(string pPath,
                                              IVgmtWorkerStruct pExamineChecksumGeneratorStruct, DoWorkEventArgs e)
        {
            ExamineChecksumGeneratorStruct examineChecksumGeneratorStruct =
                (ExamineChecksumGeneratorStruct)pExamineChecksumGeneratorStruct;

            string crc32;
            string md5;
            string sha1;

            string vgmtCrc32 = "Not implemented for this format.";
            string vgmtMd5   = "Not implemented for this format.";
            string vgmtSha1  = "Not implemented for this format.";

            string checksumKey;

            Type    formatType = null;
            IFormat vgmData    = null;

            using (FileStream fs = File.OpenRead(pPath))
            {
                crc32 = ChecksumUtil.GetCrc32OfFullFile(fs);
                md5   = ChecksumUtil.GetMd5OfFullFile(fs);
                sha1  = ChecksumUtil.GetSha1OfFullFile(fs);

                if (examineChecksumGeneratorStruct.CheckForDuplicates)
                {
                    checksumKey = String.Format("{0}/{1}/{2}", crc32, md5, sha1);
                    this.addChecksumToHash(checksumKey, pPath, true);
                }

                if (examineChecksumGeneratorStruct.DoVgmtChecksums)
                {
                    formatType = FormatUtil.getObjectType(fs);
                    if (formatType != null)
                    {
                        vgmData = (IFormat)Activator.CreateInstance(formatType);
                        vgmData.Initialize(fs, pPath);
                    }
                }
            }

            if (vgmData != null)
            {
                Crc32 crc32Generator = new Crc32();

                MD5CryptoServiceProvider md5Hash = new MD5CryptoServiceProvider();
                FileStream   md5FileStream       = new FileStream(Path.GetTempFileName(), FileMode.Create, FileAccess.Write);
                CryptoStream md5CryptoStream     = new CryptoStream(md5FileStream, md5Hash, CryptoStreamMode.Write);

                SHA1CryptoServiceProvider sha1Hash = new SHA1CryptoServiceProvider();
                FileStream   sha1FileStream        = new FileStream(Path.GetTempFileName(), FileMode.Create, FileAccess.Write);
                CryptoStream sha1CryptoStream      = new CryptoStream(sha1FileStream, sha1Hash, CryptoStreamMode.Write);

                vgmData.GetDatFileChecksums(ref crc32Generator, ref md5CryptoStream,
                                            ref sha1CryptoStream);
                md5CryptoStream.FlushFinalBlock();
                sha1CryptoStream.FlushFinalBlock();

                vgmtCrc32 = crc32Generator.Value.ToString("X8");
                vgmtMd5   = ParseFile.ByteArrayToString(md5Hash.Hash);
                vgmtSha1  = ParseFile.ByteArrayToString(sha1Hash.Hash);

                if (examineChecksumGeneratorStruct.CheckForDuplicates)
                {
                    checksumKey = String.Format("{0}/{1}/{2}", vgmtCrc32, vgmtMd5, vgmtSha1);
                    this.addChecksumToHash(checksumKey, pPath, false);
                }

                md5FileStream.Close();
                md5FileStream.Dispose();
                sha1FileStream.Close();
                sha1FileStream.Dispose();

                md5CryptoStream.Close();
                md5CryptoStream.Dispose();
                sha1CryptoStream.Close();
                sha1CryptoStream.Dispose();
            }

            this.outputBuffer.AppendFormat("<{0}>{1}", pPath, Environment.NewLine);
            this.outputBuffer.AppendFormat("CRC32: {0}{1}", crc32, Environment.NewLine);
            this.outputBuffer.AppendFormat("MD5: {0}{1}", md5, Environment.NewLine);
            this.outputBuffer.AppendFormat("SHA1: {0}{1}", sha1, Environment.NewLine);

            if (examineChecksumGeneratorStruct.DoVgmtChecksums)
            {
                this.outputBuffer.AppendFormat("CRC32 (VGMT): {0}{1}", vgmtCrc32, Environment.NewLine);
                this.outputBuffer.AppendFormat("MD5 (VGMT): {0}{1}", vgmtMd5, Environment.NewLine);
                this.outputBuffer.AppendFormat("SHA1 (VGMT): {0}{1}", vgmtSha1, Environment.NewLine);
            }
            this.outputBuffer.AppendLine();
        }