Skip to content

Commit 1e3dd30

Browse files
committed
Fixes + NEC98 support
1 parent c63765a commit 1e3dd30

File tree

5 files changed

+101
-55
lines changed

5 files changed

+101
-55
lines changed

Windows Build Identifier/Identification/Common.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public static MachineType GetMachineTypeFromFile(Stream fs)
2121
throw new Exception("Can't find PE header");
2222
}
2323

24-
MachineType machineType = (MachineType)br.ReadUInt16();
24+
var type = br.ReadUInt16();
25+
26+
Console.WriteLine("Machine type: " + type);
27+
28+
MachineType machineType = (MachineType)type;
2529
br.Close();
2630
fs.Close();
2731
return machineType;

Windows Build Identifier/Identification/InstalledImage/DetectionHandler.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
4949
//
5050

5151
string kernelPath = "";
52+
string shell32Path = "";
5253
string softwareHivePath = "";
5354
string systemHivePath = "";
5455
string userPath = "";
@@ -65,13 +66,19 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
6566
kernelPath = installProvider.ExpandFile(kernelEntry);
6667
}
6768

68-
var softwareHiveEntry = fileentries.FirstOrDefault(x => x.Equals(@"windows\system32\config\software", StringComparison.InvariantCultureIgnoreCase));
69+
var shell32Entry = fileentries.FirstOrDefault(x => x.EndsWith(@"system32\shell32.dll", StringComparison.InvariantCultureIgnoreCase));
70+
if (shell32Entry != null)
71+
{
72+
shell32Path = installProvider.ExpandFile(shell32Entry);
73+
}
74+
75+
var softwareHiveEntry = fileentries.FirstOrDefault(x => x.EndsWith(@"system32\config\software", StringComparison.InvariantCultureIgnoreCase));
6976
if (softwareHiveEntry != null)
7077
{
7178
softwareHivePath = installProvider.ExpandFile(softwareHiveEntry);
7279
}
7380

74-
var systemHiveEntry = fileentries.FirstOrDefault(x => x.Equals(@"windows\system32\config\system", StringComparison.InvariantCultureIgnoreCase));
81+
var systemHiveEntry = fileentries.FirstOrDefault(x => x.EndsWith(@"system32\config\system", StringComparison.InvariantCultureIgnoreCase));
7582
if (systemHiveEntry != null)
7683
{
7784
systemHivePath = installProvider.ExpandFile(systemHiveEntry);
@@ -95,6 +102,13 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
95102

96103
report.Architecture = info.Architecture;
97104
report.BuildType = info.BuildType;
105+
106+
if (report.Architecture == MachineType.x86)
107+
{
108+
var possibleNec98 = fileentries.FirstOrDefault(x => x.Contains(@"system32\hal98", StringComparison.InvariantCultureIgnoreCase));
109+
if (possibleNec98 != null)
110+
report.Architecture = MachineType.nec98;
111+
}
98112
}
99113

100114
if (!string.IsNullOrEmpty(softwareHivePath) && !string.IsNullOrEmpty(systemHivePath))
@@ -117,6 +131,11 @@ public static WindowsImage IdentifyWindowsNT(WindowsInstallProviderInterface ins
117131
{
118132
FileVersionInfo infover = FileVersionInfo.GetVersionInfo(kernelPath);
119133

134+
if (infover.Language == "Language Neutral")
135+
{
136+
infover = FileVersionInfo.GetVersionInfo(shell32Path);
137+
}
138+
120139
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
121140
foreach (var culture in cultures)
122141
{

Windows Build Identifier/Identification/Structures.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace WindowsBuildIdentifier.Identification
45
{
@@ -274,6 +275,7 @@ public enum MachineType : ushort
274275
sh5 = 0x1a8,
275276
thumb = 0x1c2,
276277
wcemipsv2 = 0x169,
278+
nec98 = 0xffff
277279
}
278280

279281
public class WindowsVersion

Windows Build Identifier/Interfaces/TxtSetupBridge.cs

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,26 @@ private class TxtSetupFileEntry
140140

141141
public enum ProductMasks
142142
{
143-
VER_SUITE_SMALLBUSINESS = 0x00000001,
144-
VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020,
143+
VER_SUITE_SMALLBUSINESS = 0x00000001,
144+
VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020,
145145

146-
VER_SUITE_EMBEDDEDNT = 0x00000040,
147-
VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800,
146+
VER_SUITE_EMBEDDEDNT = 0x00000040,
147+
VER_SUITE_EMBEDDED_RESTRICTED = 0x00000800,
148148

149-
VER_SUITE_TERMINAL = 0x00000010,
150-
VER_SUITE_SINGLEUSERTS = 0x00000100,
151-
VER_SUITE_MULTIUSERTS = 0x00020000,
149+
VER_SUITE_TERMINAL = 0x00000010,
150+
VER_SUITE_SINGLEUSERTS = 0x00000100,
151+
VER_SUITE_MULTIUSERTS = 0x00020000,
152152

153-
VER_SUITE_ENTERPRISE = 0x00000002,
154-
VER_SUITE_BACKOFFICE = 0x00000004,
155-
VER_SUITE_COMMUNICATIONS = 0x00000008,
156-
VER_SUITE_DATACENTER = 0x00000080,
157-
VER_SUITE_PERSONAL = 0x00000200,
158-
VER_SUITE_BLADE = 0x00000400,
159-
VER_SUITE_SECURITY_APPLIANCE = 0x00001000,
160-
VER_SUITE_STORAGE_SERVER = 0x00002000,
161-
VER_SUITE_COMPUTE_SERVER = 0x00004000,
162-
VER_SUITE_WH_SERVER = 0x00008000
153+
VER_SUITE_ENTERPRISE = 0x00000002,
154+
VER_SUITE_BACKOFFICE = 0x00000004,
155+
VER_SUITE_COMMUNICATIONS = 0x00000008,
156+
VER_SUITE_DATACENTER = 0x00000080,
157+
VER_SUITE_PERSONAL = 0x00000200,
158+
VER_SUITE_BLADE = 0x00000400,
159+
VER_SUITE_SECURITY_APPLIANCE = 0x00001000,
160+
VER_SUITE_STORAGE_SERVER = 0x00002000,
161+
VER_SUITE_COMPUTE_SERVER = 0x00004000,
162+
VER_SUITE_WH_SERVER = 0x00008000
163163
}
164164

165165
public string GetSkuFromTxtSetupMedia(ulong build)
@@ -393,47 +393,63 @@ private void LoadTxtSetupData(IFileSystem originalFs, string pathInFs)
393393
var vdata = el.Value.Split(',');
394394

395395
var filename = el.KeyName;
396-
if (vdata.Length >= filenameid + 1 && !string.IsNullOrEmpty(vdata[filenameid]))
396+
try
397397
{
398-
filename = vdata[filenameid];
398+
if (vdata.Length >= filenameid + 1 && !string.IsNullOrEmpty(vdata[filenameid]))
399+
{
400+
filename = vdata[filenameid];
401+
}
399402
}
403+
catch { }
400404

401405
filename = filename.Replace("\"", "");
402406

403-
if (filename.Contains("%"))
407+
try
404408
{
405-
var nonescapedpart = filename.Split("%")[1];
406-
var replacement = strings[nonescapedpart];
407-
filename = filename.Replace("%" + nonescapedpart + "%", replacement).Replace("\"", "");
409+
if (filename.Contains("%"))
410+
{
411+
var nonescapedpart = filename.Split("%")[1];
412+
var replacement = strings[nonescapedpart];
413+
filename = filename.Replace("%" + nonescapedpart + "%", replacement).Replace("\"", "");
414+
}
408415
}
416+
catch { }
409417

410-
var directoryId = vdata[dirid];
411-
string directory;
412-
int ret;
413-
if (directoryId == "" || !int.TryParse(directoryId, out ret) || dstdirs.GetKeyData(directoryId) == null)
414-
{
415-
directory = "system32";
416-
}
417-
else
418+
try
418419
{
419-
directory = dstdirs.GetKeyData(directoryId).Value.Replace("\"", "");
420-
}
420+
var directoryId = vdata[dirid];
421+
string directory;
422+
int ret;
423+
if (directoryId == "" || !int.TryParse(directoryId, out ret) || dstdirs.GetKeyData(directoryId) == null)
424+
{
425+
directory = "system32";
426+
}
427+
else
428+
{
429+
directory = dstdirs.GetKeyData(directoryId).Value.Replace("\"", "");
430+
}
421431

422-
if (directory.Contains("%"))
423-
{
424-
var nonescapedpart = directory.Split("%")[1];
425-
var replacement = strings[nonescapedpart];
426-
directory = directory.Replace("%" + nonescapedpart + "%", replacement).Replace("\"", "");
427-
}
432+
try
433+
{
434+
if (directory.Contains("%"))
435+
{
436+
var nonescapedpart = directory.Split("%")[1];
437+
var replacement = strings[nonescapedpart];
438+
directory = directory.Replace("%" + nonescapedpart + "%", replacement).Replace("\"", "");
439+
}
440+
}
441+
catch { }
428442

429-
if (directory == @"\")
430-
{
431-
fileList.Add(new TxtSetupFileEntry() { Path = Path.Combine(defdir, filename), DiscLocation = el.KeyName });
432-
}
433-
else
434-
{
435-
fileList.Add(new TxtSetupFileEntry() { Path = Path.Combine(defdir, directory, filename), DiscLocation = el.KeyName });
443+
if (directory == @"\")
444+
{
445+
fileList.Add(new TxtSetupFileEntry() { Path = Path.Combine(defdir, filename), DiscLocation = el.KeyName });
446+
}
447+
else
448+
{
449+
fileList.Add(new TxtSetupFileEntry() { Path = Path.Combine(defdir, directory, filename), DiscLocation = el.KeyName });
450+
}
436451
}
452+
catch { }
437453
}
438454

439455
entries = fileList.ToArray();

Windows Build Identifier/Program.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ static int Main(string[] args)
152152
errs => 1);
153153
}
154154

155+
public static string ReplaceInvalidChars(string filename)
156+
{
157+
return Path.Join(filename.Replace(Path.GetFileName(filename), ""), string.Join("_", Path.GetFileName(filename).Split(Path.GetInvalidFileNameChars())));
158+
}
159+
155160
private static (string, string) GetAdequateNameFromImageIndexes(WindowsImageIndex[] imageIndexes)
156161
{
157162
var f = imageIndexes[0].WindowsImage;
@@ -289,14 +294,14 @@ private static int RunBulkRenameAndReturnExitCode(BulkRenameOptions opts)
289294
Console.WriteLine($"Target filename: {dst}");
290295
Console.WriteLine();
291296

292-
if (file == dst)
297+
if (file == ReplaceInvalidChars(dst))
293298
{
294299
Console.WriteLine("Nothing to do, file name is already good");
295300
}
296301
else
297302
{
298303
Console.WriteLine("Renaming");
299-
File.Move(file, dst);
304+
File.Move(file, ReplaceInvalidChars(dst));
300305
}
301306

302307
Console.WriteLine("Done.");
@@ -402,7 +407,7 @@ private static int RunBulkSortAndReturnExitCode(BulkSortOptions opts)
402407
Directory.CreateDirectory(finalpath);
403408
}
404409

405-
File.Move(file, Path.Combine(finalpath, file.Split(@"\")[^1]));
410+
File.Move(file, ReplaceInvalidChars(Path.Combine(finalpath, file.Split(@"\")[^1])));
406411
}
407412

408413
return 0;
@@ -458,14 +463,14 @@ private static int RunRenameAndReturnExitCode(RenameOptions opts)
458463
Console.WriteLine($"Target filename: {dst}");
459464
Console.WriteLine();
460465

461-
if (opts.Media == dst)
466+
if (opts.Media == ReplaceInvalidChars(dst))
462467
{
463468
Console.WriteLine("Nothing to do, file name is already good");
464469
}
465470
else
466471
{
467472
Console.WriteLine("Renaming");
468-
File.Move(opts.Media, dst);
473+
File.Move(opts.Media, ReplaceInvalidChars(dst));
469474
}
470475

471476
Console.WriteLine("Done.");

0 commit comments

Comments
 (0)