2011-09-27 05:19:01 +02:00
|
|
|
|
/* This file is part of Sharpii.
|
2013-02-16 07:55:46 +01:00
|
|
|
|
* Copyright (C) 2013 Person66
|
2011-09-27 05:19:01 +02:00
|
|
|
|
*
|
|
|
|
|
* Sharpii is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* Sharpii is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2011-11-02 02:02:11 +01:00
|
|
|
|
* along with Sharpii. If not, see <http://www.gnu.org/licenses/>.
|
2011-09-27 05:19:01 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using libWiiSharp;
|
|
|
|
|
|
|
|
|
|
namespace Sharpii
|
|
|
|
|
{
|
|
|
|
|
partial class IOS_Stuff
|
|
|
|
|
{
|
|
|
|
|
public static void IOS(string[] args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length < 3)
|
|
|
|
|
{
|
|
|
|
|
IOS_help();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string input = args[1];
|
|
|
|
|
string output = "";
|
|
|
|
|
bool fs = false;
|
|
|
|
|
bool es = false;
|
|
|
|
|
bool np = false;
|
2011-10-03 05:43:22 +02:00
|
|
|
|
bool vp = false;
|
2011-09-27 05:19:01 +02:00
|
|
|
|
int slot = -1;
|
|
|
|
|
int version = -1;
|
|
|
|
|
|
|
|
|
|
//Check if file exists
|
|
|
|
|
if (File.Exists(input) == false)
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("ERROR: Unable to open file: {0}", input);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Get parameters
|
|
|
|
|
for (int i = 1; i < args.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
switch (args[i].ToUpper())
|
|
|
|
|
{
|
|
|
|
|
case "-FS":
|
|
|
|
|
fs = true;
|
|
|
|
|
break;
|
|
|
|
|
case "-ES":
|
|
|
|
|
es = true;
|
|
|
|
|
break;
|
|
|
|
|
case "-NP":
|
|
|
|
|
np = true;
|
|
|
|
|
break;
|
2011-10-03 05:43:22 +02:00
|
|
|
|
case "-VP":
|
|
|
|
|
vp = true;
|
|
|
|
|
break;
|
2011-09-27 05:19:01 +02:00
|
|
|
|
case "-SLOT":
|
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("ERROR: No slot set");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!int.TryParse(args[i + 1], out slot))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid slot {0}...", args[i + 1]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (slot < 3 || slot > 255)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid slot {0}...", slot);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2011-10-03 05:43:22 +02:00
|
|
|
|
case "-S":
|
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("ERROR: No slot set");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!int.TryParse(args[i + 1], out slot))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid slot {0}...", args[i + 1]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (slot < 3 || slot > 255)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid slot {0}...", slot);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2011-09-27 05:19:01 +02:00
|
|
|
|
case "-V":
|
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("ERROR: No version set");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!int.TryParse(args[i + 1], out version))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid version {0}...", args[i + 1]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (version < 0 || version > 65535)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid version {0}...", version);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "-O":
|
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("ERROR: No output set");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
output = args[i + 1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Main part (most of it was borrowed from PatchIOS)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
WAD ios = new WAD();
|
|
|
|
|
ios.KeepOriginalFooter = true;
|
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Loading File...");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
ios.LoadFile(input);
|
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Done!\n");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
//Check if WAD is an IOS
|
|
|
|
|
if ((ios.TitleID >> 32) != 1 || (ios.TitleID & 0xffffffff) > 255 || (ios.TitleID & 0xffffffff) < 3)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Only IOS WADs can be patched...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IosPatcher patcher = new IosPatcher();
|
|
|
|
|
|
|
|
|
|
patcher.LoadIOS(ref ios);
|
|
|
|
|
|
|
|
|
|
//apply patches
|
|
|
|
|
if (fs == true)
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Applying Fakesigning patch");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
patcher.PatchFakeSigning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (es == true)
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Applying ES_Identify patch");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
patcher.PatchEsIdentify();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (np == true)
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Applying NAND permissions patch");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
patcher.PatchNandPermissions();
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-03 05:43:22 +02:00
|
|
|
|
if (vp == true)
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Applying Version patch");
|
2011-10-03 05:43:22 +02:00
|
|
|
|
patcher.PatchVP();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-27 05:19:01 +02:00
|
|
|
|
if (slot > -1 || version > -1)
|
|
|
|
|
ios.FakeSign = true;
|
|
|
|
|
|
|
|
|
|
if (slot > -1)
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Changing IOS slot to: {0}", slot);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
ios.TitleID = (ulong)((1UL << 32) | (uint)slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (version > -1)
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Changing title version to: {0}", version);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
ios.TitleVersion = (ushort)version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check if output was set
|
|
|
|
|
if (output != "")
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Saving to file: {0}", output);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
ios.Save(output);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Saving file...");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
2011-10-03 05:43:22 +02:00
|
|
|
|
if (output != "")
|
|
|
|
|
{
|
|
|
|
|
if (output.Substring(output.Length - 4, 4).ToUpper() != ".WAD")
|
|
|
|
|
output = output + ".wad";
|
|
|
|
|
}
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
ios.Save(input);
|
2011-10-03 05:43:22 +02:00
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Done!\n");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
}
|
|
|
|
|
if (Quiet.quiet > 1)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Operation completed succesfully!");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("An unknown error occured, please try again");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void IOS_help()
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("Sharpii {0} - IOS - A tool by person66, using libWiiSharp.dll by leathl", Version.version);
|
2011-11-13 01:28:35 +01:00
|
|
|
|
Console.WriteLine(" Code based off PatchIOS by leathl");
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Usage:");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Sharpii.exe IOS input [-o output] [-fs] [-es] [-np] [-vp] [-s slot]");
|
|
|
|
|
Console.WriteLine(" [-v version]");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Arguments:");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" input The input file");
|
|
|
|
|
Console.WriteLine(" -o output The output file");
|
|
|
|
|
Console.WriteLine(" -fs Patch Fakesigning");
|
|
|
|
|
Console.WriteLine(" -es Patch ES_Identify");
|
|
|
|
|
Console.WriteLine(" -np Patch NAND Permissions");
|
|
|
|
|
Console.WriteLine(" -vp Add version patch");
|
|
|
|
|
Console.WriteLine(" -s # Change IOS slot to #");
|
|
|
|
|
Console.WriteLine(" -v # Change IOS version to #");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|