Esempio n. 1
0
        // Magic!
        internal byte[] Patch()
        {
            byte[] SecurityDxe = GetFile("SecurityDxe");
            ClearEfiChecksum(SecurityDxe);

            UInt32?PatchOffset = ByteOperations.FindPattern(SecurityDxe,
                                                            new byte[] { 0xF0, 0x41, 0x2D, 0xE9, 0xFF, 0xFF, 0xB0, 0xE1, 0x28, 0xD0, 0x4D, 0xE2, 0xFF, 0xFF, 0xA0, 0xE1, 0x00, 0x00, 0xFF, 0x13, 0x20, 0xFF, 0xA0, 0xE3 },
                                                            new byte[] { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00 },
                                                            null);

            if (PatchOffset == null)
            {
                throw new BadImageFormatException();
            }

            Buffer.BlockCopy(new byte[] { 0x00, 0x00, 0xA0, 0xE3, 0x1E, 0xFF, 0x2F, 0xE1 }, 0, SecurityDxe, (int)PatchOffset, 8);

            ReplaceFile("SecurityDxe", SecurityDxe);

            byte[] SecurityServicesDxe = GetFile("SecurityServicesDxe");
            ClearEfiChecksum(SecurityServicesDxe);

            PatchOffset = ByteOperations.FindPattern(SecurityServicesDxe,
                                                     new byte[] { 0x10, 0xFF, 0xFF, 0xE5, 0x80, 0xFF, 0x10, 0xE3, 0xFF, 0xFF, 0xFF, 0x0A },
                                                     new byte[] { 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00 },
                                                     null);

            if (PatchOffset == null)
            {
                throw new BadImageFormatException();
            }

            ByteOperations.WriteUInt8(SecurityServicesDxe, (UInt32)PatchOffset + 0x0B, 0xEA);

            PatchOffset = ByteOperations.FindPattern(SecurityServicesDxe,
                                                     new byte[] { 0x11, 0xFF, 0xFF, 0xE5, 0x40, 0xFF, 0x10, 0xE3, 0xFF, 0xFF, 0xFF, 0x0A },
                                                     new byte[] { 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00 },
                                                     null);

            if (PatchOffset == null)
            {
                throw new BadImageFormatException();
            }

            ByteOperations.WriteUInt8(SecurityServicesDxe, (UInt32)PatchOffset + 0x0B, 0xEA);

            ReplaceFile("SecurityServicesDxe", SecurityServicesDxe);

            return(Rebuild());
        }
Esempio n. 2
0
        private void CalculateFileChecksum(byte[] Image, UInt32 Offset)
        {
            UInt16 FileHeaderSize = 0x18;
            UInt32 FileSize       = ByteOperations.ReadUInt24(Image, Offset + 0x14);

            ByteOperations.WriteUInt16(Image, Offset + 0x10, 0); // Clear checksum
            byte NewChecksum = ByteOperations.CalculateChecksum8(Image, Offset, (UInt32)FileHeaderSize - 1);

            ByteOperations.WriteUInt8(Image, Offset + 0x10, NewChecksum); // File-Header checksum

            byte FileAttribs = ByteOperations.ReadUInt8(Image, Offset + 0x13);

            if ((FileAttribs & 0x40) > 0)
            {
                // Calculate file checksum
                byte CalculatedFileChecksum = ByteOperations.CalculateChecksum8(Image, Offset + FileHeaderSize, FileSize - FileHeaderSize);
                ByteOperations.WriteUInt8(Image, Offset + 0x11, CalculatedFileChecksum);
            }
            else
            {
                // Fixed file checksum
                ByteOperations.WriteUInt8(Image, Offset + 0x11, 0xAA);
            }
        }