2 using System.Collections.Generic;
6 using System.Text.RegularExpressions;
21 return string.Equals(x.
Name, y.
Name);
26 return obj.
Name.GetHashCode();
32 private string _baseDirectory;
33 private string[] _files;
34 private string _outputFile;
35 private string _header =
"";
36 private string _footer =
"";
38 private List<ServiceDefinition> _defs;
40 private string UnEscape(
string text)
42 return text.Replace(
"\\r",
"\r").Replace(
"\\n",
"\n").Replace(
"\\\\",
"\\");
47 string[] lines = File.ReadAllLines(fileName);
49 foreach (
string line
in lines)
51 string[] split = line.Split(
new char[] {
'=' }, 2);
56 _baseDirectory = split[1];
59 _files = split[1].Split(
';');
62 _outputFile = split[1];
65 _header = UnEscape(split[1]);
68 _footer = UnEscape(split[1]);
74 private void Parse(
string text)
76 Regex regex =
new Regex(
@"NTSYSCALLAPI[\w\s_]*NTAPI\s*(Nt(\w)*)\(.*?\);", RegexOptions.Compiled | RegexOptions.Singleline);
77 MatchCollection matches;
79 matches = regex.Matches(text);
81 foreach (Match match
in matches)
83 _defs.Add(
new ServiceDefinition() { Name = match.Groups[1].Value, Text = match.Value, NameIndex = match.Groups[1].Index - match.Index });
91 _defs =
new List<ServiceDefinition>();
93 foreach (
string fileName
in _files)
94 Parse(File.ReadAllText(_baseDirectory +
"\\" + fileName));
96 StreamWriter sw =
new StreamWriter(_baseDirectory +
"\\" + _outputFile);
100 _defs.Sort((x, y) =>
string.CompareOrdinal(x.Name, y.Name));
108 foreach (var d
in _defs)
110 Console.WriteLine(
"System service: " + d.Name);
113 sw.Write(d.Text.Substring(0, d.NameIndex) +
"Zw" + d.Text.Substring(d.NameIndex + 2) +
"\r\n\r\n");