Skip to content

Commit c63765a

Browse files
committed
Sync with latest repository
1 parent f0c0798 commit c63765a

File tree

5 files changed

+406
-77
lines changed

5 files changed

+406
-77
lines changed

Windows Build Identifier/Identification/Common.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public static WindowsVersion ParseBuildString(string BuildString)
8080

8181
var splitver = rawversion.Split('.');
8282

83+
Console.WriteLine(rawversion);
84+
8385
verinfo.MajorVersion = ulong.Parse(splitver[0]);
8486
verinfo.MinorVersion = ulong.Parse(splitver[1]);
8587
verinfo.BuildNumber = ulong.Parse(splitver[2]);

Windows Build Identifier/Identification/InstalledImage/DetectionHandler.cs

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
9393
Console.WriteLine("Extracting version information from the image 1");
9494
info = ExtractVersionInfo(kernelPath);
9595

96-
File.Delete(kernelPath);
97-
9896
report.Architecture = info.Architecture;
9997
report.BuildType = info.BuildType;
10098
}
@@ -115,6 +113,24 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
115113
report.Licensing = info2.Licensing;
116114
report.LanguageCodes = info2.LanguageCodes;
117115

116+
if (report.LanguageCodes == null || report.LanguageCodes.Length == 0)
117+
{
118+
FileVersionInfo infover = FileVersionInfo.GetVersionInfo(kernelPath);
119+
120+
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
121+
foreach (var culture in cultures)
122+
{
123+
if (culture.EnglishName == infover.Language)
124+
{
125+
report.LanguageCodes = new string[] { culture.Name };
126+
break;
127+
}
128+
}
129+
}
130+
131+
if (!string.IsNullOrEmpty(kernelPath))
132+
File.Delete(kernelPath);
133+
118134
WindowsVersion correctVersion = Common.GetGreaterVersion(info.version, info2.version);
119135
correctVersion = Common.GetGreaterVersion(correctVersion, info3.version);
120136

@@ -127,6 +143,49 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
127143
report.BranchName = correctVersion.BranchName;
128144
report.CompileDate = correctVersion.CompileDate;
129145
}
146+
147+
// we have to scan all binaries because early versions of NT
148+
// do not report the same versions in all binaries
149+
if (report.BuildNumber < 1130)
150+
{
151+
Console.WriteLine("Determined the reported build number was unreliable. Checking a few more binaries...");
152+
ulong buildwindow = report.BuildNumber + 50;
153+
foreach (var binary in installProvider.GetFileSystemEntries())
154+
{
155+
if (binary.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
156+
binary.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) ||
157+
binary.EndsWith(".sys", StringComparison.InvariantCultureIgnoreCase))
158+
{
159+
string file = "";
160+
try
161+
{
162+
file = installProvider.ExpandFile(binary);
163+
var verinfo = ExtractVersionInfo(file);
164+
165+
if (verinfo.version != null && verinfo.version.MajorVersion == report.MajorVersion && verinfo.version.MinorVersion == report.MinorVersion &&
166+
verinfo.version.BuildNumber < buildwindow && report.BuildNumber < verinfo.version.BuildNumber) // allow a gap of 50 builds max
167+
{
168+
Console.WriteLine("File with newer version found: " + binary + " => " + verinfo.version.BuildNumber);
169+
170+
report.BuildNumber = verinfo.version.BuildNumber;
171+
report.DeltaVersion = verinfo.version.DeltaVersion;
172+
}
173+
}
174+
catch { }
175+
finally
176+
{
177+
if (!string.IsNullOrEmpty(file) && File.Exists(file))
178+
{
179+
try
180+
{
181+
File.Delete(file);
182+
} catch { };
183+
}
184+
};
185+
}
186+
}
187+
}
188+
130189
#endregion
131190

132191
#region Edition Gathering
@@ -193,6 +252,18 @@ public static WindowsImage FixSkuNames(WindowsImage report, bool IsUnstaged)
193252
{
194253
report.Sku = "Home";
195254
}
255+
256+
if (report.Sku.Equals("advancedserver", StringComparison.InvariantCultureIgnoreCase))
257+
{
258+
report.Sku = "EnterpriseServer";
259+
}
260+
}
261+
else
262+
{
263+
if (report.Sku.Equals("EnterpriseServer", StringComparison.InvariantCultureIgnoreCase))
264+
{
265+
report.Sku = "AdvancedServer";
266+
}
196267
}
197268

198269
if (report.BuildNumber >= 1911)
@@ -288,12 +359,15 @@ private static VersionInfo1 ExtractVersionInfo(string kernelPath)
288359

289360
var ver = info.FileVersion;
290361

291-
if (ver.Count(x => x == '.') < 4)
362+
if (ver != null)
292363
{
293-
ver = info.FileMajorPart + "." + info.FileMinorPart + "." + info.FileBuildPart + "." + info.FilePrivatePart;
294-
}
364+
if (ver.Count(x => x == '.') < 4)
365+
{
366+
ver = info.FileMajorPart + "." + info.FileMinorPart + "." + info.FileBuildPart + "." + info.FilePrivatePart;
367+
}
295368

296-
result.version = Common.ParseBuildString(ver);
369+
result.version = Common.ParseBuildString(ver);
370+
}
297371

298372
result.BuildType = info.IsDebug ? BuildType.chk : BuildType.fre;
299373

Windows Build Identifier/Identification/MediaHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ private static FileItem[] HandleFacade(IFileSystem facade, bool Recursivity = fa
380380

381381
}
382382
}
383-
catch { };
383+
catch (Exception ex) { Console.WriteLine(ex.ToString()); };
384384
break;
385385
}
386386
case "mui":

Windows Build Identifier/Interfaces/TxtSetupBridge.cs

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public string GetSkuFromTxtSetupMedia(ulong build)
169169
var subkey = hive.Root.OpenSubKey(@"ControlSet001\Services\setupdd");
170170
byte[] buffer = (byte[])subkey.GetValue("");
171171

172-
if (buffer.Length >= 16)
172+
if (buffer != null && buffer.Length >= 16)
173173
{
174174
// value is storred in big endian...
175175
byte[] productsuiteData = buffer[12..16];
@@ -267,62 +267,75 @@ public string GetSkuFromTxtSetupMedia(ulong build)
267267
sku = data["SetupData"]["ProductSuite"].Replace(" ", "").Replace("\"", "");
268268
}
269269

270-
var cdtag = data["SourceDisksNames"]["_x"].Split(",")[1].Replace("\"", "");
271-
272-
if (cdtag.Contains("%"))
270+
string cdtag = null;
271+
if (data.Sections.Any(x => x.SectionName == "SourceDisksNames"))
273272
{
274-
var strings = data["Strings"];
275-
var nonescapedpart = cdtag.Split("%")[1];
276-
var replacement = strings[nonescapedpart];
277-
cdtag = cdtag.Replace("%" + nonescapedpart + "%", replacement).Replace("\"", "");
278-
}
279-
280-
string editionletter = cdtag.Replace("cdrom.", "").Split(".")[0];
281-
char _editionletter2 = editionletter[^2];
282-
char _editionletter = editionletter[^1];
283-
284-
if (_editionletter == 'p')
285-
{
286-
sku = "Professional";
287-
}
288-
else if (_editionletter == 'c')
289-
{
290-
sku = "Personal";
273+
cdtag = data["SourceDisksNames"]["_x"].Split(",")[1].Replace("\"", "");
291274
}
292-
else if (_editionletter == 'w')
275+
else if (data.Sections.Any(x => x.SectionName == "Media"))
293276
{
294-
sku = "Workstation";
277+
cdtag = data["Media"]["dx"].Split(",")[1].Replace("\"", "");
295278
}
296-
else if (_editionletter == 'b')
297-
{
298-
sku = "WebServer";
299-
}
300-
else if (_editionletter == 's')
279+
280+
if (cdtag != null)
301281
{
302-
sku = "StandardServer";
303-
if (_editionletter2 == 't')
282+
if (cdtag.Contains("%"))
304283
{
305-
sku = "TerminalServer";
284+
var strings = data["Strings"];
285+
var nonescapedpart = cdtag.Split("%")[1];
286+
var replacement = strings[nonescapedpart];
287+
cdtag = cdtag.Replace("%" + nonescapedpart + "%", replacement).Replace("\"", "");
306288
}
307-
}
308-
else if (_editionletter == 'a')
309-
{
310-
if (build < 2202)
289+
290+
string editionletter = cdtag.Replace("cdrom.", "").Split(".")[0];
291+
char _editionletter2 = '\0';
292+
if (editionletter.Length >= 2)
293+
_editionletter2 = editionletter[^2];
294+
char _editionletter = editionletter[^1];
295+
296+
if (_editionletter == 'p')
311297
{
312-
sku = "AdvancedServer";
298+
sku = "Professional";
313299
}
314-
else
300+
else if (_editionletter == 'c')
315301
{
316-
sku = "EnterpriseServer";
302+
sku = "Personal";
303+
}
304+
else if (_editionletter == 'w')
305+
{
306+
sku = "Workstation";
307+
}
308+
else if (_editionletter == 'b')
309+
{
310+
sku = "WebServer";
311+
}
312+
else if (_editionletter == 's')
313+
{
314+
sku = "StandardServer";
315+
if (_editionletter2 == 't')
316+
{
317+
sku = "TerminalServer";
318+
}
319+
}
320+
else if (_editionletter == 'a')
321+
{
322+
if (build < 2202)
323+
{
324+
sku = "AdvancedServer";
325+
}
326+
else
327+
{
328+
sku = "EnterpriseServer";
329+
}
330+
}
331+
else if (_editionletter == 'l')
332+
{
333+
sku = "SmallbusinessServer";
334+
}
335+
else if (_editionletter == 'd')
336+
{
337+
sku = "DatacenterServer";
317338
}
318-
}
319-
else if (_editionletter == 'l')
320-
{
321-
sku = "SmallbusinessServer";
322-
}
323-
else if (_editionletter == 'd')
324-
{
325-
sku = "DatacenterServer";
326339
}
327340
}
328341

0 commit comments

Comments
 (0)