示例#1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Overwrite the key value stored within the Prime Time executable file
        /// </summary>
        /// <param name="exePath">The path to the executable</param>
        /// <param name="value">The key value to use</param>
        /// <param name="keyOffset">The offset within the file to the key value and the offset
        /// between the two DWORDs that make up the 64-bit integer</param>
        ///////////////////////////////////////////////////////////////////////////////////////////
        public void OverwriteValueInEXE(string exePath, UInt64 value, FullKeyOffset keyOffset)
        {
            FileStream   exeFileStream = File.OpenWrite(exePath);
            BinaryWriter writer        = new BinaryWriter(exeFileStream);

            // Get to the offset
            exeFileStream.Seek(keyOffset.KeyOffset, SeekOrigin.Begin);

            // Break the value into its components
            byte[] valBytes = UInt64ToArray(value, CharByteOrder);

            // Write the first 4 bytes
            for (int byteIndex = 0; byteIndex < 4; ++byteIndex)
            {
                writer.Write(valBytes[byteIndex]);
            }

            // Seek past the first 4-byte block seperating a 64-bit integer
            exeFileStream.Seek(keyOffset.Intra64bitPadding, SeekOrigin.Current);

            // Write the last 4 bytes
            for (int byteIndex = 4; byteIndex < 8; ++byteIndex)
            {
                writer.Write(valBytes[byteIndex]);
            }

            exeFileStream.Close();
        }
示例#2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>Get the key embedded within an executable</summary>
        /// <param name="exeFile">The executable file path</param>
        /// <param name="keyOffset">The offset within the EXE file of the game key</param>
        /// <param name="keyPadding">The number of bytes between the two double words that make up
        /// the key</param>
        ///////////////////////////////////////////////////////////////////////////////////////////
        public UInt64 GetKeyFromExe(string exeFile, FullKeyOffset keyOffset)
        {
            FileStream   exeFileStream = File.OpenRead(exeFile);
            BinaryReader reader        = new BinaryReader(exeFileStream);

            // Get to the offset
            exeFileStream.Seek(keyOffset.KeyOffset, SeekOrigin.Begin);

            // Write the first 4 bytes
            byte[] valBytes = new byte[8];
            for (int byteIndex = 0; byteIndex < 4; ++byteIndex)
            {
                valBytes[byteIndex] = reader.ReadByte();
            }

            // Seek past the 4-byte block seperating a 64-bit value within a file
            exeFileStream.Seek(keyOffset.Intra64bitPadding, SeekOrigin.Current);

            // Write the last 4 bytes
            for (int byteIndex = 4; byteIndex < 8; ++byteIndex)
            {
                valBytes[byteIndex] = reader.ReadByte();
            }

            // Close the file stream
            exeFileStream.Close();

            // Return the 64-bit key formed from its components
            return(ArrayToUInt64(valBytes));
        }