mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-06-14 03:16:40 +10:00
Code update
- WPinternals is now a .NET Core 3.0 application - Implemented new unlock process for Spec A devices - Updated logic for unlocking Spec B devices - Implemented MMOS support for Spec B devices - Implemented battery status in Flash Mode - Implemented Fuse configuration information in Flash Mode - Implemented Reboot from mass storage for Spec A and some Spec B devices - Implemented shutdown from flash mode (preliminary) - Fixed label mode support for Spec B
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -211,10 +212,10 @@ namespace WPinternals
|
||||
LogFile.Log("Rebooting phone to Flash mode", LogType.FileAndConsole);
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Label:
|
||||
DeviceMode = "Test";
|
||||
DeviceMode = "Flash";
|
||||
IsSwitchingInterface = true;
|
||||
ModeSwitchProgressWrapper("Rebooting phone to Label mode...", null);
|
||||
LogFile.Log("Rebooting phone to Label mode", LogType.FileAndConsole);
|
||||
ModeSwitchProgressWrapper("First rebooting phone to Flash mode...", null);
|
||||
LogFile.Log("First rebooting phone to Flash mode (then attempt Label mode)", LogType.FileAndConsole);
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_MassStorage:
|
||||
DeviceMode = "Flash";
|
||||
@@ -259,8 +260,11 @@ namespace WPinternals
|
||||
((NokiaFlashModel)CurrentModel).Shutdown();
|
||||
ModeSwitchProgressWrapper("Shutting down phone...", null);
|
||||
LogFile.Log("Shutting down phone", LogType.FileAndConsole);
|
||||
PhoneNotifier.WaitForRemoval().Wait();
|
||||
ModeSwitchSuccessWrapper();
|
||||
new Thread(() =>
|
||||
{
|
||||
PhoneNotifier.WaitForRemoval().Wait();
|
||||
//ModeSwitchSuccessWrapper(); TODO: Display UI
|
||||
}).Start();
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Normal:
|
||||
((NokiaPhoneModel)CurrentModel).ExecuteRawVoidMethod(RebootCommand);
|
||||
@@ -275,12 +279,7 @@ namespace WPinternals
|
||||
LogFile.Log("Rebooting phone to Bootloader mode", LogType.FileAndConsole);
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Label:
|
||||
BootModeFlagCommand[0x0F] = 0x59;
|
||||
((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(BootModeFlagCommand);
|
||||
((NokiaPhoneModel)CurrentModel).ExecuteRawVoidMethod(RebootCommand);
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||
ModeSwitchProgressWrapper("Rebooting phone to Label mode...", null);
|
||||
LogFile.Log("Rebooting phone to Label mode", LogType.FileAndConsole);
|
||||
SwitchFromFlashToLabelMode();
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Flash: // attempt to boot from limited flash to full flash
|
||||
byte[] RebootToFlashCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x53 }; // NOKS
|
||||
@@ -312,7 +311,30 @@ namespace WPinternals
|
||||
}
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_MassStorage:
|
||||
// TODO: don't know how to switch from Mass Storage to other mode
|
||||
IsSwitchingInterface = true;
|
||||
switch (TargetMode)
|
||||
{
|
||||
case PhoneInterfaces.Lumia_Normal:
|
||||
((MassStorage)CurrentModel).Reboot();
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||
ModeSwitchProgressWrapper("Rebooting phone to Normal mode...", null);
|
||||
LogFile.Log("Rebooting phone to Normal mode", LogType.FileAndConsole);
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Label:
|
||||
((MassStorage)CurrentModel).Reboot();
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrivedFromMassStorageMode;
|
||||
ModeSwitchProgressWrapper("Rebooting phone to Label mode...", null);
|
||||
LogFile.Log("Rebooting phone to Label mode...", LogType.FileAndConsole);
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Flash:
|
||||
((MassStorage)CurrentModel).Reboot();
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrivedFromMassStorageMode;
|
||||
ModeSwitchProgressWrapper("Rebooting phone to Flash mode...", null);
|
||||
LogFile.Log("Rebooting phone to Flash mode...", LogType.FileAndConsole);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case PhoneInterfaces.Qualcomm_Download:
|
||||
// TODO: don't know how to switch from Qualcomm Download mode to other mode
|
||||
@@ -320,6 +342,59 @@ namespace WPinternals
|
||||
}
|
||||
}
|
||||
|
||||
private void NewDeviceArrivedFromMassStorageMode(ArrivalEventArgs Args)
|
||||
{
|
||||
PhoneNotifier.NewDeviceArrived -= NewDeviceArrivedFromMassStorageMode;
|
||||
|
||||
CurrentModel = (IDisposable)Args.NewModel;
|
||||
CurrentMode = Args.NewInterface;
|
||||
|
||||
// After the mass storage mode reboot command, the phone must be in Bootloader mode.
|
||||
// If it isn't, something unexpected happened and the phone can't be switched.
|
||||
//
|
||||
if (CurrentMode == PhoneInterfaces.Lumia_Bootloader)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await SwitchToWithStatus(PhoneNotifier, TargetMode, SetWorkingStatus, UpdateWorkingStatus);
|
||||
ModeSwitchSuccessWrapper();
|
||||
}
|
||||
catch
|
||||
{
|
||||
switch (TargetMode)
|
||||
{
|
||||
case PhoneInterfaces.Lumia_Flash:
|
||||
ModeSwitchErrorWrapper("Failed to switch to Flash mode");
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Label:
|
||||
ModeSwitchErrorWrapper("Failed to switch to Label mode");
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Normal:
|
||||
ModeSwitchErrorWrapper("Failed to switch to Normal mode");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (TargetMode)
|
||||
{
|
||||
case PhoneInterfaces.Lumia_Flash:
|
||||
ModeSwitchErrorWrapper("Failed to switch to Flash mode");
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Label:
|
||||
ModeSwitchErrorWrapper("Failed to switch to Label mode");
|
||||
break;
|
||||
case PhoneInterfaces.Lumia_Normal:
|
||||
ModeSwitchErrorWrapper("Failed to switch to Normal mode");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NewDeviceArrived(ArrivalEventArgs Args)
|
||||
{
|
||||
PhoneNotifier.NewDeviceArrived -= NewDeviceArrived;
|
||||
@@ -363,6 +438,10 @@ namespace WPinternals
|
||||
{
|
||||
SwitchFromFlashToMassStorageMode(Continuation: true);
|
||||
}
|
||||
else if ((CurrentMode == PhoneInterfaces.Lumia_Flash) && (TargetMode == PhoneInterfaces.Lumia_Label))
|
||||
{
|
||||
SwitchFromFlashToLabelMode(Continuation: true);
|
||||
}
|
||||
else if ((CurrentMode == PhoneInterfaces.Lumia_Flash) && (TargetMode == PhoneInterfaces.Qualcomm_Download))
|
||||
{
|
||||
byte[] RebootCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x52 };
|
||||
@@ -407,6 +486,93 @@ namespace WPinternals
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchFromFlashToLabelMode(bool Continuation = false)
|
||||
{
|
||||
string ProgressText;
|
||||
if (Continuation)
|
||||
ProgressText = "And now preparing to boot the phone to Label mode...";
|
||||
else
|
||||
ProgressText = "Preparing to boot the phone to Label mode...";
|
||||
|
||||
NokiaFlashModel FlashModel = (NokiaFlashModel)CurrentModel;
|
||||
if (CurrentMode == PhoneInterfaces.Lumia_Bootloader)
|
||||
{
|
||||
try
|
||||
{
|
||||
FlashModel.SwitchToFlashAppContext();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
PhoneInfo Info = FlashModel.ReadPhoneInfo(ExtendedInfo: true);
|
||||
|
||||
if (Info.MmosOverUsbSupported)
|
||||
{
|
||||
new Thread(() =>
|
||||
{
|
||||
LogFile.BeginAction("SwitchToLabelMode");
|
||||
|
||||
try
|
||||
{
|
||||
ModeSwitchProgressWrapper(ProgressText, null);
|
||||
string TempFolder = Environment.GetEnvironmentVariable("TEMP") + @"\WPInternals";
|
||||
string ENOSWPackage = LumiaDownloadModel.SearchENOSW(Info.Type, Info.Firmware);
|
||||
SetWorkingStatus("Downloading " + Info.Type + " Test Mode package...", MaxProgressValue: 100);
|
||||
DownloadEntry downloadEntry = new DownloadEntry(ENOSWPackage, TempFolder, null, null, null);
|
||||
|
||||
downloadEntry.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
|
||||
{
|
||||
if (e.PropertyName == "Progress")
|
||||
{
|
||||
int progress = (sender as DownloadEntry).Progress;
|
||||
ulong progressret;
|
||||
ulong.TryParse(progress.ToString(), out progressret);
|
||||
UpdateWorkingStatus(null, CurrentProgressValue: progressret);
|
||||
|
||||
if (progress == 100)
|
||||
{
|
||||
ModeSwitchProgressWrapper("Initializing Flash...", null);
|
||||
|
||||
string MMOSPath = TempFolder + "\\" + (sender as DownloadEntry).Name;
|
||||
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||
FileInfo info = new FileInfo(MMOSPath);
|
||||
uint length = uint.Parse(info.Length.ToString());
|
||||
int maximumbuffersize = 0x00240000;
|
||||
uint totalcounts = (uint)Math.Truncate((decimal)length / maximumbuffersize);
|
||||
|
||||
SetWorkingStatus("Flashing Test Mode package...", MaxProgressValue: 100);
|
||||
|
||||
ProgressUpdater progressUpdater = new ProgressUpdater(totalcounts + 1, (int i, TimeSpan? time) => UpdateWorkingStatus(null, CurrentProgressValue: (ulong)i));
|
||||
FlashModel.FlashMMOS(MMOSPath, progressUpdater);
|
||||
|
||||
SetWorkingStatus("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.");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (Exception Ex)
|
||||
{
|
||||
LogFile.LogException(Ex);
|
||||
ModeSwitchErrorWrapper(Ex.Message);
|
||||
}
|
||||
|
||||
LogFile.EndAction("SwitchToLabelMode");
|
||||
}).Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] BootModeFlagCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x58, 0x46, 0x57, 0x00, 0x55, 0x42, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }; // NOKFW UBF
|
||||
byte[] RebootCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x52 }; // NOKR
|
||||
|
||||
BootModeFlagCommand[0x0F] = 0x59;
|
||||
((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(BootModeFlagCommand);
|
||||
((NokiaPhoneModel)CurrentModel).ExecuteRawVoidMethod(RebootCommand);
|
||||
PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
|
||||
ModeSwitchProgressWrapper("Rebooting phone to Label mode", null);
|
||||
LogFile.Log("Rebooting phone to Label mode", LogType.FileAndConsole);
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchFromFlashToMassStorageMode(bool Continuation = false)
|
||||
{
|
||||
string ProgressText;
|
||||
@@ -442,7 +608,7 @@ namespace WPinternals
|
||||
if (IsNewLumia)
|
||||
{
|
||||
GPT GPT = FlashModel.ReadGPT();
|
||||
IsUnlockedNew = ((GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null));
|
||||
IsUnlockedNew = ((GPT.GetPartition("IS_UNLOCKED") != null) || (GPT.GetPartition("BACKUP_EFIESP") != null) || (GPT.GetPartition("BACKUP_BS_NV") != null));
|
||||
}
|
||||
bool IsOriginalEngineeringLumia = ((!Info.SecureFfuEnabled || Info.Authenticated || Info.RdcPresent) && !IsUnlockedNew);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user