Exemplo n.º 1
0
        public bool VerifyIntegrity(bool verbose, bool green)
        {
            bool valid = true;

            byte[] decryptedSignature;

            if (green)
            {
                decryptedSignature = PublicKey.Decrypt(ImageHeader.DigitalSignature);
            }
            else
            {
                decryptedSignature = PublicKey.DecryptRed(ImageHeader.DigitalSignature);
            }

            if (verbose)
            {
                Console.WriteLine("Checking digital signature...");
            }

            // Check the digital signature
            // TODO: We must also check the padding. The Xbox checks this too!
            if (decryptedSignature.Take(20).ToArray().SequenceEqual(MetaHash))
            {
                if (verbose)
                {
                    Console.WriteLine("\n\tValid\n");
                }
            }
            else
            {
                valid = false;

                if (verbose)
                {
                    Console.WriteLine("\n\tInvalid\n");
                }
            }

            // Verify that the section hashes in the section header table match the data in the xbe
            // The section header table hashes can not be modified because they have already been validated with the digital signature
            // As far as I can tell, this is the order in which the xbox validates the xbe, contrary to what is found here: http://xboxdevwiki.net/Kernel/XboxSignatureKey

            if (verbose)
            {
                Console.WriteLine("Checking section hashes...");
            }

            foreach (SectionHeader section in SectionHeaders)
            {
                if (section.VerifyDigest())
                {
                    if (verbose)
                    {
                        Console.WriteLine(section.SectionName + ":\n\tValid\n");
                    }
                }
                else
                {
                    valid = false;

                    if (verbose)
                    {
                        Console.WriteLine(section.SectionName + ":\n\tInvalid\n");
                    }
                }
            }

            if (verbose)
            {
                if (valid)
                {
                    Console.WriteLine("\nXBE is NOT valid");
                }
                else
                {
                    Console.WriteLine("\nXBE is valid");
                }
            }

            return(valid);
        }