From 95db3ad19b9f069958ff41019207efa4c2908625 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Fri, 11 Dec 2020 16:48:59 +0100 Subject: [PATCH] IL2CPP: Fix potential corruption after last string when saving decrypted strings --- Il2CppInspector.Common/IL2CPP/Metadata.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Il2CppInspector.Common/IL2CPP/Metadata.cs b/Il2CppInspector.Common/IL2CPP/Metadata.cs index 17452b0..1b6fa46 100644 --- a/Il2CppInspector.Common/IL2CPP/Metadata.cs +++ b/Il2CppInspector.Common/IL2CPP/Metadata.cs @@ -178,12 +178,18 @@ namespace Il2CppInspector Console.WriteLine("Decrypting strings..."); statusCallback?.Invoke(this, "Decrypting strings"); + // There may be zero-padding at the end of the last string since counts seem to be word-aligned + // Find the true location one byte after the final character of the final string + var endOfStrings = Header.stringCount; + while (ReadByte(Header.stringOffset + endOfStrings - 1) == 0) + endOfStrings--; + // Start again Strings.Clear(); Position = Header.stringOffset; // Read in all of the strings as if they are fixed length rather than null-terminated - foreach (var offset in stringOffsets.Zip(stringOffsets.Skip(1).Append(Header.stringCount), (a, b) => (current: a, next: b))) { + foreach (var offset in stringOffsets.Zip(stringOffsets.Skip(1).Append(endOfStrings), (a, b) => (current: a, next: b))) { var encryptedString = ReadBytes(offset.next - offset.current - 1); // The null terminator is the XOR key