Added 4MB limitation check...

git-svn-id: svn://localhost/Users/andi/Downloads/code/trunk@28 eddbe33b-e435-4246-ac25-f5eb65f9a13c
This commit is contained in:
imruon@gmail.com 2010-01-12 19:13:00 +00:00
parent 1274623f1a
commit dcce4223f6

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Security.Cryptography; using System.Security.Cryptography;
@ -26,6 +27,16 @@ namespace CustomizeMiiInstaller
public static MemoryStream CreateInstaller(string wadFile, byte iosToUse) public static MemoryStream CreateInstaller(string wadFile, byte iosToUse)
{ {
const int injectionPosition = 0x5A74C; 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 //1. Open the stub installer from resources
MemoryStream compressedStubInstallerStream = LoadCompressedStubInstaller("CustomizeMiiInstaller.dol.z"); 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 //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; byte[] shaHash;
using (SHA1 shaGen = SHA1.Create()) using (SHA1 shaGen = SHA1.Create())
{ {