From 993bb00a6190f950c0f7db4ba48d978d63a6dc19 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 23 Feb 2019 18:02:50 -0800 Subject: [PATCH] Remove powersave unused logic unused & deprecated in favor of using cfw (powersaves price >>> ntrboot-b9s flashcart) --- PKHeX.Core/Saves/Util/SaveUtil.cs | 100 ------------------------------ 1 file changed, 100 deletions(-) diff --git a/PKHeX.Core/Saves/Util/SaveUtil.cs b/PKHeX.Core/Saves/Util/SaveUtil.cs index 899e5e547..4c74984ca 100644 --- a/PKHeX.Core/Saves/Util/SaveUtil.cs +++ b/PKHeX.Core/Saves/Util/SaveUtil.cs @@ -69,8 +69,6 @@ public static class SaveUtil SIZE_G7BANK, SIZE_G4BANK, SIZE_G4RANCH, SIZE_G4RANCH_PLAT, }; - private static readonly int[] mainSizes = { SIZE_G6XY, SIZE_G6ORAS, SIZE_G7SM, SIZE_G7USUM }; - private static readonly byte[] FOOTER_DSV = Encoding.ASCII.GetBytes("|-DESMUME SAVE-|"); internal static readonly string[] HEADER_COLO = { "GC6J","GC6E","GC6P" }; // NTSC-J, NTSC-U, PAL internal static readonly string[] HEADER_XD = { "GXXJ","GXXE","GXXP" }; // NTSC-J, NTSC-U, PAL @@ -1196,104 +1194,6 @@ public static void AdvanceGCKeys(ushort[] keys) return new Tuple(TID, SID); } - /// - /// Creates a via decryption using a stored xorpad. - /// - /// Encrypted byte array of savedata to decrypt. - /// Possible paths to check for xorpad compatibility. - /// Returns a if decryption was successful, else null. - public static SaveFile GetSAVfromXORpads(byte[] input, IEnumerable xorpadPaths) - { - byte[] savID = new byte[0x10]; - Array.Copy(input, 0x10, savID, 0, 0x10); - - var pads = GetXorpadsFromFiles(xorpadPaths); - foreach (var xorpad in pads) - { - // Check if encrypted 00's match save - if (!xorpad.Skip(0x10).Take(0x10).SequenceEqual(savID)) - continue; - - DecryptFromXorpad(input, xorpad); - var main = GetMainFromSaveContainer(input); - if (main.Length == 0) - continue; - - // Save file is now decrypted! - var SAV = GetVariantSAV(main); - if (SAV == null) - continue; - - return SAV; - } - return null; // no xorpad compatible - } - - /// - /// Filters the specified files and returns a list of valid enumerable xorpads (keystreams). - /// - /// Files that may (or may not) be xorpads. - /// Valid xorpads to enumerate. - public static IEnumerable GetXorpadsFromFiles(IEnumerable files) - { - foreach (var file in files) - { - // Check if xorpad - FileInfo fi = new FileInfo(file); - - string filename = fi.Name.ToLower(); - if (!filename.Contains("xorpad") && !filename.Contains("key")) - continue; - - var length = fi.Length; - if (length != 0x10009C && length != 0x100000) - continue; - - // Fix xorpad alignment - byte[] xorpad = File.ReadAllBytes(file); - if (xorpad.Length == 0x10009C) // Trim off Powersaves' header - { - Array.Copy(xorpad, 0x9C, xorpad, 0, 0x100000); - Array.Resize(ref xorpad, 0x100000); - } - yield return xorpad; - } - } - - /// - /// Decrypts an input array with a xorpad. - /// - /// Input byte array which will be decrypted in place. - /// Keystream data - public static void DecryptFromXorpad(IList input, IReadOnlyList xorpad) - { - for (int z = 0; z < input.Count; z++) - input[z] ^= xorpad[z]; - } - - /// - /// Gets the "main" save file from an input data array. - /// - /// Input data array - /// Offset shift to rip from - /// Output data array containing raw save data - public static byte[] GetMainFromSaveContainer(byte[] input, int shift = 0) - { - // Check the validity of the decrypted content by finding the checksum block - int mainOffset = 0x5400 + shift; - foreach (int size in mainSizes.OrderByDescending(z => z)) - { - int chkBlockOffset = mainOffset + size - 0x1F0; - if (BitConverter.ToUInt32(input, chkBlockOffset) != BEEF) - continue; - - byte[] data = new byte[size]; - Buffer.BlockCopy(input, mainOffset, data, 0, size); - return data; - } - return Array.Empty(); - } - /// /// Force loads the provided to the requested . ///