From cec77987e4520999b2fd95f8cde3610c452409a3 Mon Sep 17 00:00:00 2001 From: dmex Date: Fri, 13 Dec 2024 15:40:06 +1100 Subject: [PATCH] GenerateZw: Update to .NET 9 --- tools/GenerateZw/GenerateZw.csproj | 5 ++- tools/GenerateZw/ZwGen.cs | 72 +++++++++++------------------- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/tools/GenerateZw/GenerateZw.csproj b/tools/GenerateZw/GenerateZw.csproj index 4e63ed31dce4..18fb4c873947 100644 --- a/tools/GenerateZw/GenerateZw.csproj +++ b/tools/GenerateZw/GenerateZw.csproj @@ -4,23 +4,26 @@ Exe AnyCPU AnyCPU - net7.0 + net9.0 win-x64 $(ProjectDir)obj\$(Configuration)\$(TargetFramework)-$(PlatformTarget)\ $(ProjectDir)bin\$(Configuration)\$(TargetFramework)-$(PlatformTarget)\ true + False DEBUG;TRACE full true + 4096 embedded true + 4096 diff --git a/tools/GenerateZw/ZwGen.cs b/tools/GenerateZw/ZwGen.cs index 88faaf8c903d..61dcd7a16d3a 100644 --- a/tools/GenerateZw/ZwGen.cs +++ b/tools/GenerateZw/ZwGen.cs @@ -24,33 +24,7 @@ public static class ZwGen private static readonly string OutputFile = "ntzwapi.h"; private static readonly string Header = "#ifndef _NTZWAPI_H\r\n#define _NTZWAPI_H\r\n\r\n// This file was automatically generated. Do not edit.\r\n\r\n"; private static readonly string Footer = "#endif\r\n"; - public static readonly string[] Files = - { - "ntdbg.h", - "ntexapi.h", - "ntgdi.h", - "ntioapi.h", - "ntkeapi.h", - "ntldr.h", - "ntlpcapi.h", - "ntmisc.h", - "ntmmapi.h", - "ntnls.h", - "ntobapi.h", - "ntpebteb.h", - "ntpfapi.h", - "ntpnpapi.h", - "ntpoapi.h", - "ntpsapi.h", - "ntregapi.h", - "ntrtl.h", - "ntsam.h", - "ntseapi.h", - "nttmapi.h", - "nttp.h", - "ntwow64.h", - "ntxcapi.h" - }; + public static readonly string[] Exclude = { "ntuser.h" }; static ZwGen() { @@ -70,26 +44,30 @@ static ZwGen() public static void Execute() { + var files = Directory.EnumerateFiles(BaseDirectory, "*.h", SearchOption.AllDirectories); + // Build up a list of definitions. var definitions = new List(); var regex = RegexDefinition.Regex(); - foreach (string fileName in Files) + foreach (string fileName in files) { - var file = BaseDirectory + Path.DirectorySeparatorChar + fileName; - var text = File.ReadAllText(file); + if (Exclude.Contains(Path.GetFileName(fileName), StringComparer.OrdinalIgnoreCase)) + continue; + + var text = File.ReadAllText(fileName); MatchCollection matches = regex.Matches(text); foreach (Match match in matches) { definitions.Add(new ServiceDefinition - { - Name = match.Groups[1].Value, - Text = match.Value, - NameIndex = match.Groups[1].Index - match.Index - }); + ( + match.Groups[1].Value, + match.Value, + match.Groups[1].Index - match.Index + )); } } @@ -108,10 +86,10 @@ public static void Execute() foreach (var d in _defs) { - Console.WriteLine("System service: " + d.Name); + Console.WriteLine($"System service: {d.Name}"); // Write the original definition, replacing "Nt" with "Zw". - sw.Write(string.Concat(d.Text.AsSpan(0, d.NameIndex), "Zw", d.Text.AsSpan(d.NameIndex + 2), "\r\n\r\n")); + sw.Write($"{d.Text.AsSpan(0, d.NameIndex)}Zw{d.Text.AsSpan(d.NameIndex + 2)}\r\n\r\n"); } // Footer @@ -123,15 +101,22 @@ public static void Execute() public static partial class RegexDefinition { - [GeneratedRegex(@"NTSYSCALLAPI[\w\s_]*NTAPI\s*(Nt(\w)*)\(.*?\);", RegexOptions.Singleline)] + [GeneratedRegex(@"NTSYSCALLAPI[\w\s_]*NTAPI\s*(Nt(\w)*)\(.*?\);", RegexOptions.Singleline | RegexOptions.Compiled)] public static partial Regex Regex(); } public class ServiceDefinition : IEquatable { - public string Name; - public string Text; - public int NameIndex; + public readonly string Name; + public readonly string Text; + public readonly int NameIndex; + + public ServiceDefinition(string Name, string Text, int NameIndex) + { + this.Name = Name; + this.Text = Text; + this.NameIndex = NameIndex; + } public override string ToString() { @@ -145,9 +130,6 @@ public override int GetHashCode() public override bool Equals(object obj) { - if (obj == null) - return false; - if (obj is not ServiceDefinition service) return false; @@ -156,7 +138,7 @@ public override bool Equals(object obj) public bool Equals(ServiceDefinition other) { - return this.Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase); + return other != null && this.Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase); } }