Esempio n. 1
0
        private static void CheckHactoolExe()
        {
            if (!File.Exists("hactool.exe"))
            {
                MessageBox.Show("The hactool executable was not found, please make sure the hactool executable is in the same path as the EZ-HAC executable!", "Error!", MessageBoxButtons.OK);
                Environment.Exit(0);
            }

            bool   InvalidHash = true;
            string HacHash     = GetFileHash("hactool.exe");

            // Debug outputs hactool executable hash
#if DEBUG
            Console.WriteLine($"hactool Executable File Hash: {HacHash}");
#endif

            for (int Index = 0; Index < HacVersions.Length; Index++)
            {
                HacInfo HacVersionInfo = HacVersions[Index];

                if (HacVersionInfo.FileHash == HacHash)
                {
                    InvalidHash      = false;
                    HacVersionString = HacVersionInfo.VersionString;
                }
            }

            // Debug does not show a messagebox for invalid hactool executable hashes
            if (InvalidHash)
            {
#if !DEBUG
                DialogResult HashResult = MessageBox.Show("The hactool executable hash does not match verified hactool hashes, do you want to continue? Some functions of EZ-HAC may not function with an invalid hactool executable!", "Warning!", MessageBoxButtons.YesNo);

                if (HashResult == DialogResult.No)
                {
                    Environment.Exit(0);
                }
                else
                {
#endif
                HacVersionString = "Unknown";
#if !DEBUG
            }
#endif
            }
        }
Esempio n. 2
0
        private static void CheckHactoolExe()
        {
            try
            {
                string GetFileHash(string FileName)
                {
                    using (SHA256 HashContext = SHA256.Create())
                    {
                        using (FileStream Stream = File.OpenRead(FileName))
                        {
                            return(BitConverter.ToString(HashContext.ComputeHash(Stream)).Replace("-", ""));
                        }
                    }
                }
                string HacHash = GetFileHash(Binary);
                for (int Index = 0; Index < VerifiedHacVersions.Length; Index++)
                {
                    HacInfo HacVersionInfo = VerifiedHacVersions[Index];
                    if (HacVersionInfo.FileHash == HacHash)
                    {
                        HacVersionId = HacVersionInfo.VersionId;
                        return;
                    }
                }
                DialogResult HashResult = MessageBox.Show(ErrBadHash, ErrHeader, MessageBoxButtons.YesNo);
                if (HashResult == DialogResult.No)
                {
                    Exit(0);
                }
                else
                {
                    HacVersionId = Unknown;
                }
            }

            catch (FileNotFoundException)
            {
                MessageBox.Show(ErrBinaryMissing, ErrHeaderFatal, MessageBoxButtons.OK);
                Exit(0);
            }
        }