private void doUnpack(object files) { setControls(false, false); string input = ((string[])files)[0]; string output = ((string[])files)[1]; try { WAD w = new WAD(); w.Progress += new EventHandler <System.ComponentModel.ProgressChangedEventArgs>(unpack_Progress); w.LoadFile(input); w.Unpack(output, cidName); MessageBox.Show("Successfully unpacked WAD to:\n" + output, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { setControls(true, false); } }
private static void Info(string[] args) { string input = args[2]; string output = ""; bool titles = false; //Check if file exists if (File.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open file: {0}", input); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E81); } else { Environment.Exit(0x00000003); } return; } for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-O": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No output set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_OUTPUT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8D); } else { Environment.Exit(0x0000000F); } return; } output = args[i + 1]; break; case "-OUTPUT": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No output set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_OUTPUT"); if (OperatingSystem.Windows()) { Environment.Exit(0x00003E8D); } else { Environment.Exit(0x0000000F); } return; } output = args[i + 1]; break; case "-TITLES": titles = true; break; } } try { WAD wad = new WAD(); if (BeQuiet.quiet > 2) { Console.Write("Loading file..."); } wad.LoadFile(input); if (BeQuiet.quiet > 2) { Console.Write("Done!\n"); } if (BeQuiet.quiet > 1 && output == "") { Console.WriteLine("WAD Info:"); Console.WriteLine(""); if (titles == false) { Console.WriteLine("Title: {0}", wad.ChannelTitles[1]); } else { Console.WriteLine("Titles:\n"); Console.WriteLine(" Japanese: {0}", wad.ChannelTitles[0]); Console.WriteLine(" English: {0}", wad.ChannelTitles[1]); Console.WriteLine(" German: {0}", wad.ChannelTitles[2]); Console.WriteLine(" French: {0}", wad.ChannelTitles[3]); Console.WriteLine(" Spanish: {0}", wad.ChannelTitles[4]); Console.WriteLine(" Italian: {0}", wad.ChannelTitles[5]); Console.WriteLine(" Dutch: {0}", wad.ChannelTitles[6]); Console.WriteLine(" Korean: {0}\n", wad.ChannelTitles[7]); } Console.WriteLine("Title ID: {0}", wad.UpperTitleID); Console.WriteLine("Full Title ID: {0}", wad.TitleID.ToString("X16").Substring(0, 8) + "-" + wad.TitleID.ToString("X16")[8..]);
void bwLoadChannel_DoWork(object sender, DoWorkEventArgs e) { try { BackgroundWorker bwLoadChannel = sender as BackgroundWorker; initialize(); if (e.Argument is string) { setControlText(tbSourceWad, (string)e.Argument); } else if (e.Argument is DownloadDataCompletedEventArgs) { setControlText(tbSourceWad, (string)((DownloadDataCompletedEventArgs)e.Argument).UserState); } bwLoadChannel.ReportProgress(0, "Loading WAD..."); if (e.Argument is string) { sourceWad.LoadFile((string)e.Argument); } else if (e.Argument is DownloadDataCompletedEventArgs) { sourceWad.LoadFile(((DownloadDataCompletedEventArgs)e.Argument).Result); } if (!sourceWad.HasBanner) { throw new Exception("CustomizeMii only edits Channel WADs!"); } int progressValue = 30; for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++) { if (sourceWad.BannerApp.StringTable[i].ToLower() == "banner.bin") { progressValue += 20; bwLoadChannel.ReportProgress(progressValue, "Loading banner.bin..."); bannerBin.LoadFile(sourceWad.BannerApp.Data[i]); } else if (sourceWad.BannerApp.StringTable[i].ToLower() == "icon.bin") { progressValue += 20; bwLoadChannel.ReportProgress(progressValue, "Loading icon.bin..."); iconBin.LoadFile(sourceWad.BannerApp.Data[i]); } } bwLoadChannel.ReportProgress(90, "Loading Channel Information..."); setControlText(tbTitleID, sourceWad.UpperTitleID); setControlText(tbStartupIos, ((int)sourceWad.StartupIOS).ToString()); string[] channelTitles = ((Headers.IMET)sourceWad.BannerApp.Header).GetTitles(); bool allLangs = true; if (channelTitles[0] != channelTitles[1]) { setControlText(tbJapanese, channelTitles[0]); } else { allLangs = false; } if (channelTitles[2] != channelTitles[1]) { setControlText(tbGerman, channelTitles[2]); } else { allLangs = false; } if (channelTitles[3] != channelTitles[1]) { setControlText(tbFrench, channelTitles[3]); } else { allLangs = false; } if (channelTitles[4] != channelTitles[1]) { setControlText(tbSpanish, channelTitles[4]); } else { allLangs = false; } if (channelTitles[5] != channelTitles[1]) { setControlText(tbItalian, channelTitles[5]); } else { allLangs = false; } if (channelTitles[6] != channelTitles[1]) { setControlText(tbDutch, channelTitles[6]); } else { allLangs = false; } if (channelTitles[7] != channelTitles[1]) { setControlText(tbKorean, channelTitles[7]); } if (allLangs) { setControlText(tbEnglish, channelTitles[1]); } else { setControlText(tbAllLanguages, channelTitles[1]); } bwLoadChannel.ReportProgress(95, "Loading Footer..."); if (sourceWad.CreationTimeUTC > new DateTime(1970, 1, 1)) { setControlText(lbCreatedValue, sourceWad.CreationTimeUTC.ToString() + " (UTC)"); } else { setControlText(lbCreatedValue, "No Timestamp!"); } addTpls(); addBrlyts(); addBrlans(); enableControls(); setControlText(btnBrowseSource, "Clear"); } catch (Exception ex) { setControlText(tbSourceWad, string.Empty); errorBox(ex.Message); } }
private static void Info(string[] args) { string input = args[2]; string output = ""; bool titles = false; //Check if file exists if (File.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open file: {0}", input); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-O": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No output set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_OUTPUT_01"); Environment.Exit(0x00003E8D); return; } output = args[i + 1]; break; case "-OUTPUT": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No output set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_OUTPUT_01"); Environment.Exit(0x00003E8D); return; } output = args[i + 1]; break; case "-TITLES": titles = true; break; } } try { WAD wad = new WAD(); if (BeQuiet.quiet > 2) Console.Write("Loading file..."); wad.LoadFile(input); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (BeQuiet.quiet > 1 && output == "") { Console.WriteLine("WAD Info:"); Console.WriteLine(""); if (titles == false) Console.WriteLine("Title: {0}", wad.ChannelTitles[1]); else { Console.WriteLine("Titles:\n"); Console.WriteLine(" Japanese: {0}", wad.ChannelTitles[0]); Console.WriteLine(" English: {0}", wad.ChannelTitles[1]); Console.WriteLine(" German: {0}", wad.ChannelTitles[2]); Console.WriteLine(" French: {0}", wad.ChannelTitles[3]); Console.WriteLine(" Spanish: {0}", wad.ChannelTitles[4]); Console.WriteLine(" Italian: {0}", wad.ChannelTitles[5]); Console.WriteLine(" Dutch: {0}", wad.ChannelTitles[6]); Console.WriteLine(" Korean: {0}\n", wad.ChannelTitles[7]); } Console.WriteLine("Title ID: {0}", wad.UpperTitleID); Console.WriteLine("Full Title ID: {0}", wad.TitleID.ToString("X16").Substring(0, 8) + "-" + wad.TitleID.ToString("X16").Substring(8)); Console.WriteLine("IOS: {0}", ((int)wad.StartupIOS).ToString()); Console.WriteLine("Region: {0}", wad.Region); Console.WriteLine("Version: {0}", wad.TitleVersion); Console.WriteLine("Blocks: {0}", wad.NandBlocks); } else { if (BeQuiet.quiet > 2) Console.Write("Saving file..."); if (output.Substring(output.Length - 4, 4).ToUpper() != ".TXT") output = output + ".txt"; TextWriter txt = new StreamWriter(output); txt.WriteLine("WAD Info:"); txt.WriteLine(""); if (titles == false) txt.WriteLine("Title: {0}", wad.ChannelTitles[1]); else { txt.WriteLine("Titles:"); txt.WriteLine(" Japanese: {0}", wad.ChannelTitles[0]); txt.WriteLine(" English: {0}", wad.ChannelTitles[1]); txt.WriteLine(" German: {0}", wad.ChannelTitles[2]); txt.WriteLine(" French: {0}", wad.ChannelTitles[3]); txt.WriteLine(" Spanish: {0}", wad.ChannelTitles[4]); txt.WriteLine(" Italian: {0}", wad.ChannelTitles[5]); txt.WriteLine(" Dutch: {0}", wad.ChannelTitles[6]); txt.WriteLine(" Korean: {0}", wad.ChannelTitles[7]); } txt.WriteLine("Title ID: {0}", wad.UpperTitleID); txt.WriteLine("Full Title ID: {0}", wad.TitleID.ToString("X16").Substring(0, 8) + "-" + wad.TitleID.ToString("X16").Substring(8)); txt.WriteLine("IOS: {0}", ((int)wad.StartupIOS).ToString()); txt.WriteLine("Region: {0}", wad.Region); txt.WriteLine("Version: {0}", wad.TitleVersion); txt.WriteLine("Blocks: {0}", wad.NandBlocks); txt.Close(); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (BeQuiet.quiet > 1) Console.WriteLine("Operation completed succesfully!"); } } catch (Exception ex) { Console.WriteLine("An unknown error occured, please try again"); Console.WriteLine(""); Console.WriteLine("ERROR DETAILS: {0}", ex.Message); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_01"); Environment.Exit(0x00003E82); return; } }
private static void Unpack(string[] args) { //setting up variables string input = args[2]; string output = args[3]; bool cid = false; //Check if file exists if (File.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open file: {0}", input); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } //-cid argument for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-CID": cid = true; break; } } //Run main part, and check for exceptions try { WAD wad = new WAD(); if (BeQuiet.quiet > 2) Console.Write("Loading file..."); wad.LoadFile(input); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (BeQuiet.quiet > 2) Console.Write("Unpacking WAD..."); wad.Unpack(output, cid); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (BeQuiet.quiet > 1) Console.WriteLine("Operation completed succesfully!"); } catch (Exception ex) { Console.WriteLine("An unknown error occured, please try again"); Console.WriteLine(""); Console.WriteLine("ERROR DETAILS: {0}", ex.Message); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_01"); Environment.Exit(0x00003E82); return; } }
private static void Editor(string[] args, bool edit) { //Setting up variables string input = args[2]; string output = args[3]; string id = ""; int ios = -1; string title = ""; string lwrid = ""; bool fake = false; string sound = ""; string banner = ""; string icon = ""; string app = ""; //Check if file/folder exists if (edit == true) if (File.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open file: {0}", input); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } if (edit == false) if (Directory.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open folder: {0}", input); Console.WriteLine("Either the folder doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FOLDER_ERR_01"); Environment.Exit(0x00003E94); return; } for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-F": fake = true; break; case "-ID": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No ID set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_ID_01"); Environment.Exit(0x00003E8E); return; } id = args[i + 1]; if (id.Length < 4) { Console.WriteLine("ERROR: ID too short"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_SHORT_ID_01"); Environment.Exit(0x00003E97); return; } id = id.Substring(0, 4); break; case "-TYPE": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No type set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TYPE_01"); Environment.Exit(0x00003E98); return; } lwrid = args[i + 1].ToUpper(); if (lwrid != "CHANNEL" && lwrid != "DLC" && lwrid != "GAMECHANNEL" && lwrid != "HIDDENCHANNELS" && lwrid != "SYSTEMCHANNELS" && lwrid != "SYSTEMTITLES") { Console.WriteLine("ERROR: Unknown WAD type: {0}", args[i + 1]); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_TYPE_01"); Environment.Exit(0x00003E99); return; } break; case "-IOS": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No type set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TYPE_01"); Environment.Exit(0x00003E98); return; } if (!int.TryParse(args[i + 1], out ios)) { Console.WriteLine("Invalid slot {0}...", args[i + 1]); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_INVALID_SLOT_01"); Environment.Exit(0x00003E8A); return; } if (ios < 0 || ios > 255) { Console.WriteLine("Invalid slot {0}...", ios); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_INVALID_SLOT_01"); Environment.Exit(0x00003E8A); return; } break; case "-TITLE": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No title set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TITLE_01"); Environment.Exit(0x00003E95); return; } title = args[i + 1]; break; case "-SOUND": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No sound set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_SOUND_01"); Environment.Exit(0x00003E9A); return; } sound = args[i + 1]; if (File.Exists(sound) == false) { Console.WriteLine("ERROR: Unable to find sound wad"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; case "-BANNER": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No banner set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_BANNER_01"); Environment.Exit(0x00003E9B); return; } banner = args[i + 1]; if (File.Exists(banner) == false) { Console.WriteLine("ERROR: Unable to find banner wad"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; case "-ICON": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No sound set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_SOUND_01"); Environment.Exit(0x00003E9A); return; } icon = args[i + 1]; if (File.Exists(icon) == false) { Console.WriteLine("ERROR: Unable to find icon wad"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; case "-DOL": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No dol set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_DOL_01"); Environment.Exit(0x00003E84); return; } app = args[i + 1]; if (File.Exists(app) == false) { Console.WriteLine("ERROR: Unable to find dol wad/file"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; } } //Run main part, and check for exceptions try { WAD wad = new WAD(); if (edit == true) { if (BeQuiet.quiet > 2) Console.Write("Loading file..."); wad.LoadFile(input); } else { if (BeQuiet.quiet > 2) Console.Write("Loading folder..."); wad.CreateNew(input); } if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (sound != "" || banner != "" || icon != "" || app != "") { string temp = Path.GetTempPath() + "Sharpii.tmp"; if (Directory.Exists(temp) == true) DeleteADir.DeleteDirectory(temp); Directory.CreateDirectory(temp); wad.Unpack(Path.Combine(temp, "main")); U8 u = new U8(); u.LoadFile(Path.Combine(temp, "main", "00000000.app")); u.Extract(Path.Combine(temp, "main", "00000000")); WAD twad = new WAD(); if (sound != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing sound..."); twad.LoadFile(sound); twad.Unpack(Path.Combine(temp + "sound")); U8 tu = new U8(); tu.LoadFile(Path.Combine(temp, "sound", "00000000.app")); tu.Extract(Path.Combine(temp, "sound", "00000000")); File.Copy(Path.Combine(temp, "sound", "00000000", "meta", "sound.bin"), Path.Combine(temp, "main", "00000000", "meta", "sound.bin"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } if (banner != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing banner..."); twad.LoadFile(banner); twad.Unpack(Path.Combine(temp, "banner")); U8 tu = new U8(); tu.LoadFile(Path.Combine(temp, "banner", "00000000.app")); tu.Extract(Path.Combine(temp, "banner", "00000000")); File.Copy(Path.Combine(temp, "banner", "00000000", "meta", "banner.bin"), Path.Combine(temp, "main", "00000000", "meta", "banner.bin"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } if (icon != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing icon..."); twad.LoadFile(icon); twad.Unpack(Path.Combine(temp, "icon")); U8 tu = new U8(); tu.LoadFile(Path.Combine(temp, "icon", "00000000.app")); tu.Extract(Path.Combine(temp, "icon", "00000000")); File.Copy(Path.Combine(temp, "icon", "00000000", "meta", "icon.bin"), Path.Combine(temp, "main", "00000000", "meta", "icon.bin"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } if (app != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing dol..."); if (app.Substring(app.Length - 4, 4) == ".dol") { Directory.CreateDirectory(Path.Combine(temp, "dol")); File.Copy(app, Path.Combine(temp, "dol", "00000001.app")); } else { twad.LoadFile(app); twad.Unpack(Path.Combine(temp, "dol")); } File.Copy(Path.Combine(temp, "dol", "00000001.app"), Path.Combine(temp, "main", "00000001.app"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } u.ReplaceFile(1, Path.Combine(temp, "main", "00000000", "meta", "banner.bin")); u.ReplaceFile(2, Path.Combine(temp, "main", "00000000", "meta", "icon.bin")); u.ReplaceFile(3, Path.Combine(temp, "main", "00000000", "meta", "sound.bin")); u.Save(Path.Combine(temp, "main", "00000000.app")); DeleteADir.DeleteDirectory(Path.Combine(temp, "main", "00000000")); wad.CreateNew(Path.Combine(temp, "main")); DeleteADir.DeleteDirectory(temp); } if (BeQuiet.quiet > 2 && fake == true) Console.WriteLine("FakeSigning WAD"); wad.FakeSign = fake; if (id != "" || lwrid != "") { if (id != "") { if (BeQuiet.quiet > 2) Console.WriteLine("Changing channel ID to: {0}", id); } else { id = wad.UpperTitleID; } if (lwrid != "") { if (BeQuiet.quiet > 2) Console.WriteLine("Changing channel type to: {0}", lwrid); } else { lwrid = "CHANNEL"; } if (lwrid == "CHANNEL") wad.ChangeTitleID(LowerTitleID.Channel, id); else if (lwrid == "DLC") wad.ChangeTitleID(LowerTitleID.DLC, id); else if (lwrid == "GAMECHANNEL") wad.ChangeTitleID(LowerTitleID.GameChannel, id); else if (lwrid == "HIDDENCHANNELS") wad.ChangeTitleID(LowerTitleID.HiddenChannels, id); else if (lwrid == "SYSTEMCHANNELS") wad.ChangeTitleID(LowerTitleID.SystemChannels, id); else if (lwrid == "SYSTEMTITLES") wad.ChangeTitleID(LowerTitleID.SystemTitles, id); } if (ios > -1) { if (BeQuiet.quiet > 2) Console.WriteLine("Changing startup IOS to: {0}", ios); wad.ChangeStartupIOS(ios); } if (title != "") { if (BeQuiet.quiet > 2) Console.WriteLine("Changing channel title to: {0}", title); wad.ChangeChannelTitles(title); } if (BeQuiet.quiet > 2) Console.Write("Saving file..."); if (output.Substring(output.Length - 4, 4).ToUpper() != ".WAD") output = output + ".wad"; wad.Save(output); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (BeQuiet.quiet > 1) Console.WriteLine("Operation completed succesfully!"); } catch (Exception ex) { if (ex.Message == "Index was outside the bounds of the array.") { Console.WriteLine("You need to have all the required .app files, a tmd file, a tik file, and a cert file to do this."); Console.WriteLine(""); Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_MISSING_FILES_01"); ExceptionListRan = 1; Environment.Exit(0x00003E9D); } if (ExceptionListRan == 0) { Console.WriteLine("An unknown error occured, please try again"); Console.WriteLine(""); Console.WriteLine("ERROR DETAILS: {0}", ex.Message); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_01"); Environment.Exit(0x00003E82); } } }
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; bool vp = false; int slot = -1; int version = -1; //Check if file exists if (File.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open file: {0}", input); 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; case "-VP": vp = true; break; 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; 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; 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) { Console.Write("Loading File..."); } ios.LoadFile(input); if (Quiet.quiet > 2) { Console.Write("Done!\n"); } //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) { Console.WriteLine("Applying Fakesigning patch"); } patcher.PatchFakeSigning(); } if (es == true) { if (Quiet.quiet > 2) { Console.WriteLine("Applying ES_Identify patch"); } patcher.PatchEsIdentify(); } if (np == true) { if (Quiet.quiet > 2) { Console.WriteLine("Applying NAND permissions patch"); } patcher.PatchNandPermissions(); } if (vp == true) { if (Quiet.quiet > 2) { Console.WriteLine("Applying Version patch"); } patcher.PatchVP(); } if (slot > -1 || version > -1) { ios.FakeSign = true; } if (slot > -1) { if (Quiet.quiet > 2) { Console.WriteLine("Changing IOS slot to: {0}", slot); } ios.TitleID = (ulong)((1UL << 32) | (uint)slot); } if (version > -1) { if (Quiet.quiet > 2) { Console.WriteLine("Changing title version to: {0}", version); } ios.TitleVersion = (ushort)version; } //check if output was set if (output != "") { if (Quiet.quiet > 2) { Console.WriteLine("Saving to file: {0}", output); } ios.Save(output); } else { if (Quiet.quiet > 2) { Console.Write("Saving file..."); } if (output != "") { if (output.Substring(output.Length - 4, 4).ToUpper() != ".WAD") { output = output + ".wad"; } } ios.Save(input); if (Quiet.quiet > 2) { Console.Write("Done!\n"); } } if (Quiet.quiet > 1) { Console.WriteLine("Operation completed succesfully!"); } } catch (Exception ex) { Console.WriteLine("An unknown error occured, please try again"); Console.WriteLine(""); Console.WriteLine("ERROR DETAILS: {0}", ex.Message); return; } return; }