Пример #1
0
        private string getFileNameForChecksum(string pFileName, string pHashKey)
        {
            string checksumKey;
            string newFileName;
            string ret;

            using (FileStream fs = File.OpenRead(pFileName))
            {
                checksumKey = String.Format("{0}_{1}_{2}", ChecksumUtil.GetCrc32OfFullFile(fs), ChecksumUtil.GetMd5OfFullFile(fs),
                                            ChecksumUtil.GetSha1OfFullFile(fs));
            }

            if (this.fileNameHash[pHashKey].ContainsKey(checksumKey))
            {
                ret = this.fileNameHash[pHashKey][checksumKey];
            }
            else
            {
                newFileName = this.fileNameHash[pHashKey].Count.ToString("X8");
                this.fileNameHash[pHashKey].Add(checksumKey, newFileName);
                ret = newFileName;
            }

            return(ret);
        }
Пример #2
0
        private static bool CheckForTestPackNds()
        {
            bool   ret          = true;
            string testpackPath =
                Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), Mk2sfWorker.TESTPACK_PATH);

            if (!File.Exists(testpackPath))
            {
                ret = false;
                MessageBox.Show(String.Format(ConfigurationManager.AppSettings["Form_Make2sf_ErrorMessageTestpackMissing"],
                                              Path.GetFileName(testpackPath), Path.GetDirectoryName(testpackPath)),
                                String.Format(ConfigurationManager.AppSettings["Form_Make2sf_ErrorMessageTestpackMissingHeader"], Path.GetFileName(testpackPath)));
            }
            else
            {
                using (FileStream fs = File.OpenRead(testpackPath))
                {
                    if (!ChecksumUtil.GetCrc32OfFullFile(fs).Equals(Mk2sfWorker.TESTPACK_CRC32))
                    {
                        ret = false;
                        MessageBox.Show(String.Format(ConfigurationManager.AppSettings["Form_Make2sf_ErrorMessageTestpackCrc32"],
                                                      Path.GetFileName(testpackPath), Path.GetDirectoryName(testpackPath), Mk2sfWorker.TESTPACK_CRC32),
                                        String.Format(ConfigurationManager.AppSettings["Form_Make2sf_ErrorMessageTestpackCrc32Header"], Path.GetFileName(testpackPath)));
                    }
                }
            }

            return(ret);
        }
Пример #3
0
        private PsfPsyQAddresses getAdditionalDriverInfo(PsfPsyQAddresses existingValues, PsfStubMakerStruct stubMakerParameters,
                                                         string driverPath)
        {
            string checksum;

            byte[]           jumpAddress;
            PsfPsyQAddresses ret = existingValues;

            using (FileStream checksumStream = File.OpenRead(driverPath))
            {
                checksum    = ChecksumUtil.GetCrc32OfFullFile(checksumStream);
                jumpAddress = ParseFile.ParseSimpleOffset(checksumStream, 0x10, 0x04);
            }

            ret.DriverTextString = stubMakerParameters.DriverText;
            ret.ExeFileNameCrc   = String.Format("  (int)\"{0}\", 0x{1},", Path.GetFileName(driverPath), checksum);
            ret.JumpPatchAddress = String.Format("0x{0}", BitConverter.ToUInt32(jumpAddress, 0).ToString("X8"));

            return(ret);
        }
Пример #4
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();
        }