mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-06-14 03:16:40 +10:00
Fixes for Spec A unlocking
In memories of the cyan RM-821 from a fellow care center Rest in peace, 12th of October 2024
This commit is contained in:
@@ -401,25 +401,5 @@ namespace WPinternals.Models.UEFIApps.BootMgr
|
|||||||
RaiseInterfaceChanged(PhoneInterfaces.Lumia_PhoneInfo);
|
RaiseInterfaceChanged(PhoneInterfaces.Lumia_PhoneInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RebootToFlashApp()
|
|
||||||
{
|
|
||||||
LumiaBootManagerPhoneInfo info = ReadPhoneInfoBootManager();
|
|
||||||
|
|
||||||
bool ModernFlashApp = info.BootManagerVersionMajor >= 2;
|
|
||||||
|
|
||||||
byte[] Request = new byte[4];
|
|
||||||
ByteOperations.WriteAsciiString(Request, 0, RebootToFlashAppSignature); // This will let the phone charge
|
|
||||||
ExecuteRawVoidMethod(Request); // On phone with bootloader Spec A this triggers a reboot, so DisableRebootTimeOut() cannot be called immediately.
|
|
||||||
|
|
||||||
if (ModernFlashApp)
|
|
||||||
{
|
|
||||||
DisableRebootTimeOut();
|
|
||||||
|
|
||||||
info.App = FlashAppType.FlashApp;
|
|
||||||
|
|
||||||
RaiseInterfaceChanged(PhoneInterfaces.Lumia_Flash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace WPinternals
|
|||||||
// Make sure the RootKeyHash is not blank
|
// Make sure the RootKeyHash is not blank
|
||||||
// If the RootKeyHash is blank, this is an engineering device, and it will accept any RKH
|
// If the RootKeyHash is blank, this is an engineering device, and it will accept any RKH
|
||||||
// We expect the user to know what he is doing in such case and we will ignore checks
|
// We expect the user to know what he is doing in such case and we will ignore checks
|
||||||
if (!StructuralComparisons.StructuralEqualityComparer.Equals(RootKeyHash, new byte[RootKeyHash.Length]))
|
if (RootKeyHash != null && !StructuralComparisons.StructuralEqualityComparer.Equals(RootKeyHash, new byte[RootKeyHash.Length]))
|
||||||
{
|
{
|
||||||
if (StructuralComparisons.StructuralEqualityComparer.Equals(Loader.RootKeyHash, RootKeyHash)
|
if (StructuralComparisons.StructuralEqualityComparer.Equals(Loader.RootKeyHash, RootKeyHash)
|
||||||
&& (ByteOperations.FindUnicode(Loader.Binary, "QHSUSB_ARMPRG") != null)) // To detect that this is a loader, and not SBL1 or something. V1 loaders are QHSUSB_ARMPRG. V2 loaders are QHSUSB__BULK. Only V1 supported for now, because V2 only accepts signed payload.
|
&& (ByteOperations.FindUnicode(Loader.Binary, "QHSUSB_ARMPRG") != null)) // To detect that this is a loader, and not SBL1 or something. V1 loaders are QHSUSB_ARMPRG. V2 loaders are QHSUSB__BULK. Only V1 supported for now, because V2 only accepts signed payload.
|
||||||
|
|||||||
@@ -180,7 +180,6 @@ namespace WPinternals
|
|||||||
this.LoadersPath = LoadersPath;
|
this.LoadersPath = LoadersPath;
|
||||||
this.SBL3Path = SBL3Path;
|
this.SBL3Path = SBL3Path;
|
||||||
this.SupportedFFUPath = SupportedFFUPath;
|
this.SupportedFFUPath = SupportedFFUPath;
|
||||||
StorePaths();
|
|
||||||
|
|
||||||
LogFile.Log("Processing resources:");
|
LogFile.Log("Processing resources:");
|
||||||
LogFile.Log("FFU: " + FFUPath);
|
LogFile.Log("FFU: " + FFUPath);
|
||||||
@@ -196,14 +195,19 @@ namespace WPinternals
|
|||||||
|
|
||||||
ActivateSubContext(new BusyViewModel("Processing resources..."));
|
ActivateSubContext(new BusyViewModel("Processing resources..."));
|
||||||
|
|
||||||
if (DoUnlock)
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
|
await StorePaths();
|
||||||
}
|
|
||||||
else
|
if (DoUnlock)
|
||||||
{
|
{
|
||||||
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
|
await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DoUnlock)
|
if (DoUnlock)
|
||||||
@@ -234,7 +238,6 @@ namespace WPinternals
|
|||||||
this.ProfileFFUPath = ProfileFFUPath;
|
this.ProfileFFUPath = ProfileFFUPath;
|
||||||
this.EDEPath = EDEPath;
|
this.EDEPath = EDEPath;
|
||||||
this.SupportedFFUPath = SupportedFFUPath;
|
this.SupportedFFUPath = SupportedFFUPath;
|
||||||
StorePaths();
|
|
||||||
|
|
||||||
if (DoFixBoot)
|
if (DoFixBoot)
|
||||||
{
|
{
|
||||||
@@ -255,6 +258,8 @@ namespace WPinternals
|
|||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
await StorePaths();
|
||||||
|
|
||||||
bool AlreadyUnlocked = false;
|
bool AlreadyUnlocked = false;
|
||||||
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
|
||||||
|
|
||||||
@@ -418,7 +423,6 @@ namespace WPinternals
|
|||||||
this.FFUPath = FFUPath;
|
this.FFUPath = FFUPath;
|
||||||
this.LoadersPath = LoadersPath;
|
this.LoadersPath = LoadersPath;
|
||||||
this.SBL3Path = SBL3Path;
|
this.SBL3Path = SBL3Path;
|
||||||
StorePaths();
|
|
||||||
|
|
||||||
LogFile.Log("Processing resources:");
|
LogFile.Log("Processing resources:");
|
||||||
LogFile.Log("FFU: " + FFUPath);
|
LogFile.Log("FFU: " + FFUPath);
|
||||||
@@ -434,14 +438,19 @@ namespace WPinternals
|
|||||||
|
|
||||||
ActivateSubContext(new BusyViewModel("Processing resources..."));
|
ActivateSubContext(new BusyViewModel("Processing resources..."));
|
||||||
|
|
||||||
if (DoUnlock)
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
|
await StorePaths();
|
||||||
}
|
|
||||||
else
|
if (DoUnlock)
|
||||||
{
|
{
|
||||||
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
|
await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (DoUnlock)
|
if (DoUnlock)
|
||||||
@@ -513,15 +522,15 @@ namespace WPinternals
|
|||||||
{
|
{
|
||||||
// SwitchModeViewModel must be created on the UI thread
|
// SwitchModeViewModel must be created on the UI thread
|
||||||
IsSwitchingInterface = false;
|
IsSwitchingInterface = false;
|
||||||
UIContext.Post((t) =>
|
UIContext.Post(async (t) =>
|
||||||
{
|
{
|
||||||
StorePaths();
|
await StorePaths();
|
||||||
LogFile.Log("Aborting.");
|
LogFile.Log("Aborting.");
|
||||||
Exit();
|
Exit();
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void StorePaths()
|
private async Task StorePaths()
|
||||||
{
|
{
|
||||||
RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software\WPInternals", true) ?? Registry.CurrentUser.CreateSubKey(@"Software\WPInternals");
|
RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software\WPInternals", true) ?? Registry.CurrentUser.CreateSubKey(@"Software\WPInternals");
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ using WPinternals.HelperClasses;
|
|||||||
using WPinternals.Models.Lumia.UEFI.Flash;
|
using WPinternals.Models.Lumia.UEFI.Flash;
|
||||||
using WPinternals.Models.UEFIApps.BootMgr;
|
using WPinternals.Models.UEFIApps.BootMgr;
|
||||||
using WPinternals.Models.UEFIApps.Flash;
|
using WPinternals.Models.UEFIApps.Flash;
|
||||||
|
using WPinternals.Models.UEFIApps.PhoneInfo;
|
||||||
|
|
||||||
namespace WPinternals
|
namespace WPinternals
|
||||||
{
|
{
|
||||||
@@ -55,7 +56,17 @@ namespace WPinternals
|
|||||||
|
|
||||||
if (FlashModel.CanReadGPT())
|
if (FlashModel.CanReadGPT())
|
||||||
{
|
{
|
||||||
FlashModel.SwitchToBootManagerContext();
|
bool ModernFlashApp = FlashModel.ReadPhoneInfoFlashApp().FlashAppProtocolVersionMajor >= 2;
|
||||||
|
|
||||||
|
if (ModernFlashApp)
|
||||||
|
{
|
||||||
|
FlashModel.SwitchToFlashAppContext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FlashModel.ResetPhone();
|
||||||
|
await Notifier.WaitForRemoval();
|
||||||
|
}
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
|
||||||
{
|
{
|
||||||
@@ -69,7 +80,14 @@ namespace WPinternals
|
|||||||
|
|
||||||
GPT GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadGPT();
|
GPT GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadGPT();
|
||||||
|
|
||||||
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
if (ModernFlashApp)
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).ResetPhoneToFlashMode();
|
||||||
|
}
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
{
|
{
|
||||||
@@ -129,7 +147,15 @@ namespace WPinternals
|
|||||||
|
|
||||||
byte[] GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).GetGptChunk(Size);
|
byte[] GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).GetGptChunk(Size);
|
||||||
|
|
||||||
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
bool ModernFlashApp = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadPhoneInfo().BootManagerProtocolVersionMajor >= 2;
|
||||||
|
if (ModernFlashApp)
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).ResetPhoneToFlashMode();
|
||||||
|
}
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
{
|
{
|
||||||
@@ -851,6 +877,29 @@ namespace WPinternals
|
|||||||
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.");
|
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
bool ModernFlashApp = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadPhoneInfo().BootManagerProtocolVersionMajor >= 2;
|
||||||
|
if (ModernFlashApp)
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).ResetPhoneToFlashMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
await Notifier.WaitForArrival();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
|
||||||
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)Notifier.CurrentModel;
|
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)Notifier.CurrentModel;
|
||||||
if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Flash && FlashModel.ReadParam("FS")[3] > 0)
|
if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Flash && FlashModel.ReadParam("FS")[3] > 0)
|
||||||
{
|
{
|
||||||
@@ -1446,6 +1495,7 @@ namespace WPinternals
|
|||||||
LogFile.Log("Flash MBR at 0x" + ((UInt32)0).ToString("X8"));
|
LogFile.Log("Flash MBR at 0x" + ((UInt32)0).ToString("X8"));
|
||||||
Flasher.Flash(0, MBR, Progress, 0, 0x200);
|
Flasher.Flash(0, MBR, Progress, 0, 0x200);
|
||||||
|
|
||||||
|
// TIMEOUT
|
||||||
LogFile.Log("Flash GPT at 0x" + ((UInt32)0x200).ToString("X8"));
|
LogFile.Log("Flash GPT at 0x" + ((UInt32)0x200).ToString("X8"));
|
||||||
Flasher.Flash(0x200, GPT, Progress, 0, 0x41FF); // Bad bounds-check in the flash-loader prohibits to write the last byte.
|
Flasher.Flash(0x200, GPT, Progress, 0, 0x41FF); // Bad bounds-check in the flash-loader prohibits to write the last byte.
|
||||||
|
|
||||||
@@ -1760,6 +1810,11 @@ namespace WPinternals
|
|||||||
await SwitchModeViewModel.SwitchToWithStatus(Notifier, PhoneInterfaces.Lumia_Flash, SetWorkingStatus, UpdateWorkingStatus);
|
await SwitchModeViewModel.SwitchToWithStatus(Notifier, PhoneInterfaces.Lumia_Flash, SetWorkingStatus, UpdateWorkingStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
}
|
||||||
|
|
||||||
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
{
|
{
|
||||||
await Notifier.WaitForArrival();
|
await Notifier.WaitForArrival();
|
||||||
@@ -2583,7 +2638,29 @@ namespace WPinternals
|
|||||||
throw new WPinternalsException("Phone is in wrong mode", "The phone should have been detected in bootloader mode. Instead it has been detected in " + Notifier.CurrentInterface.ToString() + " mode.");
|
throw new WPinternalsException("Phone is in wrong mode", "The phone should have been detected in bootloader mode. Instead it has been detected in " + Notifier.CurrentInterface.ToString() + " mode.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
|
||||||
|
if (Notifier.CurrentInterface == PhoneInterfaces.Lumia_Bootloader)
|
||||||
|
{
|
||||||
|
bool ModernFlashApp = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadPhoneInfo().BootManagerProtocolVersionMajor >= 2;
|
||||||
|
if (ModernFlashApp)
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((LumiaBootManagerAppModel)Notifier.CurrentModel).ResetPhoneToFlashMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
await Notifier.WaitForArrival();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
|
||||||
|
{
|
||||||
|
throw new WPinternalsException("Unexpected Mode");
|
||||||
|
}
|
||||||
|
|
||||||
Parts = LumiaGenerateEFIESPFlashPayload(UnlockedEFIESP, GPT, ProfileFFU, IsSpecB);
|
Parts = LumiaGenerateEFIESPFlashPayload(UnlockedEFIESP, GPT, ProfileFFU, IsSpecB);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user