From f07b7a049e8292cf11047a42e6f4a7d9737d193c Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 31 Jul 2025 09:41:36 -0400 Subject: [PATCH] Ensure endianness of reads --- .../Deserializers/SecuROMDFA.cs | 4 ++-- SabreTools.Serialization/Wrappers/Nitro.cs | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/SabreTools.Serialization/Deserializers/SecuROMDFA.cs b/SabreTools.Serialization/Deserializers/SecuROMDFA.cs index 04a4f3d4..b3658e36 100644 --- a/SabreTools.Serialization/Deserializers/SecuROMDFA.cs +++ b/SabreTools.Serialization/Deserializers/SecuROMDFA.cs @@ -29,7 +29,7 @@ namespace SabreTools.Serialization.Deserializers if (!dfa.Signature.EqualsExactly(DFAMagicBytes)) return null; - dfa.BlockOrHeaderSize = data.ReadUInt32(); + dfa.BlockOrHeaderSize = data.ReadUInt32LittleEndian(); #endregion @@ -70,7 +70,7 @@ namespace SabreTools.Serialization.Deserializers byte[] name = data.ReadBytes(4); obj.Name = Encoding.ASCII.GetString(name); - obj.Length = data.ReadUInt32(); + obj.Length = data.ReadUInt32LittleEndian(); if (obj.Length > 0) obj.Value = data.ReadBytes((int)obj.Length); diff --git a/SabreTools.Serialization/Wrappers/Nitro.cs b/SabreTools.Serialization/Wrappers/Nitro.cs index 41fdfe0a..2a8e6659 100644 --- a/SabreTools.Serialization/Wrappers/Nitro.cs +++ b/SabreTools.Serialization/Wrappers/Nitro.cs @@ -151,8 +151,8 @@ namespace SabreTools.Serialization.Wrappers int readOffset = 0; // Grab the first two blocks - uint p0 = SecureArea.ReadUInt32(ref readOffset); - uint p1 = SecureArea.ReadUInt32(ref readOffset); + uint p0 = SecureArea.ReadUInt32LittleEndian(ref readOffset); + uint p1 = SecureArea.ReadUInt32LittleEndian(ref readOffset); // Perform the initialization steps Init1(tableData); @@ -168,8 +168,8 @@ namespace SabreTools.Serialization.Wrappers uint size = 0x800 - 8; while (size > 0) { - p0 = SecureArea.ReadUInt32(ref readOffset); - p1 = SecureArea.ReadUInt32(ref readOffset); + p0 = SecureArea.ReadUInt32LittleEndian(ref readOffset); + p1 = SecureArea.ReadUInt32LittleEndian(ref readOffset); Encrypt(ref p1, ref p0); @@ -183,8 +183,8 @@ namespace SabreTools.Serialization.Wrappers readOffset = 0; writeOffset = 0; - p0 = SecureArea.ReadUInt32(ref readOffset); - p1 = SecureArea.ReadUInt32(ref readOffset); + p0 = SecureArea.ReadUInt32LittleEndian(ref readOffset); + p1 = SecureArea.ReadUInt32LittleEndian(ref readOffset); if (p0 == 0xE7FFDEFF && p1 == 0xE7FFDEFF) { @@ -274,8 +274,8 @@ namespace SabreTools.Serialization.Wrappers int writeOffset = 0; // Grab the first two blocks - uint p0 = SecureArea.ReadUInt32(ref readOffset); - uint p1 = SecureArea.ReadUInt32(ref readOffset); + uint p0 = SecureArea.ReadUInt32LittleEndian(ref readOffset); + uint p1 = SecureArea.ReadUInt32LittleEndian(ref readOffset); // Perform the initialization steps Init1(tableData); @@ -303,8 +303,8 @@ namespace SabreTools.Serialization.Wrappers uint size = 0x800 - 8; while (size > 0) { - p0 = SecureArea.ReadUInt32(ref readOffset); - p1 = SecureArea.ReadUInt32(ref readOffset); + p0 = SecureArea.ReadUInt32LittleEndian(ref readOffset); + p1 = SecureArea.ReadUInt32LittleEndian(ref readOffset); Decrypt(ref p1, ref p0); @@ -354,8 +354,8 @@ namespace SabreTools.Serialization.Wrappers } int offset = 0; - uint firstValue = SecureArea.ReadUInt32(ref offset); - uint secondValue = SecureArea.ReadUInt32(ref offset); + uint firstValue = SecureArea.ReadUInt32LittleEndian(ref offset); + uint secondValue = SecureArea.ReadUInt32LittleEndian(ref offset); // Empty secure area standard if (firstValue == 0x00000000 && secondValue == 0x00000000)