[ARCHIVED] Windows Editions Reconstruction Project

Discussion in 'Windows 10' started by whatever127, Jan 10, 2020.

Thread Status:
Not open for further replies.
  1. Sum_Ting_Wong

    Sum_Ting_Wong MDL Member

    Jan 30, 2024
    157
    229
    10
    This seems to be the relevant section of the source for Starter, G, and S: BootlegEditionCreator.cs
    The program generally runs off Edition~~~~~~.xml files.
    Code:
    //
    // Perform edition hack
    //
    string servicingPath = Path.Combine(MountedImagePath, "Windows", "servicing", "Packages");
    string manifest = $"Microsoft-Windows-{SourceEdition}Edition~31bf3856ad364e35~*~~10.0.*.*.mum";
    string catalog = $"Microsoft-Windows-{SourceEdition}Edition~31bf3856ad364e35~*~~10.0.*.*.cat";
    string manifestPath = Directory.EnumerateFiles(servicingPath, manifest, new EnumerationOptions() { MatchCasing = MatchCasing.CaseInsensitive }).First();
    string catalogPath = Directory.EnumerateFiles(servicingPath, catalog, new EnumerationOptions() { MatchCasing = MatchCasing.CaseInsensitive }).First();
    
    bool LTSB = false;
    if (EditionID.StartsWith("enterpriseg", StringComparison.CurrentCultureIgnoreCase) || EditionID.StartsWith("enterprises", StringComparison.CurrentCultureIgnoreCase) || EditionID.StartsWith("iotenterprises", StringComparison.CurrentCultureIgnoreCase))
    {
        LTSB = true;
    }
    
    bool HasEditionPack = Directory.EnumerateFiles(UUPPath, "*.esd", SearchOption.AllDirectories).Any(x =>
        Path.GetFileName(x).Equals($"microsoft-windows-editionpack-{EditionID}-package.esd", StringComparison.InvariantCultureIgnoreCase)
    );
    progressCallback?.Invoke(Common.Messaging.Common.ProcessPhase.ApplyingImage, true, 0, "Has edition pack: " + HasEditionPack);
    
    string TemporaryFolder = tempManager.GetTempPath();
    _ = Directory.CreateDirectory(TemporaryFolder);
    
    string SxSFolder = Path.Combine(TemporaryFolder, "SxS");
    _ = Directory.CreateDirectory(SxSFolder);
    
    //
    // Build reconstructed edition xml
    //
    progressCallback?.Invoke(Common.Messaging.Common.ProcessPhase.ApplyingImage, true, 0, "Generating edition manifest");
    string packageFilter = $"microsoft-windows-edition*{EditionID}-*.esd";
    System.Collections.Generic.IEnumerable<string> packages = Directory.EnumerateFiles(UUPPath, packageFilter, SearchOption.AllDirectories);
    
    string manifestFileName = Path.GetFileName(manifestPath).Replace(SourceEdition, EditionID);
    string catalogFileName = Path.GetFileName(catalogPath).Replace(SourceEdition, EditionID);
    
    string newManifestPath = Path.Combine(SxSFolder, manifestFileName);
    string newCatalogPath = Path.Combine(SxSFolder, catalogFileName);
    
    File.Copy(manifestPath, newManifestPath, true);
    File.Copy(catalogPath, newCatalogPath, true);
    
    string ManifestContent = File.ReadAllText(newManifestPath);
    ManifestContent = ManifestContent.Replace($"EditionSpecific-{SourceEdition}", $"EditionSpecific-{EditionID}").Replace($"Windows {SourceEdition} Edition", $"Windows {EditionID} Edition").Replace($"Microsoft-Windows-{SourceEdition}Edition", $"Microsoft-Windows-{EditionID}Edition");
    
    if (HasEditionPack)
    {
        ManifestContent = ManifestContent.Replace($"EditionPack-{SourceEdition}", $"EditionPack-{EditionID}");
    }
    
    File.WriteAllText(newManifestPath, ManifestContent);
    
    if (LTSB)
    {
        AssemblyManifestHandler.RemoveNonLTSBPackages(newManifestPath);
    }
    
    // Cleanup WOW64
    if (!packages.Any(x => x.Equals($"microsoft-windows-editionspecific-{EditionID}-wow64-package.esd", StringComparison.InvariantCultureIgnoreCase)))
    {
        progressCallback?.Invoke(Common.Messaging.Common.ProcessPhase.ApplyingImage, true, 0, "Cleaning up WOW64");
        AssemblyManifestHandler.RemoveWOW64Package(newManifestPath, $"microsoft-windows-editionspecific-{EditionID}-wow64-package");
    }
    
    //
    // Expand LP to folder
    //
    if (languagePackFolder == null)
    {
        languagePackFolder = tempManager.GetTempPath();
        _ = Directory.CreateDirectory(languagePackFolder);
    
        string languagePackCabinetFilter = $"*fre_client_{languagecode}_lp.cab";
        System.Collections.Generic.IEnumerable<string> paths = Directory.EnumerateFiles(UUPPath, languagePackCabinetFilter, SearchOption.AllDirectories);
        if (paths.Any())
        {
            string languagePackPackage = paths.First();
            void ProgressCallback(int percent, string file)
            {
                progressCallback?.Invoke(Common.Messaging.Common.ProcessPhase.PreparingFiles, false, percent, "Unpacking " + file + "...");
            }
    
            CabinetExtractor.ExtractCabinet(languagePackPackage, languagePackFolder, ProgressCallback);
        }
        else
        {
            string languagePackPackage = "";
    
            string languagePackEsdFilter = $"*fre_client_{languagecode}_lp.esd";
            if (!Directory.EnumerateFiles(UUPPath, languagePackEsdFilter, SearchOption.AllDirectories).Any())
            {
                languagePackEsdFilter = $"microsoft-windows-client-languagepack-package_{languagecode}-*-{languagecode}.esd";
                if (!Directory.EnumerateFiles(UUPPath, languagePackEsdFilter, SearchOption.AllDirectories).Any())
                {
                    languagePackEsdFilter = $"microsoft-windows-client-languagepack-package_{languagecode}~*~{languagecode}~.esd";
                    if (!Directory.EnumerateFiles(UUPPath, languagePackEsdFilter, SearchOption.AllDirectories).Any())
                    {
                        languagePackEsdFilter = $"microsoft-windows-client-languagepack-package~*~*~{languagecode}~.esd";
                        if (!Directory.EnumerateFiles(UUPPath, languagePackEsdFilter, SearchOption.AllDirectories).Any())
                        {
                            progressCallback?.Invoke(Common.Messaging.Common.ProcessPhase.Error, true, 0, "Unable to find LP package!");
                            result = false;
                            goto exit;
                        }
                    }
                }
            }
    
            languagePackPackage = Directory.EnumerateFiles(UUPPath, languagePackEsdFilter, SearchOption.AllDirectories).First();
    
            result = Constants.imagingInterface.ApplyImage(languagePackPackage, 1, languagePackFolder, PreserveACL: false, progressCallback: callback2);
            if (!result)
            {
                goto exit;
            }
        }
    }
    
    //
    // Expand Edition related packages to SxS folder
    //
    foreach (string package in packages)
    {
        result = Constants.imagingInterface.ApplyImage(package, 1, SxSFolder, PreserveACL: false, progressCallback: callback2);
        if (!result)
        {
            goto exit;
        }
    
        if (File.Exists(Path.Combine(SxSFolder, "update.mum")))
        {
            Assembly assembly = AssemblyManifestHandler.Deserialize(File.ReadAllText(Path.Combine(SxSFolder, "update.mum")));
            string cbsKey = assembly.AssemblyIdentity.Name + "~" + assembly.AssemblyIdentity.PublicKeyToken + "~" + assembly.AssemblyIdentity.ProcessorArchitecture + "~" + (string.Equals(assembly.AssemblyIdentity.Language, "neutral", StringComparison.CurrentCultureIgnoreCase) ? "" : assembly.AssemblyIdentity.Language) + "~" + assembly.AssemblyIdentity.Version;
            if (!File.Exists(Path.Combine(SxSFolder, cbsKey + ".mum")))
            {
                File.Move(Path.Combine(SxSFolder, "update.mum"), Path.Combine(SxSFolder, cbsKey + ".mum"));
            }
            else
            {
                File.Delete(Path.Combine(SxSFolder, "update.mum"));
            }
    
            if (File.Exists(Path.Combine(SxSFolder, "update.cat")))
            {
                if (!File.Exists(Path.Combine(SxSFolder, cbsKey + ".cat")))
                {
                    File.Move(Path.Combine(SxSFolder, "update.cat"), Path.Combine(SxSFolder, cbsKey + ".cat"));
                }
                else
                {
                    File.Delete(Path.Combine(SxSFolder, "update.cat"));
                }
            }
        }
        File.Delete(Path.Combine(SxSFolder, "$filehashes$.dat"));
    }
    
    //
    // Generate unattend
    //
    progressCallback?.Invoke(Common.Messaging.Common.ProcessPhase.ApplyingImage, true, 0, "Generating unattend");
    string arch = manifestFileName.Split('~')[2];
    string ver = manifestFileName.Split('~')[4].Replace(".mum", "");
    
    bool removeogedition = true;
    
    // TODO: get these from matrix
    //
    if (SourceEdition.Equals("core", StringComparison.InvariantCultureIgnoreCase))
    {
        if (EditionID.Equals("corecountryspecific", StringComparison.InvariantCultureIgnoreCase))
        {
            removeogedition = false;
        }
    }
    if (SourceEdition.Equals("professional", StringComparison.InvariantCultureIgnoreCase))
    {
        if (EditionID.Equals("core", StringComparison.InvariantCultureIgnoreCase))
        {
            removeogedition = false;
        }
    }
    if (SourceEdition.Equals("professionaln", StringComparison.InvariantCultureIgnoreCase))
    {
        if (EditionID.Equals("coren", StringComparison.InvariantCultureIgnoreCase))
        {
            removeogedition = false;
        }
    }
    if (SourceEdition.Equals("core", StringComparison.InvariantCultureIgnoreCase))
    {
        if (EditionID.Equals("starter", StringComparison.InvariantCultureIgnoreCase))
        {
            removeogedition = false;
        }
    }
    if (SourceEdition.Equals("coren", StringComparison.InvariantCultureIgnoreCase))
    {
        if (EditionID.Equals("startern", StringComparison.InvariantCultureIgnoreCase))
        {
            removeogedition = false;
        }
    }
    
    string unattend = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                        "<unattend xmlns=\"urn:schemas-microsoft-com:unattend\">\n" +
                        "    <servicing>\n";
    
    if (!removeogedition)
    {
        unattend +=
                       "        <package action=\"stage\">\n" +
                       $"            <assemblyIdentity name=\"Microsoft-Windows-{SourceEdition}Edition\" version=\"{ver}\" processorArchitecture=\"{arch}\" publicKeyToken=\"31bf3856ad364e35\" language=\"neutral\" />\n" +
                       "        </package>\n";
    }
    
    unattend +=
                        "        <package action=\"stage\">\n" +
                        $"            <assemblyIdentity name=\"Microsoft-Windows-{EditionID}Edition\" version=\"{ver}\" processorArchitecture=\"{arch}\" publicKeyToken=\"31bf3856ad364e35\" language=\"neutral\" />\n" +
                        $"            <source location=\"{newManifestPath}\" />\n" +
                        "        </package>\n";
    
    if (removeogedition)
    {
        unattend +=
                       "        <package action=\"remove\">\n" +
                       $"            <assemblyIdentity name=\"Microsoft-Windows-{SourceEdition}Edition\" version=\"{ver}\" processorArchitecture=\"{arch}\" publicKeyToken=\"31bf3856ad364e35\" language=\"neutral\" />\n" +
                       "        </package>\n";
    }
    
    unattend +=
                        "        <package action=\"install\">\n" +
                        $"            <assemblyIdentity name=\"Microsoft-Windows-{EditionID}Edition\" version=\"{ver}\" processorArchitecture=\"{arch}\" publicKeyToken=\"31bf3856ad364e35\" language=\"neutral\" />\n" +
                        "        </package>\n" +
                        "        <package action=\"install\">\n" +
                        $"            <assemblyIdentity name=\"Microsoft-Windows-Client-LanguagePack-Package\" version=\"{ver}\" processorArchitecture=\"{arch}\" publicKeyToken=\"31bf3856ad364e35\" language=\"{languagecode}\" />\n" +
                        $"            <source location=\"{languagePackFolder}\\update.mum\" />\n" +
                        "        </package>\n" +
                        "    </servicing>\n" +
                        "</unattend>";
    
    string unattendPath = Path.Combine(TemporaryFolder, "unattend.xml");
    File.WriteAllText(unattendPath, unattend);
     
  2. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,691
    14,421
    340
    #14822 xinso, Mar 13, 2024
    Last edited: Mar 13, 2024
    Test 19044.4170 Windows 10 Enterprise LTSC arm64 en-US
    Code:
    WIM XML Information:
    ---------------------------
    <WIM>
      <TOTALBYTES>6028558877</TOTALBYTES>
      <IMAGE INDEX="1">
        <DIRCOUNT>36221</DIRCOUNT>
        <FILECOUNT>116972</FILECOUNT>
        <TOTALBYTES>19806606761</TOTALBYTES>
        <HARDLINKBYTES>6638988728</HARDLINKBYTES>
        <CREATIONTIME>
          <HIGHPART>0x01DA7501</HIGHPART>
          <LOWPART>0x0184BD75</LOWPART>
        </CREATIONTIME>
        <LASTMODIFICATIONTIME>
          <HIGHPART>0x01DA7501</HIGHPART>
          <LOWPART>0x21ABE8F2</LOWPART>
        </LASTMODIFICATIONTIME>
        <WIMBOOT>0</WIMBOOT>
        <WINDOWS>
          <ARCH>12</ARCH>
          <PRODUCTNAME>Microsoft® Windows® Operating System</PRODUCTNAME>
          <EDITIONID>EnterpriseS</EDITIONID>
          <INSTALLATIONTYPE>Client</INSTALLATIONTYPE>
          <SERVICINGDATA>
            <IMAGESTATE>IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE</IMAGESTATE>
            <GDRDUREVISION>0</GDRDUREVISION>
            <PKEYCONFIGVERSION>10.0.19041.4170;2016-01-01T00:00:00Z</PKEYCONFIGVERSION>
          </SERVICINGDATA>
          <PRODUCTTYPE>WinNT</PRODUCTTYPE>
          <PRODUCTSUITE>Terminal Server</PRODUCTSUITE>
          <LANGUAGES>
            <LANGUAGE>en-US</LANGUAGE>
            <DEFAULT>en-US</DEFAULT>
          </LANGUAGES>
          <VERSION>
            <MAJOR>10</MAJOR>
            <MINOR>0</MINOR>
            <BUILD>19044</BUILD>
            <SPBUILD>4170</SPBUILD>
            <SPLEVEL>0</SPLEVEL>
            <BRANCH>vb_release</BRANCH>
          </VERSION>
          <SYSTEMROOT>WINDOWS</SYSTEMROOT>
        </WINDOWS>
        <NAME>Windows 10 Enterprise LTSC 2021</NAME>
        <DESCRIPTION>Windows 10 Enterprise LTSC 2021</DESCRIPTION>
        <FLAGS>EnterpriseS</FLAGS>
        <DISPLAYNAME>Windows 10 Enterprise LTSC</DISPLAYNAME>
        <DISPLAYDESCRIPTION>19044.4170 Windows 10 Enterprise LTSC</DISPLAYDESCRIPTION>
      </IMAGE>
    </WIM>
    

    Test 19044.4170 Windows 10 Enterprise N LTSC arm64 en-GB
    Code:
    WIM XML Information:
    ---------------------------
    <WIM>
      <TOTALBYTES>5794065441</TOTALBYTES>
      <IMAGE INDEX="1">
        <DIRCOUNT>35148</DIRCOUNT>
        <FILECOUNT>113326</FILECOUNT>
        <TOTALBYTES>19020969258</TOTALBYTES>
        <HARDLINKBYTES>6371576840</HARDLINKBYTES>
        <CREATIONTIME>
          <HIGHPART>0x01DA7505</HIGHPART>
          <LOWPART>0xC967BA7F</LOWPART>
        </CREATIONTIME>
        <LASTMODIFICATIONTIME>
          <HIGHPART>0x01DA7505</HIGHPART>
          <LOWPART>0xE92E205E</LOWPART>
        </LASTMODIFICATIONTIME>
        <WIMBOOT>0</WIMBOOT>
        <WINDOWS>
          <ARCH>12</ARCH>
          <PRODUCTNAME>Microsoft® Windows® Operating System</PRODUCTNAME>
          <EDITIONID>EnterpriseSN</EDITIONID>
          <INSTALLATIONTYPE>Client</INSTALLATIONTYPE>
          <SERVICINGDATA>
            <IMAGESTATE>IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE</IMAGESTATE>
            <GDRDUREVISION>0</GDRDUREVISION>
            <PKEYCONFIGVERSION>10.0.19041.4170;2016-01-01T00:00:00Z</PKEYCONFIGVERSION>
          </SERVICINGDATA>
          <PRODUCTTYPE>WinNT</PRODUCTTYPE>
          <PRODUCTSUITE>Terminal Server</PRODUCTSUITE>
          <LANGUAGES>
            <LANGUAGE>en-GB</LANGUAGE>
            <FALLBACK LANGUAGE="en-GB">en-US</FALLBACK>
            <DEFAULT>en-GB</DEFAULT>
          </LANGUAGES>
          <VERSION>
            <MAJOR>10</MAJOR>
            <MINOR>0</MINOR>
            <BUILD>19044</BUILD>
            <SPBUILD>4170</SPBUILD>
            <SPLEVEL>0</SPLEVEL>
            <BRANCH>vb_release</BRANCH>
          </VERSION>
          <SYSTEMROOT>WINDOWS</SYSTEMROOT>
        </WINDOWS>
        <NAME>Windows 10 Enterprise N LTSC 2021</NAME>
        <DESCRIPTION>Windows 10 Enterprise N LTSC 2021</DESCRIPTION>
        <FLAGS>EnterpriseSN</FLAGS>
        <DISPLAYNAME>Windows 10 Enterprise N LTSC</DISPLAYNAME>
        <DISPLAYDESCRIPTION>19044.4170 Windows 10 Enterprise N LTSC</DISPLAYDESCRIPTION>
      </IMAGE>
    </WIM>
    
     
  3. Ace2

    Ace2 MDL Expert

    Oct 10, 2014
    1,861
    1,521
    60
  4. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,691
    14,421
    340
  5. Ace2

    Ace2 MDL Expert

    Oct 10, 2014
    1,861
    1,521
    60
    #14825 Ace2, Mar 13, 2024
    Last edited: Mar 13, 2024
    Testing
    cd C:\Users\User\Desktop\win-x86-binaries
    UUPMediaConverter.exe -i D:\*.iso -u D:\UUPs -e EnterpriseG -l en-US -c LZX

    because win-x64-binaries failed to create iso for me.
     
  6. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,691
    14,421
    340
  7. iamaHUN

    iamaHUN MDL Member

    Jun 6, 2018
    107
    156
    10
  8. Ace2

    Ace2 MDL Expert

    Oct 10, 2014
    1,861
    1,521
    60
    #14828 Ace2, Mar 13, 2024
    Last edited: Mar 13, 2024
    Thanks xinso

    i will give iso a name and add -t temp\

    I will try win-x64-binaries again with

    cd C:\Users\User\Desktop\win-x64-binaries
    UUPMediaConverter.exe -i D:\22621.1.220506-1250.NI_RELEASE_CLIENTENTG_OEMRET_X64FRE_EN-US.iso -u D:\UUPs -e EnterpriseG -l en-US -c LZX D:\Temp
     
  9. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,691
    14,421
    340
    #14830 xinso, Mar 13, 2024
    Last edited: Mar 13, 2024
    No.

    You can use a script. e.g. Create.cmd.
    Code:
    @echo off
    pushd "%~dp0"
    
    uupmediaconverter -i 26058.1000_CLIENTENTERPRISEG_VOLUME_X64FRE_EN-US.ISO -u 10.0.26058.1000 -e EnterpriseG -l en-US -c LZX -t temp\
    
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    :END
    echo.
    pause
    exit
    
    
     
  10. Ace2

    Ace2 MDL Expert

    Oct 10, 2014
    1,861
    1,521
    60
    Thanks.
     
  11. iamaHUN

    iamaHUN MDL Member

    Jun 6, 2018
    107
    156
    10
  12. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,691
    14,421
    340
  13. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,691
    14,421
    340
    Do you know how to set 25941.1000. I want to test EnterpriseS. Thanks. (If not possible, please never mind. Thanks.)
     
  14. Ace2

    Ace2 MDL Expert

    Oct 10, 2014
    1,861
    1,521
    60
    do you mean download settings ?
     
  15. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,691
    14,421
    340
    #14840 xinso, Mar 13, 2024
    Last edited: Mar 13, 2024
    Yes.