mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-06-21 22:51:02 +10:00
Some cleanup
This commit is contained in:
@@ -185,10 +185,8 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
Notifier = new PhoneNotifierViewModel();
|
Notifier = new PhoneNotifierViewModel();
|
||||||
UIContext.Send(s => Notifier.Start(), null);
|
UIContext.Send(s => Notifier.Start(), null);
|
||||||
|
await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Bootloader);
|
||||||
BootMgrModel = (LumiaBootManagerAppModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Bootloader); // This also works for Bootloader Spec A
|
GPT GPT = await LumiaUnlockBootloaderViewModel.ReadGPTFromFlashOrBootMgr(Notifier);
|
||||||
|
|
||||||
GPT GPT = BootMgrModel.ReadGPT(); // May throw NotSupportedException
|
|
||||||
foreach (Partition Partition in GPT.Partitions)
|
foreach (Partition Partition in GPT.Partitions)
|
||||||
{
|
{
|
||||||
LogFile.Log(Partition.Name.PadRight(20) + "0x" + Partition.FirstSector.ToString("X8") + " - 0x" + Partition.LastSector.ToString("X8") + " " + Partition.Volume, LogType.ConsoleOnly);
|
LogFile.Log(Partition.Name.PadRight(20) + "0x" + Partition.FirstSector.ToString("X8") + " - 0x" + Partition.LastSector.ToString("X8") + " " + Partition.Volume, LogType.ConsoleOnly);
|
||||||
@@ -216,8 +214,8 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
Notifier = new PhoneNotifierViewModel();
|
Notifier = new PhoneNotifierViewModel();
|
||||||
UIContext.Send(s => Notifier.Start(), null);
|
UIContext.Send(s => Notifier.Start(), null);
|
||||||
BootMgrModel = (LumiaBootManagerAppModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Bootloader);
|
await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Bootloader);
|
||||||
GPT GPT = BootMgrModel.ReadGPT(); // May throw NotSupportedException
|
GPT GPT = await LumiaUnlockBootloaderViewModel.ReadGPTFromFlashOrBootMgr(Notifier);
|
||||||
string DirPath = Path.GetDirectoryName(args[2]);
|
string DirPath = Path.GetDirectoryName(args[2]);
|
||||||
if (!string.IsNullOrEmpty(DirPath) && !Directory.Exists(DirPath))
|
if (!string.IsNullOrEmpty(DirPath) && !Directory.Exists(DirPath))
|
||||||
{
|
{
|
||||||
@@ -275,8 +273,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
Notifier = new PhoneNotifierViewModel();
|
Notifier = new PhoneNotifierViewModel();
|
||||||
UIContext.Send(s => Notifier.Start(), null);
|
UIContext.Send(s => Notifier.Start(), null);
|
||||||
BootMgrModel = (LumiaBootManagerAppModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Bootloader);
|
byte[] GptChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
byte[] GptChunk = BootMgrModel.GetGptChunk(0x20000);
|
|
||||||
GPT GPT = new(GptChunk);
|
GPT GPT = new(GptChunk);
|
||||||
string Xml = File.ReadAllText(args[2]);
|
string Xml = File.ReadAllText(args[2]);
|
||||||
GPT.MergePartitions(Xml, false);
|
GPT.MergePartitions(Xml, false);
|
||||||
@@ -1671,8 +1668,10 @@ namespace WPinternals
|
|||||||
Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = new(stdHandle, true);
|
Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = new(stdHandle, true);
|
||||||
FileStream fileStream = new(safeFileHandle, FileAccess.Write);
|
FileStream fileStream = new(safeFileHandle, FileAccess.Write);
|
||||||
Encoding encoding = Encoding.GetEncoding(MY_CODE_PAGE);
|
Encoding encoding = Encoding.GetEncoding(MY_CODE_PAGE);
|
||||||
StreamWriter standardOutput = new(fileStream, encoding);
|
StreamWriter standardOutput = new(fileStream, encoding)
|
||||||
standardOutput.AutoFlush = true;
|
{
|
||||||
|
AutoFlush = true
|
||||||
|
};
|
||||||
Console.SetOut(standardOutput);
|
Console.SetOut(standardOutput);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -430,9 +430,10 @@ namespace WPinternals
|
|||||||
|
|
||||||
if (SaveDialog)
|
if (SaveDialog)
|
||||||
{
|
{
|
||||||
Microsoft.Win32.SaveFileDialog savedlg = new();
|
Microsoft.Win32.SaveFileDialog savedlg = new()
|
||||||
|
{
|
||||||
savedlg.FileName = Path ?? DefaultFileName;
|
FileName = Path ?? DefaultFileName
|
||||||
|
};
|
||||||
|
|
||||||
// Show open file dialog box
|
// Show open file dialog box
|
||||||
result = savedlg.ShowDialog();
|
result = savedlg.ShowDialog();
|
||||||
@@ -447,9 +448,10 @@ namespace WPinternals
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Select file
|
// Select file
|
||||||
Microsoft.Win32.OpenFileDialog dlg = new();
|
Microsoft.Win32.OpenFileDialog dlg = new()
|
||||||
|
{
|
||||||
dlg.FileName = Path ?? DefaultFileName;
|
FileName = Path ?? DefaultFileName
|
||||||
|
};
|
||||||
|
|
||||||
// Show open file dialog box
|
// Show open file dialog box
|
||||||
result = dlg.ShowDialog();
|
result = dlg.ShowDialog();
|
||||||
|
|||||||
@@ -81,13 +81,15 @@ namespace WPinternals
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Partition CurrentPartition = new();
|
Partition CurrentPartition = new()
|
||||||
CurrentPartition.Name = Name;
|
{
|
||||||
CurrentPartition.FirstSector = ByteOperations.ReadUInt64(GPTBuffer, PartitionOffset + 0x20);
|
Name = Name,
|
||||||
CurrentPartition.LastSector = ByteOperations.ReadUInt64(GPTBuffer, PartitionOffset + 0x28);
|
FirstSector = ByteOperations.ReadUInt64(GPTBuffer, PartitionOffset + 0x20),
|
||||||
CurrentPartition.PartitionTypeGuid = ByteOperations.ReadGuid(GPTBuffer, PartitionOffset + 0x00);
|
LastSector = ByteOperations.ReadUInt64(GPTBuffer, PartitionOffset + 0x28),
|
||||||
CurrentPartition.PartitionGuid = ByteOperations.ReadGuid(GPTBuffer, PartitionOffset + 0x10);
|
PartitionTypeGuid = ByteOperations.ReadGuid(GPTBuffer, PartitionOffset + 0x00),
|
||||||
CurrentPartition.Attributes = ByteOperations.ReadUInt64(GPTBuffer, PartitionOffset + 0x30);
|
PartitionGuid = ByteOperations.ReadGuid(GPTBuffer, PartitionOffset + 0x10),
|
||||||
|
Attributes = ByteOperations.ReadUInt64(GPTBuffer, PartitionOffset + 0x30)
|
||||||
|
};
|
||||||
Partitions.Add(CurrentPartition);
|
Partitions.Add(CurrentPartition);
|
||||||
PartitionOffset += PartitionEntrySize;
|
PartitionOffset += PartitionEntrySize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace WPinternals.Models.Lumia.MSR
|
|||||||
string Config = null;
|
string Config = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Config = Client.DownloadString("https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/" + ProductType + "/emergency_flash_config.xml");
|
Config = Client.DownloadString($"https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/{ProductType}/emergency_flash_config.xml");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,7 @@ namespace WPinternals.Models.Lumia.MSR
|
|||||||
if (Node != null)
|
if (Node != null)
|
||||||
{
|
{
|
||||||
FileName = Node.Attributes["image_path"].InnerText;
|
FileName = Node.Attributes["image_path"].InnerText;
|
||||||
Src = "https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/" + ProductType + "/" + FileName;
|
Src = $"https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/{ProductType}/{FileName}";
|
||||||
LogFile.Log("Hex-file: " + Src);
|
LogFile.Log("Hex-file: " + Src);
|
||||||
Result.Add(Src);
|
Result.Add(Src);
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ namespace WPinternals.Models.Lumia.MSR
|
|||||||
if (Node != null)
|
if (Node != null)
|
||||||
{
|
{
|
||||||
FileName = Node.Attributes["image_path"].InnerText;
|
FileName = Node.Attributes["image_path"].InnerText;
|
||||||
Src = "https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/" + ProductType + "/" + FileName;
|
Src = $"https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/{ProductType}/{FileName}";
|
||||||
LogFile.Log("Mbn-file: " + Src);
|
LogFile.Log("Mbn-file: " + Src);
|
||||||
Result.Add(Src);
|
Result.Add(Src);
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ namespace WPinternals.Models.Lumia.MSR
|
|||||||
foreach (XmlNode SubNode in Doc.SelectNodes("//emergency_flash_config/first_boot_images/first_boot_image"))
|
foreach (XmlNode SubNode in Doc.SelectNodes("//emergency_flash_config/first_boot_images/first_boot_image"))
|
||||||
{
|
{
|
||||||
FileName = SubNode.Attributes["image_path"].InnerText;
|
FileName = SubNode.Attributes["image_path"].InnerText;
|
||||||
Src = "https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/" + ProductType + "/" + FileName;
|
Src = $"https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/{ProductType}/{FileName}";
|
||||||
LogFile.Log("Firehose-programmer-file: " + Src);
|
LogFile.Log("Firehose-programmer-file: " + Src);
|
||||||
Result.Add(Src);
|
Result.Add(Src);
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ namespace WPinternals.Models.Lumia.MSR
|
|||||||
foreach (XmlNode SubNode in Doc.SelectNodes("//emergency_flash_config/second_boot_firehose_single_image/firehose_image"))
|
foreach (XmlNode SubNode in Doc.SelectNodes("//emergency_flash_config/second_boot_firehose_single_image/firehose_image"))
|
||||||
{
|
{
|
||||||
FileName = SubNode.Attributes["image_path"].InnerText;
|
FileName = SubNode.Attributes["image_path"].InnerText;
|
||||||
Src = "https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/" + ProductType + "/" + FileName;
|
Src = $"https://repairavoidance.blob.core.windows.net/packages/EmergencyFlash/{ProductType}/{FileName}";
|
||||||
LogFile.Log("Firehose-payload-file: " + Src);
|
LogFile.Log("Firehose-payload-file: " + Src);
|
||||||
Result.Add(Src);
|
Result.Add(Src);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,8 +323,10 @@ namespace WPinternals.Models.UEFIApps.BootMgr
|
|||||||
0x0002 => "Flash read failed",
|
0x0002 => "Flash read failed",
|
||||||
_ => "Unknown error",
|
_ => "Unknown error",
|
||||||
};
|
};
|
||||||
WPinternalsException Ex = new("Flash failed!");
|
WPinternalsException Ex = new("Flash failed!")
|
||||||
Ex.SubMessage = "Error 0x" + ErrorCode.ToString("X4") + ": " + SubMessage;
|
{
|
||||||
|
SubMessage = "Error 0x" + ErrorCode.ToString("X4") + ": " + SubMessage
|
||||||
|
};
|
||||||
|
|
||||||
throw Ex;
|
throw Ex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,12 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
|
|
||||||
byte[] Response = ExecuteRawMethod(Request);
|
byte[] Response = ExecuteRawMethod(Request);
|
||||||
|
|
||||||
|
if (Response == null)
|
||||||
|
{
|
||||||
|
// Succeeded
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ByteOperations.ReadAsciiString(Response, 0, 4) == "NOKU")
|
if (ByteOperations.ReadAsciiString(Response, 0, 4) == "NOKU")
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
@@ -185,12 +191,9 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
LumiaFlashAppPhoneInfo Result = FlashAppInfo;
|
LumiaFlashAppPhoneInfo Result = FlashAppInfo;
|
||||||
|
|
||||||
if (ExtendedInfo && Result.State == PhoneInfoState.Basic)
|
if (ExtendedInfo && Result.State == PhoneInfoState.Basic)
|
||||||
{
|
|
||||||
if (Result.App == FlashAppType.FlashApp)
|
|
||||||
{
|
{
|
||||||
Result.Firmware = ReadStringParam("FVER");
|
Result.Firmware = ReadStringParam("FVER");
|
||||||
Result.RKH = ReadParam("RRKH");
|
Result.RKH = ReadParam("RRKH");
|
||||||
}
|
|
||||||
|
|
||||||
Result.State = PhoneInfoState.Extended;
|
Result.State = PhoneInfoState.Extended;
|
||||||
}
|
}
|
||||||
@@ -294,6 +297,13 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal bool CanReadGPT()
|
||||||
|
{
|
||||||
|
LumiaFlashAppPhoneInfo Info = ReadPhoneInfo(ExtendedInfo: false);
|
||||||
|
FlashAppType OriginalAppType = Info.App;
|
||||||
|
return Info.IsBootloaderSecure;
|
||||||
|
}
|
||||||
|
|
||||||
internal GPT ReadGPT()
|
internal GPT ReadGPT()
|
||||||
{
|
{
|
||||||
// If this function is used with a locked BootMgr v1,
|
// If this function is used with a locked BootMgr v1,
|
||||||
@@ -302,10 +312,7 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
|
|
||||||
// Only works in BootLoader-mode or on unlocked bootloaders in Flash-mode!!
|
// Only works in BootLoader-mode or on unlocked bootloaders in Flash-mode!!
|
||||||
|
|
||||||
LumiaFlashAppPhoneInfo Info = ReadPhoneInfo(ExtendedInfo: false);
|
if (CanReadGPT())
|
||||||
FlashAppType OriginalAppType = Info.App;
|
|
||||||
bool Switch = Info.IsBootloaderSecure;
|
|
||||||
if (Switch)
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Bootloader is not unlocked!");
|
throw new InvalidOperationException("Bootloader is not unlocked!");
|
||||||
}
|
}
|
||||||
@@ -324,7 +331,8 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
ushort Error = (ushort)((Buffer[6] << 8) + Buffer[7]);
|
ushort Error = (ushort)((Buffer[6] << 8) + Buffer[7]);
|
||||||
if (Error > 0)
|
if (Error > 0)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException("ReadGPT: Error 0x" + Error.ToString("X4"));
|
ThrowFlashError(Error);
|
||||||
|
//throw new NotSupportedException("ReadGPT: Error 0x" + Error.ToString("X4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] GPTBuffer = new byte[Buffer.Length - 0x208];
|
byte[] GPTBuffer = new byte[Buffer.Length - 0x208];
|
||||||
@@ -333,20 +341,23 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
return new GPT(GPTBuffer); // NOKT message header and MBR are ignored
|
return new GPT(GPTBuffer); // NOKT message header and MBR are ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
internal byte[] GetGptChunk(uint Size) // TODO!
|
internal byte[] GetGptChunk(uint Size)
|
||||||
{
|
{
|
||||||
// This function is also used to generate a dummy chunk to flash for testing.
|
// If this function is used with a locked BootMgr v1,
|
||||||
// The dummy chunk will contain the GPT, so it can be flashed to the first sectors for testing.
|
// then the mode-switching should be done outside this function,
|
||||||
byte[] GPTChunk = new byte[Size];
|
// because the context-switches that are used here are not supported on BootMgr v1.
|
||||||
|
|
||||||
LumiaFlashAppPhoneInfo Info = ReadPhoneInfo(ExtendedInfo: false);
|
// Only works in BootLoader-mode or on unlocked bootloaders in Flash-mode!!
|
||||||
FlashAppType OriginalAppType = Info.App;
|
|
||||||
bool Switch = Info.IsBootloaderSecure;
|
if (CanReadGPT())
|
||||||
if (Switch)
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Bootloader is not unlocked!");
|
throw new InvalidOperationException("Bootloader is not unlocked!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is also used to generate a dummy chunk to flash for testing.
|
||||||
|
// The dummy chunk will contain the GPT, so it can be flashed to the first sectors for testing.
|
||||||
|
byte[] GPTChunk = new byte[Size];
|
||||||
|
|
||||||
byte[] Request = new byte[0x04];
|
byte[] Request = new byte[0x04];
|
||||||
const string Header = "NOKT";
|
const string Header = "NOKT";
|
||||||
|
|
||||||
@@ -449,16 +460,17 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UefiSecurityStatusResponse Result = new();
|
UefiSecurityStatusResponse Result = new()
|
||||||
|
{
|
||||||
Result.IsTestDevice = Response[0];
|
IsTestDevice = Response[0],
|
||||||
Result.PlatformSecureBootStatus = Convert.ToBoolean(Response[1]);
|
PlatformSecureBootStatus = Convert.ToBoolean(Response[1]),
|
||||||
Result.SecureFfuEfuseStatus = Convert.ToBoolean(Response[2]);
|
SecureFfuEfuseStatus = Convert.ToBoolean(Response[2]),
|
||||||
Result.DebugStatus = Convert.ToBoolean(Response[3]);
|
DebugStatus = Convert.ToBoolean(Response[3]),
|
||||||
Result.RdcStatus = Convert.ToBoolean(Response[4]);
|
RdcStatus = Convert.ToBoolean(Response[4]),
|
||||||
Result.AuthenticationStatus = Convert.ToBoolean(Response[5]);
|
AuthenticationStatus = Convert.ToBoolean(Response[5]),
|
||||||
Result.UefiSecureBootStatus = Convert.ToBoolean(Response[6]);
|
UefiSecureBootStatus = Convert.ToBoolean(Response[6]),
|
||||||
Result.CryptoHardwareKey = Convert.ToBoolean(Response[7]);
|
CryptoHardwareKey = Convert.ToBoolean(Response[7])
|
||||||
|
};
|
||||||
|
|
||||||
_SecurityStatus = Result;
|
_SecurityStatus = Result;
|
||||||
|
|
||||||
@@ -473,12 +485,13 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlashVersion Result = new();
|
FlashVersion Result = new()
|
||||||
|
{
|
||||||
Result.ProtocolMajor = Response[1];
|
ProtocolMajor = Response[1],
|
||||||
Result.ProtocolMinor = Response[2];
|
ProtocolMinor = Response[2],
|
||||||
Result.ApplicationMajor = Response[3];
|
ApplicationMajor = Response[3],
|
||||||
Result.ApplicationMinor = Response[4];
|
ApplicationMinor = Response[4]
|
||||||
|
};
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@@ -830,8 +843,10 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
0x0002 => "Flash read failed",
|
0x0002 => "Flash read failed",
|
||||||
_ => "Unknown error",
|
_ => "Unknown error",
|
||||||
};
|
};
|
||||||
WPinternalsException Ex = new("Flash failed!");
|
WPinternalsException Ex = new("Flash failed!")
|
||||||
Ex.SubMessage = "Error 0x" + ErrorCode.ToString("X4") + ": " + SubMessage;
|
{
|
||||||
|
SubMessage = "Error 0x" + ErrorCode.ToString("X4") + ": " + SubMessage
|
||||||
|
};
|
||||||
|
|
||||||
throw Ex;
|
throw Ex;
|
||||||
}
|
}
|
||||||
@@ -1112,7 +1127,7 @@ namespace WPinternals.Models.UEFIApps.Flash
|
|||||||
private void FlashRawPartition(string Path, Stream Stream, string PartitionName, Action<int, TimeSpan?> ProgressUpdateCallback, ProgressUpdater UpdaterPerSector)
|
private void FlashRawPartition(string Path, Stream Stream, string PartitionName, Action<int, TimeSpan?> ProgressUpdateCallback, ProgressUpdater UpdaterPerSector)
|
||||||
{
|
{
|
||||||
GPT GPT = ReadGPT();
|
GPT GPT = ReadGPT();
|
||||||
FlashRawPartition(Path, Stream, PartitionName, ProgressUpdateCallback, UpdaterPerSector);
|
FlashRawPartition(GPT, Path, Stream, PartitionName, ProgressUpdateCallback, UpdaterPerSector);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FlashRawPartition(GPT GPT, string Path, Stream Stream, string PartitionName, Action<int, TimeSpan?> ProgressUpdateCallback, ProgressUpdater UpdaterPerSector)
|
private void FlashRawPartition(GPT GPT, string Path, Stream Stream, string PartitionName, Action<int, TimeSpan?> ProgressUpdateCallback, ProgressUpdater UpdaterPerSector)
|
||||||
|
|||||||
@@ -111,9 +111,10 @@ namespace WPinternals
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QualcommSerial SerialDevice = new(Serial);
|
QualcommSerial SerialDevice = new(Serial)
|
||||||
|
{
|
||||||
SerialDevice.EncodeCommands = false;
|
EncodeCommands = false
|
||||||
|
};
|
||||||
|
|
||||||
// This will succeed on new models
|
// This will succeed on new models
|
||||||
SerialDevice.SendData([0x7, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0]);
|
SerialDevice.SendData([0x7, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0]);
|
||||||
|
|||||||
@@ -415,8 +415,10 @@ namespace WPinternals
|
|||||||
(this.tlsContents.ReferenceCountValue > 1 ||
|
(this.tlsContents.ReferenceCountValue > 1 ||
|
||||||
!this.tlsContents.IsImpersonating))
|
!this.tlsContents.IsImpersonating))
|
||||||
{
|
{
|
||||||
NativeMethods.TOKEN_PRIVILEGE newState = new();
|
NativeMethods.TOKEN_PRIVILEGE newState = new()
|
||||||
newState.PrivilegeCount = 1;
|
{
|
||||||
|
PrivilegeCount = 1
|
||||||
|
};
|
||||||
newState.Privilege.Luid = this.luid;
|
newState.Privilege.Luid = this.luid;
|
||||||
newState.Privilege.Attributes = this.initialState ? NativeMethods.SE_PRIVILEGE_ENABLED : NativeMethods.SE_PRIVILEGE_DISABLED;
|
newState.Privilege.Attributes = this.initialState ? NativeMethods.SE_PRIVILEGE_ENABLED : NativeMethods.SE_PRIVILEGE_DISABLED;
|
||||||
|
|
||||||
@@ -544,8 +546,10 @@ namespace WPinternals
|
|||||||
this.tlsContents.IncrementReferenceCount();
|
this.tlsContents.IncrementReferenceCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeMethods.TOKEN_PRIVILEGE newState = new();
|
NativeMethods.TOKEN_PRIVILEGE newState = new()
|
||||||
newState.PrivilegeCount = 1;
|
{
|
||||||
|
PrivilegeCount = 1
|
||||||
|
};
|
||||||
newState.Privilege.Luid = this.luid;
|
newState.Privilege.Luid = this.luid;
|
||||||
newState.Privilege.Attributes = enable ? NativeMethods.SE_PRIVILEGE_ENABLED : NativeMethods.SE_PRIVILEGE_DISABLED;
|
newState.Privilege.Attributes = enable ? NativeMethods.SE_PRIVILEGE_ENABLED : NativeMethods.SE_PRIVILEGE_DISABLED;
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,11 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
string FFUPath = null;
|
string FFUPath = null;
|
||||||
|
|
||||||
OpenFileDialog dlg = new();
|
OpenFileDialog dlg = new()
|
||||||
dlg.DefaultExt = ".ffu"; // Default file extension
|
{
|
||||||
dlg.Filter = "ROM images (.ffu)|*.ffu"; // Filter files by extension
|
DefaultExt = ".ffu", // Default file extension
|
||||||
|
Filter = "ROM images (.ffu)|*.ffu" // Filter files by extension
|
||||||
|
};
|
||||||
|
|
||||||
bool? result = dlg.ShowDialog();
|
bool? result = dlg.ShowDialog();
|
||||||
|
|
||||||
@@ -95,9 +97,11 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
string SecWIMPath = null;
|
string SecWIMPath = null;
|
||||||
|
|
||||||
OpenFileDialog dlg = new();
|
OpenFileDialog dlg = new()
|
||||||
dlg.DefaultExt = ".secwim"; // Default file extension
|
{
|
||||||
dlg.Filter = "Secure WIM images (.secwim)|*.secwim"; // Filter files by extension
|
DefaultExt = ".secwim", // Default file extension
|
||||||
|
Filter = "Secure WIM images (.secwim)|*.secwim" // Filter files by extension
|
||||||
|
};
|
||||||
|
|
||||||
bool? result = dlg.ShowDialog();
|
bool? result = dlg.ShowDialog();
|
||||||
|
|
||||||
|
|||||||
@@ -93,15 +93,13 @@ namespace WPinternals
|
|||||||
|
|
||||||
internal void FlashPartitionsTask(string EFIESPPath, string MainOSPath, string DataPath)
|
internal void FlashPartitionsTask(string EFIESPPath, string MainOSPath, string DataPath)
|
||||||
{
|
{
|
||||||
new Thread(() =>
|
new Thread(async () =>
|
||||||
{
|
{
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
ActivateSubContext(new BusyViewModel("Initializing flash..."));
|
ActivateSubContext(new BusyViewModel("Initializing flash..."));
|
||||||
|
|
||||||
LumiaFlashAppModel Phone = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
GPT GPT = await LumiaUnlockBootloaderViewModel.ReadGPTFromFlashOrBootMgr(PhoneNotifier);
|
||||||
|
|
||||||
GPT GPT = Phone.ReadGPT();
|
|
||||||
|
|
||||||
ulong TotalSizeSectors = 0;
|
ulong TotalSizeSectors = 0;
|
||||||
int PartitionCount = 0;
|
int PartitionCount = 0;
|
||||||
@@ -157,6 +155,8 @@ namespace WPinternals
|
|||||||
Result = false;
|
Result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LumiaFlashAppModel Phone = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
|
||||||
if ((MainOSNewSectorCount > 0) && (DataNewSectorCount > 0))
|
if ((MainOSNewSectorCount > 0) && (DataNewSectorCount > 0))
|
||||||
{
|
{
|
||||||
if ((MainOSNewSectorCount > MainOSOldSectorCount) || (DataNewSectorCount > DataOldSectorCount))
|
if ((MainOSNewSectorCount > MainOSOldSectorCount) || (DataNewSectorCount > DataOldSectorCount))
|
||||||
@@ -206,7 +206,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
Busy.Message = "Flashing partition EFIESP (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
Busy.Message = "Flashing partition EFIESP (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
Phone.FlashRawPartition(EFIESPPath, "EFIESP", Updater);
|
Phone.FlashRawPartition(GPT, EFIESPPath, "EFIESP", Updater);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
@@ -224,7 +224,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
Busy.Message = "Flashing partition MainOS (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
Busy.Message = "Flashing partition MainOS (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
Phone.FlashRawPartition(MainOSPath, "MainOS", Updater);
|
Phone.FlashRawPartition(GPT, MainOSPath, "MainOS", Updater);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
@@ -242,7 +242,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
Busy.Message = "Flashing partition Data (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
Busy.Message = "Flashing partition Data (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
Phone.FlashRawPartition(DataPath, "Data", Updater);
|
Phone.FlashRawPartition(GPT, DataPath, "Data", Updater);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
@@ -288,12 +288,10 @@ namespace WPinternals
|
|||||||
|
|
||||||
internal void FlashArchiveTask(string ArchivePath)
|
internal void FlashArchiveTask(string ArchivePath)
|
||||||
{
|
{
|
||||||
new Thread(() =>
|
new Thread(async () =>
|
||||||
{
|
{
|
||||||
ActivateSubContext(new BusyViewModel("Initializing flash..."));
|
ActivateSubContext(new BusyViewModel("Initializing flash..."));
|
||||||
|
|
||||||
LumiaFlashAppModel Phone = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
|
||||||
|
|
||||||
ulong TotalSizeSectors = 0;
|
ulong TotalSizeSectors = 0;
|
||||||
int PartitionCount = 0;
|
int PartitionCount = 0;
|
||||||
ulong MainOSOldSectorCount = 0;
|
ulong MainOSOldSectorCount = 0;
|
||||||
@@ -305,7 +303,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GPT GPT = Phone.ReadGPT();
|
GPT GPT = await LumiaUnlockBootloaderViewModel.ReadGPTFromFlashOrBootMgr(PhoneNotifier);
|
||||||
|
|
||||||
using FileStream FileStream = new(ArchivePath, FileMode.Open);
|
using FileStream FileStream = new(ArchivePath, FileMode.Open);
|
||||||
using ZipArchive Archive = new(FileStream, ZipArchiveMode.Read);
|
using ZipArchive Archive = new(FileStream, ZipArchiveMode.Read);
|
||||||
@@ -412,6 +410,8 @@ namespace WPinternals
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LumiaFlashAppModel Phone = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
|
||||||
if (GPTChanged)
|
if (GPTChanged)
|
||||||
{
|
{
|
||||||
Phone.WriteGPT(GPT);
|
Phone.WriteGPT(GPT);
|
||||||
@@ -453,7 +453,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
Busy.Message = "Flashing partition " + Partition.Name + " (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
Busy.Message = "Flashing partition " + Partition.Name + " (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
Phone.FlashRawPartition(DecompressedStream, Partition.Name, Updater);
|
Phone.FlashRawPartition(GPT, DecompressedStream, Partition.Name, Updater);
|
||||||
}
|
}
|
||||||
DecompressedStream.Close();
|
DecompressedStream.Close();
|
||||||
}
|
}
|
||||||
@@ -522,33 +522,9 @@ namespace WPinternals
|
|||||||
|
|
||||||
if (Info.FlashAppProtocolVersionMajor >= 2)
|
if (Info.FlashAppProtocolVersionMajor >= 2)
|
||||||
{
|
{
|
||||||
Phone.SwitchToBootManagerContext();
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(PhoneNotifier, 0x20000); // TODO: Get proper profile FFU and get ChunkSizeInBytes
|
||||||
|
|
||||||
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
await PhoneNotifier.WaitForArrival();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
throw new WPinternalsException("Unexpected Mode");
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] GPTChunk = ((LumiaBootManagerAppModel)PhoneNotifier.CurrentModel).GetGptChunk(0x20000); // TODO: Get proper profile FFU and get ChunkSizeInBytes
|
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
|
|
||||||
((LumiaBootManagerAppModel)PhoneNotifier.CurrentModel).SwitchToFlashAppContext();
|
|
||||||
|
|
||||||
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
|
||||||
{
|
|
||||||
await PhoneNotifier.WaitForArrival();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
|
||||||
{
|
|
||||||
throw new WPinternalsException("Unexpected Mode");
|
|
||||||
}
|
|
||||||
|
|
||||||
Phone = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
Phone = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
|
||||||
FlashPart Part;
|
FlashPart Part;
|
||||||
@@ -790,8 +766,10 @@ namespace WPinternals
|
|||||||
IsSwitchingInterface = false; // From here on a device will be forced to Flash mode again on this screen which is meant for flashing
|
IsSwitchingInterface = false; // From here on a device will be forced to Flash mode again on this screen which is meant for flashing
|
||||||
Callback();
|
Callback();
|
||||||
ActivateSubContext(null);
|
ActivateSubContext(null);
|
||||||
});
|
})
|
||||||
SuccessMessageViewModel.SubMessage = SubMessage;
|
{
|
||||||
|
SubMessage = SubMessage
|
||||||
|
};
|
||||||
ActivateSubContext(SuccessMessageViewModel);
|
ActivateSubContext(SuccessMessageViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -802,8 +780,10 @@ namespace WPinternals
|
|||||||
IsSwitchingInterface = false;
|
IsSwitchingInterface = false;
|
||||||
Callback();
|
Callback();
|
||||||
ActivateSubContext(null);
|
ActivateSubContext(null);
|
||||||
});
|
})
|
||||||
ErrorMessageViewModel.SubMessage = SubMessage;
|
{
|
||||||
|
SubMessage = SubMessage
|
||||||
|
};
|
||||||
ActivateSubContext(ErrorMessageViewModel);
|
ActivateSubContext(ErrorMessageViewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,19 +221,6 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool AlreadyUnlocked = false;
|
|
||||||
if (DoUnlock)
|
|
||||||
{
|
|
||||||
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
|
||||||
GPT GPT = FlashModel.ReadGPT();
|
|
||||||
if ((GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null))
|
|
||||||
{
|
|
||||||
//ExitMessage("Phone is already unlocked", null);
|
|
||||||
//return;
|
|
||||||
AlreadyUnlocked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TestPos = 4;
|
TestPos = 4;
|
||||||
|
|
||||||
// Stop responding to device arrival here, because all connections are handled by subfunctions, not here.
|
// Stop responding to device arrival here, because all connections are handled by subfunctions, not here.
|
||||||
@@ -272,6 +259,14 @@ namespace WPinternals
|
|||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
bool AlreadyUnlocked = false;
|
||||||
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
GPT GPT = await LumiaUnlockBootloaderViewModel.ReadGPTFromFlashOrBootMgr(PhoneNotifier);
|
||||||
|
if ((GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null))
|
||||||
|
{
|
||||||
|
AlreadyUnlocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (DoFixBoot)
|
if (DoFixBoot)
|
||||||
{
|
{
|
||||||
await LumiaV2UnlockBootViewModel.LumiaV2FixBoot(PhoneNotifier, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
|
await LumiaV2UnlockBootViewModel.LumiaV2FixBoot(PhoneNotifier, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
|
||||||
@@ -666,8 +661,10 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
State = MachineState.Default;
|
State = MachineState.Default;
|
||||||
Exit();
|
Exit();
|
||||||
});
|
})
|
||||||
SuccessMessageViewModel.SubMessage = SubMessage;
|
{
|
||||||
|
SubMessage = SubMessage
|
||||||
|
};
|
||||||
ActivateSubContext(SuccessMessageViewModel);
|
ActivateSubContext(SuccessMessageViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,126 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
internal static class LumiaUnlockBootloaderViewModel
|
internal static class LumiaUnlockBootloaderViewModel
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This function reads GPT from the device, while preserving the current application running.
|
||||||
|
/// This works whenever the device is unlocked or not, from Flash or Bootloader apps
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="WPinternalsException">The device entered an unexpected mode.</exception>
|
||||||
|
public static async Task<GPT> ReadGPTFromFlashOrBootMgr(PhoneNotifierViewModel Notifier)
|
||||||
|
{
|
||||||
|
switch (Notifier.CurrentInterface)
|
||||||
|
{
|
||||||
|
case PhoneInterfaces.Lumia_Bootloader:
|
||||||
|
{
|
||||||
|
return ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadGPT();
|
||||||
|
}
|
||||||
|
case PhoneInterfaces.Lumia_Flash:
|
||||||
|
{
|
||||||
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)Notifier.CurrentModel;
|
||||||
|
|
||||||
|
if (FlashModel.CanReadGPT())
|
||||||
|
{
|
||||||
|
FlashModel.SwitchToBootManagerContext();
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
await Notifier.WaitForArrival();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
GPT GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadGPT();
|
||||||
|
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
await Notifier.WaitForArrival();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
return GPT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FlashModel.ReadGPT();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This function reads GPT from the device, while preserving the current application running.
|
||||||
|
/// This works whenever the device is unlocked or not, from Flash or Bootloader apps
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="WPinternalsException">The device entered an unexpected mode.</exception>
|
||||||
|
public static async Task<byte[]> GetGptChunkFromFlashOrBootMgr(PhoneNotifierViewModel Notifier, uint Size)
|
||||||
|
{
|
||||||
|
switch (Notifier.CurrentInterface)
|
||||||
|
{
|
||||||
|
case PhoneInterfaces.Lumia_Bootloader:
|
||||||
|
{
|
||||||
|
return ((LumiaBootManagerAppModel)Notifier.CurrentModel).GetGptChunk(Size);
|
||||||
|
}
|
||||||
|
case PhoneInterfaces.Lumia_Flash:
|
||||||
|
{
|
||||||
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)Notifier.CurrentModel;
|
||||||
|
|
||||||
|
if (FlashModel.CanReadGPT())
|
||||||
|
{
|
||||||
|
FlashModel.SwitchToBootManagerContext();
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
await Notifier.WaitForArrival();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).GetGptChunk(Size);
|
||||||
|
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
await Notifier.WaitForArrival();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
return GPT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FlashModel.GetGptChunk(Size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Add logging
|
// TODO: Add logging
|
||||||
private static void PerformSoftBrick(PhoneNotifierViewModel Notifier, FFU FFU)
|
private static void PerformSoftBrick(PhoneNotifierViewModel Notifier, FFU FFU)
|
||||||
{
|
{
|
||||||
@@ -353,33 +473,9 @@ namespace WPinternals
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
GPT NewGPT = null;
|
GPT NewGPT = null;
|
||||||
if (Notifier.CurrentModel is LumiaFlashAppModel)
|
if (Notifier.CurrentModel is LumiaFlashAppModel or LumiaBootManagerAppModel)
|
||||||
{
|
{
|
||||||
((LumiaFlashAppModel)Notifier.CurrentModel).ResetPhone();
|
NewGPT = await ReadGPTFromFlashOrBootMgr(Notifier);
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
await Notifier.WaitForArrival();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
throw new WPinternalsException("Phone is in an unexpected mode.", "The phone should have been detected in bootloader mode. Instead it has been detected in " + Notifier.CurrentInterface.ToString() + " mode.");
|
|
||||||
}
|
|
||||||
|
|
||||||
NewGPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadGPT();
|
|
||||||
|
|
||||||
await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Flash);
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
|
||||||
{
|
|
||||||
await Notifier.WaitForArrival();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
|
||||||
{
|
|
||||||
throw new WPinternalsException("Phone is in an unexpected mode.", "The phone should have been detected in flash mode. Instead it has been detected in " + Notifier.CurrentInterface.ToString() + " mode.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -592,11 +688,11 @@ namespace WPinternals
|
|||||||
Progress.SetProgress(0x21);
|
Progress.SetProgress(0x21);
|
||||||
|
|
||||||
LogFile.Log("Flash SBL2 at 0x" + ((UInt32)NewGPT.GetPartition("SBL2").FirstSector * 0x200).ToString("X8"));
|
LogFile.Log("Flash SBL2 at 0x" + ((UInt32)NewGPT.GetPartition("SBL2").FirstSector * 0x200).ToString("X8"));
|
||||||
CurrentModel.FlashRawPartition(SBL2, "SBL2", Progress);
|
CurrentModel.FlashRawPartition(NewGPT, SBL2, "SBL2", Progress);
|
||||||
LogFile.Log("Flash SBL3 at 0x" + ((UInt32)NewGPT.GetPartition("SBL3").FirstSector * 0x200).ToString("X8"));
|
LogFile.Log("Flash SBL3 at 0x" + ((UInt32)NewGPT.GetPartition("SBL3").FirstSector * 0x200).ToString("X8"));
|
||||||
CurrentModel.FlashRawPartition(SBL3, "SBL3", Progress);
|
CurrentModel.FlashRawPartition(NewGPT, SBL3, "SBL3", Progress);
|
||||||
LogFile.Log("Flash UEFI at 0x" + ((UInt32)NewGPT.GetPartition("UEFI").FirstSector * 0x200).ToString("X8"));
|
LogFile.Log("Flash UEFI at 0x" + ((UInt32)NewGPT.GetPartition("UEFI").FirstSector * 0x200).ToString("X8"));
|
||||||
CurrentModel.FlashRawPartition(UEFI, "UEFI", Progress);
|
CurrentModel.FlashRawPartition(NewGPT, UEFI, "UEFI", Progress);
|
||||||
|
|
||||||
// phone is in flash mode, we can exit
|
// phone is in flash mode, we can exit
|
||||||
}
|
}
|
||||||
@@ -907,33 +1003,9 @@ namespace WPinternals
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
GPT NewGPT = null;
|
GPT NewGPT = null;
|
||||||
if (Notifier.CurrentModel is LumiaFlashAppModel)
|
if (Notifier.CurrentModel is LumiaFlashAppModel or LumiaBootManagerAppModel)
|
||||||
{
|
{
|
||||||
((LumiaFlashAppModel)Notifier.CurrentModel).ResetPhone();
|
NewGPT = await ReadGPTFromFlashOrBootMgr(Notifier);
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
await Notifier.WaitForArrival();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
throw new WPinternalsException("Phone is in an unexpected mode.", "The phone should have been detected in bootloader mode. Instead it has been detected in " + Notifier.CurrentInterface.ToString() + " mode.");
|
|
||||||
}
|
|
||||||
|
|
||||||
NewGPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadGPT();
|
|
||||||
|
|
||||||
await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Flash);
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
|
||||||
{
|
|
||||||
await Notifier.WaitForArrival();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
|
||||||
{
|
|
||||||
throw new WPinternalsException("Phone is in an unexpected mode.", "The phone should have been detected in flash mode. Instead it has been detected in " + Notifier.CurrentInterface.ToString() + " mode.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1273,15 +1345,15 @@ namespace WPinternals
|
|||||||
if (ExtraSector != null)
|
if (ExtraSector != null)
|
||||||
{
|
{
|
||||||
LogFile.Log("Flash EXT at 0x" + ((UInt32)NewGPT.GetPartition("HACK").FirstSector * 0x200).ToString("X8"));
|
LogFile.Log("Flash EXT at 0x" + ((UInt32)NewGPT.GetPartition("HACK").FirstSector * 0x200).ToString("X8"));
|
||||||
CurrentModel.FlashRawPartition(ExtraSector, "HACK", Progress);
|
CurrentModel.FlashRawPartition(NewGPT, ExtraSector, "HACK", Progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogFile.Log("Flash SBL2 at 0x" + ((UInt32)NewGPT.GetPartition("SBL2").FirstSector * 0x200).ToString("X8"));
|
LogFile.Log("Flash SBL2 at 0x" + ((UInt32)NewGPT.GetPartition("SBL2").FirstSector * 0x200).ToString("X8"));
|
||||||
CurrentModel.FlashRawPartition(SBL2, "SBL2", Progress);
|
CurrentModel.FlashRawPartition(NewGPT, SBL2, "SBL2", Progress);
|
||||||
LogFile.Log("Flash SBL3 at 0x" + ((UInt32)NewGPT.GetPartition("SBL3").FirstSector * 0x200).ToString("X8"));
|
LogFile.Log("Flash SBL3 at 0x" + ((UInt32)NewGPT.GetPartition("SBL3").FirstSector * 0x200).ToString("X8"));
|
||||||
CurrentModel.FlashRawPartition(SBL3, "SBL3", Progress);
|
CurrentModel.FlashRawPartition(NewGPT, SBL3, "SBL3", Progress);
|
||||||
LogFile.Log("Flash UEFI at 0x" + ((UInt32)NewGPT.GetPartition("UEFI").FirstSector * 0x200).ToString("X8"));
|
LogFile.Log("Flash UEFI at 0x" + ((UInt32)NewGPT.GetPartition("UEFI").FirstSector * 0x200).ToString("X8"));
|
||||||
CurrentModel.FlashRawPartition(UEFI, "UEFI", Progress);
|
CurrentModel.FlashRawPartition(NewGPT, UEFI, "UEFI", Progress);
|
||||||
|
|
||||||
// phone is in flash mode, we can exit
|
// phone is in flash mode, we can exit
|
||||||
}
|
}
|
||||||
@@ -1517,31 +1589,7 @@ namespace WPinternals
|
|||||||
bool IsSpecB = Info.FlashAppProtocolVersionMajor >= 2;
|
bool IsSpecB = Info.FlashAppProtocolVersionMajor >= 2;
|
||||||
bool UndoEFIESPPadding = false;
|
bool UndoEFIESPPadding = false;
|
||||||
|
|
||||||
byte[] GPTChunk;
|
byte[] GPTChunk = await GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
|
|
||||||
if (!IsSpecB)
|
|
||||||
{
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
|
||||||
{
|
|
||||||
((LumiaFlashAppModel)Notifier.CurrentModel).ResetPhone();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
await Notifier.WaitForArrival();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
throw new WPinternalsException("Phone is in an unexpected mode.", "The phone should have been detected in bootloader mode. Instead it has been detected in " + Notifier.CurrentInterface.ToString() + " mode.");
|
|
||||||
}
|
|
||||||
|
|
||||||
GPTChunk = ((LumiaBootManagerAppModel)Notifier.CurrentModel).GetGptChunk(0x20000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GPTChunk = ((LumiaFlashAppModel)Notifier.CurrentModel).GetGptChunk(0x20000);
|
|
||||||
}
|
|
||||||
|
|
||||||
GPT = new GPT(GPTChunk);
|
GPT = new GPT(GPTChunk);
|
||||||
bool GPTChanged = false;
|
bool GPTChanged = false;
|
||||||
@@ -1579,7 +1627,7 @@ namespace WPinternals
|
|||||||
await SwitchModeViewModel.SwitchToWithStatus(Notifier, PhoneInterfaces.Lumia_MassStorage, SetWorkingStatus, UpdateWorkingStatus);
|
await SwitchModeViewModel.SwitchToWithStatus(Notifier, PhoneInterfaces.Lumia_MassStorage, SetWorkingStatus, UpdateWorkingStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(Notifier.CurrentModel is MassStorage))
|
if (Notifier.CurrentModel is not MassStorage)
|
||||||
{
|
{
|
||||||
throw new WPinternalsException("Failed to switch to Mass Storage mode");
|
throw new WPinternalsException("Failed to switch to Mass Storage mode");
|
||||||
}
|
}
|
||||||
@@ -1922,7 +1970,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
LumiaPatchEFIESP(SupportedFFU, UnlockedEFIESP, IsSpecB);
|
LumiaPatchEFIESP(SupportedFFU, UnlockedEFIESP, IsSpecB);
|
||||||
|
|
||||||
byte[] GPTChunk = FlashModel.GetGptChunk((UInt32)ProfileFFU.ChunkSize);
|
byte[] GPTChunk = await GetGptChunkFromFlashOrBootMgr(Notifier, (UInt32)ProfileFFU.ChunkSize);
|
||||||
byte[] GPTChunkBackup = new byte[GPTChunk.Length];
|
byte[] GPTChunkBackup = new byte[GPTChunk.Length];
|
||||||
Buffer.BlockCopy(GPTChunk, 0, GPTChunkBackup, 0, GPTChunk.Length);
|
Buffer.BlockCopy(GPTChunk, 0, GPTChunkBackup, 0, GPTChunk.Length);
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
@@ -2533,9 +2581,11 @@ namespace WPinternals
|
|||||||
|
|
||||||
List<FlashPart> Parts = [];
|
List<FlashPart> Parts = [];
|
||||||
|
|
||||||
FlashPart Part = new();
|
FlashPart Part = new()
|
||||||
Part.StartSector = (uint)EFIESP.FirstSector;
|
{
|
||||||
Part.Stream = new MemoryStream(FirstSector);
|
StartSector = (uint)EFIESP.FirstSector,
|
||||||
|
Stream = new MemoryStream(FirstSector)
|
||||||
|
};
|
||||||
Parts.Add(Part);
|
Parts.Add(Part);
|
||||||
|
|
||||||
Part = new FlashPart
|
Part = new FlashPart
|
||||||
@@ -2564,9 +2614,11 @@ namespace WPinternals
|
|||||||
|
|
||||||
List<FlashPart> Parts = [];
|
List<FlashPart> Parts = [];
|
||||||
|
|
||||||
FlashPart Part = new();
|
FlashPart Part = new()
|
||||||
Part.StartSector = (uint)EFIESP.FirstSector;
|
{
|
||||||
Part.Stream = new MemoryStream(FirstSector);
|
StartSector = (uint)EFIESP.FirstSector,
|
||||||
|
Stream = new MemoryStream(FirstSector)
|
||||||
|
};
|
||||||
Parts.Add(Part);
|
Parts.Add(Part);
|
||||||
|
|
||||||
return Parts;
|
return Parts;
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
||||||
// We need the fist sector if we want to write back the GPT.
|
// We need the fist sector if we want to write back the GPT.
|
||||||
byte[] GPTChunk = FlashModel.GetGptChunk(0x20000);
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
bool GPTChanged = false;
|
bool GPTChanged = false;
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
||||||
// We need the fist sector if we want to write back the GPT.
|
// We need the fist sector if we want to write back the GPT.
|
||||||
byte[] GPTChunk = FlashModel.GetGptChunk(0x20000);
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
bool GPTChanged = false;
|
bool GPTChanged = false;
|
||||||
Partition BACKUP_BS_NV = GPT.GetPartition("BACKUP_BS_NV");
|
Partition BACKUP_BS_NV = GPT.GetPartition("BACKUP_BS_NV");
|
||||||
@@ -299,9 +299,11 @@ namespace WPinternals
|
|||||||
if (GPTChanged)
|
if (GPTChanged)
|
||||||
{
|
{
|
||||||
GPT.Rebuild();
|
GPT.Rebuild();
|
||||||
FlashPart Part = new();
|
FlashPart Part = new()
|
||||||
Part.StartSector = 0;
|
{
|
||||||
Part.Stream = new MemoryStream(GPTChunk);
|
StartSector = 0,
|
||||||
|
Stream = new MemoryStream(GPTChunk)
|
||||||
|
};
|
||||||
Parts.Add(Part);
|
Parts.Add(Part);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +350,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
||||||
// We need the fist sector if we want to write back the GPT.
|
// We need the fist sector if we want to write back the GPT.
|
||||||
byte[] GPTChunk = FlashModel.GetGptChunk(0x20000);
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
|
|
||||||
Partition TargetPartition = GPT.GetPartition(PartitionName);
|
Partition TargetPartition = GPT.GetPartition(PartitionName);
|
||||||
@@ -487,11 +489,11 @@ namespace WPinternals
|
|||||||
|
|
||||||
internal async static Task LumiaV2CustomFlash(PhoneNotifierViewModel Notifier, string FFUPath, bool PerformFullFlashFirst, bool SkipWrite, List<FlashPart> FlashParts, bool DoResetFirst = true, bool ClearFlashingStatusAtEnd = true, bool CheckSectorAlignment = true, bool ShowProgress = true, bool Experimental = false, SetWorkingStatus SetWorkingStatus = null, UpdateWorkingStatus UpdateWorkingStatus = null, ExitSuccess ExitSuccess = null, ExitFailure ExitFailure = null, string ProgrammerPath = null)
|
internal async static Task LumiaV2CustomFlash(PhoneNotifierViewModel Notifier, string FFUPath, bool PerformFullFlashFirst, bool SkipWrite, List<FlashPart> FlashParts, bool DoResetFirst = true, bool ClearFlashingStatusAtEnd = true, bool CheckSectorAlignment = true, bool ShowProgress = true, bool Experimental = false, SetWorkingStatus SetWorkingStatus = null, UpdateWorkingStatus UpdateWorkingStatus = null, ExitSuccess ExitSuccess = null, ExitFailure ExitFailure = null, string ProgrammerPath = null)
|
||||||
{
|
{
|
||||||
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 131072u);
|
||||||
|
|
||||||
LumiaFlashAppModel Model = (LumiaFlashAppModel)Notifier.CurrentModel;
|
LumiaFlashAppModel Model = (LumiaFlashAppModel)Notifier.CurrentModel;
|
||||||
LumiaFlashAppPhoneInfo Info = Model.ReadPhoneInfo();
|
LumiaFlashAppPhoneInfo Info = Model.ReadPhoneInfo();
|
||||||
|
|
||||||
byte[] GPTChunk = Model.GetGptChunk(131072u);
|
|
||||||
|
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
|
|
||||||
Partition UefiBSNV = GPT.GetPartition("UEFI_BS_NV");
|
Partition UefiBSNV = GPT.GetPartition("UEFI_BS_NV");
|
||||||
@@ -719,7 +721,7 @@ namespace WPinternals
|
|||||||
MaximumAttempts = (int)(((MaximumGapFill / FFU.ChunkSize) + 1) * 8);
|
MaximumAttempts = (int)(((MaximumGapFill / FFU.ChunkSize) + 1) * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] GPTChunk = ((LumiaFlashAppModel)Notifier.CurrentModel).GetGptChunk((UInt32)FFU.ChunkSize);
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, (UInt32)FFU.ChunkSize);
|
||||||
|
|
||||||
// Start with a reset
|
// Start with a reset
|
||||||
if (DoResetFirst)
|
if (DoResetFirst)
|
||||||
@@ -2012,7 +2014,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
||||||
// We need the fist sector if we want to write back the GPT.
|
// We need the fist sector if we want to write back the GPT.
|
||||||
byte[] GPTChunk = FlashModel.GetGptChunk(0x20000);
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
|
|
||||||
Partition Target;
|
Partition Target;
|
||||||
@@ -2405,7 +2407,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
// Use GetGptChunk() here instead of ReadGPT(), because ReadGPT() skips the first sector.
|
||||||
// We need the fist sector if we want to write back the GPT.
|
// We need the fist sector if we want to write back the GPT.
|
||||||
byte[] GPTChunk = FlashModel.GetGptChunk(0x20000);
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
|
|
||||||
Partition Target;
|
Partition Target;
|
||||||
@@ -2956,9 +2958,11 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FreeMemRange NewFreeRange = new();
|
FreeMemRange NewFreeRange = new()
|
||||||
NewFreeRange.Start = Allocation.TotalStart;
|
{
|
||||||
NewFreeRange.End = Allocation.TotalEnd;
|
Start = Allocation.TotalStart,
|
||||||
|
End = Allocation.TotalEnd
|
||||||
|
};
|
||||||
|
|
||||||
bool Added = false;
|
bool Added = false;
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -272,9 +272,10 @@ namespace WPinternals
|
|||||||
// ==============================
|
// ==============================
|
||||||
// Header 2 start
|
// Header 2 start
|
||||||
|
|
||||||
StoreHeader store = new();
|
StoreHeader store = new()
|
||||||
|
{
|
||||||
store.WriteDescriptorCount = (UInt32)payloads.Length;
|
WriteDescriptorCount = (UInt32)payloads.Length
|
||||||
|
};
|
||||||
store.FinalTableIndex = (UInt32)payloads.Length - store.FinalTableCount;
|
store.FinalTableIndex = (UInt32)payloads.Length - store.FinalTableCount;
|
||||||
store.PlatformId = Info.PlatformID;
|
store.PlatformId = Info.PlatformID;
|
||||||
|
|
||||||
@@ -283,7 +284,7 @@ namespace WPinternals
|
|||||||
store.WriteDescriptorLength += payload.GetStoreHeaderSize();
|
store.WriteDescriptorLength += payload.GetStoreHeaderSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] GPTChunk = Model.GetGptChunk(0x20000);
|
byte[] GPTChunk = await LumiaUnlockBootloaderViewModel.GetGptChunkFromFlashOrBootMgr(Notifier, 0x20000);
|
||||||
GPT GPT = new(GPTChunk);
|
GPT GPT = new(GPTChunk);
|
||||||
UInt64 PlatEnd = 0;
|
UInt64 PlatEnd = 0;
|
||||||
if (GPT.Partitions.Any(x => x.Name == "PLAT"))
|
if (GPT.Partitions.Any(x => x.Name == "PLAT"))
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace WPinternals
|
|||||||
|
|
||||||
internal void RestoreTask(string EFIESPPath, string MainOSPath, string DataPath)
|
internal void RestoreTask(string EFIESPPath, string MainOSPath, string DataPath)
|
||||||
{
|
{
|
||||||
new Thread(() =>
|
new Thread(async () =>
|
||||||
{
|
{
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
@@ -121,6 +121,8 @@ namespace WPinternals
|
|||||||
ProgressUpdater Updater = Busy.ProgressUpdater;
|
ProgressUpdater Updater = Busy.ProgressUpdater;
|
||||||
ActivateSubContext(Busy);
|
ActivateSubContext(Busy);
|
||||||
|
|
||||||
|
GPT GPT = await LumiaUnlockBootloaderViewModel.ReadGPTFromFlashOrBootMgr(PhoneNotifier);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (Result)
|
if (Result)
|
||||||
{
|
{
|
||||||
@@ -130,7 +132,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
Busy.Message = "Restoring partition EFIESP (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
Busy.Message = "Restoring partition EFIESP (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
Phone.FlashRawPartition(EFIESPPath, "EFIESP", Updater);
|
Phone.FlashRawPartition(GPT, EFIESPPath, "EFIESP", Updater);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
@@ -148,7 +150,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
Busy.Message = "Restoring partition MainOS (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
Busy.Message = "Restoring partition MainOS (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
Phone.FlashRawPartition(EFIESPPath, "MainOS", Updater);
|
Phone.FlashRawPartition(GPT, EFIESPPath, "MainOS", Updater);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
@@ -166,7 +168,7 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
Busy.Message = "Restoring partition Data (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
Busy.Message = "Restoring partition Data (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
|
||||||
Phone.FlashRawPartition(EFIESPPath, "Data", Updater);
|
Phone.FlashRawPartition(GPT, EFIESPPath, "Data", Updater);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception Ex)
|
catch (Exception Ex)
|
||||||
|
|||||||
@@ -240,8 +240,6 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
IsSwitching = true;
|
IsSwitching = true;
|
||||||
|
|
||||||
byte[] RebootCommandResult;
|
|
||||||
|
|
||||||
bool ModernFlashApp;
|
bool ModernFlashApp;
|
||||||
|
|
||||||
// Make switch and set message or navigate to error
|
// Make switch and set message or navigate to error
|
||||||
@@ -338,7 +336,7 @@ namespace WPinternals
|
|||||||
break;
|
break;
|
||||||
case PhoneInterfaces.Lumia_Bootloader:
|
case PhoneInterfaces.Lumia_Bootloader:
|
||||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||||
((LumiaBootManagerAppModel)PhoneNotifier.CurrentModel).ResetPhone();
|
((LumiaFlashAppModel)PhoneNotifier.CurrentModel).ResetPhone();
|
||||||
ModeSwitchProgressWrapper("Rebooting phone to Bootloader mode...", null);
|
ModeSwitchProgressWrapper("Rebooting phone to Bootloader mode...", null);
|
||||||
LogFile.Log("Rebooting phone to Bootloader mode", LogType.FileAndConsole);
|
LogFile.Log("Rebooting phone to Bootloader mode", LogType.FileAndConsole);
|
||||||
break;
|
break;
|
||||||
@@ -664,7 +662,6 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
else if ((CurrentMode == PhoneInterfaces.Lumia_Flash) && (TargetMode == PhoneInterfaces.Qualcomm_Download))
|
else if ((CurrentMode == PhoneInterfaces.Lumia_Flash) && (TargetMode == PhoneInterfaces.Qualcomm_Download))
|
||||||
{
|
{
|
||||||
byte[] RebootCommand = [0x4E, 0x4F, 0x4B, 0x52];
|
|
||||||
IsSwitchingInterface = true;
|
IsSwitchingInterface = true;
|
||||||
LogFile.Log("Sending command for rebooting to Emergency Download mode");
|
LogFile.Log("Sending command for rebooting to Emergency Download mode");
|
||||||
try
|
try
|
||||||
@@ -884,24 +881,13 @@ namespace WPinternals
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ENOSWDownloadCompleted(string[] URLs, object State)
|
public void BootMMOS(string MMOSPath)
|
||||||
{
|
|
||||||
string Firmware = (string)State;
|
|
||||||
string ENOSWFileUrl = URLs[0];
|
|
||||||
string Name = DownloadsViewModel.GetFileNameFromURL(ENOSWFileUrl);
|
|
||||||
string TempFolder = $@"{Environment.GetEnvironmentVariable("TEMP")}\WPInternals";
|
|
||||||
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
|
||||||
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
ModeSwitchProgressWrapper("Initializing Flash...", null);
|
ModeSwitchProgressWrapper("Initializing Flash...", null);
|
||||||
|
|
||||||
string MMOSPath = Path.Combine(TempFolder, Name);
|
|
||||||
|
|
||||||
App.Config.AddSecWimToRepository(MMOSPath, Firmware);
|
|
||||||
|
|
||||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||||
|
|
||||||
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo();
|
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo();
|
||||||
|
|
||||||
FileInfo info = new(MMOSPath);
|
FileInfo info = new(MMOSPath);
|
||||||
@@ -918,15 +904,12 @@ namespace WPinternals
|
|||||||
FlashModel.FlashMMOS(MMOSPath, progressUpdater);
|
FlashModel.FlashMMOS(MMOSPath, progressUpdater);
|
||||||
|
|
||||||
ModeSwitchProgressWrapper("And now booting phone to MMOS...", "If the phone stays on the lightning cog screen for a while, you may need to unplug and replug the phone to continue the boot process.");
|
ModeSwitchProgressWrapper("And now booting phone to MMOS...", "If the phone stays on the lightning cog screen for a while, you may need to unplug and replug the phone to continue the boot process.");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SwitchFromPhoneInfoToMassStorageMode(bool Continuation = false)
|
private void SwitchFromPhoneInfoToMassStorageMode(bool Continuation = false)
|
||||||
{
|
{
|
||||||
string ProgressText = Continuation ? "And now rebooting phone to Mass Storage mode..." : "Rebooting phone to Mass Storage mode...";
|
string ProgressText = Continuation ? "And now rebooting phone to Mass Storage mode..." : "Rebooting phone to Mass Storage mode...";
|
||||||
|
|
||||||
new Thread(async () =>
|
|
||||||
{
|
|
||||||
bool ModernFlashApp = ((LumiaPhoneInfoAppModel)PhoneNotifier.CurrentModel).ReadPhoneInfo().PhoneInfoAppVersionMajor >= 2;
|
bool ModernFlashApp = ((LumiaPhoneInfoAppModel)PhoneNotifier.CurrentModel).ReadPhoneInfo().PhoneInfoAppVersionMajor >= 2;
|
||||||
if (ModernFlashApp)
|
if (ModernFlashApp)
|
||||||
{
|
{
|
||||||
@@ -936,13 +919,35 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
((LumiaPhoneInfoAppModel)PhoneNotifier.CurrentModel).ContinueBoot();
|
((LumiaPhoneInfoAppModel)PhoneNotifier.CurrentModel).ContinueBoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Thread(async () =>
|
||||||
|
{
|
||||||
await PhoneNotifier.WaitForArrival();
|
await PhoneNotifier.WaitForArrival();
|
||||||
|
|
||||||
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
bool IsModernFlashApp = false;
|
||||||
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: false);
|
|
||||||
|
switch (CurrentMode)
|
||||||
|
{
|
||||||
|
case PhoneInterfaces.Lumia_Flash:
|
||||||
|
{
|
||||||
|
LumiaFlashAppModel _FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
LumiaFlashAppPhoneInfo _Info = _FlashModel.ReadPhoneInfo(ExtendedInfo: false);
|
||||||
|
|
||||||
|
IsModernFlashApp = _Info.FlashAppProtocolVersionMajor >= 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PhoneInterfaces.Lumia_Bootloader:
|
||||||
|
{
|
||||||
|
LumiaBootManagerAppModel _FlashModel = (LumiaBootManagerAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
LumiaBootManagerPhoneInfo _Info = _FlashModel.ReadPhoneInfo(ExtendedInfo: false);
|
||||||
|
|
||||||
|
IsModernFlashApp = _Info.BootManagerProtocolVersionMajor >= 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MassStorageWarning = null;
|
MassStorageWarning = null;
|
||||||
if (Info.FlashAppProtocolVersionMajor < 2)
|
if (!IsModernFlashApp)
|
||||||
{
|
{
|
||||||
MassStorageWarning = "Switching to Mass Storage mode should take about 10 seconds. The phone should be unlocked using an Engineering SBL3 to enable Mass Storage mode. When you unlocked the bootloader, but you did not use an Engineering SBL3, an attempt to boot to Mass Storage mode may result in an unresponsive state. Installing drivers for this interface may also cause to hang the PC. So when this switch is taking too long, you should reboot both the PC and the phone. To reboot the phone, you have to perform a soft-reset. Press and hold the volume-down-button and the power-button at the same time for at least 10 seconds. This will trigger a power-cycle and the phone will reboot. Once fully booted, the phone may show strange behavior, like complaining about mail-accounts, showing old text-messages, inability to load https-websites, etc. This is expected behavior, because the time-settings of the phone are incorrect. Just wait a few seconds for the phone to get a data-connection and have the date/time synced. After that the strange behavior will stop automatically and normal operation is resumed.";
|
MassStorageWarning = "Switching to Mass Storage mode should take about 10 seconds. The phone should be unlocked using an Engineering SBL3 to enable Mass Storage mode. When you unlocked the bootloader, but you did not use an Engineering SBL3, an attempt to boot to Mass Storage mode may result in an unresponsive state. Installing drivers for this interface may also cause to hang the PC. So when this switch is taking too long, you should reboot both the PC and the phone. To reboot the phone, you have to perform a soft-reset. Press and hold the volume-down-button and the power-button at the same time for at least 10 seconds. This will trigger a power-cycle and the phone will reboot. Once fully booted, the phone may show strange behavior, like complaining about mail-accounts, showing old text-messages, inability to load https-websites, etc. This is expected behavior, because the time-settings of the phone are incorrect. Just wait a few seconds for the phone to get a data-connection and have the date/time synced. After that the strange behavior will stop automatically and normal operation is resumed.";
|
||||||
}
|
}
|
||||||
@@ -955,17 +960,36 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsOldLumia = Info.FlashAppProtocolVersionMajor < 2;
|
|
||||||
bool IsNewLumia = Info.FlashAppProtocolVersionMajor >= 2;
|
|
||||||
bool IsUnlockedNew = false;
|
bool IsUnlockedNew = false;
|
||||||
if (IsNewLumia)
|
GPT GPT = null;
|
||||||
|
|
||||||
|
if (IsModernFlashApp)
|
||||||
{
|
{
|
||||||
GPT GPT = FlashModel.ReadGPT();
|
GPT = await ReadGPTFromFlashOrBootMgr();
|
||||||
IsUnlockedNew = (GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null) || (GPT.GetPartition("BACKUP_BS_NV") != null);
|
IsUnlockedNew = (GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null) || (GPT.GetPartition("BACKUP_BS_NV") != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CurrentMode == PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)PhoneNotifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
|
||||||
|
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
await PhoneNotifier.WaitForArrival();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: false);
|
||||||
|
|
||||||
bool IsOriginalEngineeringLumia = !Info.IsBootloaderSecure && !IsUnlockedNew;
|
bool IsOriginalEngineeringLumia = !Info.IsBootloaderSecure && !IsUnlockedNew;
|
||||||
|
|
||||||
if (IsOldLumia || IsOriginalEngineeringLumia)
|
if (!IsModernFlashApp || IsOriginalEngineeringLumia)
|
||||||
{
|
{
|
||||||
IsSwitchingInterface = true;
|
IsSwitchingInterface = true;
|
||||||
try
|
try
|
||||||
@@ -996,8 +1020,6 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsUnlockedNew)
|
else if (IsUnlockedNew)
|
||||||
{
|
|
||||||
new Thread(async () =>
|
|
||||||
{
|
{
|
||||||
LogFile.BeginAction("SwitchToMassStorageMode");
|
LogFile.BeginAction("SwitchToMassStorageMode");
|
||||||
|
|
||||||
@@ -1024,15 +1046,16 @@ namespace WPinternals
|
|||||||
// because the SecureBoot flag is disabled here.
|
// because the SecureBoot flag is disabled here.
|
||||||
// So either the NV was already backupped or already overwritten.
|
// So either the NV was already backupped or already overwritten.
|
||||||
|
|
||||||
GPT GPT = FlashModel.ReadGPT();
|
|
||||||
Partition Target = GPT.GetPartition("UEFI_BS_NV");
|
Partition Target = GPT.GetPartition("UEFI_BS_NV");
|
||||||
|
|
||||||
// We've been reading the GPT, so we let the phone reset once more to be sure that memory maps are the same
|
// We've been reading the GPT, so we let the phone reset once more to be sure that memory maps are the same
|
||||||
WPinternalsStatus LastStatus = WPinternalsStatus.Undefined;
|
WPinternalsStatus LastStatus = WPinternalsStatus.Undefined;
|
||||||
List<FlashPart> Parts = [];
|
List<FlashPart> Parts = [];
|
||||||
FlashPart Part = new();
|
FlashPart Part = new()
|
||||||
Part.StartSector = (uint)Target.FirstSector;
|
{
|
||||||
Part.Stream = SB;
|
StartSector = (uint)Target.FirstSector,
|
||||||
|
Stream = SB
|
||||||
|
};
|
||||||
Parts.Add(Part);
|
Parts.Add(Part);
|
||||||
await LumiaV2UnlockBootViewModel.LumiaV2CustomFlash(PhoneNotifier, null, false, false, Parts, DoResetFirst: true, ClearFlashingStatusAtEnd: false, ShowProgress: false,
|
await LumiaV2UnlockBootViewModel.LumiaV2CustomFlash(PhoneNotifier, null, false, false, Parts, DoResetFirst: true, ClearFlashingStatusAtEnd: false, ShowProgress: false,
|
||||||
SetWorkingStatus: (m, s, v, a, st) =>
|
SetWorkingStatus: (m, s, v, a, st) =>
|
||||||
@@ -1120,7 +1143,6 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogFile.EndAction("SwitchToMassStorageMode");
|
LogFile.EndAction("SwitchToMassStorageMode");
|
||||||
}).Start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1129,25 +1151,28 @@ namespace WPinternals
|
|||||||
}).Start();
|
}).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This function reads GPT from the device, while preserving the current application running.
|
||||||
|
/// This works whenever the device is unlocked or not, from Flash or Bootloader apps
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="WPinternalsException">The device entered an unexpected mode.</exception>
|
||||||
|
private async Task<GPT> ReadGPTFromFlashOrBootMgr()
|
||||||
|
{
|
||||||
|
return await LumiaUnlockBootloaderViewModel.ReadGPTFromFlashOrBootMgr(PhoneNotifier);
|
||||||
|
}
|
||||||
|
|
||||||
private void SwitchFromFlashToMassStorageMode(bool Continuation = false)
|
private void SwitchFromFlashToMassStorageMode(bool Continuation = false)
|
||||||
{
|
{
|
||||||
string ProgressText = Continuation ? "And now rebooting phone to Mass Storage mode..." : "Rebooting phone to Mass Storage mode...";
|
string ProgressText = Continuation ? "And now rebooting phone to Mass Storage mode..." : "Rebooting phone to Mass Storage mode...";
|
||||||
if (CurrentMode == PhoneInterfaces.Lumia_Bootloader)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
((LumiaBootManagerAppModel)PhoneNotifier.CurrentModel).SwitchToFlashAppContext();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LogFile.LogException(ex, LogType.FileOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: false);
|
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: false);
|
||||||
|
|
||||||
|
bool IsModernFlashApp = Info.FlashAppProtocolVersionMajor >= 2;
|
||||||
|
|
||||||
MassStorageWarning = null;
|
MassStorageWarning = null;
|
||||||
if (Info.FlashAppProtocolVersionMajor < 2)
|
if (!IsModernFlashApp)
|
||||||
{
|
{
|
||||||
MassStorageWarning = "Switching to Mass Storage mode should take about 10 seconds. The phone should be unlocked using an Engineering SBL3 to enable Mass Storage mode. When you unlocked the bootloader, but you did not use an Engineering SBL3, an attempt to boot to Mass Storage mode may result in an unresponsive state. Installing drivers for this interface may also cause to hang the PC. So when this switch is taking too long, you should reboot both the PC and the phone. To reboot the phone, you have to perform a soft-reset. Press and hold the volume-down-button and the power-button at the same time for at least 10 seconds. This will trigger a power-cycle and the phone will reboot. Once fully booted, the phone may show strange behavior, like complaining about mail-accounts, showing old text-messages, inability to load https-websites, etc. This is expected behavior, because the time-settings of the phone are incorrect. Just wait a few seconds for the phone to get a data-connection and have the date/time synced. After that the strange behavior will stop automatically and normal operation is resumed.";
|
MassStorageWarning = "Switching to Mass Storage mode should take about 10 seconds. The phone should be unlocked using an Engineering SBL3 to enable Mass Storage mode. When you unlocked the bootloader, but you did not use an Engineering SBL3, an attempt to boot to Mass Storage mode may result in an unresponsive state. Installing drivers for this interface may also cause to hang the PC. So when this switch is taking too long, you should reboot both the PC and the phone. To reboot the phone, you have to perform a soft-reset. Press and hold the volume-down-button and the power-button at the same time for at least 10 seconds. This will trigger a power-cycle and the phone will reboot. Once fully booted, the phone may show strange behavior, like complaining about mail-accounts, showing old text-messages, inability to load https-websites, etc. This is expected behavior, because the time-settings of the phone are incorrect. Just wait a few seconds for the phone to get a data-connection and have the date/time synced. After that the strange behavior will stop automatically and normal operation is resumed.";
|
||||||
}
|
}
|
||||||
@@ -1160,17 +1185,24 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsOldLumia = Info.FlashAppProtocolVersionMajor < 2;
|
new Thread(async () =>
|
||||||
bool IsNewLumia = Info.FlashAppProtocolVersionMajor >= 2;
|
|
||||||
bool IsUnlockedNew = false;
|
|
||||||
if (IsNewLumia)
|
|
||||||
{
|
{
|
||||||
GPT GPT = FlashModel.ReadGPT();
|
bool IsUnlockedNew = false;
|
||||||
|
|
||||||
|
GPT GPT = null;
|
||||||
|
|
||||||
|
if (IsModernFlashApp)
|
||||||
|
{
|
||||||
|
GPT = await ReadGPTFromFlashOrBootMgr();
|
||||||
IsUnlockedNew = (GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null) || (GPT.GetPartition("BACKUP_BS_NV") != null);
|
IsUnlockedNew = (GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null) || (GPT.GetPartition("BACKUP_BS_NV") != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
LumiaFlashAppPhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: false);
|
||||||
|
|
||||||
bool IsOriginalEngineeringLumia = !Info.IsBootloaderSecure && !IsUnlockedNew;
|
bool IsOriginalEngineeringLumia = !Info.IsBootloaderSecure && !IsUnlockedNew;
|
||||||
|
|
||||||
if (IsOldLumia || IsOriginalEngineeringLumia)
|
if (!IsModernFlashApp || IsOriginalEngineeringLumia)
|
||||||
{
|
{
|
||||||
IsSwitchingInterface = true;
|
IsSwitchingInterface = true;
|
||||||
try
|
try
|
||||||
@@ -1200,8 +1232,6 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IsUnlockedNew)
|
else if (IsUnlockedNew)
|
||||||
{
|
|
||||||
new Thread(async () =>
|
|
||||||
{
|
{
|
||||||
LogFile.BeginAction("SwitchToMassStorageMode");
|
LogFile.BeginAction("SwitchToMassStorageMode");
|
||||||
|
|
||||||
@@ -1228,15 +1258,16 @@ namespace WPinternals
|
|||||||
// because the SecureBoot flag is disabled here.
|
// because the SecureBoot flag is disabled here.
|
||||||
// So either the NV was already backupped or already overwritten.
|
// So either the NV was already backupped or already overwritten.
|
||||||
|
|
||||||
GPT GPT = FlashModel.ReadGPT();
|
|
||||||
Partition Target = GPT.GetPartition("UEFI_BS_NV");
|
Partition Target = GPT.GetPartition("UEFI_BS_NV");
|
||||||
|
|
||||||
// We've been reading the GPT, so we let the phone reset once more to be sure that memory maps are the same
|
// We've been reading the GPT, so we let the phone reset once more to be sure that memory maps are the same
|
||||||
WPinternalsStatus LastStatus = WPinternalsStatus.Undefined;
|
WPinternalsStatus LastStatus = WPinternalsStatus.Undefined;
|
||||||
List<FlashPart> Parts = [];
|
List<FlashPart> Parts = [];
|
||||||
FlashPart Part = new();
|
FlashPart Part = new()
|
||||||
Part.StartSector = (uint)Target.FirstSector;
|
{
|
||||||
Part.Stream = SB;
|
StartSector = (uint)Target.FirstSector,
|
||||||
|
Stream = SB
|
||||||
|
};
|
||||||
Parts.Add(Part);
|
Parts.Add(Part);
|
||||||
await LumiaV2UnlockBootViewModel.LumiaV2CustomFlash(PhoneNotifier, null, false, false, Parts, DoResetFirst: true, ClearFlashingStatusAtEnd: false, ShowProgress: false,
|
await LumiaV2UnlockBootViewModel.LumiaV2CustomFlash(PhoneNotifier, null, false, false, Parts, DoResetFirst: true, ClearFlashingStatusAtEnd: false, ShowProgress: false,
|
||||||
SetWorkingStatus: (m, s, v, a, st) =>
|
SetWorkingStatus: (m, s, v, a, st) =>
|
||||||
@@ -1324,12 +1355,12 @@ namespace WPinternals
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogFile.EndAction("SwitchToMassStorageMode");
|
LogFile.EndAction("SwitchToMassStorageMode");
|
||||||
}).Start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ModeSwitchErrorWrapper("Bootloader was not unlocked. First unlock bootloader before you try to switch to Mass Storage Mode.");
|
ModeSwitchErrorWrapper("Bootloader was not unlocked. First unlock bootloader before you try to switch to Mass Storage Mode.");
|
||||||
}
|
}
|
||||||
|
}).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async static Task<IDisposable> SwitchTo(PhoneNotifierViewModel Notifier, PhoneInterfaces? TargetMode, string RequestedVolumeForMassStorage = "MainOS")
|
internal async static Task<IDisposable> SwitchTo(PhoneNotifierViewModel Notifier, PhoneInterfaces? TargetMode, string RequestedVolumeForMassStorage = "MainOS")
|
||||||
|
|||||||
@@ -167,13 +167,15 @@ namespace MadWizard.WinUSBNet.API
|
|||||||
}
|
}
|
||||||
private static DeviceDetails GetDeviceDetails(string devicePath, IntPtr deviceInfoSet, SP_DEVINFO_DATA deviceInfoData)
|
private static DeviceDetails GetDeviceDetails(string devicePath, IntPtr deviceInfoSet, SP_DEVINFO_DATA deviceInfoData)
|
||||||
{
|
{
|
||||||
DeviceDetails details = new();
|
DeviceDetails details = new()
|
||||||
details.DevicePath = devicePath;
|
{
|
||||||
details.DeviceDescription = GetStringProperty(deviceInfoSet, deviceInfoData, SPDRP.SPDRP_DEVICEDESC);
|
DevicePath = devicePath,
|
||||||
details.Manufacturer = GetStringProperty(deviceInfoSet, deviceInfoData, SPDRP.SPDRP_MFG);
|
DeviceDescription = GetStringProperty(deviceInfoSet, deviceInfoData, SPDRP.SPDRP_DEVICEDESC),
|
||||||
|
Manufacturer = GetStringProperty(deviceInfoSet, deviceInfoData, SPDRP.SPDRP_MFG),
|
||||||
|
|
||||||
// Heathcliff74
|
// Heathcliff74
|
||||||
details.BusName = "";
|
BusName = ""
|
||||||
|
};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
details.BusName = GetStringProperty(deviceInfoSet, deviceInfoData, new DEVPROPKEY(new Guid(0x540b947e, 0x8b40, 0x45bc, 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2), 4));
|
details.BusName = GetStringProperty(deviceInfoSet, deviceInfoData, new DEVPROPKEY(new Guid(0x540b947e, 0x8b40, 0x45bc, 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2), 4));
|
||||||
|
|||||||
@@ -341,9 +341,10 @@ namespace MadWizard.WinUSBNet.API
|
|||||||
|
|
||||||
public void ReadPipeOverlapped(int ifaceIndex, byte pipeID, byte[] buffer, int offset, int bytesToRead, USBAsyncResult result)
|
public void ReadPipeOverlapped(int ifaceIndex, byte pipeID, byte[] buffer, int offset, int bytesToRead, USBAsyncResult result)
|
||||||
{
|
{
|
||||||
Overlapped overlapped = new();
|
Overlapped overlapped = new()
|
||||||
|
{
|
||||||
overlapped.AsyncResult = result;
|
AsyncResult = result
|
||||||
|
};
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
@@ -364,8 +365,10 @@ namespace MadWizard.WinUSBNet.API
|
|||||||
|
|
||||||
public void WriteOverlapped(int ifaceIndex, byte pipeID, byte[] buffer, int offset, int bytesToWrite, USBAsyncResult result)
|
public void WriteOverlapped(int ifaceIndex, byte pipeID, byte[] buffer, int offset, int bytesToWrite, USBAsyncResult result)
|
||||||
{
|
{
|
||||||
Overlapped overlapped = new();
|
Overlapped overlapped = new()
|
||||||
overlapped.AsyncResult = result;
|
{
|
||||||
|
AsyncResult = result
|
||||||
|
};
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
@@ -396,8 +399,10 @@ namespace MadWizard.WinUSBNet.API
|
|||||||
setupPacket.Index = index;
|
setupPacket.Index = index;
|
||||||
setupPacket.Length = length;
|
setupPacket.Length = length;
|
||||||
|
|
||||||
Overlapped overlapped = new();
|
Overlapped overlapped = new()
|
||||||
overlapped.AsyncResult = result;
|
{
|
||||||
|
AsyncResult = result
|
||||||
|
};
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user