internal void AttachQualcommSerial(string DevicePath) { try { QualcommSerial SerialDevice = new QualcommSerial(DevicePath); SerialDevice.Close(); SerialDevice.Dispose(); Serial = DevicePath; } catch (Exception ex) { LogFile.Log(ex.Message); } }
public async Task <bool> Reset(string ProgrammerPath) { bool SendImageResult = await Task.Run(() => SendImage(ProgrammerPath)); if (!SendImageResult) { return(false); } await Task.Run(() => StartProgrammer()); bool Connected = await Task.Run(() => ConnectToProgrammerInTestMode()); if (!Connected) { return(false); } LogFile.Log("Rebooting phone", LogType.FileAndConsole); string Command03 = "<?xml version=\"1.0\" ?><data><power value=\"reset\"/></data>"; LogFile.Log("Out: " + Command03, LogType.FileOnly); Serial.SendData(System.Text.Encoding.ASCII.GetBytes(Command03)); string Incoming; do { Incoming = System.Text.Encoding.ASCII.GetString(Serial.GetResponse(null)); LogFile.Log("In: " + Incoming, LogType.FileOnly); }while (Incoming.IndexOf("response value") < 0); // Workaround for problem // SerialPort is sometimes not disposed correctly when the device is already removed. // So explicitly dispose here Serial.Close(); return(true); }
internal void Reboot() { if (Serial == null) { return; } try { QualcommSerial SerialDevice = new QualcommSerial(Serial); SerialDevice.EncodeCommands = false; // This will succeed on new models SerialDevice.SendData(new byte[] { 0x7, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0 }); // This will succeed on old models SerialDevice.SendData(new byte[] { 0x7E, 0xA, 0x0, 0x0, 0xB6, 0xB5, 0x7E }); SerialDevice.Close(); SerialDevice.Dispose(); } catch { } }
public void CloseSerial() { Serial.Close(); }
internal static async Task RecoverBadGPT(string GPTPath, string LoadersPath) { byte[] GPT = File.ReadAllBytes(GPTPath); PhoneNotifierViewModel PhoneNotifier = new PhoneNotifierViewModel(); PhoneNotifier.Start(); await SwitchModeViewModel.SwitchTo(PhoneNotifier, PhoneInterfaces.Qualcomm_Download); byte[] RootKeyHash = null; if (PhoneNotifier.CurrentInterface == PhoneInterfaces.Qualcomm_Download) { QualcommDownload Download2 = new QualcommDownload((QualcommSerial)PhoneNotifier.CurrentModel); RootKeyHash = Download2.GetRKH(); } List <QualcommPartition> PossibleLoaders = null; if (PhoneNotifier.CurrentInterface == PhoneInterfaces.Qualcomm_Download) { try { PossibleLoaders = QualcommLoaders.GetPossibleLoadersForRootKeyHash(LoadersPath, RootKeyHash); if (PossibleLoaders.Count == 0) { throw new Exception("Error: No matching loaders found for RootKeyHash."); } } catch (Exception Ex) { LogFile.LogException(Ex); throw new Exception("Error: Unexpected error during scanning for loaders."); } } QualcommSerial Serial = (QualcommSerial)PhoneNotifier.CurrentModel; QualcommDownload Download = new QualcommDownload(Serial); if (Download.IsAlive()) { int Attempt = 1; bool Result = false; foreach (QualcommPartition Loader in PossibleLoaders) { LogFile.Log("Attempt " + Attempt.ToString(), LogType.ConsoleOnly); try { Download.SendToPhoneMemory(0x2A000000, Loader.Binary); Download.StartBootloader(0x2A000000); Result = true; LogFile.Log("Loader sent successfully", LogType.ConsoleOnly); } catch { } if (Result) { break; } Attempt++; } Serial.Close(); if (!Result) { LogFile.Log("Loader failed", LogType.ConsoleOnly); } } else { LogFile.Log("Failed to communicate to Qualcomm Emergency Download mode", LogType.ConsoleOnly); throw new BadConnectionException(); } if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Qualcomm_Flash) { await PhoneNotifier.WaitForArrival(); } if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Qualcomm_Flash) { throw new WPinternalsException("Phone failed to switch to emergency flash mode."); } // Flash bootloader QualcommSerial Serial2 = (QualcommSerial)PhoneNotifier.CurrentModel; Serial2.EncodeCommands = false; QualcommFlasher Flasher = new QualcommFlasher(Serial2); Flasher.Hello(); Flasher.SetSecurityMode(0); Flasher.OpenPartition(0x21); LogFile.Log("Partition opened.", LogType.ConsoleOnly); LogFile.Log("Flash GPT at 0x" + ((UInt32)0x200).ToString("X8"), LogType.ConsoleOnly); Flasher.Flash(0x200, GPT, 0, 0x41FF); // Bad bounds-check in the flash-loader prohibits to write the last byte. Flasher.ClosePartition(); LogFile.Log("Partition closed. Flashing ready. Rebooting."); Flasher.Reboot(); Flasher.CloseSerial(); }