From 50e0af05b23af909fe1cd5b79c09548d2fc39d4e Mon Sep 17 00:00:00 2001 From: Razmoth <32140579+Razmoth@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:27:38 +0400 Subject: [PATCH] - [Core] fix bug with certain files [GI] --- AssetStudio/MhyFile.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AssetStudio/MhyFile.cs b/AssetStudio/MhyFile.cs index dbbea0f..6e0e367 100644 --- a/AssetStudio/MhyFile.cs +++ b/AssetStudio/MhyFile.cs @@ -193,23 +193,23 @@ private void ReadFiles(Stream blocksStream, string path) private void DescrambleChunk(Span input) { - byte[] vector = new byte[0x10]; + byte[] vector = new byte[input.Length]; for (int i = 0; i < 3; i++) { - for (int j = 0; j < 0x10; j++) + for (int j = 0; j < input.Length; j++) { int k = mhy.MhyShiftRow[(2 - i) * 0x10 + j]; int idx = j % 8; - vector[j] = (byte)(mhy.MhyKey[idx] ^ mhy.SBox[(j % 4 * 0x100) | GF256Mul(mhy.MhyMul[idx], input[k])]); + vector[j] = (byte)(mhy.MhyKey[idx] ^ mhy.SBox[(j % 4 * 0x100) | GF256Mul(mhy.MhyMul[idx], input[k % input.Length])]); } - vector.CopyTo(input); + vector.AsSpan(0, input.Length).CopyTo(input); } } private void Descramble(Span input, int blockSize, int entrySize) { var roundedEntrySize = (entrySize + 0xF) / 0x10 * 0x10; for (int i = 0; i < roundedEntrySize; i += 0x10) - DescrambleChunk(input.Slice(i + 4, 0x10)); + DescrambleChunk(input.Slice(i + 4, Math.Min(input.Length - 4, 0x10))); for (int i = 0; i < 4; i++) input[i] ^= input[i + 4];