/// <summary> /// Resigns save data. /// </summary> /// <param name="sav7">The save data to resign.</param> /// <param name="throwIfUnsupported">If true, throw an <see cref="InvalidOperationException"/> if MemeCrypto is unsupported. If false, calling this function will have no effect.</param> /// <exception cref="InvalidOperationException">Thrown if the current platform has FIPS mode enabled on a platform that does not support the required crypto service providers.</exception> /// <returns>The resigned save data.</returns> public static byte[] Resign(byte[] sav7, bool throwIfUnsupported = true) { if (sav7 == null || sav7.Length != 0x6BE00) { return(null); } try { byte[] outSav = (byte[])sav7.Clone(); using (var sha256 = Util.GetSHA256Provider()) { byte[] CurSig = new byte[0x80]; Array.Copy(sav7, 0x6BB00, CurSig, 0, 0x80); byte[] ChecksumTable = new byte[0x140]; Array.Copy(sav7, 0x6BC00, ChecksumTable, 0, 0x140); SignMemeData(sha256.ComputeHash(ChecksumTable).Concat(ReverseCrypt(CurSig) ?? new byte[0x60]).ToArray()).CopyTo(outSav, 0x6BB00); } return(outSav); } catch (InvalidOperationException) { if (throwIfUnsupported) { throw; } else { return((byte[])sav7.Clone()); } } }
public static bool CanUseMemeCrypto() { try { Util.GetSHA256Provider(); } catch (InvalidOperationException) { return(false); } return(true); }
/// <summary> /// Resigns save data. /// </summary> /// <param name="sav7">The save data to resign.</param> /// <param name="throwIfUnsupported"> /// If true, throw an <see cref="InvalidOperationException" /> if MemeCrypto is /// unsupported. If false, calling this function will have no effect. /// </param> /// <exception cref="InvalidOperationException"> /// Thrown if the current platform has FIPS mode enabled on a platform that /// does not support the required crypto service providers. /// </exception> /// <returns>The resigned save data.</returns> public static byte[] Resign(byte[] sav7, bool throwIfUnsupported = true) { if (sav7 == null || sav7.Length != 0x6BE00) { return(null); } try { var outSav = (byte[])sav7.Clone(); using (var sha256 = Util.GetSHA256Provider()) { var CurSig = new byte[0x80]; Array.Copy(sav7, 0x6BB00, CurSig, 0, 0x80); var ChecksumTable = new byte[0x140]; Array.Copy(sav7, 0x6BC00, ChecksumTable, 0, 0x140); var newSig = new byte[0x80]; sha256.ComputeHash(ChecksumTable).CopyTo(newSig, 0); var memeSig = VerifyMemeData(CurSig); if (memeSig != null) { Array.Copy(memeSig, 0x20, newSig, 0x20, 0x60); } SignMemeData(newSig).CopyTo(outSav, 0x6BB00); } return(outSav); } catch (InvalidOperationException) { if (throwIfUnsupported) { throw; } return((byte[])sav7.Clone()); } }