Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Oct 12, 2024
1 parent 7c18a16 commit d9da499
Show file tree
Hide file tree
Showing 24 changed files with 193 additions and 35 deletions.
12 changes: 10 additions & 2 deletions WPinternals/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ internal static async Task ParseCommandLine(System.Threading.SynchronizationCont
? Convert.ToUInt64(args[2][2..], 16)
: Convert.ToUInt64(args[2], 10);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);
LogFile.Log("Bad start sector", LogType.ConsoleOnly);
break;
}
Expand Down Expand Up @@ -1674,8 +1678,12 @@ internal static void OpenConsole()
};
Console.SetOut(standardOutput);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);
}
}

Expand Down
7 changes: 6 additions & 1 deletion WPinternals/HelperClasses/SeekableStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ internal SeekableStream(Func<Stream> StreamInitializer, long? Length = null)
{
UnderlyingStreamLength = UnderlyingStream.Length;
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

throw new ArgumentException("Unknown stream length");
}
}
Expand Down
8 changes: 7 additions & 1 deletion WPinternals/Models/Lumia/MSR/LumiaDownloadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.Generic;
using System.Net;
using System.Xml;
Expand Down Expand Up @@ -53,8 +54,13 @@ internal static string[] SearchEmergencyFiles(string ProductType)
{
Config = Client.DownloadString($"https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/{ProductType}/emergency_flash_config.xml");
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LogFile.Log("Emergency files for " + ProductType + " not found", LogType.FileAndConsole);
return null;
}
Expand Down
17 changes: 12 additions & 5 deletions WPinternals/Models/Lumia/NCSd/NokiaCareSuiteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using WPinternals.HelperClasses;

namespace WPinternals.Models.Lumia.NCSd
{
Expand Down Expand Up @@ -73,20 +74,26 @@ public NokiaCareSuiteModel(string DevicePath) : base(DevicePath)
Length = Device.InputPipe.Read(Buffer);
}

JsonDocument ResultMessage = JsonDocument.Parse(System.Text.Encoding.ASCII.GetString(Buffer, 0, Length));
string ResultString = System.Text.Encoding.ASCII.GetString(Buffer, 0, Length);
JsonDocument ResultMessage = JsonDocument.Parse(ResultString);

try
{
JsonElement? ResultToken = ResultMessage.RootElement.GetProperty("result");
if (ResultToken == null || ResultElement == null)
bool result = ResultMessage.RootElement.TryGetProperty("result", out JsonElement ResultToken);
if (!result || ResultElement == null)
{
return null;
}

return ResultToken.Value.GetProperty(ResultElement);
return ResultToken.GetProperty(ResultElement);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,13 @@ internal void ResetPhone()
ByteOperations.WriteAsciiString(Request, 0, RebootSignature);
ExecuteRawVoidMethod(Request);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LogFile.Log("Sending reset-request failed", LogType.FileOnly);
LogFile.Log("Assuming automatic reset already in progress", LogType.FileOnly);
}
Expand Down
7 changes: 6 additions & 1 deletion WPinternals/Models/Lumia/UEFI/Flash/LumiaFlashAppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,13 @@ internal void ResetPhone()
ByteOperations.WriteAsciiString(Request, 0, RebootSignature);
ExecuteRawVoidMethod(Request);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LogFile.Log("Sending reset-request failed", LogType.FileOnly);
LogFile.Log("Assuming automatic reset already in progress", LogType.FileOnly);
}
Expand Down
8 changes: 7 additions & 1 deletion WPinternals/Models/Privileges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using System.Threading;
using WPinternals.HelperClasses;

namespace WPinternals
{
Expand Down Expand Up @@ -488,8 +489,13 @@ public static void RunWithPrivilege(string privilege, bool enabled, PrivilegedCa

callback(state);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

p.Revert();
throw;
}
Expand Down
8 changes: 7 additions & 1 deletion WPinternals/Models/QualcommDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System;
using System.IO;
using System.Linq;
using WPinternals.HelperClasses;

namespace WPinternals
{
Expand All @@ -40,8 +41,13 @@ public bool IsAlive()
Serial.SendCommand([0x06], [0x02]);
return true;
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

return false;
}
}
Expand Down
7 changes: 6 additions & 1 deletion WPinternals/Models/QualcommFirehose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ public bool ConnectToProgrammer(byte[] PacketFromPcToProgrammer)
Serial.SendData(PacketFromPcToProgrammer);
LogFile.Log("Hello packet accepted", LogType.FileOnly);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LogFile.Log("Hello packet not accepted", LogType.FileOnly);
}

Expand Down
7 changes: 6 additions & 1 deletion WPinternals/Models/QualcommSahara.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,13 @@ public bool Handshake()

byte[] Ready = Serial.SendCommand(HelloResponse, [0x03, 0x00, 0x00, 0x00]);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

Result = false;
}

Expand Down
7 changes: 6 additions & 1 deletion WPinternals/TestCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ internal static async Task RewriteParts(string PartPath)
MassStorage.RestorePartition(part, partname, (v, t) => LogFile.Log("Progress: " + v + "%", LogType.ConsoleOnly));
LogFile.Log("", LogType.ConsoleOnly);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LogFile.Log("", LogType.ConsoleOnly);
LogFile.Log($"Failed writing {partname} to the device.", LogType.ConsoleOnly);
}
Expand Down
7 changes: 6 additions & 1 deletion WPinternals/ViewModels/ContextViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ internal class ContextViewModel : INotifyPropertyChanged
{
protected SynchronizationContext UIContext;

public bool IsSwitchingInterface = false;
private bool _IsSwitchingInterface = false;
public bool IsSwitchingInterface
{
get => _IsSwitchingInterface;
set => _IsSwitchingInterface = value;
}
public bool IsFlashModeOperation = false;

public event PropertyChangedEventHandler PropertyChanged = delegate { };
Expand Down
21 changes: 18 additions & 3 deletions WPinternals/ViewModels/DownloadsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ internal DownloadsViewModel(PhoneNotifierViewModel Notifier)
{
LastFFUStatusText = $"Error: {Ex.Message}. File \"{FFUFile}\" was not added.";
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LastFFUStatusText = $"Error: File \"{FFUFile}\" was not added.";
}
}
Expand Down Expand Up @@ -120,8 +125,13 @@ internal DownloadsViewModel(PhoneNotifierViewModel Notifier)
{
LastSecWIMStatusText = $"Error: {Ex.Message}. File \"{SecWIMFile}\" was not added.";
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LastSecWIMStatusText = $"Error: File \"{SecWIMFile}\" was not added.";
}
}
Expand Down Expand Up @@ -1093,8 +1103,13 @@ public static async Task DownloadFileAsync(this HttpClient client, Uri address,

completed?.Invoke(true);
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

completed?.Invoke(false);
}
}
Expand Down
21 changes: 18 additions & 3 deletions WPinternals/ViewModels/LumiaUnlockBootViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,13 @@ private void SetSupportedFFUPath()
FFU FFU = new(_FFUPath);
IsSupportedFfuNeeded = !App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V1.1-EFIESP").TargetVersions.Any(v => v.Description == FFU.GetOSVersion());
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

IsSupportedFfuNeeded = false;
return;
}
Expand Down Expand Up @@ -918,8 +923,13 @@ private void SetSupportedFFUPath()
FFU ProfileFFU = new(_ProfileFFUPath);
IsSupportedFfuNeeded = !App.PatchEngine.PatchDefinitions.First(p => p.Name == "SecureBootHack-V2-EFIESP").TargetVersions.Any(v => v.Description == ProfileFFU.GetOSVersion());
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

IsSupportedFfuNeeded = false;
return;
}
Expand Down Expand Up @@ -1023,8 +1033,13 @@ private void ValidateSupportedFfuPath()
ValidatedSupportedFfuPath = SupportedFFUPath;
}
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

IsSupportedFfuValid = false;
}
}
Expand Down
7 changes: 6 additions & 1 deletion WPinternals/ViewModels/LumiaUnlockBootloaderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,8 +1742,13 @@ internal static async Task LumiaRelockUEFI(PhoneNotifierViewModel Notifier, stri
await Notifier.WaitForArrival();
}
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

// If switching to mass storage mode failed, then we just skip that part. This might be a half unlocked phone.
LogFile.Log("Skipping Mass Storage mode", LogType.FileAndConsole);
}
Expand Down
8 changes: 8 additions & 0 deletions WPinternals/ViewModels/LumiaV2UnlockBootViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ internal async static Task LumiaV2CustomFlashInternal(PhoneNotifierViewModel Not
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);
FailedToStartProgrammer = true;
}
}
Expand All @@ -810,6 +812,8 @@ internal async static Task LumiaV2CustomFlashInternal(PhoneNotifierViewModel Not
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);
FailedToStartProgrammer = true;
}
}
Expand Down Expand Up @@ -1507,6 +1511,8 @@ .. GetNonOptimizedPayloads(FlashParts, FFU.ChunkSize, (uint)(FlashInfo.WriteBuff
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);
FailedToStartProgrammer = true;
}
}
Expand Down Expand Up @@ -1787,6 +1793,8 @@ .. GetNonOptimizedPayloads(FlashParts, FFU.ChunkSize, (uint)(FlashInfo.WriteBuff
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);
FailedToStartProgrammer = true;
}
}
Expand Down
7 changes: 6 additions & 1 deletion WPinternals/ViewModels/NokiaFlashViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ private void StartLoadDeviceInfo()
LogFile.Log("Native Debug Status: " + NativeDebugStatus.ToString());
}
}
catch
catch (Exception ex)
{
LogFile.Log("An unexpected error happened", LogType.FileAndConsole);
LogFile.Log(ex.GetType().ToString(), LogType.FileAndConsole);
LogFile.Log(ex.Message, LogType.FileAndConsole);
LogFile.Log(ex.StackTrace, LogType.FileAndConsole);

LogFile.Log("Reading status from Flash interface was aborted.");
}
DeviceInfoLoaded = true;
Expand Down
Loading

0 comments on commit d9da499

Please sign in to comment.