private bool HasV11PatchesFromMassStorage()
        {
            bool        Result = false;
            MassStorage Phone  = (MassStorage)PhoneNotifier.CurrentModel;

            Phone.OpenVolume(false);
            byte[]    GPTBuffer = Phone.ReadSectors(1, 33);
            GPT       GPT       = new WPinternals.GPT(GPTBuffer);
            Partition Partition = GPT.GetPartition("BACKUP_BS_NV");

            Result = Partition != null;
            Phone.CloseVolume();
            return(Result);
        }
        private bool HasNewBootloaderFromMassStorage()
        {
            bool        Result = false;
            MassStorage Phone  = (MassStorage)PhoneNotifier.CurrentModel;

            Phone.OpenVolume(false);
            byte[]    GPTBuffer = Phone.ReadSectors(1, 33);
            GPT       GPT       = new WPinternals.GPT(GPTBuffer);
            Partition Partition = GPT.GetPartition("UEFI");

            byte[] UefiBuffer  = Phone.ReadSectors(Partition.FirstSector, Partition.LastSector - Partition.FirstSector + 1);
            UEFI   UEFI        = new UEFI(UefiBuffer);
            string BootMgrName = UEFI.EFIs.Where(efi => ((efi.Name != null) && ((efi.Name.Contains("BootMgrApp")) || (efi.Name.Contains("FlashApp"))))).First().Name;

            byte[] BootMgr = UEFI.GetFile(BootMgrName);
            // "Header V2"
            Result = (ByteOperations.FindAscii(BootMgr, "Header V2") != null);
            Phone.CloseVolume();
            return(Result);
        }
Esempio n. 3
0
        internal void BackupArchiveProvisioningTask(string ArchiveProvisioningPath)
        {
            IsSwitchingInterface = false;
            new Thread(() =>
            {
                bool Result = true;

                ActivateSubContext(new BusyViewModel("Initializing backup..."));

                ulong TotalSizeSectors = 0;
                int PartitionCount     = 0;

                MassStorage Phone = (MassStorage)PhoneNotifier.CurrentModel;

                try
                {
                    Phone.OpenVolume(false);
                    byte[] GPTBuffer = Phone.ReadSectors(1, 33);
                    GPT GPT          = new(GPTBuffer);

                    Partition Partition;

                    try
                    {
                        foreach (string PartitionName in ProvisioningPartitions)
                        {
                            if (GPT.Partitions.Any(p => p.Name == PartitionName))
                            {
                                Partition = GPT.Partitions.First(p => p.Name == PartitionName);
                                if (PartitionName == "UEFI_BS_NV" && GPT.Partitions.Any(p => p.Name == "BACKUP_BS_NV"))
                                {
                                    Partition = GPT.Partitions.First(p => p.Name == "BACKUP_BS_NV");
                                }

                                TotalSizeSectors += Partition.SizeInSectors;
                                PartitionCount++;
                            }
                        }
                    }
                    catch (Exception Ex)
                    {
                        LogFile.LogException(Ex);
                        Result = false;
                    }

                    BusyViewModel Busy      = new("Create backup...", MaxProgressValue: TotalSizeSectors, UIContext: UIContext);
                    ProgressUpdater Updater = Busy.ProgressUpdater;
                    ActivateSubContext(Busy);
                    ZipArchiveEntry Entry;
                    Stream EntryStream = null;

                    using FileStream FileStream = new(ArchiveProvisioningPath, FileMode.Create);
                    using ZipArchive Archive    = new(FileStream, ZipArchiveMode.Create);
                    int i = 0;

                    foreach (string PartitionName in ProvisioningPartitions)
                    {
                        if (GPT.Partitions.Any(p => p.Name == PartitionName) && Result)
                        {
                            try
                            {
                                Entry       = Archive.CreateEntry(PartitionName + ".bin", CompressionLevel.Optimal);
                                EntryStream = Entry.Open();
                                i++;
                                Busy.Message = "Create backup of partition " + PartitionName + " (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
                                if (PartitionName == "UEFI_BS_NV" && GPT.Partitions.Any(p => p.Name == "BACKUP_BS_NV"))
                                {
                                    Phone.BackupPartition("BACKUP_BS_NV", EntryStream, Updater);
                                }
                                else
                                {
                                    Phone.BackupPartition(PartitionName, EntryStream, Updater);
                                }
                            }
                            catch (Exception Ex)
                            {
                                LogFile.LogException(Ex);
                                Result = false;
                            }
                            finally
                            {
                                EntryStream?.Close();
                                EntryStream = null;
                            }
                        }
                    }
                }
                catch { }
                finally
                {
                    Phone.CloseVolume();
                }

                if (!Result)
                {
                    ActivateSubContext(new MessageViewModel("Failed to create backup!", Exit));
                    return;
                }

                ActivateSubContext(new MessageViewModel("Successfully created a backup!", Exit));
            }).Start();
        }
Esempio n. 4
0
        internal void BackupTask(string EFIESPPath, string MainOSPath, string DataPath)
        {
            IsSwitchingInterface = false;
            new Thread(() =>
            {
                bool Result = true;

                ActivateSubContext(new BusyViewModel("Initializing backup..."));

                ulong TotalSizeSectors = 0;
                int PartitionCount     = 0;

                MassStorage Phone = (MassStorage)PhoneNotifier.CurrentModel;

                Phone.OpenVolume(false);
                byte[] GPTBuffer = Phone.ReadSectors(1, 33);
                GPT GPT          = new(GPTBuffer);
                Partition Partition;
                try
                {
                    if (EFIESPPath != null)
                    {
                        Partition         = GPT.Partitions.First(p => p.Name == "EFIESP");
                        TotalSizeSectors += Partition.SizeInSectors;
                        PartitionCount++;
                    }

                    if (MainOSPath != null)
                    {
                        Partition         = GPT.Partitions.First(p => p.Name == "MainOS");
                        TotalSizeSectors += Partition.SizeInSectors;
                        PartitionCount++;
                    }

                    if (DataPath != null)
                    {
                        Partition         = GPT.Partitions.First(p => p.Name == "Data");
                        TotalSizeSectors += Partition.SizeInSectors;
                        PartitionCount++;
                    }
                }
                catch (Exception Ex)
                {
                    LogFile.LogException(Ex);
                    Result = false;
                }

                BusyViewModel Busy      = new("Create backup...", MaxProgressValue: TotalSizeSectors, UIContext: UIContext);
                ProgressUpdater Updater = Busy.ProgressUpdater;
                ActivateSubContext(Busy);

                int i = 0;
                if (Result)
                {
                    try
                    {
                        if (EFIESPPath != null)
                        {
                            i++;
                            Busy.Message = "Create backup of partition EFIESP (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
                            Phone.BackupPartition("EFIESP", EFIESPPath, Updater);
                        }
                    }
                    catch (Exception Ex)
                    {
                        LogFile.LogException(Ex);
                        Result = false;
                    }
                }

                if (Result)
                {
                    try
                    {
                        if (MainOSPath != null)
                        {
                            i++;
                            Busy.Message = "Create backup of partition MainOS (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
                            Phone.BackupPartition("MainOS", MainOSPath, Updater);
                        }
                    }
                    catch (Exception Ex)
                    {
                        LogFile.LogException(Ex);
                        Result = false;
                    }
                }

                if (Result)
                {
                    try
                    {
                        if (DataPath != null)
                        {
                            i++;
                            Busy.Message = "Create backup of partition Data (" + i.ToString() + "/" + PartitionCount.ToString() + ")";
                            Phone.BackupPartition("Data", DataPath, Updater);
                        }
                    }
                    catch (Exception Ex)
                    {
                        LogFile.LogException(Ex);
                        Result = false;
                    }
                }

                Phone.CloseVolume();

                if (!Result)
                {
                    ActivateSubContext(new MessageViewModel("Failed to create backup!", Exit));
                    return;
                }

                ActivateSubContext(new MessageViewModel("Successfully created a backup!", Exit));
            }).Start();
        }
Esempio n. 5
0
        internal void BackupArchiveTask(string ArchivePath)
        {
            IsSwitchingInterface = false;
            new Thread(() =>
            {
                bool Result = true;

                ActivateSubContext(new BusyViewModel("Initializing backup..."));

                ulong TotalSizeSectors = 0;
                int PartitionCount     = 3;

                MassStorage Phone = (MassStorage)PhoneNotifier.CurrentModel;

                try
                {
                    Phone.OpenVolume(false);
                    byte[] GPTBuffer = Phone.ReadSectors(1, 33);
                    GPT GPT          = new WPinternals.GPT(GPTBuffer);

                    Partition Partition;

                    try
                    {
                        Partition         = GPT.Partitions.Where(p => p.Name == "EFIESP").First();
                        TotalSizeSectors += Partition.SizeInSectors;

                        Partition         = GPT.Partitions.Where(p => p.Name == "MainOS").First();
                        TotalSizeSectors += Partition.SizeInSectors;

                        Partition         = GPT.Partitions.Where(p => p.Name == "Data").First();
                        TotalSizeSectors += Partition.SizeInSectors;
                    }
                    catch (Exception Ex)
                    {
                        LogFile.LogException(Ex);
                        Result = false;
                    }

                    BusyViewModel Busy      = new BusyViewModel("Create backup...", MaxProgressValue: TotalSizeSectors, UIContext: UIContext);
                    ProgressUpdater Updater = Busy.ProgressUpdater;
                    ActivateSubContext(Busy);
                    ZipArchiveEntry Entry;
                    Stream EntryStream = null;

                    using (FileStream FileStream = new FileStream(ArchivePath, FileMode.Create))
                    {
                        using (ZipArchive Archive = new ZipArchive(FileStream, ZipArchiveMode.Create))
                        {
                            int i = 0;

                            if (Result)
                            {
                                try
                                {
                                    Entry       = Archive.CreateEntry("EFIESP.bin", CompressionLevel.Optimal);
                                    EntryStream = Entry.Open();
                                    i++;
                                    Busy.Message = "Create backup of partition EFIESP (" + i.ToString() + @"/" + PartitionCount.ToString() + ")";
                                    Phone.BackupPartition("EFIESP", EntryStream, Updater);
                                }
                                catch (Exception Ex)
                                {
                                    LogFile.LogException(Ex);
                                    Result = false;
                                }
                                finally
                                {
                                    if (EntryStream != null)
                                    {
                                        EntryStream.Close();
                                    }
                                    EntryStream = null;
                                }
                            }

                            if (Result)
                            {
                                try
                                {
                                    Entry       = Archive.CreateEntry("MainOS.bin", CompressionLevel.Optimal);
                                    EntryStream = Entry.Open();
                                    i++;
                                    Busy.Message = "Create backup of partition MainOS (" + i.ToString() + @"/" + PartitionCount.ToString() + ")";
                                    Phone.BackupPartition("MainOS", EntryStream, Updater);
                                }
                                catch (Exception Ex)
                                {
                                    LogFile.LogException(Ex);
                                    Result = false;
                                }
                                finally
                                {
                                    if (EntryStream != null)
                                    {
                                        EntryStream.Close();
                                    }
                                    EntryStream = null;
                                }
                            }

                            if (Result)
                            {
                                try
                                {
                                    Entry       = Archive.CreateEntry("Data.bin", CompressionLevel.Optimal);
                                    EntryStream = Entry.Open();
                                    i++;
                                    Busy.Message = "Create backup of partition Data (" + i.ToString() + @"/" + PartitionCount.ToString() + ")";
                                    Phone.BackupPartition("Data", EntryStream, Updater);
                                }
                                catch (Exception Ex)
                                {
                                    LogFile.LogException(Ex);
                                    Result = false;
                                }
                                finally
                                {
                                    if (EntryStream != null)
                                    {
                                        EntryStream.Close();
                                    }
                                    EntryStream = null;
                                }
                            }
                        }
                    }
                }
                catch { }
                finally
                {
                    Phone.CloseVolume();
                }

                if (!Result)
                {
                    ActivateSubContext(new MessageViewModel("Failed to create backup!", Exit));
                    return;
                }

                ActivateSubContext(new MessageViewModel("Successfully created a backup!", Exit));
            }).Start();
        }