Skip to content

Commit 334650c

Browse files
committed
Improvements to TxtSetup support
1 parent 4481c63 commit 334650c

File tree

5 files changed

+339
-17
lines changed

5 files changed

+339
-17
lines changed

Windows Build Identifier/Identification/InstalledImage/DetectionHandler.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
5151
string kernelPath = "";
5252
string softwareHivePath = "";
5353
string systemHivePath = "";
54+
string userPath = "";
5455

5556
var kernelEntry = fileentries.FirstOrDefault(x =>
5657
x.EndsWith(
@@ -76,9 +77,16 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
7677
systemHivePath = installProvider.ExpandFile(systemHiveEntry);
7778
}
7879

80+
var userEntry = fileentries.FirstOrDefault(x => x.EndsWith(@"\system32\user.exe", StringComparison.InvariantCultureIgnoreCase));
81+
if (userEntry != null)
82+
{
83+
userPath = installProvider.ExpandFile(userEntry);
84+
}
85+
7986
#region Version Gathering
8087
VersionInfo1 info = new VersionInfo1();
8188
VersionInfo2 info2 = new VersionInfo2();
89+
VersionInfo1 info3 = new VersionInfo1();
8290

8391
if (!string.IsNullOrEmpty(kernelPath))
8492
{
@@ -97,11 +105,18 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
97105
info2 = ExtractVersionInfo2(softwareHivePath, systemHivePath);
98106
}
99107

108+
if (!string.IsNullOrEmpty(userPath))
109+
{
110+
Console.WriteLine("Extracting version information from the image 3");
111+
info3 = ExtractVersionInfo(userPath);
112+
}
113+
100114
report.Tag = info2.Tag;
101115
report.Licensing = info2.Licensing;
102116
report.LanguageCodes = info2.LanguageCodes;
103117

104118
WindowsVersion correctVersion = Common.GetGreaterVersion(info.version, info2.version);
119+
correctVersion = Common.GetGreaterVersion(correctVersion, info3.version);
105120

106121
if (correctVersion != null)
107122
{
@@ -163,6 +178,13 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
163178
if (!string.IsNullOrEmpty(systemHivePath))
164179
File.Delete(systemHivePath);
165180

181+
report = FixSkuNames(report, IsUnstaged);
182+
183+
return report;
184+
}
185+
186+
public static WindowsImage FixSkuNames(WindowsImage report, bool IsUnstaged)
187+
{
166188
if (!string.IsNullOrEmpty(report.Sku))
167189
{
168190
if (report.BuildNumber > 2195)
@@ -255,7 +277,14 @@ private static VersionInfo1 ExtractVersionInfo(string kernelPath)
255277

256278
FileVersionInfo info = FileVersionInfo.GetVersionInfo(kernelPath);
257279

258-
result.Architecture = Common.GetMachineTypeFromFile(new FileStream(kernelPath, FileMode.Open));
280+
try
281+
{
282+
result.Architecture = Common.GetMachineTypeFromFile(new FileStream(kernelPath, FileMode.Open));
283+
}
284+
catch
285+
{
286+
287+
}
259288

260289
var ver = info.FileVersion;
261290

Windows Build Identifier/Identification/MediaHandler.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,14 @@ private static void IdentifyWindowsNTFromVHD(Stream vhdstream)
218218
Common.DisplayReport(report);
219219
}
220220

221-
private static WindowsImageIndex[] IdentifyWindowsNTFromRootFs(IFileSystem fileSystem)
221+
private static WindowsImageIndex[] IdentifyWindowsNTFromRootFs(TxtSetupBridge fileSystem)
222222
{
223223
RootFsInstallProviderInterface provider = new RootFsInstallProviderInterface(fileSystem);
224224

225225
var report = InstalledImage.DetectionHandler.IdentifyWindowsNT(provider);
226+
report.Sku = fileSystem.GetSkuFromTxtSetupMedia(report.BuildNumber);
227+
report = InstalledImage.DetectionHandler.FixSkuNames(report, false);
228+
226229
Common.DisplayReport(report);
227230

228231
var index = new WindowsImageIndex() { WindowsImage = report };
@@ -365,13 +368,19 @@ private static FileItem[] HandleFacade(IFileSystem facade, bool Recursivity = fa
365368
}
366369
case "sif":
367370
{
368-
if (fileItem.Location.Contains("txtsetup.sif", StringComparison.InvariantCultureIgnoreCase))
371+
try
369372
{
370-
var bridge = new TxtSetupBridge(facade, string.Join("\\", fileItem.Location.Split('\\')[0..^1]));
371-
var tempIndexes = IdentifyWindowsNTFromRootFs(bridge);
372-
fileItem.Metadata = new MetaData();
373-
fileItem.Metadata.WindowsImageIndexes = tempIndexes;
373+
if (fileItem.Location.Contains("txtsetup.sif", StringComparison.InvariantCultureIgnoreCase))
374+
{
375+
var bridge = new TxtSetupBridge(facade, string.Join("\\", fileItem.Location.Split('\\')[0..^1]));
376+
var tempIndexes = IdentifyWindowsNTFromRootFs(bridge);
377+
378+
fileItem.Metadata = new MetaData();
379+
fileItem.Metadata.WindowsImageIndexes = tempIndexes;
380+
381+
}
374382
}
383+
catch { };
375384
break;
376385
}
377386
case "mui":

Windows Build Identifier/Identification/Structures.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ public class WindowsImage
252252
public enum MachineType : ushort
253253
{
254254
unknown = 0x0,
255+
axp = 0x184,
255256
am33 = 0x1d3,
256257
amd64 = 0x8664,
257258
arm = 0x1c0,

0 commit comments

Comments
 (0)