Example #1
0
        private void Form12_Load(object sender, EventArgs e)
        {
            try
            {
                using (FileStream wimstream = new FileStream(WindowsSetup.Variabile.locatie, FileMode.Open, FileAccess.Read))
                {
                    WimFile x = new WimFile(wimstream);
                }
            }
            catch
            {
            }

            string install = "Get-WindowsImage -Imagepath \"" + WindowsSetup.Variabile.locatie + "\" | Select-Object ImageName > Packages\\fix.txt ";

            CMD_Process_Class.Process_Powershell(install);
            string[] lines     = File.ReadAllLines("Packages\\fix.txt");
            var      lineCount = File.ReadAllLines("Packages\\fix.txt").Length;

            for (int i = 3; i < lineCount; i++)
            {
                if (lines[i].Length > 1)
                {
                    checkedListBox1.Items.Add(lines[i]);
                }
            }
        }
Example #2
0
 public void LoadWin10Rs1MultipleImages()
 {
     using (WimFile wf = new WimFile($"{AppContext.BaseDirectory}\\TestFiles\\Win10-RS1-MultiImage-Integrity.wim"))
     {
         wf.LoadImageMetadata();
         Assert.IsTrue(wf.ImageCount == 2);
     }
 }
Example #3
0
 public void LoadWin10WithBrokenIntegrityAndCheck()
 {
     using (WimFile wf = new WimFile($"{AppContext.BaseDirectory}\\TestFiles\\Win10-RS1-BrokenIntegrity.wim"))
     {
         bool success = wf.CheckIntegrity();
         Assert.IsTrue(!success);
     }
 }
Example #4
0
 public void LoadWin10Rs1CompressMax()
 {
     using (WimFile wf = new WimFile($"{AppContext.BaseDirectory}\\TestFiles\\Win10-RS1-CompressMax.wim"))
     {
         wf.LoadImageMetadata();
         Assert.IsTrue((wf.Flags & WimHeaderFlags.CompressLzx) > 0);
     }
 }
Example #5
0
        public void LoadWin10MultipleImagesWithIntegrityAndCheck()
        {
            using (WimFile wf = new WimFile($"{AppContext.BaseDirectory}\\TestFiles\\Win10-RS1-MultiImage-Integrity.wim"))
            {
                Assert.IsTrue(wf.ImageCount == 2);

                bool success = wf.CheckIntegrity();
                Assert.IsTrue(success);
            }
        }
Example #6
0
        public void LoadInvalidMagicWithError()
        {
            WimInvalidException wnvex = Assert.ThrowsException <WimInvalidException>(() =>
            {
                using (WimFile wf = new WimFile($"{AppContext.BaseDirectory}\\TestFiles\\Error-InvalidMagic.wim"))
                {
                }
            });

            Assert.AreEqual(WimInvalidExceptionType.InvalidMagic, wnvex.Type);
        }
Example #7
0
        public void CheckIntegrityWithNoIntegrityData()
        {
            WimIntegrityException ex = Assert.ThrowsException <WimIntegrityException>(() =>
            {
                using (WimFile wf = new WimFile($"{AppContext.BaseDirectory}\\TestFiles\\Win10-RS1-CompressNone.wim"))
                {
                    bool succcess = wf.CheckIntegrity();
                }
            });

            Assert.AreEqual(WimIntegrityExceptionType.NoIntegrityData, ex.Type);
        }
Example #8
0
        private static void Main(string[] args)
        {
            Options = new CliOptions();
            if (!Parser.Default.ParseArguments(args, Options))
            {
                return;
            }

            if (string.IsNullOrEmpty(Options.CustomKey))
            {
                CryptoKey.LoadKeysFromXml();
            }
            else
            {
                try
                {
                    CryptoKey.UseCustomKey(Options.CustomKey);
                }
                catch (FormatException)
                {
                    Console.WriteLine("The key you have specified is not valid. Loading the keys from the XML file instead...");
                    CryptoKey.LoadKeysFromXml();
                }
            }

            foreach (string file in Options.EsdFiles)
            {
                if (File.Exists(file))
                {
                    try
                    {
                        using (WimFile wf = new WimFile(file))
                        {
                            wf.DecryptEsd();
                        }
                    }
                    catch (NoValidCryptoKeyException)
                    {
                        Console.WriteLine($"We could not find the correct CryptoKey for \"{file}\".");
                    }
                    catch (UnencryptedImageException)
                    {
                        Console.WriteLine($"You are trying to decrypt \"{file}\", but it is already decrypted.");
                    }
                }
                else
                {
                    Console.WriteLine($"The file \"{file}\" does not exist.");
                }
            }
        }
        private bool GetDiskCapacityImage(out string error)
        {
            error = string.Empty;
            string filename = m_textBoxFile.Text;

            FileInfo info = new FileInfo(filename);

            ImageLength = info.Length > 0 ? (ulong)info.Length : 0;

            if (IsWIM)
            {
                try
                {
                    using (FileStream wimstream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                    {
                        WimFile      wimDisk     = new WimFile(wimstream);
                        string       manifest    = wimDisk.Manifest;
                        Wim_Manifest wimManifest = (Wim_Manifest)Tools.Deserialize(manifest, typeof(Wim_Manifest));
                        DiskCapacity = wimManifest.Image[wimDisk.BootImage].TotalBytes;                         //image data size
                        return(true);
                    }
                }
                catch (Exception)
                {
                    error = Messages.IMAGE_SELECTION_PAGE_ERROR_CORRUPT_FILE;
                    return(false);
                }
            }

            try
            {
                using (VirtualDisk vd = VirtualDisk.OpenDisk(filename, FileAccess.Read))
                {
                    DiskCapacity = (ulong)vd.Capacity;
                    return(true);
                }
            }
            catch (IOException ioe)
            {
                error = ioe.Message.Contains("Invalid VMDK descriptor file")
                                                ? Messages.IMAGE_SELECTION_PAGE_ERROR_INVALID_VMDK_DESCRIPTOR
                                                : Messages.IMAGE_SELECTION_PAGE_ERROR_INVALID_FILE_TYPE;
                return(false);
            }
            catch (Exception)
            {
                error = Messages.IMAGE_SELECTION_PAGE_ERROR_CORRUPT_FILE;
                return(false);
            }
        }
Example #10
0
        private static void OnConsoleCancelKeyPress(object sender, ConsoleCancelEventArgs e)
        {
            Console.WriteLine();
            Console.WriteLine("Aborting...");

            if (_iso != null)
            {
                ManagementExtensions.UnmountDiskImage(_iso);
                _iso = null;
                Console.WriteLine(inputFilePath + " has been unmounted.");
            }

            if (_logFilePath != null)
            {
                WimFile.UnregisterLogfile(_logFilePath);
            }
        }
Example #11
0
        private void Form12_Load(object sender, EventArgs e)
        {
            try
            {
                using (FileStream wimstream = new FileStream(WindowsSetup.Variabile.locatie, FileMode.Open, FileAccess.Read))
                {
                    WimFile x = new WimFile(wimstream);
                }
            }
            catch
            {
            }
            string dism       = "dism /Get-WimInfo /WimFile:";
            string install    = "\"" + WindowsSetup.Variabile.locatie + "\" > Packages\\fix.txt";
            string installing = dism + install;

            CMD_Process_Class.Process_CMD(installing);
            string[] lines = File.ReadAllLines("Packages\\fix.txt");
            var      lineCount = File.ReadAllLines("Packages\\fix.txt").Length;
            int      i = 7, j = 1;

            for (i = 7; i < lineCount; i += 5)
            {
                string   ep          = lines[i];
                string[] lines3      = ep.Split(':');
                string   gamma       = lines[i + 2];
                string   lines2      = "Index " + j.ToString() + ":" + lines3[1] + " ";
                string[] lines1      = new String[] { lines2 };
                string[] gamma_space = gamma.Split(':');
                string   comp        = gamma_space[1];
                lines2 += comp;
                string[] comp_sp  = comp.Split(',');
                int      space_nu = Int32.Parse(comp_sp[0]);
                WindowsSetup.Variabile.space_gb_ver = space_nu;
                checkedListBox1.Items.AddRange(lines1);
                if (i > lineCount)
                {
                    break;
                }
                j++;
            }
        }
Example #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("ConvertIsoToVhdx - Copyright (C) 2017-" + DateTime.Now.Year + " Simon Mourier. All rights reserved.");
            Console.WriteLine();

            if (CommandLine.HelpRequested || args.Length < 2)
            {
                Help();
                return;
            }

            inputFilePath  = CommandLine.GetNullifiedArgument(0);
            outputFilePath = CommandLine.GetNullifiedArgument(1);
            if (inputFilePath == null || outputFilePath == null)
            {
                Help();
                return;
            }

            inputFilePath  = Path.GetFullPath(inputFilePath);
            outputFilePath = Path.GetFullPath(outputFilePath);
            Console.WriteLine("Input file: " + inputFilePath);
            Console.WriteLine("Output file: " + outputFilePath);

            _logFilePath = CommandLine.GetNullifiedArgument("log");
            int systemPartitionSizeInMB = Math.Max(CommandLine.GetArgument("systemPartitionSizeInMB", 0), 100);

            if (_logFilePath != null)
            {
                _logFilePath = Path.GetFullPath(_logFilePath);
                WimFile.RegisterLogfile(_logFilePath);
                Console.WriteLine("Logging Imaging information to log file: " + _logFilePath);
            }

            Console.WriteLine();
            Console.CancelKeyPress += OnConsoleCancelKeyPress;
            _iso = ManagementExtensions.MountDiskImage(inputFilePath, out var driveLetter);
            Console.WriteLine(inputFilePath + " has been mounted as drive '" + driveLetter + "'.");
            try
            {
                var input = driveLetter + @":\sources\install.wim";
                if (!File.Exists(input))
                {
                    Console.WriteLine("Error: windows image file at '" + input + "' was not found.");
                    return;
                }

                var options = new WimFileOpenOptions();
                options.RegisterForEvents = true;
                Console.WriteLine("Opening windows image file '" + input + "'.");

                using (var file = new WimFile(input, options))
                {
                    if (file.ImagesCount == 0)
                    {
                        Console.WriteLine("Error: windows image file at '" + input + "' does not contain any image.");
                        return;
                    }

                    file.Event += OnFileEvent;
                    var diskSize = 512 * (file.Images[0].Size / 512);
                    Console.WriteLine("Creating virtual disk '" + outputFilePath + "'. Maximum size: " + diskSize + " (" + Conversions.FormatByteSize(diskSize) + ")");
                    using (var vdisk = VirtualHardDisk.CreateDisk(outputFilePath, diskSize, IntPtr.Zero, true))
                    {
                        vdisk.Attach();

                        var disk = ManagementExtensions.GetDisk(vdisk.DiskIndex);
                        Console.WriteLine("Virtual disk path: " + disk["Path"]);
                        var size = (ulong)disk["Size"];
                        Console.WriteLine("Virtual disk size: " + size + " bytes (" + Conversions.FormatByteSize(size) + ")");
                        //disk.Dump();

                        var result = disk.InvokeMethod("Initialize", new Dictionary <string, object>
                        {
                            { "PartitionStyle", 2 }    // GPT
                        });

                        // reread the disk
                        disk = ManagementExtensions.GetDisk(vdisk.DiskIndex);
                        Console.WriteLine("Virtual disk partition style: " + disk["PartitionStyle"]);
                        //disk.Dump();

                        //var PARTITION_SYSTEM_GUID = "{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}";

                        //// https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/configure-uefigpt-based-hard-drive-partitions
                        //result = disk.InvokeMethod("CreatePartition", new Dictionary<string, object>
                        //    {
                        //        { "Size", systemPartitionSizeInMB * 1024 * 1024L },
                        //        { "GptType", PARTITION_SYSTEM_GUID }
                        //    });

                        //var systemPartition = (ManagementBaseObject)result["CreatedPartition"];
                        //Console.WriteLine("System partition GPT Type: " + systemPartition["GptType"]);
                        ////systemPartition.Dump();

                        //var systemVolume = ManagementExtensions.GetPartitionVolume(systemPartition);
                        //systemVolume.InvokeMethod("Format", new Dictionary<string, object>
                        //    {
                        //        { "FileSystem", "FAT32" },
                        //        //{ "Force", true },
                        //        //{ "Full", false },
                        //        { "Compress", true }
                        //    });

                        //// reread the disk
                        //disk = ManagementExtensions.GetDisk(vdisk.DiskIndex);
                        ////disk.Dump();

                        var PARTITION_BASIC_DATA_GUID = "{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}";

                        result = disk.InvokeMethod("CreatePartition", new Dictionary <string, object>
                        {
                            { "UseMaximumSize", true },
                            //{ "AssignDriveLetter", true },
                            { "GptType", PARTITION_BASIC_DATA_GUID }
                        });

                        var partition = (ManagementBaseObject)result["CreatedPartition"];
                        //partition.Dump();
                        Console.WriteLine("Data partition GPT Type: " + partition["GptType"]);

                        var volume = ManagementExtensions.GetPartitionVolume(partition);
                        volume.InvokeMethod("Format", new Dictionary <string, object>
                        {
                            { "FileSystem", "NTFS" },
                            { "Compress", true }
                            //{ "Force", true },
                            //{ "Full", false }
                        });

                        //volume.Dump();
                        Console.WriteLine("Data volume path: " + volume["Path"]);
                        Console.WriteLine("Applying...");
                        Console.WriteLine();
                        Console.WriteLine("Completed 00%");

                        int col        = 10;
                        int fixedLines = 1;
                        _percentLeft = col;
                        _percentTop  = Console.CursorTop - fixedLines;

                        Console.CursorVisible = false;
                        file.Images[0].Apply((string)volume["Path"]);
                    }
                }
            }
            finally
            {
                Console.CursorVisible = true;
                Console.WriteLine();
                ManagementExtensions.UnmountDiskImage(_iso);
                Console.WriteLine(inputFilePath + " has been unmounted.");
            }
        }