From acf711796755c789acb48a2c41f9f348b04ed1d7 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 22 Sep 2019 09:34:02 +0200 Subject: [PATCH] Added vWii and Korean common-key and Korea to TMD region --- README.md | 6 ++++++ ShowMiiWads/ShowMiiWads.csproj | 3 ++- ShowMiiWads/ShowMiiWads_Main.cs | 2 +- ShowMiiWads/Wii.cs | 20 ++++++++++++++++++-- libWiiSharp/CommonKey.cs | 6 ++++++ libWiiSharp/TMD.cs | 1 + libWiiSharp/Ticket.cs | 29 +++++++++++++++++++++++++++-- 7 files changed, 61 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2ca320e..20dfe36 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ Mod of showmiiwads-mod This is a modification of [showmiiwads-mod](https://code.google.com/archive/p/showmiiwads-mod/) by orwel. The original was coded by [Leathl](https://code.google.com/archive/p/showmiiwads/). ## Changelog +### v1.5.2 +* Backport my [libWiiSharp fixes](https://github.com/WiiDatabase/libWiiSharp/releases/tag/v0.31): + * Added vWii Common-Key: Decrypting and encrypting vWii titles is supported now (last one is untested) + * Added Korean Common-Key + * Add Korea to TMD region + ### v1.5.1 Important fixes to the WAD building process from NAND dumps: * Tickets are not faked with the "beer ticket" anymore diff --git a/ShowMiiWads/ShowMiiWads.csproj b/ShowMiiWads/ShowMiiWads.csproj index b6ca401..577113d 100644 --- a/ShowMiiWads/ShowMiiWads.csproj +++ b/ShowMiiWads/ShowMiiWads.csproj @@ -29,7 +29,7 @@ false true 0 - 1.5.1.%2a + 1.5.2.%2a false true true @@ -43,6 +43,7 @@ prompt 4 AllRules.ruleset + AnyCPU pdbonly diff --git a/ShowMiiWads/ShowMiiWads_Main.cs b/ShowMiiWads/ShowMiiWads_Main.cs index e117905..90e3606 100644 --- a/ShowMiiWads/ShowMiiWads_Main.cs +++ b/ShowMiiWads/ShowMiiWads_Main.cs @@ -40,7 +40,7 @@ namespace ShowMiiWads public partial class ShowMiiWads_Main : Form { //Define global variables - public const string version = "1.5.1"; + public const string version = "1.5.2"; private string language = "English"; private string langfile = ""; private string oldlang = ""; diff --git a/ShowMiiWads/Wii.cs b/ShowMiiWads/Wii.cs index 331174a..72586e3 100644 --- a/ShowMiiWads/Wii.cs +++ b/ShowMiiWads/Wii.cs @@ -1326,6 +1326,8 @@ public static byte[] GetTitleKey(byte[] wadtik) byte[] encryptedkey = new byte[16]; byte[] iv = new byte[16]; + byte[] ckey; + byte ckeyindex; int tikpos = 0; if (IsThisWad(wadtik) == true) @@ -1345,13 +1347,27 @@ public static byte[] GetTitleKey(byte[] wadtik) iv[j + 8] = 0x00; } + ckeyindex = wadtik[tikpos + 0x1f1]; + + switch (ckeyindex) + { + default: + ckey = libWiiSharp.CommonKey.GetStandardKey(); + break; + case 0x01: + ckey = libWiiSharp.CommonKey.GetKoreanKey(); + break; + case 0x02: + ckey = libWiiSharp.CommonKey.GetvWiiKey(); + break; + } + RijndaelManaged decrypt = new RijndaelManaged(); decrypt.Mode = CipherMode.CBC; decrypt.Padding = PaddingMode.None; decrypt.KeySize = 128; decrypt.BlockSize = 128; - //decrypt.Key = commonkey; - decrypt.Key = libWiiSharp.CommonKey.GetStandardKey(); + decrypt.Key = ckey; decrypt.IV = iv; ICryptoTransform cryptor = decrypt.CreateDecryptor(); diff --git a/libWiiSharp/CommonKey.cs b/libWiiSharp/CommonKey.cs index 0e7cc32..5116630 100644 --- a/libWiiSharp/CommonKey.cs +++ b/libWiiSharp/CommonKey.cs @@ -21,6 +21,7 @@ public class CommonKey { private static string standardKey = "ebe42a225e8593e448d9c5457381aaf7"; private static string koreanKey = "63b82bb4f4614e2e13f2fefbba4c9b7e"; + private static string vwiiKey = "30bfc76e7c19afbb23163330ced7c28d"; public static byte[] GetStandardKey() { @@ -31,5 +32,10 @@ public static byte[] GetKoreanKey() { return Shared.HexStringToByteArray(koreanKey); } + + public static byte[] GetvWiiKey() + { + return Shared.HexStringToByteArray(vwiiKey); + } } } diff --git a/libWiiSharp/TMD.cs b/libWiiSharp/TMD.cs index ff8d336..5824ae1 100644 --- a/libWiiSharp/TMD.cs +++ b/libWiiSharp/TMD.cs @@ -35,6 +35,7 @@ public enum Region : ushort USA = 1, Europe = 2, Free = 3, + Korea = 4, } public class TMD : IDisposable diff --git a/libWiiSharp/Ticket.cs b/libWiiSharp/Ticket.cs index 17997c8..d61c423 100644 --- a/libWiiSharp/Ticket.cs +++ b/libWiiSharp/Ticket.cs @@ -25,6 +25,7 @@ public enum CommonKeyType : byte { Standard = 0x00, Korean = 0x01, + vWii = 0x02, } public class Ticket : IDisposable @@ -532,7 +533,19 @@ private void parseTicket(Stream ticketFile) private void decryptTitleKey() { - byte[] ckey = (commonKeyIndex == 0x01) ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey(); + byte[] ckey; + switch (commonKeyIndex) + { + default: + ckey = CommonKey.GetStandardKey(); + break; + case 0x01: + ckey = CommonKey.GetKoreanKey(); + break; + case 0x02: + ckey = CommonKey.GetvWiiKey(); + break; + } byte[] iv = BitConverter.GetBytes(Shared.Swap(titleId)); Array.Resize(ref iv, 16); @@ -560,7 +573,19 @@ private void decryptTitleKey() private void encryptTitleKey() { commonKeyIndex = newKeyIndex; - byte[] ckey = (commonKeyIndex == 0x01) ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey(); + byte[] ckey = CommonKey.GetStandardKey(); + switch (commonKeyIndex) + { + default: + ckey = CommonKey.GetStandardKey(); + break; + case 0x01: + ckey = CommonKey.GetKoreanKey(); + break; + case 0x02: + ckey = CommonKey.GetvWiiKey(); + break; + } byte[] iv = BitConverter.GetBytes(Shared.Swap(titleId)); Array.Resize(ref iv, 16);