From dcce4223f656d406bda8d15dff1743acd05f8667 Mon Sep 17 00:00:00 2001 From: "imruon@gmail.com" Date: Tue, 12 Jan 2010 19:13:00 +0000 Subject: [PATCH] Added 4MB limitation check... git-svn-id: svn://localhost/Users/andi/Downloads/code/trunk@28 eddbe33b-e435-4246-ac25-f5eb65f9a13c --- CustomizeMiiInstaller/InstallerHelper.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CustomizeMiiInstaller/InstallerHelper.cs b/CustomizeMiiInstaller/InstallerHelper.cs index 45c8c75..a6fbdea 100644 --- a/CustomizeMiiInstaller/InstallerHelper.cs +++ b/CustomizeMiiInstaller/InstallerHelper.cs @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +using System; using System.IO; using System.IO.Compression; using System.Security.Cryptography; @@ -26,6 +27,16 @@ namespace CustomizeMiiInstaller public static MemoryStream CreateInstaller(string wadFile, byte iosToUse) { const int injectionPosition = 0x5A74C; + const int maxAllowedSizeForWads = 4 * 1024 * 1024 - 32; //(Max 4MB-32bytes ) + + //0. Read length of the wad to ensure it has an allowed size + byte[] wadFileBytes = File.ReadAllBytes(wadFile); + uint wadLength = (uint)wadFileBytes.Length; + + if (wadLength > maxAllowedSizeForWads) + { + throw new ArgumentException(String.Format("The file {0} is sized above the max allowed limit of {1} for network installation.", wadFile, maxAllowedSizeForWads)); + } //1. Open the stub installer from resources MemoryStream compressedStubInstallerStream = LoadCompressedStubInstaller("CustomizeMiiInstaller.dol.z"); @@ -50,9 +61,6 @@ namespace CustomizeMiiInstaller //3. Take SHA of the wad and store it in the stub installer along with the size of the wad - byte[] wadFileBytes = File.ReadAllBytes(wadFile); - uint wadLength = (uint) wadFileBytes.Length; - byte[] shaHash; using (SHA1 shaGen = SHA1.Create()) {