Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
82348fe
Don't include empty WIM metadata
hounsell Aug 8, 2021
7fb0142
Fix duplicated archs and additional space in licensing string
hounsell Aug 9, 2021
7f7ef09
Fix issue with some paths including leading backslash
hounsell Aug 9, 2021
4099eb6
Read additional CU build string information
hounsell Aug 9, 2021
c426628
Add ARM64 HyperVisor version check
hounsell Aug 10, 2021
03cf514
Update to .NET 5.0
hounsell Aug 10, 2021
6e32938
Update Edition IDs using BetaWiki-sourced data
hounsell Aug 10, 2021
3378401
Use Kernel-BrandingInfo over Kernel-ProductInfo if available
hounsell Aug 10, 2021
48394b3
Detect Base / Virtual SKU distinctions
hounsell Aug 14, 2021
ca6763c
Performance improvement for multi-image WIMs
hounsell Aug 15, 2021
d92c192
Update renaming logic to use Base SKUs if more than 5 SKUs
hounsell Aug 15, 2021
fd3c3f7
Add defaults for some options
hounsell Aug 15, 2021
f7d78ae
Add fork copyright to banner
hounsell Aug 16, 2021
da36f14
Performance: Reduce reloading of WIM further
hounsell Aug 17, 2021
f5876ca
Bugfixes for real-world issues
hounsell Aug 17, 2021
e1d61df
ReplaceInvalidChars rewrite to minimise string reallocations
hounsell Aug 17, 2021
b602a56
Favour EditionID / CompositionEditionID over Product Policy
hounsell Aug 17, 2021
850fc94
Fix date-parsing bug
hounsell Aug 17, 2021
9cc49f9
Don't use Base SKU multi filename variant if Base SKU list is identic…
hounsell Aug 19, 2021
98faadf
Adjust copyright notice
hounsell Aug 22, 2021
d1ccb08
Update accompanying SHA1 checksum file on rename
hounsell Sep 6, 2021
aa1bce9
Fix crash on rename where no Base SKU is available
hounsell Sep 6, 2021
0b11374
Fix issue on unstaged ia64chk images where x86 ntoskrnl is checked in…
hounsell Sep 6, 2021
48ab6c5
Remove Core SKUs from generated label if full SKUs present also
hounsell Sep 6, 2021
1de55e7
Use relative filename, not absolute path for rewriting SHA1 files
hounsell Sep 6, 2021
1ca9520
Add support for reading installed licence type via DPID4.
hounsell Sep 11, 2021
c884eab
Favour EditionID over Product Policies
hounsell Sep 11, 2021
f22c9df
Sort list of names used in renaming
hounsell Sep 11, 2021
f6c9509
Fix crash on WIM identify
hounsell Sep 11, 2021
ab01904
If only a boot.wim PE is available, still write identification file f…
hounsell Sep 19, 2021
86d7402
Only search in System32 for HV Kernel (excludes LCU cache)
hounsell Oct 19, 2021
5193946
Update to .NET 6.0; Nuget packages update
hounsell Nov 14, 2021
917d548
Update CI to .NET 6.0.x
hounsell Nov 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: "5.0.x"
dotnet-version: "6.0.x"

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
Expand Down
3 changes: 2 additions & 1 deletion Windows Build Identifier/Identification/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static WindowsVersion GetGreaterVersion(WindowsVersion version1, WindowsV

CultureInfo provider = CultureInfo.InvariantCulture;

string format = "yyMMDD-HHmm";
const string format = "yyMMdd-HHmm";

DateTime date1 = DateTime.ParseExact(version1.CompileDate, format, provider);
DateTime date2 = DateTime.ParseExact(version2.CompileDate, format, provider);
Expand Down Expand Up @@ -249,6 +249,7 @@ public static void DisplayReport(WindowsImage report)
Console.WriteLine("Architecture : " + report.Architecture);
Console.WriteLine("BuildType : " + report.BuildType);
Console.WriteLine("Types : " + typedisp);
Console.WriteLine("Base Sku : " + report.BaseSku);
Console.WriteLine("Sku : " + report.Sku);
Console.WriteLine("Editions : " + editiondisp);
Console.WriteLine("Licensing : " + report.Licensing);
Expand Down

Large diffs are not rendered by default.

67 changes: 33 additions & 34 deletions Windows Build Identifier/Identification/MediaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,27 @@ public class UnsupportedWIMException : Exception { }

public class UnsupportedWIMXmlException : Exception { }

private static string ExtractWIMXml(Stream wimstream)
private static string ExtractWIMXml(ArchiveFile archiveFile)
{
try
{
using (ArchiveFile archiveFile = new ArchiveFile(wimstream, SevenZipFormat.Wim))
if (archiveFile.Entries.Any(x => x.FileName == "[1].xml"))
{
if (archiveFile.Entries.Any(x => x.FileName == "[1].xml"))
{
Entry wimXmlEntry = archiveFile.Entries.First(x => x.FileName == "[1].xml");

string xml;
using (MemoryStream memoryStream = new MemoryStream())
{
wimXmlEntry.Extract(memoryStream);
Entry wimXmlEntry = archiveFile.Entries.First(x => x.FileName == "[1].xml");

xml = Encoding.Unicode.GetString(memoryStream.ToArray(), 2, (int)memoryStream.Length - 2);
}

return xml;
}
else if (archiveFile.Entries.Any(x => x.FileName == "Windows"))
string xml;
using (MemoryStream memoryStream = new MemoryStream())
{
return archiveFile.GetArchiveComment();
wimXmlEntry.Extract(memoryStream);

xml = Encoding.Unicode.GetString(memoryStream.ToArray(), 2, (int)memoryStream.Length - 2);
}

return xml;
}
else if (archiveFile.Entries.Any(x => x.FileName == "Windows"))
{
return archiveFile.GetArchiveComment();
}

throw new UnsupportedWIMException();
Expand Down Expand Up @@ -80,22 +77,26 @@ private static WindowsImageIndex[] IdentifyWindowsNTFromWIM(Stream wimstream, bo

Console.WriteLine("Gathering WIM information XML file");

string xml = ExtractWIMXml(wimstream);

using ArchiveFile archiveFile = new ArchiveFile(wimstream, SevenZipFormat.Wim);
string xml = ExtractWIMXml(archiveFile);

Console.WriteLine("Parsing WIM information XML file");
XmlFormats.WIMXml.WIM wim = GetWIMClassFromXml(xml);

Console.WriteLine($"Found {wim.IMAGE.Length} images in the wim according to the XML");

Console.WriteLine("Evaluating relevant images in the WIM according to the XML");
int irelevantcount2 = (wim.IMAGE.Any(x => x.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0);
int irelevantcount2 = (wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0) +
(wim.IMAGE.Any(x => x.DESCRIPTION != null && x.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase)) ? 1 : 0);

Console.WriteLine($"Found {irelevantcount2} irrelevant images in the wim according to the XML");

var provider = new WIMInstallProviderInterface(archiveFile);

foreach (var image in wim.IMAGE)
{
Console.WriteLine();
Expand All @@ -105,11 +106,11 @@ private static WindowsImageIndex[] IdentifyWindowsNTFromWIM(Stream wimstream, bo
// If what we're trying to identify isn't just a winpe, and we are accessing a winpe image
// skip the image
//
int irelevantcount = (image.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0);
int irelevantcount = (image.DESCRIPTION != null && image.DESCRIPTION.Contains("winpe", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION != null && image.DESCRIPTION.Contains("setup", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION != null && image.DESCRIPTION.Contains("preinstallation", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION != null && image.DESCRIPTION.Contains("winre", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0) +
(image.DESCRIPTION != null && image.DESCRIPTION.Contains("recovery", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0);

Console.WriteLine($"Index contains {irelevantcount} flags indicating this is a preinstallation environment");

Expand All @@ -125,7 +126,6 @@ private static WindowsImageIndex[] IdentifyWindowsNTFromWIM(Stream wimstream, bo

if (index != null && wim.IMAGE[0].INDEX == "0")
{
using ArchiveFile archiveFile = new ArchiveFile(wimstream, SevenZipFormat.Wim);
if (!archiveFile.Entries.Any(x => x.FileName.StartsWith("0\\")))
{
WorkaroundForWIMFormatBug = true;
Expand All @@ -140,12 +140,10 @@ private static WindowsImageIndex[] IdentifyWindowsNTFromWIM(Stream wimstream, bo

Console.WriteLine($"Index value: {index}");

var provider = new WIMInstallProviderInterface(wimstream, index);
provider.SetIndex(index);

var report = InstalledImage.DetectionHandler.IdentifyWindowsNT(provider);

provider.Close();

// fallback
if ((string.IsNullOrEmpty(report.Sku) || report.Sku == "TerminalServer") && !string.IsNullOrEmpty(image.FLAGS))
{
Expand Down Expand Up @@ -205,7 +203,7 @@ private static WindowsImageIndex[] IdentifyWindowsNTFromWIM(Stream wimstream, bo
results.Add(imageIndex);
}

wimstream.Dispose();
provider.Close();

return results.ToArray();
}
Expand Down Expand Up @@ -575,7 +573,7 @@ public static FileItem[] IdentifyWindowsFromISO(string isopath, bool deep, bool
using FileStream isoStream = File.Open(isopath, FileMode.Open, FileAccess.Read);

VfsFileSystemFacade cd = new CDReader(isoStream, true);
if (cd.FileExists(@"README.TXT"))
if (cd.FileExists(@"README.TXT") || cd.Root.GetDirectories().Length == 0)
{
cd = new UdfReader(isoStream);
}
Expand Down Expand Up @@ -646,6 +644,7 @@ public static WindowsImageIndex[] IdentifyWindowsFromWIM(Stream wim, bool includ
Console.WriteLine(ex.ToString());
}

wim.Dispose();
return result;
}

Expand Down
Loading