示例#1
0
        private void btnFix_Click(object sender, EventArgs e)
        {
            if (_stream != null && _stream.CanWrite && streamReader != null && textBox1.Text != "")
            {
                streamWriter = new SaveWriter(new FileStream(textBox1.Text, FileMode.OpenOrCreate));

                // Load the whole stream into memory
                MemoryStream memoryStream = new MemoryStream((int)streamReader.Length);
                memoryStream.SetLength(streamReader.Length);
                streamReader.Seek(0x00, SeekOrigin.Begin);
                streamReader.ReadBlock(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);

                // Hash the contents
                memoryStream.Position = 0x2D25C;
                memoryStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 20);
                byte[] hash = SaveSHA1.ComputeHash(memoryStream.GetBuffer());

                // Write the new digest
                streamWriter.Seek(0x2D25C, SeekOrigin.Begin);
                foreach (byte hashPart in hash)
                {
                    streamWriter.WriteByte(hashPart);
                }

                streamWriter.Close();

                MessageBox.Show("Save resigned.");
            }
        }