From bcc24ddba0a9e6f47966b4c9584cfaf67ff841a3 Mon Sep 17 00:00:00 2001 From: MouriNaruto Date: Wed, 1 Mar 2023 14:22:52 +0800 Subject: [PATCH] Update generator. --- Tools/ZwGen/ZwGen/Program.cs | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/Tools/ZwGen/ZwGen/Program.cs b/Tools/ZwGen/ZwGen/Program.cs index 274ae41..2153a23 100644 --- a/Tools/ZwGen/ZwGen/Program.cs +++ b/Tools/ZwGen/ZwGen/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Text.RegularExpressions; @@ -6,13 +7,45 @@ namespace ZwGen { class Program { + public static string GetRepositoryRoot() + { + Process process = new Process + { + StartInfo = new ProcessStartInfo + { + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardOutput = true, + FileName = "git.exe", + Arguments = "rev-parse --show-toplevel" + } + }; + + if (process.Start()) + { + process.WaitForExit(); + if (process.ExitCode == 0) + { + string? result = process.StandardOutput.ReadLine(); + if (result != null) + { + return Path.GetFullPath(result); + } + } + } + + return string.Empty; + } + static void Main(string[] args) { - string currentFilePath = @"D:\Projects\Chuyu-Team\MINT\Tools\amalgamate\MINT.h"; + string currentFilePath = GetRepositoryRoot() + @"\Tools\amalgamate\MINT.h"; string text = File.ReadAllText(currentFilePath); - Regex regex = new Regex(@"NTSYSCALLAPI[\w\s_]*NTAPI\s*(Nt(\w)*)\(.*?\);", RegexOptions.Compiled | RegexOptions.Singleline); + Regex regex = new Regex( + @"NTSYSCALLAPI[\w\s_]*NTAPI\s*(Nt(\w)*)\(.*?\);", + RegexOptions.Compiled | RegexOptions.Singleline); MatchCollection matches; matches = regex.Matches(text); @@ -23,8 +56,11 @@ namespace ZwGen string currentText = match.Value; int currentNameIndex = match.Groups[1].Index - match.Index; - string newText = currentText + "\r\n\r\n" + currentText.Substring(0, currentNameIndex) + "Zw" + currentText.Substring(currentNameIndex + 2); - + string newText = string.Format( + "{0}\r\n\r\n{1}Zw{2}", + currentText, + currentText.Substring(0, currentNameIndex), + currentText.Substring(currentNameIndex + 2)); // Make sure we don't add definitions repeatedly. if (text.IndexOf(newText) == -1) { @@ -32,10 +68,16 @@ namespace ZwGen } } - string outputFile = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "\\FileTemplate.txt"); + string outputFile = File.ReadAllText( + System.AppDomain.CurrentDomain.BaseDirectory + "\\FileTemplate.txt", + System.Text.Encoding.UTF8); + outputFile = outputFile.Replace("{FILE_CONTENT}", text); - File.WriteAllText(currentFilePath, outputFile); + File.WriteAllText( + currentFilePath, + outputFile, + System.Text.Encoding.UTF8); } } }