Update generator.

This commit is contained in:
MouriNaruto
2023-03-01 14:22:52 +08:00
parent 30eb06d151
commit bcc24ddba0
+48 -6
View File
@@ -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);
}
}
}