From 14bf607111040ad0f01ccec8030c0edfd16c431b Mon Sep 17 00:00:00 2001 From: Gustave Monce Date: Sat, 12 Oct 2024 17:14:06 +0200 Subject: [PATCH] Remove Defunct MSR Downloads --- WPinternals/CommandLine.cs | 519 +--------- .../Models/Lumia/MSR/LumiaDownloadModel.cs | 894 ------------------ .../UEFI/BootMgr/LumiaBootManagerPhoneInfo.cs | 1 - .../UEFI/Flash/LumiaFlashAppPhoneInfo.cs | 1 - WPinternals/ViewModels/DownloadsViewModel.cs | 104 +- .../ViewModels/LumiaV2UnlockBootViewModel.cs | 1 - .../ViewModels/PhoneNotifierViewModel.cs | 2 - WPinternals/ViewModels/SwitchModeViewModel.cs | 30 - 8 files changed, 54 insertions(+), 1498 deletions(-) diff --git a/WPinternals/CommandLine.cs b/WPinternals/CommandLine.cs index 88e8189..e55e671 100644 --- a/WPinternals/CommandLine.cs +++ b/WPinternals/CommandLine.cs @@ -32,7 +32,6 @@ using WPinternals.Models.Lumia.NCSd; using WPinternals.Models.UEFIApps.BootMgr; using WPinternals.Models.UEFIApps.Flash; -using WPinternals.Models.UEFIApps.PhoneInfo; namespace WPinternals { @@ -92,20 +91,14 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont PhoneNotifierViewModel Notifier; LumiaFlashAppModel FlashModel; LumiaBootManagerAppModel BootMgrModel; - LumiaPhoneInfoAppModel PhoneInfoModel; NokiaCareSuiteModel NormalModel; LumiaFlashAppPhoneInfo FlashInfo; - LumiaPhoneInfoAppPhoneInfo PhoneInfo; LumiaBootManagerPhoneInfo BootManagerInfo; string ProductType; - string ProductCode; - string OperatorCode; string DownloadFolder; string FFUFilePath; - string URL; string[] URLs; Uri URI; - string FFUFileName; string EmergencyFileName; string EmergencyFilePath; string ProgrammerPath = ""; @@ -1274,211 +1267,6 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont LogFile.Log("Root access enabled on image", LogType.FileAndConsole); break; - case "downloadffu": - LogFile.Log("Command: Download FFU", LogType.FileAndConsole); - Notifier = new PhoneNotifierViewModel(); - UIContext.Send(s => Notifier.Start(), null); - if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Normal) - { - NormalModel = (NokiaCareSuiteModel)Notifier.CurrentModel; - ProductCode = NormalModel.ExecuteJsonMethodAsString("ReadProductCode", "ProductCode"); - } - else if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Bootloader) - { - (Notifier.CurrentModel as LumiaBootManagerAppModel).SwitchToPhoneInfoAppContext(); - - if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_PhoneInfo) - { - await Notifier.WaitForArrival(); - } - - if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_PhoneInfo) - { - throw new WPinternalsException("Unexpected Mode"); - } - - PhoneInfoModel = (LumiaPhoneInfoAppModel)Notifier.CurrentModel; - PhoneInfo = PhoneInfoModel.ReadPhoneInfo(); - ProductCode = PhoneInfo.ProductCode; - } - else if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_PhoneInfo) - { - PhoneInfoModel = (LumiaPhoneInfoAppModel)Notifier.CurrentModel; - PhoneInfo = PhoneInfoModel.ReadPhoneInfo(); - ProductCode = PhoneInfo.ProductCode; - } - else if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Flash) - { - bool ModernFlashApp = ((LumiaFlashAppModel)Notifier.CurrentModel).ReadPhoneInfo().FlashAppProtocolVersionMajor >= 2; - if (ModernFlashApp) - { - ((LumiaFlashAppModel)Notifier.CurrentModel).SwitchToPhoneInfoAppContext(); - } - else - { - ((LumiaFlashAppModel)Notifier.CurrentModel).SwitchToPhoneInfoAppContextLegacy(); - } - - if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_PhoneInfo) - { - await Notifier.WaitForArrival(); - } - - if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_PhoneInfo) - { - throw new WPinternalsException("Unexpected Mode"); - } - - PhoneInfoModel = (LumiaPhoneInfoAppModel)Notifier.CurrentModel; - PhoneInfo = PhoneInfoModel.ReadPhoneInfo(); - ProductCode = PhoneInfo.ProductCode; - } - else - { - NormalModel = (NokiaCareSuiteModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Normal); - ProductCode = NormalModel.ExecuteJsonMethodAsString("ReadProductCode", "ProductCode"); - } - URL = LumiaDownloadModel.SearchFFU(null, ProductCode, null, out ProductType); - DownloadFolder = args.Length >= 3 - ? args[4] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - Notifier.Stop(); - break; - case "downloadffubyoperatorcode": - LogFile.Log("Command: Download FFU by Operator Code", LogType.FileAndConsole); - if (args.Length < 4) - { - throw new ArgumentException("Wrong number of arguments. Usage: WPinternals.exe -DownloadFFUbyOperatorCode "); - } - - ProductType = args[2]; - LogFile.Log("Product type: " + ProductType, LogType.FileAndConsole); - OperatorCode = args[3]; - LogFile.Log("Operator code: " + OperatorCode, LogType.FileAndConsole); - DownloadFolder = args.Length >= 5 - ? args[4] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - URL = LumiaDownloadModel.SearchFFU(ProductType, null, OperatorCode); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - break; - case "downloadffubyproductcode": - LogFile.Log("Command: Download FFU by Product Code", LogType.FileAndConsole); - if (args.Length < 3) - { - throw new ArgumentException("Wrong number of arguments. Usage: WPinternals.exe -DownloadFFUbyProductCode "); - } - - ProductCode = args[2]; - LogFile.Log("Product code: " + ProductCode, LogType.FileAndConsole); - URL = LumiaDownloadModel.SearchFFU(null, ProductCode, null, out ProductType); - DownloadFolder = args.Length >= 4 - ? args[3] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - break; - case "downloadffubyproducttype": - LogFile.Log("Command: Download FFU by Product Type", LogType.FileAndConsole); - if (args.Length < 3) - { - throw new ArgumentException("Wrong number of arguments. Usage: WPinternals.exe -DownloadFFUbyProductType "); - } - - ProductType = args[2]; - LogFile.Log("Product type: " + ProductType, LogType.FileAndConsole); - DownloadFolder = args.Length >= 4 - ? args[3] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - URL = LumiaDownloadModel.SearchFFU(ProductType, null, null); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - break; - case "searchffubyproducttype": - LogFile.Log("Command: Search FFU by Product Type", LogType.FileAndConsole); - if (args.Length < 3) - { - throw new ArgumentException("Wrong number of arguments. Usage: WPinternals.exe -SearchFFUbyProductType "); - } - - ProductType = args[2]; - LogFile.Log("Lumia model: " + ProductType, LogType.FileAndConsole); - URL = LumiaDownloadModel.SearchFFU(ProductType, null, null); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - break; case "downloademergency": LogFile.Log("Command: Download Emergency files", LogType.FileAndConsole); Notifier = new PhoneNotifierViewModel(); @@ -1609,28 +1397,36 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Normal) { NormalModel = (NokiaCareSuiteModel)Notifier.CurrentModel; - ProductCode = NormalModel.ExecuteJsonMethodAsString("ReadProductCode", "ProductCode"); + ProductType = NormalModel.ExecuteJsonMethodAsString("ReadManufacturerModelName", "ManufacturerModelName"); + if (ProductType.Contains('_')) + { + ProductType = ProductType.Substring(0, ProductType.IndexOf('_')); + } } else if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Bootloader) { BootMgrModel = (LumiaBootManagerAppModel)Notifier.CurrentModel; BootManagerInfo = BootMgrModel.ReadPhoneInfo(); - //ProductCode = BootManagerInfo.ProductCode; // TODO: FIXME - ProductCode = ""; + //ProductType = BootManagerInfo.Type; // TODO: FIXME + ProductType = ""; } else if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Flash) { FlashModel = (LumiaFlashAppModel)Notifier.CurrentModel; FlashInfo = FlashModel.ReadPhoneInfo(); - //ProductCode = FlashInfo.ProductCode; // TODO: FIXME - ProductCode = ""; + //ProductType = FlashInfo.Type; // TODO: FIXME + ProductType = ""; } else { NormalModel = (NokiaCareSuiteModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Normal); - ProductCode = NormalModel.ExecuteJsonMethodAsString("ReadProductCode", "ProductCode"); + ProductType = NormalModel.ExecuteJsonMethodAsString("ReadManufacturerModelName", "ManufacturerModelName"); + if (ProductType.Contains('_')) + { + ProductType = ProductType.Substring(0, ProductType.IndexOf('_')); + } } - URL = LumiaDownloadModel.SearchFFU(null, ProductCode, null, out ProductType); + DownloadFolder = args.Length >= 3 ? args[2] : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); @@ -1640,20 +1436,6 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont Directory.CreateDirectory(DownloadFolder); } - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - URLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); if (URLs != null) { @@ -1685,36 +1467,7 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) { - ProductType = "RM-1085"; - - URL = LumiaDownloadModel.SearchFFU(ProductType, null, null); - DownloadFolder = args.Length >= 3 - ? args[2] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - - if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) - { - throw new WPinternalsException("Unable to find compatible FFU", "No donor-FFU has been found in the repository with a supported OS version. You can add a donor-FFU within the download section of the tool or by using the command line. A donor-FFU can be for a different device and a different CPU than your device. It is only used to gather Operating System specific binaries to be patched and used as part of the unlock process."); - } + throw new WPinternalsException("Unable to find compatible FFU", "No donor-FFU has been found in the repository with a supported OS version. You can add a donor-FFU within the download section of the tool or by using the command line. A donor-FFU can be for a different device and a different CPU than your device. It is only used to gather Operating System specific binaries to be patched and used as part of the unlock process."); } Notifier.Stop(); break; @@ -1736,117 +1489,6 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont Directory.CreateDirectory(DownloadFolder); } - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - URL = LumiaDownloadModel.SearchFFU(ProductType, null, null); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - - URLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); - if (URLs != null) - { - for (int i = 0; i < URLs.Length; i++) - { - LogFile.Log("URL: " + URLs[i], LogType.FileAndConsole); - URI = new Uri(URLs[i]); - EmergencyFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + EmergencyFileName, LogType.FileAndConsole); - EmergencyFilePath = Path.Combine(DownloadFolder, EmergencyFileName); - if (i == 0) - { - ProgrammerPath = EmergencyFilePath; - } - else - { - PayloadPath = EmergencyFilePath; - } - - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URLs[i], EmergencyFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - } - App.Config.AddEmergencyToRepository(ProductType, ProgrammerPath, PayloadPath); - } - - if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) - { - ProductType = "RM-1085"; - - URL = LumiaDownloadModel.SearchFFU(ProductType, null, null); - DownloadFolder = args.Length >= 4 - ? args[3] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - - if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) - { - throw new WPinternalsException("Unable to find compatible FFU", "No donor-FFU has been found in the repository with a supported OS version. You can add a donor-FFU within the download section of the tool or by using the command line. A donor-FFU can be for a different device and a different CPU than your device. It is only used to gather Operating System specific binaries to be patched and used as part of the unlock process."); - } - } - break; - case "downloadallbyproductcode": - LogFile.Log("Command: Download all by Product Code", LogType.FileAndConsole); - if (args.Length < 3) - { - throw new ArgumentException("Wrong number of arguments. Usage: WPinternals.exe -DownloadAllByProductCode "); - } - - ProductCode = args[2]; - LogFile.Log("Product code: " + ProductCode, LogType.FileAndConsole); - URL = LumiaDownloadModel.SearchFFU(null, ProductCode, null, out ProductType); - DownloadFolder = args.Length >= 4 - ? args[3] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - URLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); if (URLs != null) { @@ -1878,134 +1520,7 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) { - ProductType = "RM-1085"; - - URL = LumiaDownloadModel.SearchFFU(ProductType, null, null); - DownloadFolder = args.Length >= 4 - ? args[3] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - - if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) - { - throw new WPinternalsException("Unable to find compatible FFU", "No donor-FFU has been found in the repository with a supported OS version. You can add a donor-FFU within the download section of the tool or by using the command line. A donor-FFU can be for a different device and a different CPU than your device. It is only used to gather Operating System specific binaries to be patched and used as part of the unlock process."); - } - } - break; - case "downloadallbyoperatorcode": - LogFile.Log("Command: Download FFU by Operator Code", LogType.FileAndConsole); - if (args.Length < 4) - { - throw new ArgumentException("Wrong number of arguments. Usage: WPinternals.exe -DownloadFFUbyOperatorCode "); - } - - ProductType = args[2]; - LogFile.Log("Product type: " + ProductType, LogType.FileAndConsole); - OperatorCode = args[3]; - LogFile.Log("Operator code: " + OperatorCode, LogType.FileAndConsole); - DownloadFolder = args.Length >= 5 - ? args[4] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - URL = LumiaDownloadModel.SearchFFU(ProductType, null, OperatorCode); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - - URLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); - if (URLs != null) - { - for (int i = 0; i < URLs.Length; i++) - { - LogFile.Log("URL: " + URLs[i], LogType.FileAndConsole); - URI = new Uri(URLs[i]); - EmergencyFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + EmergencyFileName, LogType.FileAndConsole); - EmergencyFilePath = Path.Combine(DownloadFolder, EmergencyFileName); - if (i == 0) - { - ProgrammerPath = EmergencyFilePath; - } - else - { - PayloadPath = EmergencyFilePath; - } - - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URLs[i], EmergencyFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - } - App.Config.AddEmergencyToRepository(ProductType, ProgrammerPath, PayloadPath); - } - - if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) - { - ProductType = "RM-1085"; - - URL = LumiaDownloadModel.SearchFFU(ProductType, null, null); - DownloadFolder = args.Length >= 5 - ? args[4] - : Environment.ExpandEnvironmentVariables("%ALLUSERSPROFILE%\\WPInternals\\Repository\\" + ProductType.ToUpper()); - - if (!Directory.Exists(DownloadFolder)) - { - Directory.CreateDirectory(DownloadFolder); - } - - LogFile.Log("Download folder: " + DownloadFolder, LogType.FileAndConsole); - LogFile.Log("URL: " + URL, LogType.FileAndConsole); - URI = new Uri(URL); - FFUFileName = Path.GetFileName(URI.LocalPath); - LogFile.Log("File: " + FFUFileName, LogType.FileAndConsole); - FFUFilePath = Path.Combine(DownloadFolder, FFUFileName); - LogFile.Log("Downloading...", LogType.FileAndConsole); - using (System.Net.WebClient myWebClient = new()) - { - await myWebClient.DownloadFileTaskAsync(URL, FFUFilePath); - } - LogFile.Log("Download finished", LogType.FileAndConsole); - App.Config.AddFfuToRepository(FFUFilePath); - - if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) - { - throw new WPinternalsException("Unable to find compatible FFU", "No donor-FFU has been found in the repository with a supported OS version. You can add a donor-FFU within the download section of the tool or by using the command line. A donor-FFU can be for a different device and a different CPU than your device. It is only used to gather Operating System specific binaries to be patched and used as part of the unlock process."); - } + throw new WPinternalsException("Unable to find compatible FFU", "No donor-FFU has been found in the repository with a supported OS version. You can add a donor-FFU within the download section of the tool or by using the command line. A donor-FFU can be for a different device and a different CPU than your device. It is only used to gather Operating System specific binaries to be patched and used as part of the unlock process."); } break; case "rewritepartitionsfrommassstorage": diff --git a/WPinternals/Models/Lumia/MSR/LumiaDownloadModel.cs b/WPinternals/Models/Lumia/MSR/LumiaDownloadModel.cs index 985c29e..41ab8f5 100644 --- a/WPinternals/Models/Lumia/MSR/LumiaDownloadModel.cs +++ b/WPinternals/Models/Lumia/MSR/LumiaDownloadModel.cs @@ -18,300 +18,15 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Json; -using System.Text; -using System.Threading.Tasks; using System.Xml; -using System.Xml.Serialization; using WPinternals.HelperClasses; namespace WPinternals.Models.Lumia.MSR { internal static class LumiaDownloadModel { - internal static string SearchFFU(string ProductType, string ProductCode, string OperatorCode) - { - return SearchFFU(ProductType, ProductCode, OperatorCode, out string FoundProductType); - } - - internal static string SearchFFU(string ProductType, string ProductCode, string OperatorCode, out string FoundProductType) - { - if (ProductType?.Length == 0) - { - ProductType = null; - } - - if (ProductCode?.Length == 0) - { - ProductCode = null; - } - - if (OperatorCode?.Length == 0) - { - OperatorCode = null; - } - - if (ProductCode != null) - { - ProductCode = ProductCode.ToUpper(); - ProductType = null; - OperatorCode = null; - } - if (ProductType != null) - { - ProductType = ProductType.ToUpper(); - if (ProductType.StartsWith("RM") && !ProductType.StartsWith("RM-")) - { - ProductType = "RM-" + ProductType[2..]; - } - } - if (OperatorCode != null) - { - OperatorCode = OperatorCode.ToUpper(); - } - - DiscoveryQueryParameters DiscoveryQueryParams = new() - { - manufacturerName = "Microsoft", - manufacturerProductLine = "Lumia", - packageType = "Firmware", - packageClass = "Public", - manufacturerHardwareModel = ProductType, - manufacturerHardwareVariant = ProductCode, - operatorName = OperatorCode - }; - DiscoveryParameters DiscoveryParams = new() - { - query = DiscoveryQueryParams - }; - - DataContractJsonSerializer Serializer1 = new(typeof(DiscoveryParameters)); - MemoryStream JsonStream1 = new(); - Serializer1.WriteObject(JsonStream1, DiscoveryParams); - JsonStream1.Seek(0L, SeekOrigin.Begin); - string JsonContent = new StreamReader(JsonStream1).ReadToEnd(); - - Uri RequestUri = new("https://api.swrepository.com/rest-api/discovery/1/package"); - - HttpClient HttpClient = new(); - HttpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("SoftwareRepository"); - HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - - Task HttpPostTask = HttpClient.PostAsync(RequestUri, new StringContent(JsonContent, Encoding.UTF8, "application/json")); - HttpPostTask.Wait(); - HttpResponseMessage Response = HttpPostTask.Result; - - string JsonResultString = ""; - if (Response.StatusCode == HttpStatusCode.OK) - { - Task ReadResponseTask = Response.Content.ReadAsStringAsync(); - ReadResponseTask.Wait(); - JsonResultString = ReadResponseTask.Result; - } - - SoftwarePackage Package = null; - using (MemoryStream JsonStream2 = new(Encoding.UTF8.GetBytes(JsonResultString))) - { - DataContractJsonSerializer Serializer2 = new(typeof(SoftwarePackages)); - SoftwarePackages SoftwarePackages = (SoftwarePackages)Serializer2.ReadObject(JsonStream2); - if (SoftwarePackages != null) - { - Package = SoftwarePackages.softwarePackages.FirstOrDefault(); - } - } - - if (Package == null) - { - throw new WPinternalsException("FFU not found", "No FFU has been found in the remote software repository for the requested model."); - } - - FoundProductType = Package.manufacturerHardwareModel[0]; - - SoftwareFile FileInfo = Package.files.First(f => f.fileName.EndsWith(".ffu", StringComparison.OrdinalIgnoreCase)); - - Uri FileInfoUri = new("https://api.swrepository.com/rest-api/discovery/fileurl/1/" + Package.id + "/" + FileInfo.fileName); - Task GetFileInfoTask = HttpClient.GetStringAsync(FileInfoUri); - GetFileInfoTask.Wait(); - string FileInfoString = GetFileInfoTask.Result; - - string FfuUrl = ""; - FileUrlResult FileUrl = null; - using (MemoryStream JsonStream3 = new(Encoding.UTF8.GetBytes(FileInfoString))) - { - DataContractJsonSerializer Serializer3 = new(typeof(FileUrlResult)); - FileUrl = (FileUrlResult)Serializer3.ReadObject(JsonStream3); - if (FileUrl != null) - { - FfuUrl = FileUrl.url.Replace("sr.azureedge.net", "softwarerepo.blob.core.windows.net"); - } - } - - HttpClient.Dispose(); - - return FfuUrl; - } - - internal static (string SecureWIMUrl, string DPLUrl) SearchENOSW(string ProductType, string PhoneFirmwareRevision) - { - if (ProductType?.Length == 0) - { - ProductType = null; - } - - if (ProductType != null) - { - ProductType = ProductType.ToUpper(); - if (ProductType.StartsWith("RM") && !ProductType.StartsWith("RM-")) - { - ProductType = $"RM-{ProductType[2..]}"; - } - } - - DiscoveryQueryParameters DiscoveryQueryParams = new() - { - manufacturerName = "Microsoft", - manufacturerProductLine = "Lumia", - packageType = "Test Mode", - packageClass = "Public", - manufacturerHardwareModel = ProductType - }; - - DiscoveryParameters DiscoveryParams = new() - { - query = DiscoveryQueryParams - }; - - DataContractJsonSerializer Serializer1 = new(typeof(DiscoveryParameters)); - MemoryStream JsonStream1 = new(); - Serializer1.WriteObject(JsonStream1, DiscoveryParams); - JsonStream1.Seek(0L, SeekOrigin.Begin); - string JsonContent = new StreamReader(JsonStream1).ReadToEnd(); - - Uri RequestUri = new("https://api.swrepository.com/rest-api/discovery/1/package"); - - HttpClient HttpClient = new(); - HttpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("SoftwareRepository"); - HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - - Task HttpPostTask = HttpClient.PostAsync(RequestUri, new StringContent(JsonContent, Encoding.UTF8, "application/json")); - HttpPostTask.Wait(); - HttpResponseMessage Response = HttpPostTask.Result; - - string JsonResultString = ""; - if (Response.StatusCode == HttpStatusCode.OK) - { - Task ReadResponseTask = Response.Content.ReadAsStringAsync(); - ReadResponseTask.Wait(); - JsonResultString = ReadResponseTask.Result; - } - - SoftwarePackage Package = null; - using MemoryStream JsonResultStream = new(Encoding.UTF8.GetBytes(JsonResultString)); - DataContractJsonSerializer SoftwarePackagesJsonSerializer = new(typeof(SoftwarePackages)); - SoftwarePackages SoftwarePackages = (SoftwarePackages)SoftwarePackagesJsonSerializer.ReadObject(JsonResultStream); - - if (SoftwarePackages != null) - { - foreach (SoftwarePackage pkg in SoftwarePackages.softwarePackages) - { - Package = SoftwarePackages.softwarePackages.FirstOrDefault(); - } - } - - if (Package == null) - { - throw new WPinternalsException("ENOSW package not found", "No ENOSW package has been found in the remote software repository for the requested model."); - } - - SoftwareFile SecureWimSoftwareFile = Package.files.First(f => f.fileName.EndsWith(".secwim", StringComparison.OrdinalIgnoreCase)); - SoftwareFile DPLSoftwareFile = Package.files.First(f => f.fileName.EndsWith(".dpl", StringComparison.OrdinalIgnoreCase)); - - Uri DPLFileUrlUri = new($"https://api.swrepository.com/rest-api/discovery/fileurl/1/{Package.id}/{DPLSoftwareFile.fileName}"); - - Task GetDPLTask = HttpClient.GetStringAsync(DPLFileUrlUri); - GetDPLTask.Wait(); - - string DPLFileUrlResultContent = GetDPLTask.Result; - FileUrlResult DPLFileUrlResult = null; - using MemoryStream DPLFileUrlResultStream = new(Encoding.UTF8.GetBytes(DPLFileUrlResultContent)); - DataContractJsonSerializer DPLFileUrlResultSerializer = new(typeof(FileUrlResult)); - DPLFileUrlResult = (FileUrlResult)DPLFileUrlResultSerializer.ReadObject(DPLFileUrlResultStream); - - string DPLFileUrl = ""; - - if (DPLFileUrlResult != null) - { - DPLFileUrl = DPLFileUrlResult.url.Replace("sr.azureedge.net", "softwarerepo.blob.core.windows.net"); - } - - if (DPLFileUrl?.Length == 0) - { - throw new WPinternalsException("DPL not found", "No DPL has been found in the remote software repository for the requested model."); - } - - Task GetDPLStrTask = HttpClient.GetStringAsync(DPLFileUrl); - GetDPLStrTask.Wait(); - string DPLStrString = GetDPLStrTask.Result; - - DPL.Package dpl; - XmlSerializer serializer = new(typeof(DPL.Package)); - using StringReader reader = new(DPLStrString.Replace("ft:", "").Replace("dpl:", "").Replace("typedes:", "")); - dpl = (DPL.Package)serializer.Deserialize(reader); - - foreach (DPL.File file in dpl.Content.Files.File) - { - string name = file.Name; - - DPL.Range range = file.Extensions.MmosWimFile.UseCaseCompatibilities.Compatibility.FirstOrDefault().Range; - - if (IsFirmwareBetween(PhoneFirmwareRevision, range.From, range.To)) - { - SecureWimSoftwareFile = Package.files.First(f => f.fileName.EndsWith(name, StringComparison.OrdinalIgnoreCase)); - } - } - - Uri FileInfoUri = new("https://api.swrepository.com/rest-api/discovery/fileurl/1/" + Package.id + "/" + SecureWimSoftwareFile.fileName); - Task GetFileInfoTask = HttpClient.GetStringAsync(FileInfoUri); - GetFileInfoTask.Wait(); - string FileInfoString = GetFileInfoTask.Result; - - string ENOSWFileUrl = ""; - - FileUrlResult FileUrl = null; - - using MemoryStream JsonStream4 = new(Encoding.UTF8.GetBytes(FileInfoString)); - DataContractJsonSerializer Serializer4 = new(typeof(FileUrlResult)); - FileUrl = (FileUrlResult)Serializer4.ReadObject(JsonStream4); - if (FileUrl != null) - { - ENOSWFileUrl = FileUrl.url.Replace("sr.azureedge.net", "softwarerepo.blob.core.windows.net"); - } - - HttpClient.Dispose(); - - return (ENOSWFileUrl, DPLFileUrl); - } - - private static bool IsFirmwareBetween(string PhoneFirmwareRevision, string Limit1, string Limit2) - { - Version version = new Version(PhoneFirmwareRevision); - Version version1 = new Version(Limit1); - Version version2 = new Version(Limit2); - - int result = version.CompareTo(version1); - int result2 = version.CompareTo(version2); - - return result >= 0 && result2 <= 0; - } - internal static string[] SearchEmergencyFiles(string ProductType) { ProductType = ProductType.ToUpper(); @@ -389,613 +104,4 @@ internal static string[] SearchEmergencyFiles(string ProductType) return [.. Result]; } } - -#pragma warning disable 0649 - [DataContract] - internal class FileUrlResult - { - [DataMember] - internal string url; - - [DataMember] - internal List alternateUrl; - - [DataMember] - internal long fileSize; - - [DataMember] - internal List checksum; - } -#pragma warning restore 0649 - - [DataContract] - public class DiscoveryQueryParameters - { - [DataMember(EmitDefaultValue = false)] - public string customerName; - - [DataMember(EmitDefaultValue = false)] - public ExtendedAttributes extendedAttributes; - - [DataMember(EmitDefaultValue = false)] - public string manufacturerHardwareModel; - - [DataMember(EmitDefaultValue = false)] - public string manufacturerHardwareVariant; - - [DataMember(EmitDefaultValue = false)] - public string manufacturerModelName; - - [DataMember] - public string manufacturerName; - - [DataMember(EmitDefaultValue = false)] - public string manufacturerPackageId; - - [DataMember(EmitDefaultValue = false)] - public string manufacturerPlatformId; - - [DataMember] - public string manufacturerProductLine; - - [DataMember(EmitDefaultValue = false)] - public string manufacturerVariantName; - - [DataMember(EmitDefaultValue = false)] - public string operatorName; - - [DataMember] - public string packageClass; - - [DataMember(EmitDefaultValue = false)] - public string packageRevision; - - [DataMember(EmitDefaultValue = false)] - public string packageState; - - [DataMember(EmitDefaultValue = false)] - public string packageSubRevision; - - [DataMember(EmitDefaultValue = false)] - public string packageSubtitle; - - [DataMember(EmitDefaultValue = false)] - public string packageTitle; - - [DataMember] - public string packageType; - } - - [DataContract] - public class DiscoveryParameters - { - [DataMember(Name = "api-version")] - public string apiVersion; - - [DataMember] - public DiscoveryQueryParameters query; - - [DataMember] - public List condition; - - [DataMember] - public List response; - - public DiscoveryParameters() : this(DiscoveryCondition.Default) - { - } - - public DiscoveryParameters(DiscoveryCondition Condition) - { - apiVersion = "1"; - query = new DiscoveryQueryParameters(); - condition = []; - if (Condition == DiscoveryCondition.All) - { - condition.Add("all"); - return; - } - if (Condition == DiscoveryCondition.Latest) - { - condition.Add("latest"); - return; - } - condition.Add("default"); - } - } - - public enum DiscoveryCondition - { - Default, - All, - Latest - } - - [Serializable] - public class ExtendedAttributes : ISerializable - { - public Dictionary Dictionary; - - public ExtendedAttributes() - { - Dictionary = []; - } - - protected ExtendedAttributes(SerializationInfo info, StreamingContext context) - { - if (info != null) - { - Dictionary = []; - SerializationInfoEnumerator Enumerator = info.GetEnumerator(); - while (Enumerator.MoveNext()) - { - Dictionary.Add(Enumerator.Current.Name, (string)Enumerator.Current.Value); - } - } - } - - public virtual void GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info != null) - { - foreach (string Current in Dictionary.Keys) - { - info.AddValue(Current, Dictionary[Current]); - } - } - } - } - - [DataContract] - public class SoftwareFileChecksum - { - [DataMember] - public string type; - - [DataMember] - public string value; - } - - [DataContract] - public class SoftwarePackages - { - [DataMember] - public List softwarePackages; - } - - [DataContract] - public class SoftwarePackage - { - [DataMember] - public List customerName; - - [DataMember] - public ExtendedAttributes extendedAttributes; - - [DataMember] - public List files; - - [DataMember] - public string id; - - [DataMember] - public List manufacturerHardwareModel; - - [DataMember] - public List manufacturerHardwareVariant; - - [DataMember] - public List manufacturerModelName; - - [DataMember] - public string manufacturerName; - - [DataMember] - public string manufacturerPackageId; - - [DataMember] - public List manufacturerPlatformId; - - [DataMember] - public string manufacturerProductLine; - - [DataMember] - public List manufacturerVariantName; - - [DataMember] - public List operatorName; - - [DataMember] - public List packageClass; - - [DataMember] - public string packageDescription; - - [DataMember] - public string packageRevision; - - [DataMember] - public string packageState; - - [DataMember] - public string packageSubRevision; - - [DataMember] - public string packageSubtitle; - - [DataMember] - public string packageTitle; - - [DataMember] - public string packageType; - } - - [DataContract] - public class SoftwareFile - { - [DataMember] - public List checksum; - - [DataMember] - public string fileName; - - [DataMember] - public long fileSize; - - [DataMember] - public string fileType; - } - - public static class DPL - { - [XmlRoot(ElementName = "BasicProductCodes")] - public class BasicProductCodes - { - [XmlElement(ElementName = "BasicProductCode")] - public List BasicProductCode - { - get; set; - } - } - - [XmlRoot(ElementName = "Identification")] - public class Identification - { - [XmlElement(ElementName = "TypeDesignator")] - public string TypeDesignator - { - get; set; - } - [XmlElement(ElementName = "BasicProductCodes")] - public BasicProductCodes BasicProductCodes - { - get; set; - } - [XmlElement(ElementName = "Purpose")] - public string Purpose - { - get; set; - } - } - - [XmlRoot(ElementName = "Extensions")] - public class Extensions - { - [XmlElement(ElementName = "PackageType")] - public string PackageType - { - get; set; - } - [XmlElement(ElementName = "Identification")] - public Identification Identification - { - get; set; - } - [XmlElement(ElementName = "FileType")] - public string FileType - { - get; set; - } - [XmlElement(ElementName = "MmosWimFile")] - public MmosWimFile MmosWimFile - { - get; set; - } - } - - [XmlRoot(ElementName = "PackageDescription")] - public class PackageDescription - { - [XmlElement(ElementName = "Identifier")] - public string Identifier - { - get; set; - } - [XmlElement(ElementName = "Revision")] - public string Revision - { - get; set; - } - [XmlElement(ElementName = "Extensions")] - public Extensions Extensions - { - get; set; - } - } - - [XmlRoot(ElementName = "Digest")] - public class Digest - { - [XmlAttribute(AttributeName = "method")] - public string Method - { - get; set; - } - [XmlAttribute(AttributeName = "encoding")] - public string Encoding - { - get; set; - } - [XmlText] - public string Text - { - get; set; - } - } - - [XmlRoot(ElementName = "Digests")] - public class Digests - { - [XmlElement(ElementName = "Digest")] - public List Digest - { - get; set; - } - } - - [XmlRoot(ElementName = "Range")] - public class Range - { - [XmlAttribute(AttributeName = "from")] - public string From - { - get; set; - } - [XmlAttribute(AttributeName = "to")] - public string To - { - get; set; - } - } - - [XmlRoot(ElementName = "Compatibility")] - public class Compatibility - { - [XmlElement(ElementName = "Range")] - public Range Range - { - get; set; - } - [XmlAttribute(AttributeName = "useCase")] - public string UseCase - { - get; set; - } - } - - [XmlRoot(ElementName = "UseCaseCompatibilities")] - public class UseCaseCompatibilities - { - [XmlElement(ElementName = "Compatibility")] - public List Compatibility - { - get; set; - } - } - - [XmlRoot(ElementName = "MmosWimFile")] - public class MmosWimFile - { - [XmlElement(ElementName = "UseCaseCompatibilities")] - public UseCaseCompatibilities UseCaseCompatibilities - { - get; set; - } - } - - [XmlRoot(ElementName = "File")] - public class File - { - [XmlElement(ElementName = "Name")] - public string Name - { - get; set; - } - [XmlElement(ElementName = "Digests")] - public Digests Digests - { - get; set; - } - [XmlElement(ElementName = "Revision")] - public string Revision - { - get; set; - } - [XmlElement(ElementName = "Extensions")] - public Extensions Extensions - { - get; set; - } - } - - [XmlRoot(ElementName = "Files")] - public class Files - { - [XmlElement(ElementName = "File")] - public List File - { - get; set; - } - } - - [XmlRoot(ElementName = "Content")] - public class Content - { - [XmlElement(ElementName = "PackageDescription")] - public PackageDescription PackageDescription - { - get; set; - } - [XmlElement(ElementName = "Files")] - public Files Files - { - get; set; - } - } - - [XmlRoot(ElementName = "CanonicalizationMethod", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class CanonicalizationMethod - { - [XmlAttribute(AttributeName = "Algorithm")] - public string Algorithm - { - get; set; - } - } - - [XmlRoot(ElementName = "SignatureMethod", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class SignatureMethod - { - [XmlAttribute(AttributeName = "Algorithm")] - public string Algorithm - { - get; set; - } - } - - [XmlRoot(ElementName = "Transform", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class Transform - { - [XmlAttribute(AttributeName = "Algorithm")] - public string Algorithm - { - get; set; - } - } - - [XmlRoot(ElementName = "Transforms", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class Transforms - { - [XmlElement(ElementName = "Transform", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public Transform Transform - { - get; set; - } - } - - [XmlRoot(ElementName = "DigestMethod", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class DigestMethod - { - [XmlAttribute(AttributeName = "Algorithm")] - public string Algorithm - { - get; set; - } - } - - [XmlRoot(ElementName = "Reference", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class Reference - { - [XmlElement(ElementName = "Transforms", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public Transforms Transforms - { - get; set; - } - [XmlElement(ElementName = "DigestMethod", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public DigestMethod DigestMethod - { - get; set; - } - [XmlElement(ElementName = "DigestValue", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public string DigestValue - { - get; set; - } - [XmlAttribute(AttributeName = "URI")] - public string URI - { - get; set; - } - } - - [XmlRoot(ElementName = "SignedInfo", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class SignedInfo - { - [XmlElement(ElementName = "CanonicalizationMethod", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public CanonicalizationMethod CanonicalizationMethod - { - get; set; - } - [XmlElement(ElementName = "SignatureMethod", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public SignatureMethod SignatureMethod - { - get; set; - } - [XmlElement(ElementName = "Reference", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public Reference Reference - { - get; set; - } - } - - [XmlRoot(ElementName = "KeyInfo", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class KeyInfo - { - [XmlElement(ElementName = "KeyName", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public string KeyName - { - get; set; - } - } - - [XmlRoot(ElementName = "Signature", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public class Signature - { - [XmlElement(ElementName = "SignedInfo", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public SignedInfo SignedInfo - { - get; set; - } - [XmlElement(ElementName = "SignatureValue", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public string SignatureValue - { - get; set; - } - [XmlElement(ElementName = "KeyInfo", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public KeyInfo KeyInfo - { - get; set; - } - [XmlAttribute(AttributeName = "xmlns")] - public string Xmlns - { - get; set; - } - } - - [XmlRoot(ElementName = "Package")] - public class Package - { - [XmlElement(ElementName = "Content")] - public Content Content - { - get; set; - } - [XmlElement(ElementName = "Signature", Namespace = "http://www.w3.org/2000/09/xmldsig#")] - public Signature Signature - { - get; set; - } - } - } } diff --git a/WPinternals/Models/Lumia/UEFI/BootMgr/LumiaBootManagerPhoneInfo.cs b/WPinternals/Models/Lumia/UEFI/BootMgr/LumiaBootManagerPhoneInfo.cs index 0e8dbb3..c3fe9b7 100644 --- a/WPinternals/Models/Lumia/UEFI/BootMgr/LumiaBootManagerPhoneInfo.cs +++ b/WPinternals/Models/Lumia/UEFI/BootMgr/LumiaBootManagerPhoneInfo.cs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; using WPinternals.HelperClasses; using WPinternals.Models.Lumia.UEFI; diff --git a/WPinternals/Models/Lumia/UEFI/Flash/LumiaFlashAppPhoneInfo.cs b/WPinternals/Models/Lumia/UEFI/Flash/LumiaFlashAppPhoneInfo.cs index c3466d5..9671228 100644 --- a/WPinternals/Models/Lumia/UEFI/Flash/LumiaFlashAppPhoneInfo.cs +++ b/WPinternals/Models/Lumia/UEFI/Flash/LumiaFlashAppPhoneInfo.cs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; using WPinternals.HelperClasses; using WPinternals.Models.Lumia.UEFI; diff --git a/WPinternals/ViewModels/DownloadsViewModel.cs b/WPinternals/ViewModels/DownloadsViewModel.cs index b7333d8..71a96d5 100644 --- a/WPinternals/ViewModels/DownloadsViewModel.cs +++ b/WPinternals/ViewModels/DownloadsViewModel.cs @@ -93,6 +93,42 @@ internal DownloadsViewModel(PhoneNotifierViewModel Notifier) LastStatusText = null; } }); + + AddSecWIMCommand = new DelegateCommand(() => + { + string SecWIMPath = null; + + OpenFileDialog dlg = new(); + dlg.DefaultExt = ".secwim"; // Default file extension + dlg.Filter = "Secure WIM images (.secwim)|*.secwim"; // Filter files by extension + + bool? result = dlg.ShowDialog(); + + if (result == true) + { + SecWIMPath = dlg.FileName; + string SecWIMFile = Path.GetFileName(SecWIMPath); + + try + { + App.Config.AddSecWimToRepository(SecWIMPath, FirmwareVersion); + App.Config.WriteConfig(); + LastStatusText = $"File \"{SecWIMFile}\" was added to the repository."; + } + catch (WPinternalsException Ex) + { + LastStatusText = $"Error: {Ex.Message}. File \"{SecWIMFile}\" was not added."; + } + catch + { + LastStatusText = $"Error: File \"{SecWIMFile}\" was not added."; + } + } + else + { + LastStatusText = null; + } + }); } private string _LastStatusText = null; @@ -192,9 +228,7 @@ private void Search() new Thread(() => { - string FFUURL = null; string[] EmergencyURLs = null; - string SecureWIMURL = null; try { @@ -206,16 +240,6 @@ private void Search() ProductType = TempProductType; - try - { - FFUURL = LumiaDownloadModel.SearchFFU(ProductType, ProductCode, OperatorCode, out TempProductType); - } - catch (WPinternalsException ex) - { - LogFile.LogException(ex, LogType.FileOnly); - FFUURL = LumiaDownloadModel.SearchFFU(ProductType, null, OperatorCode, out TempProductType); - } - if (TempProductType != null) { ProductType = TempProductType; @@ -225,11 +249,6 @@ private void Search() { EmergencyURLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); } - - if (ProductType != null && FirmwareVersion != null) - { - (SecureWIMURL, string _) = LumiaDownloadModel.SearchENOSW(ProductType, FirmwareVersion); - } } catch (Exception ex) { @@ -238,20 +257,10 @@ private void Search() UIContext.Post(s => { - if (FFUURL != null) - { - SearchResultList.Add(new SearchResult(FFUURL, ProductType, FFUDownloaded, null)); - } - if (EmergencyURLs != null) { SearchResultList.Add(new SearchResult($"{ProductType} emergency-files", EmergencyURLs, ProductType, EmergencyDownloaded, ProductType)); } - - if (SecureWIMURL != null) - { - SearchResultList.Add(new SearchResult($"{ProductType} ENOSW-files", SecureWIMURL, ProductType, ENOSWDownloaded, FirmwareVersion)); - } }, null); IsSearching = false; @@ -279,9 +288,7 @@ private void DownloadAll() new Thread(() => { - string FFUURL = null; string[] EmergencyURLs = null; - string SecureWIMURL = null; try { string TempProductType = ProductType.ToUpper(); @@ -291,7 +298,6 @@ private void DownloadAll() } ProductType = TempProductType; - FFUURL = LumiaDownloadModel.SearchFFU(ProductType, ProductCode, OperatorCode, out TempProductType); if (TempProductType != null) { ProductType = TempProductType; @@ -301,11 +307,6 @@ private void DownloadAll() { EmergencyURLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); } - - if (ProductType != null && FirmwareVersion != null) - { - (SecureWIMURL, string _) = LumiaDownloadModel.SearchENOSW(ProductType, FirmwareVersion); - } } catch (Exception ex) { @@ -314,20 +315,10 @@ private void DownloadAll() UIContext.Post(s => { - if (FFUURL != null) - { - Download(FFUURL, ProductType, FFUDownloadedAndCheckSupported, null); - } - if (EmergencyURLs != null) { Download(EmergencyURLs, ProductType, EmergencyDownloaded, ProductType); } - - if (SecureWIMURL != null) - { - Download(SecureWIMURL, ProductType, ENOSWDownloaded, FirmwareVersion); - } }, null); }).Start(); } @@ -340,23 +331,6 @@ private void DownloadSelected() } } - private void FFUDownloaded(string[] Files, object State) - { - App.Config.AddFfuToRepository(Files[0]); - } - - private void FFUDownloadedAndCheckSupported(string[] Files, object State) - { - App.Config.AddFfuToRepository(Files[0]); - - if (!App.Config.FFURepository.Any(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion))) - { - const string ProductType2 = "RM-1085"; - string URL = LumiaDownloadModel.SearchFFU(ProductType2, null, null); - Download(URL, ProductType2, FFUDownloaded, null); - } - } - private void EmergencyDownloaded(string[] Files, object State) { string Type = (string)State; @@ -382,11 +356,6 @@ private void EmergencyDownloaded(string[] Files, object State) } } - private void ENOSWDownloaded(string[] Files, object State) - { - App.Config.AddSecWimToRepository(Files[0], (string)State); - } - public ObservableCollection DownloadList { get; } = []; public ObservableCollection SearchResultList { get; } = []; @@ -683,6 +652,7 @@ internal override async void EvaluateViewState() } } public DelegateCommand AddFFUCommand { get; } = null; + public DelegateCommand AddSecWIMCommand { get; } = null; } internal enum DownloadStatus diff --git a/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs b/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs index 7d5fbf0..4c34edc 100644 --- a/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs +++ b/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs @@ -28,7 +28,6 @@ using WPinternals.Config; using WPinternals.HelperClasses; using WPinternals.Models.Lumia.UEFI; -using WPinternals.Models.UEFIApps; using WPinternals.Models.UEFIApps.BootMgr; using WPinternals.Models.UEFIApps.Flash; using WPinternals.Models.UEFIApps.PhoneInfo; diff --git a/WPinternals/ViewModels/PhoneNotifierViewModel.cs b/WPinternals/ViewModels/PhoneNotifierViewModel.cs index 8af11a2..56001a7 100644 --- a/WPinternals/ViewModels/PhoneNotifierViewModel.cs +++ b/WPinternals/ViewModels/PhoneNotifierViewModel.cs @@ -24,10 +24,8 @@ using System.Threading; using System.Threading.Tasks; using WPinternals.HelperClasses; -using WPinternals.Models.Lumia; using WPinternals.Models.Lumia.NCSd; using WPinternals.Models.Lumia.UEFI; -using WPinternals.Models.UEFIApps; using WPinternals.Models.UEFIApps.BootMgr; using WPinternals.Models.UEFIApps.Flash; using WPinternals.Models.UEFIApps.PhoneInfo; diff --git a/WPinternals/ViewModels/SwitchModeViewModel.cs b/WPinternals/ViewModels/SwitchModeViewModel.cs index fc03ce6..0c3573a 100644 --- a/WPinternals/ViewModels/SwitchModeViewModel.cs +++ b/WPinternals/ViewModels/SwitchModeViewModel.cs @@ -25,10 +25,8 @@ using System.Threading.Tasks; using WPinternals.HelperClasses; using WPinternals.Models.Lumia; -using WPinternals.Models.Lumia.MSR; using WPinternals.Models.Lumia.NCSd; using WPinternals.Models.Lumia.UEFI; -using WPinternals.Models.UEFIApps; using WPinternals.Models.UEFIApps.BootMgr; using WPinternals.Models.UEFIApps.Flash; using WPinternals.Models.UEFIApps.PhoneInfo; @@ -761,21 +759,7 @@ void Finish() PhoneInfoAppInfo.Type = "RM-1151"; } - (string ENOSWFileUrl, string DPLFileUrl) = LumiaDownloadModel.SearchENOSW(PhoneInfoAppInfo.Type, Info.Firmware); - UIContext?.Post(d => SetWorkingStatus($"Downloading {PhoneInfoAppInfo.Type} Test Mode package...", MaxProgressValue: 100), null); - - DownloadEntry downloadEntry = new(ENOSWFileUrl, TempFolder, [ENOSWFileUrl], ENOSWDownloadCompleted, Info.Firmware); - - downloadEntry.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => - { - if (e.PropertyName == "Progress") - { - int progress = (sender as DownloadEntry)?.Progress ?? 0; - ulong.TryParse(progress.ToString(), out ulong progressret); - UIContext?.Post(d => UpdateWorkingStatus(null, CurrentProgressValue: progressret), null); - } - }; } catch (Exception Ex) { @@ -875,21 +859,7 @@ void Finish() PhoneInfoAppInfo.Type = "RM-1151"; } - (string ENOSWFileUrl, string DPLFileUrl) = LumiaDownloadModel.SearchENOSW(PhoneInfoAppInfo.Type, Info.Firmware); - UIContext?.Post(d => SetWorkingStatus($"Downloading {PhoneInfoAppInfo.Type} Test Mode package...", MaxProgressValue: 100), null); - - DownloadEntry downloadEntry = new(ENOSWFileUrl, TempFolder, [ENOSWFileUrl], ENOSWDownloadCompleted, Info.Firmware); - - downloadEntry.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => - { - if (e.PropertyName == "Progress") - { - int progress = (sender as DownloadEntry)?.Progress ?? 0; - ulong.TryParse(progress.ToString(), out ulong progressret); - UIContext?.Post(d => UpdateWorkingStatus(null, CurrentProgressValue: progressret), null); - } - }; } catch (Exception Ex) {