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:
Gustave Monce
2024-10-13 00:25:01 +02:00
parent 605b19aede
commit e078bb10ed
4 changed files with 111 additions and 45 deletions
@@ -401,25 +401,5 @@ namespace WPinternals.Models.UEFIApps.BootMgr
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);
}
}
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ namespace WPinternals
// Make sure the RootKeyHash is not blank
// 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
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)
&& (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.SBL3Path = SBL3Path;
this.SupportedFFUPath = SupportedFFUPath;
StorePaths();
LogFile.Log("Processing resources:");
LogFile.Log("FFU: " + FFUPath);
@@ -196,14 +195,19 @@ namespace WPinternals
ActivateSubContext(new BusyViewModel("Processing resources..."));
Task.Run(async () =>
{
await StorePaths();
if (DoUnlock)
{
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
}
else
{
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
}
});
}
if (DoUnlock)
@@ -234,7 +238,6 @@ namespace WPinternals
this.ProfileFFUPath = ProfileFFUPath;
this.EDEPath = EDEPath;
this.SupportedFFUPath = SupportedFFUPath;
StorePaths();
if (DoFixBoot)
{
@@ -255,6 +258,8 @@ namespace WPinternals
Task.Run(async () =>
{
await StorePaths();
bool AlreadyUnlocked = false;
LumiaFlashAppModel FlashModel = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
@@ -418,7 +423,6 @@ namespace WPinternals
this.FFUPath = FFUPath;
this.LoadersPath = LoadersPath;
this.SBL3Path = SBL3Path;
StorePaths();
LogFile.Log("Processing resources:");
LogFile.Log("FFU: " + FFUPath);
@@ -434,14 +438,19 @@ namespace WPinternals
ActivateSubContext(new BusyViewModel("Processing resources..."));
Task.Run(async () =>
{
await StorePaths();
if (DoUnlock)
{
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
await LumiaUnlockBootloaderViewModel.LumiaV1UnlockFirmware(PhoneNotifier, FFUPath, LoadersPath, SBL3Path, SupportedFFUPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
}
else
{
Task.Run(async () => await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage));
await LumiaUnlockBootloaderViewModel.LumiaV1RelockFirmware(PhoneNotifier, FFUPath, LoadersPath, SetWorkingStatus, UpdateWorkingStatus, ExitMessage, ExitMessage);
}
});
};
if (DoUnlock)
@@ -513,15 +522,15 @@ namespace WPinternals
{
// SwitchModeViewModel must be created on the UI thread
IsSwitchingInterface = false;
UIContext.Post((t) =>
UIContext.Post(async (t) =>
{
StorePaths();
await StorePaths();
LogFile.Log("Aborting.");
Exit();
}, null);
}
private async void StorePaths()
private async Task StorePaths()
{
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.UEFIApps.BootMgr;
using WPinternals.Models.UEFIApps.Flash;
using WPinternals.Models.UEFIApps.PhoneInfo;
namespace WPinternals
{
@@ -55,7 +56,17 @@ namespace WPinternals
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)
{
@@ -69,7 +80,14 @@ namespace WPinternals
GPT GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).ReadGPT();
if (ModernFlashApp)
{
((LumiaBootManagerAppModel)Notifier.CurrentModel).SwitchToFlashAppContext();
}
else
{
((LumiaBootManagerAppModel)Notifier.CurrentModel).ResetPhoneToFlashMode();
}
if (Notifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
{
@@ -129,7 +147,15 @@ namespace WPinternals
byte[] GPT = ((LumiaBootManagerAppModel)Notifier.CurrentModel).GetGptChunk(Size);
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)
{
@@ -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.");
}
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;
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"));
Flasher.Flash(0, MBR, Progress, 0, 0x200);
// TIMEOUT
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.
@@ -1760,6 +1810,11 @@ namespace WPinternals
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)
{
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.");
}
}
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);