From c21692491d81d83fbfd8be695f4ee22e1b151687 Mon Sep 17 00:00:00 2001 From: Gustave Monce Date: Fri, 30 Aug 2024 21:43:30 +0200 Subject: [PATCH] fix: Log all silent exceptions --- WPinternals/CommandLine.cs | 5 +- WPinternals/FilePickerControl.xaml.cs | 10 ++- WPinternals/Models/GPT.cs | 15 ++++- WPinternals/Models/MassStorage.cs | 10 ++- WPinternals/Models/NokiaFlashModel.cs | 64 ++++++++++++++++--- WPinternals/Models/NokiaPhoneModel.cs | 15 ++++- WPinternals/Models/QualcommFirehose.cs | 6 +- WPinternals/Models/QualcommLoader.cs | 15 ++++- WPinternals/Models/QualcommSerial.cs | 10 ++- WPinternals/Models/SBL3.cs | 5 +- WPinternals/ViewModels/BackupViewModel.cs | 10 ++- WPinternals/ViewModels/DownloadsViewModel.cs | 15 ++++- .../LumiaFlashRomSourceSelectionViewModel.cs | 5 +- .../ViewModels/LumiaFlashRomViewModel.cs | 10 ++- .../ViewModels/LumiaUnlockBootViewModel.cs | 40 +++++++++--- .../LumiaUnlockBootloaderViewModel.cs | 5 +- .../ViewModels/LumiaV2UnlockBootViewModel.cs | 5 +- .../ViewModels/NokiaNormalViewModel.cs | 5 +- .../ViewModels/PhoneNotifierViewModel.cs | 5 +- WPinternals/ViewModels/SwitchModeViewModel.cs | 20 ++++-- 20 files changed, 224 insertions(+), 51 deletions(-) diff --git a/WPinternals/CommandLine.cs b/WPinternals/CommandLine.cs index a19f21e..6184b6a 100644 --- a/WPinternals/CommandLine.cs +++ b/WPinternals/CommandLine.cs @@ -318,7 +318,10 @@ namespace WPinternals s = new FileStream(args[3], FileMode.Open, FileAccess.Read); Archive = new ZipArchive(s); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } if (Archive == null) { diff --git a/WPinternals/FilePickerControl.xaml.cs b/WPinternals/FilePickerControl.xaml.cs index bf532c4..9cccdb6 100644 --- a/WPinternals/FilePickerControl.xaml.cs +++ b/WPinternals/FilePickerControl.xaml.cs @@ -316,13 +316,19 @@ namespace WPinternals { filename = System.IO.Path.GetFileName(Text); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } string directory = ""; try { directory = System.IO.Path.GetDirectoryName(Text); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } FormattedText formatted; bool widthOK = false; bool changedWidth = false; diff --git a/WPinternals/Models/GPT.cs b/WPinternals/Models/GPT.cs index cc954d2..287fb9e 100644 --- a/WPinternals/Models/GPT.cs +++ b/WPinternals/Models/GPT.cs @@ -275,7 +275,10 @@ namespace WPinternals { StreamLengthInSectors = (ulong)DecompressedStream.Length / 0x200; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } if (NewPartition.LastSector == 0) @@ -471,7 +474,10 @@ namespace WPinternals { StreamLengthInSectors = (ulong)DecompressedStream.Length / 0x200; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } DecompressedStream.Close(); UInt64 MaxPartitionSizeInSectors = OldPartition.SizeInSectors; @@ -521,7 +527,10 @@ namespace WPinternals { StreamLengthInSectors = (ulong)DecompressedStream.Length / 0x200; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } DecompressedStream.Close(); if (NewPartition.SizeInSectors != StreamLengthInSectors) { diff --git a/WPinternals/Models/MassStorage.cs b/WPinternals/Models/MassStorage.cs index 4dadc1c..077073c 100644 --- a/WPinternals/Models/MassStorage.cs +++ b/WPinternals/Models/MassStorage.cs @@ -73,7 +73,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } internal void AttachQualcommSerial(string DevicePath) @@ -119,7 +122,10 @@ namespace WPinternals SerialDevice.Close(); SerialDevice.Dispose(); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } protected override void Dispose(bool disposing) diff --git a/WPinternals/Models/NokiaFlashModel.cs b/WPinternals/Models/NokiaFlashModel.cs index c497513..b8c3561 100644 --- a/WPinternals/Models/NokiaFlashModel.cs +++ b/WPinternals/Models/NokiaFlashModel.cs @@ -808,7 +808,10 @@ namespace WPinternals { InputStreamLength = (UInt64)InputStream.Length; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } if ((InputStreamLength != null) && ((UInt64)InputStream.Length > PartitionSize)) { @@ -1008,16 +1011,34 @@ namespace WPinternals try { - SwitchToPhoneInfoAppContext(); // May throw NotSupportedException + if (Result.BootManagerProtocolVersionMajor >= 2) + { + SwitchToPhoneInfoAppContext(); // May throw NotSupportedException - Result.Type = ReadPhoneInfoVariable("TYPE"); - Result.ProductCode = ReadPhoneInfoVariable("CTR"); - Result.Imei = ReadPhoneInfoVariable("IMEI"); + Result.Type = ReadPhoneInfoVariable("TYPE"); + Result.ProductCode = ReadPhoneInfoVariable("CTR"); + Result.Imei = ReadPhoneInfoVariable("IMEI"); - SwitchToFlashAppContext(); - DisableRebootTimeOut(); + SwitchToFlashAppContext(); + DisableRebootTimeOut(); + } + else if (OriginalType == FlashAppType.PhoneInfoApp) + { + Result.Type = ReadPhoneInfoVariable("TYPE"); + Result.ProductCode = ReadPhoneInfoVariable("CTR"); + Result.Imei = ReadPhoneInfoVariable("IMEI"); + } + else + { + //SwitchToPhoneInfoAppContextLegacy(); + + //SwitchAwayToPhoneInfoAppContextLegacy(); + } + } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); } - catch { } if (Result.App == FlashAppType.FlashApp) { @@ -1032,7 +1053,10 @@ namespace WPinternals SwitchToBootManagerContext(); } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } Result.State = PhoneInfoState.Extended; } @@ -1122,6 +1146,28 @@ namespace WPinternals InterfaceChanged(PhoneInterfaces.Lumia_Flash); } + internal void SwitchToPhoneInfoAppContextLegacy() + { + byte[] Request = new byte[4]; + ByteOperations.WriteAsciiString(Request, 0, "NOKP"); + ExecuteRawVoidMethod(Request); + + //DisableRebootTimeOut(); + Info.App = FlashAppType.PhoneInfoApp; + InterfaceChanged(PhoneInterfaces.Lumia_Bootloader); + } + + internal void SwitchAwayToPhoneInfoAppContextLegacy() + { + byte[] Request = new byte[4]; + ByteOperations.WriteAsciiString(Request, 0, "NOKA"); + ExecuteRawVoidMethod(Request); + + //DisableRebootTimeOut(); + //Info.App = FlashAppType.FlashApp; + //InterfaceChanged(PhoneInterfaces.Lumia_Flash); + } + internal void SwitchToFlashAppContext() { // SwitchToFlashAppContext() should only be used with BootMgr v2 diff --git a/WPinternals/Models/NokiaPhoneModel.cs b/WPinternals/Models/NokiaPhoneModel.cs index be2851d..1e9626e 100644 --- a/WPinternals/Models/NokiaPhoneModel.cs +++ b/WPinternals/Models/NokiaPhoneModel.cs @@ -40,7 +40,10 @@ namespace WPinternals { Device = new USBDevice(DevicePath); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } private JsonElement? ExecuteJsonMethodAsJsonToken(string JsonMethod, Dictionary Params, string ResultElement) @@ -335,7 +338,10 @@ namespace WPinternals Result = new byte[OutputLength]; System.Buffer.BlockCopy(Buffer, 0, Result, 0, OutputLength); } - catch { } // Reboot command looses connection + catch (Exception ex) // Reboot command looses connection + { + LogFile.LogException(ex, LogType.FileOnly); + } } return Result; } @@ -363,7 +369,10 @@ namespace WPinternals pipe.Reset(); } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } /// diff --git a/WPinternals/Models/QualcommFirehose.cs b/WPinternals/Models/QualcommFirehose.cs index 59a4aa9..28844d1 100644 --- a/WPinternals/Models/QualcommFirehose.cs +++ b/WPinternals/Models/QualcommFirehose.cs @@ -18,6 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System; using System.Collections; using System.IO; using System.Linq; @@ -100,7 +101,10 @@ namespace WPinternals LogFile.Log("Programmer failed to authenticate Digital Signature", LogType.FileOnly); } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } while (!HandshakeCompleted && (HelloSendCount < 6)); diff --git a/WPinternals/Models/QualcommLoader.cs b/WPinternals/Models/QualcommLoader.cs index 07a6289..c5ac384 100644 --- a/WPinternals/Models/QualcommLoader.cs +++ b/WPinternals/Models/QualcommLoader.cs @@ -69,10 +69,16 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } return Result; } @@ -121,7 +127,10 @@ namespace WPinternals Result = new byte[BufferSize]; System.Buffer.BlockCopy(Buffer, 0, Result, 0, BufferSize); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } return Result; } diff --git a/WPinternals/Models/QualcommSerial.cs b/WPinternals/Models/QualcommSerial.cs index 099e6e7..f95a5d2 100644 --- a/WPinternals/Models/QualcommSerial.cs +++ b/WPinternals/Models/QualcommSerial.cs @@ -58,7 +58,10 @@ namespace WPinternals { this.USBDevice = new USBDevice(DevicePath); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } } @@ -146,7 +149,10 @@ namespace WPinternals { IsIncomplete = true; } - catch { } // Will be rethrown as BadConnectionException + catch (Exception ex) // Will be rethrown as BadConnectionException + { + LogFile.LogException(ex, LogType.FileOnly); + } } while (IsIncomplete); diff --git a/WPinternals/Models/SBL3.cs b/WPinternals/Models/SBL3.cs index bc4f397..627086a 100644 --- a/WPinternals/Models/SBL3.cs +++ b/WPinternals/Models/SBL3.cs @@ -45,7 +45,10 @@ namespace WPinternals Binary = FFUFile.GetPartition("SBL3"); } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } // If not succeeded, then try to parse it as raw image if (Binary == null) diff --git a/WPinternals/ViewModels/BackupViewModel.cs b/WPinternals/ViewModels/BackupViewModel.cs index 7a36b79..ef6e5cd 100644 --- a/WPinternals/ViewModels/BackupViewModel.cs +++ b/WPinternals/ViewModels/BackupViewModel.cs @@ -360,7 +360,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } finally { Phone.CloseVolume(); @@ -463,7 +466,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } finally { Phone.CloseVolume(); diff --git a/WPinternals/ViewModels/DownloadsViewModel.cs b/WPinternals/ViewModels/DownloadsViewModel.cs index 9d5b002..1efba03 100644 --- a/WPinternals/ViewModels/DownloadsViewModel.cs +++ b/WPinternals/ViewModels/DownloadsViewModel.cs @@ -194,7 +194,10 @@ namespace WPinternals EmergencyURLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } UIContext.Post(s => { @@ -256,7 +259,10 @@ namespace WPinternals EmergencyURLs = LumiaDownloadModel.SearchEmergencyFiles(ProductType); } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } UIContext.Post(s => { @@ -369,7 +375,10 @@ namespace WPinternals { Directory.CreateDirectory(_DownloadFolder); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } if (!Directory.Exists(_DownloadFolder)) { _DownloadFolder = @"C:\ProgramData\WPinternals\Repository"; diff --git a/WPinternals/ViewModels/LumiaFlashRomSourceSelectionViewModel.cs b/WPinternals/ViewModels/LumiaFlashRomSourceSelectionViewModel.cs index d544a28..4acd07f 100644 --- a/WPinternals/ViewModels/LumiaFlashRomSourceSelectionViewModel.cs +++ b/WPinternals/ViewModels/LumiaFlashRomSourceSelectionViewModel.cs @@ -256,7 +256,10 @@ namespace WPinternals { EvaluateViewState(); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } }).Start(); } diff --git a/WPinternals/ViewModels/LumiaFlashRomViewModel.cs b/WPinternals/ViewModels/LumiaFlashRomViewModel.cs index e64ae27..66434af 100644 --- a/WPinternals/ViewModels/LumiaFlashRomViewModel.cs +++ b/WPinternals/ViewModels/LumiaFlashRomViewModel.cs @@ -343,7 +343,10 @@ namespace WPinternals { StreamLengthInSectors = (ulong)DecompressedStream.Length / 0x200; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } TotalSizeSectors += StreamLengthInSectors; PartitionCount++; @@ -438,7 +441,10 @@ namespace WPinternals { StreamLengthInSectors = (ulong)DecompressedStream.Length / 0x200; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } if (StreamLengthInSectors <= Partition.SizeInSectors) { diff --git a/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs b/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs index f045771..3ba4ca8 100644 --- a/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs +++ b/WPinternals/ViewModels/LumiaUnlockBootViewModel.cs @@ -642,7 +642,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } try { @@ -658,7 +661,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } List FFUs = App.Config.FFURepository.Where(e => PlatformID.StartsWith(e.PlatformID, StringComparison.OrdinalIgnoreCase) && e.Exists()).ToList(); if (FFUs.Count > 0) @@ -688,7 +694,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } try { @@ -703,7 +712,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } TempEDEPath = LumiaV2UnlockBootViewModel.GetProgrammerPath(RootKeyHash, ProductType); if (TempEDEPath != null) @@ -753,7 +765,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } try { @@ -770,7 +785,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } List FFUs = App.Config.FFURepository.Where(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V1.1-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion)).ToList(); if (FFUs.Count > 0) @@ -815,7 +833,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } try { @@ -832,7 +853,10 @@ namespace WPinternals } } } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } List FFUs = App.Config.FFURepository.Where(e => App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == e.OSVersion)).ToList(); if (FFUs.Count > 0) diff --git a/WPinternals/ViewModels/LumiaUnlockBootloaderViewModel.cs b/WPinternals/ViewModels/LumiaUnlockBootloaderViewModel.cs index 7bc9fbc..d175216 100644 --- a/WPinternals/ViewModels/LumiaUnlockBootloaderViewModel.cs +++ b/WPinternals/ViewModels/LumiaUnlockBootloaderViewModel.cs @@ -82,7 +82,10 @@ namespace WPinternals Result = true; LogFile.Log("Loader sent successfully"); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } if (Result) { diff --git a/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs b/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs index 934ed70..1c3c202 100644 --- a/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs +++ b/WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs @@ -2049,7 +2049,10 @@ namespace WPinternals { StreamLengthInSectors = (ulong)DecompressedStream.Length / 0x200; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } TotalSizeSectors += StreamLengthInSectors; PartitionCount++; diff --git a/WPinternals/ViewModels/NokiaNormalViewModel.cs b/WPinternals/ViewModels/NokiaNormalViewModel.cs index 45064bf..09d4304 100644 --- a/WPinternals/ViewModels/NokiaNormalViewModel.cs +++ b/WPinternals/ViewModels/NokiaNormalViewModel.cs @@ -105,7 +105,10 @@ namespace WPinternals this.Pk = Pk; LogFile.Log("PK: " + Pk); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } private string _ProductCode = null; diff --git a/WPinternals/ViewModels/PhoneNotifierViewModel.cs b/WPinternals/ViewModels/PhoneNotifierViewModel.cs index 7f35498..d375744 100644 --- a/WPinternals/ViewModels/PhoneNotifierViewModel.cs +++ b/WPinternals/ViewModels/PhoneNotifierViewModel.cs @@ -115,7 +115,10 @@ namespace WPinternals LogWatcher.Enabled = true; App.IsPnPEventLogMissing = false; } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } private void PnPEventWritten(Object obj, EventRecordWrittenEventArgs arg) diff --git a/WPinternals/ViewModels/SwitchModeViewModel.cs b/WPinternals/ViewModels/SwitchModeViewModel.cs index e5b6642..b2303e9 100644 --- a/WPinternals/ViewModels/SwitchModeViewModel.cs +++ b/WPinternals/ViewModels/SwitchModeViewModel.cs @@ -101,7 +101,10 @@ namespace WPinternals PhoneNotifier.CurrentInterface = PhoneInterfaces.Lumia_Flash; PhoneNotifier.NotifyArrival(); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } } @@ -472,7 +475,10 @@ namespace WPinternals CurrentMode = PhoneInterfaces.Lumia_Flash; PhoneNotifier.NotifyArrival(); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } if (CurrentMode == TargetMode) @@ -556,7 +562,10 @@ namespace WPinternals { FlashModel.SwitchToFlashAppContext(); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } PhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: true); @@ -641,7 +650,10 @@ namespace WPinternals { FlashModel.SwitchToFlashAppContext(); } - catch { } + catch (Exception ex) + { + LogFile.LogException(ex, LogType.FileOnly); + } } PhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: false);