From 0c0d68998ba401c53adab7ef1d6ace23bbad44b8 Mon Sep 17 00:00:00 2001 From: Steve Otteson Date: Fri, 12 Mar 2021 16:57:46 -0800 Subject: [PATCH 1/2] Adding guid/devpropkey scraping, fixing some bugs --- .../emitter/requiredNamespacesForNames.rsp | 2 + generation/scraper/enums.json | 1 + generation/scraper/manualEnums.json | 69 ++++++++++++ .../ClangSharpSourceWinmdGenerator.cs | 105 ++++++++++++++++-- .../ClangSharpSourceToWinmd/EncodeHelpers.cs | 23 ++++ .../MetadataSyntaxTreeCleaner.cs | 83 ++++++-------- sources/PartitionUtilsLib/ConstantWriter.cs | 46 +++++++- sources/PartitionUtilsLib/ConstantsScraper.cs | 83 ++++++++++---- sources/PartitionUtilsLib/EnumWriter.cs | 1 + .../GuidConstAttribute.cs | 8 -- .../PropertyKeyAttribute.cs | 11 ++ 11 files changed, 349 insertions(+), 83 deletions(-) delete mode 100644 sources/Win32MetadataInterop/GuidConstAttribute.cs create mode 100644 sources/Win32MetadataInterop/PropertyKeyAttribute.cs diff --git a/generation/emitter/requiredNamespacesForNames.rsp b/generation/emitter/requiredNamespacesForNames.rsp index 01ab2e809..d66bdf816 100644 --- a/generation/emitter/requiredNamespacesForNames.rsp +++ b/generation/emitter/requiredNamespacesForNames.rsp @@ -21269,6 +21269,8 @@ RasDialDlgA=Windows.Win32.RoutingAndRemoteAccessService RasDialDlgW=Windows.Win32.RoutingAndRemoteAccessService RasEntryDlgA=Windows.Win32.RoutingAndRemoteAccessService RasEntryDlgW=Windows.Win32.RoutingAndRemoteAccessService +RASENTRYA=Windows.Win32.RoutingAndRemoteAccessService +RASENTRYW=Windows.Win32.RoutingAndRemoteAccessService RasPhonebookDlgA=Windows.Win32.RoutingAndRemoteAccessService RasPhonebookDlgW=Windows.Win32.RoutingAndRemoteAccessService RasSecurityDialogBegin=Windows.Win32.RoutingAndRemoteAccessService diff --git a/generation/scraper/enums.json b/generation/scraper/enums.json index 9bf786e27..7f85a5495 100644 --- a/generation/scraper/enums.json +++ b/generation/scraper/enums.json @@ -31121,6 +31121,7 @@ { "name": "MPR_ET", "flags": false, + "type": "uint", "members": [ { "name": "MPR_ET_None" diff --git a/generation/scraper/manualEnums.json b/generation/scraper/manualEnums.json index 77685cdd5..8e9aa2776 100644 --- a/generation/scraper/manualEnums.json +++ b/generation/scraper/manualEnums.json @@ -1509,5 +1509,74 @@ "value": "( 1 << (int)CERT_QUERY_FORMAT_TYPE.CERT_QUERY_FORMAT_BINARY)" } ] + }, + { + "name": "Uri_CREATE_FLAGS", + "flags": true, + "autoPopulate": + { + "filter": "Uri_CREATE_", + "header": "urlmon.h" + }, + "uses": [ + { + "method": "CreateUri", + "parameter": "dwFlags" + } + ] + }, + { + "name": "MPR_INTERFACE_DIAL_MODE", + "flags": false, + "type": "uint", + "members": [ + { + "name": "MPRDM_DialFirst", + "value": "0" + }, + { + "name": "MPRDM_DialAll", + "value": "RASENTRY_DIAL_MODE.RASEDM_DialAll" + }, + { + "name": "MPRDM_DialAsNeeded", + "value": "RASENTRY_DIAL_MODE.RASEDM_DialAsNeeded" + } + ], + "uses": [ + { + "struct": "MPR_INTERFACE_3", + "field": "dwDialMode" + }, + { + "struct": "MPR_INTERFACE_2", + "field": "dwDialMode" + } + ] + }, + { + "name": "RASENTRY_DIAL_MODE", + "flags": false, + "type": "uint", + "members": [ + { + "name": "RASEDM_DialAll", + "value": "1" + }, + { + "name": "RASEDM_DialAsNeeded", + "value": "2" + } + ], + "uses": [ + { + "struct": "RASENTRYA", + "field": "dwDialMode" + }, + { + "struct": "RASENTRYW", + "field": "dwDialMode" + } + ] } ] diff --git a/sources/ClangSharpSourceToWinmd/ClangSharpSourceWinmdGenerator.cs b/sources/ClangSharpSourceToWinmd/ClangSharpSourceWinmdGenerator.cs index d78c5e502..1d63ce017 100644 --- a/sources/ClangSharpSourceToWinmd/ClangSharpSourceWinmdGenerator.cs +++ b/sources/ClangSharpSourceToWinmd/ClangSharpSourceWinmdGenerator.cs @@ -25,6 +25,7 @@ public class ClangSharpSourceWinmdGenerator public const string Win32StringType = "Windows.Win32.SystemServices.PSTR"; private const string InteropNamespace = "Windows.Win32.Interop"; + private const string ScannedSuffix = "__scanned__"; private static readonly Regex TypeImportRegex = new Regex(@"<(([^,]+),\s*Version=(\d+\.\d+\.\d+\.\d+),\s*Culture=([^,]+),\s*PublicKeyToken=([^>]+))>(\S+)"); @@ -52,6 +53,8 @@ public class ClangSharpSourceWinmdGenerator private Dictionary assemblyNamesToRefHandles = new Dictionary(); private Dictionary nameToSymbols = new Dictionary(); private Dictionary structNodesToInheritedSymbols = new Dictionary(); + private Dictionary nameToGuidConstFields = new Dictionary(); + private HashSet structNameWithGuids = new HashSet(); private ClangSharpSourceWinmdGenerator( CSharpCompilation compilation, @@ -195,14 +198,26 @@ private static byte[] ConvertKeyToByteArray(string key) return ret; } - private void AddDiagnostic(string text) + private static string GetQualifiedName(string @namespace, string name) { - Console.WriteLine(text); + return $"{@namespace}.{name}"; } - private static string GetQualifiedName(string @namespace, string name) + private static bool HasGuidAttribute(SyntaxList attributeLists) { - return $"{@namespace}.{name}"; + bool ret = attributeLists.Any(list => list.Attributes.Any(attr => attr.Name.ToString() == "Windows.Win32.Interop.Guid")); + return ret; + } + + private static bool HasPropertyKeyAttribute(SyntaxList attributeLists) + { + bool ret = attributeLists.Any(list => list.Attributes.Any(attr => attr.Name.ToString() == "PropertyKey")); + return ret; + } + + private void CacheGuidConst(FieldDeclarationSyntax guidFieldNode) + { + this.nameToGuidConstFields[guidFieldNode.Declaration.Variables.First().Identifier.ValueText] = guidFieldNode; } private void CacheInterfaceType(StructDeclarationSyntax interfaceNode) @@ -422,6 +437,28 @@ private void WriteInterfaceDef(StructDeclarationSyntax node) metadataBuilder.AddInterfaceImplementation(destTypeDefHandle, inheritsFromTypeDef); } + // If this interface node doesn't have a Guid attribute, see if we can + // match it to a Guid constant + if (!HasGuidAttribute(node.AttributeLists)) + { + string iidGuidConstName = $"IID_{name}"; + if (!this.nameToGuidConstFields.TryGetValue(iidGuidConstName, out var fieldDeclNode)) + { + iidGuidConstName += ScannedSuffix; + this.nameToGuidConstFields.TryGetValue(iidGuidConstName, out fieldDeclNode); + } + + if (fieldDeclNode != null) + { + ISymbol fieldSymbol = this.compilation.GetSymbolsWithName(iidGuidConstName).FirstOrDefault(); + + if (fieldSymbol != null) + { + this.AddCustomAttributes(fieldSymbol, destTypeDefHandle); + } + } + } + this.AddCustomAttributes(node, destTypeDefHandle); } @@ -798,22 +835,52 @@ private FieldDefinitionHandle WriteClassFields(ClassDeclarationSyntax node) var model = this.GetModel(node); var classSymbol = model.GetDeclaredSymbol(node); FieldDefinitionHandle firstField = default; - foreach (FieldDeclarationSyntax field in node.Members.Where(m => m is FieldDeclarationSyntax)) { var fieldVariable = field.Declaration.Variables.First(); IFieldSymbol fieldSymbol = (IFieldSymbol)model.GetDeclaredSymbol(fieldVariable); + string name = fieldSymbol.Name; + + FieldAttributes fieldAttributes; if (!fieldSymbol.IsConst) { - continue; + fieldAttributes = FieldAttributes.Public | FieldAttributes.Static; + + if (!HasGuidAttribute(field.AttributeLists) && !HasPropertyKeyAttribute(field.AttributeLists)) + { + continue; + } + + if (fieldSymbol.Name.StartsWith("IID_")) + { + continue; + } + + if (name.EndsWith(ScannedSuffix)) + { + name = name.Substring(0, name.Length - ScannedSuffix.Length); + } + + if (name.StartsWith("CLSID_")) + { + string testClassName = name.Substring("CLSID_".Length); + if (this.structNameWithGuids.Contains(testClassName)) + { + continue; + } + } + } + else + { + fieldAttributes = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault; } - var fieldSignature = this.EncodeFieldSignature(className, model, field, out string name); + var fieldSignature = this.EncodeFieldSignature(className, model, field, out _); var fieldDefinitionHandle = metadataBuilder.AddFieldDefinition( - FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault, + fieldAttributes, metadataBuilder.GetOrAddString(name), metadataBuilder.GetOrAddBlob(fieldSignature)); if (fieldSymbol.HasConstantValue) @@ -1378,12 +1445,17 @@ private void AddCustomAttributes(IEnumerable attrs, EntityHandle } } + private void AddCustomAttributes(ISymbol symbol, EntityHandle entityHandle) + { + this.AddCustomAttributes(symbol.GetAttributes(), entityHandle); + } + private void AddCustomAttributes(SyntaxNode node, EntityHandle entityHandle) { var model = this.GetModel(node); var symbol = model.GetDeclaredSymbol(node); - this.AddCustomAttributes(symbol.GetAttributes(), entityHandle); + this.AddCustomAttributes(symbol, entityHandle); } private ISymbol GetInheritedInterfaceSymbol(StructDeclarationSyntax node) @@ -1728,10 +1800,25 @@ public InterfaceWalker(ClangSharpSourceWinmdGenerator parent) public override void VisitStructDeclaration(StructDeclarationSyntax node) { + base.VisitStructDeclaration(node); + if (this.parent.IsInterfaceDef(node)) { this.parent.CacheInterfaceType(node); } + + if (HasGuidAttribute(node.AttributeLists)) + { + this.parent.structNameWithGuids.Add(node.Identifier.ValueText); + } + } + + public override void VisitFieldDeclaration(FieldDeclarationSyntax node) + { + if (node.Modifiers.ToString() == "public static readonly" && node.Declaration.Type.ToString() == "Guid") + { + this.parent.CacheGuidConst(node); + } } } diff --git a/sources/ClangSharpSourceToWinmd/EncodeHelpers.cs b/sources/ClangSharpSourceToWinmd/EncodeHelpers.cs index 81989db6e..52a8463b2 100644 --- a/sources/ClangSharpSourceToWinmd/EncodeHelpers.cs +++ b/sources/ClangSharpSourceToWinmd/EncodeHelpers.cs @@ -78,6 +78,11 @@ public static uint ParseHex(string text) text = text.Substring(2); } + if (char.ToUpperInvariant(text[text.Length - 1]) == 'L') + { + text = text.Substring(0, text.Length - 1); + } + return uint.Parse(text, System.Globalization.NumberStyles.HexNumber); } @@ -280,5 +285,23 @@ public static void FixedArguments(this FixedArgumentsEncoder argumentsEncoder, I argumentsEncoder.AddArgument().TypedConstant(argument); } } + + public static AttributeListSyntax ConvertGuidToAttributeList(Guid guid) + { + // Outputs in format: {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} + string formattedGuid = guid.ToString("x"); + + // Get rid of leading { and trailing }} + formattedGuid = formattedGuid.Substring(1, formattedGuid.Length - 3); + // There's one more { we need to get rid of + formattedGuid = formattedGuid.Replace("{", string.Empty); + string args = $"({formattedGuid})"; + return + SyntaxFactory.AttributeList( + SyntaxFactory.SingletonSeparatedList( + SyntaxFactory.Attribute( + SyntaxFactory.ParseName("Windows.Win32.Interop.Guid"), + SyntaxFactory.ParseAttributeArgumentList(args)))); + } } } diff --git a/sources/ClangSharpSourceToWinmd/MetadataSyntaxTreeCleaner.cs b/sources/ClangSharpSourceToWinmd/MetadataSyntaxTreeCleaner.cs index 5d8fb98cd..3a0893214 100644 --- a/sources/ClangSharpSourceToWinmd/MetadataSyntaxTreeCleaner.cs +++ b/sources/ClangSharpSourceToWinmd/MetadataSyntaxTreeCleaner.cs @@ -39,7 +39,7 @@ public override SyntaxNode VisitParameter(ParameterSyntax node) { string fullName = GetFullName(node); - if (this.GetRemapInfo(fullName, out List listAttributes, out string newType, out string newName)) + if (this.GetRemapInfo(fullName, out List listAttributes, node.Type.ToString(), out string newType, out string newName)) { node = (ParameterSyntax)base.VisitParameter(node); if (listAttributes != null) @@ -92,7 +92,7 @@ public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node) { string fullName = GetFullName(node); - this.GetRemapInfo(fullName, out var listAttributes, out string newType, out string newName); + this.GetRemapInfo(fullName, out var listAttributes, node.Declaration.Type.ToString(), out string newType, out string newName); // ClangSharp mistakenly emits string[] for WCHAR[] Foo = "Bar". // Change it to string @@ -106,15 +106,9 @@ public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node) // aren't allowed in metadata, requiring us to surface them this way if (node.Modifiers.ToString() == "public static readonly" && node.Declaration.Type.ToString() == "Guid") { - // We're ignoring all the IID_ constants, assuming projections can get them from the interfaces - // directly - if (fullName.StartsWith("IID_")) - { - return null; - } - - string guidVal = null; - if (node.Declaration.Variables.First().Initializer.Value is ObjectCreationExpressionSyntax objCreationSyntax) + Guid guidVal = Guid.Empty; + var varInitializer = node.Declaration.Variables.First().Initializer; + if (varInitializer.Value is ObjectCreationExpressionSyntax objCreationSyntax) { var args = objCreationSyntax.ArgumentList.Arguments; if (args.Count == 11) @@ -131,34 +125,27 @@ public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node) byte p9 = (byte)EncodeHelpers.ParseHex(args[9].ToString()); byte p10 = (byte)EncodeHelpers.ParseHex(args[10].ToString()); - guidVal = new Guid(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10).ToString(); + guidVal = new Guid(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } else if (objCreationSyntax.ArgumentList.Arguments.Count == 1) { - guidVal = EncodeHelpers.RemoveQuotes(objCreationSyntax.ArgumentList.Arguments[0].ToString()); + // If this is an invalid format, remove the node + if (!Guid.TryParse(objCreationSyntax.ArgumentList.Arguments[0].ToString(), out guidVal)) + { + return null; + } } } - if (guidVal == null) + if (guidVal == Guid.Empty) { return node; } - var variableDeclaration = - SyntaxFactory.VariableDeclaration(SyntaxFactory.ParseTypeName("string") - .WithTrailingTrivia(SyntaxFactory.Space)) - .AddVariables( - SyntaxFactory.VariableDeclarator(fullName) - .WithInitializer(SyntaxFactory.EqualsValueClause(SyntaxFactory.ParseExpression($"\"{guidVal}\"")))); - var attrListSyntax = SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Attribute(SyntaxFactory.ParseName("Windows.Win32.Interop.GuidConst"))); - var fieldDeclaration = - SyntaxFactory.FieldDeclaration(variableDeclaration) - .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword).WithTrailingTrivia(SyntaxFactory.Space), SyntaxFactory.Token(SyntaxKind.ConstKeyword).WithTrailingTrivia(SyntaxFactory.Space)) - .AddAttributeLists(SyntaxFactory.AttributeList(attrListSyntax)) - .WithLeadingTrivia(SyntaxFactory.CarriageReturnLineFeed) - .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed); + node = node.RemoveNode(varInitializer, SyntaxRemoveOptions.KeepExteriorTrivia | SyntaxRemoveOptions.KeepEndOfLine); + node = node.AddAttributeLists(EncodeHelpers.ConvertGuidToAttributeList(guidVal).WithLeadingTrivia(node.GetLeadingTrivia())); - return fieldDeclaration; + return node; } node = (FieldDeclarationSyntax)base.VisitFieldDeclaration(node); @@ -249,7 +236,7 @@ public override SyntaxNode VisitDelegateDeclaration(DelegateDeclarationSyntax no string returnFullName = $"{fullName}::return"; - if (this.GetRemapInfo(returnFullName, out List listAttributes, out var newType, out _)) + if (this.GetRemapInfo(returnFullName, out List listAttributes, null, out var newType, out _)) { node = (DelegateDeclarationSyntax)base.VisitDelegateDeclaration(node); if (listAttributes != null) @@ -320,7 +307,7 @@ public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node) string returnFullName = $"{fullName}::return"; // Find remap info for the return parameter for this method and apply any that we find - if (this.GetRemapInfo(returnFullName, out List listAttributes, out var newType, out _)) + if (this.GetRemapInfo(returnFullName, out List listAttributes, null, out var newType, out _)) { node = (MethodDeclarationSyntax)base.VisitMethodDeclaration(node); if (listAttributes != null) @@ -549,20 +536,7 @@ private SyntaxNode ProcessGuidAttr(AttributeSyntax guidAttr) Guid guid = Guid.Parse(guidStr); - // Outputs in format: {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} - string formattedGuid = guid.ToString("x"); - - // Get rid of leading { and trailing }} - formattedGuid = formattedGuid.Substring(1, formattedGuid.Length - 3); - // There's one more { we need to get rid of - formattedGuid = formattedGuid.Replace("{", string.Empty); - string args = $"({formattedGuid})"; - return - SyntaxFactory.AttributeList( - SyntaxFactory.SingletonSeparatedList( - SyntaxFactory.Attribute( - SyntaxFactory.ParseName("Windows.Win32.Interop.Guid"), - SyntaxFactory.ParseAttributeArgumentList(args)))); + return EncodeHelpers.ConvertGuidToAttributeList(guid); } private SyntaxNode ProcessNativeTypeNameAttr(AttributeSyntax nativeTypeNameAttr) @@ -857,11 +831,28 @@ IEnumerable GetSalAttributes(string salArgsText) } } - private bool GetRemapInfo(string fullName, out List listAttributes, out string newType, out string newName) + private bool GetRemapInfo(string fullName, out List listAttributes, string currentType, out string newType, out string newName) { if (!string.IsNullOrEmpty(fullName) && this.remaps.TryGetValue(fullName, out string remapData)) { - return EncodeHelpers.DecodeRemap(remapData, out listAttributes, out newType, out newName); + var ret = EncodeHelpers.DecodeRemap(remapData, out listAttributes, out newType, out newName); + if (currentType != null) + { + // Try to keep the pointers at the same level if we're replacing + // a uint or int. The mismatch can happen in the auto-generated + // enum remaps which don't know if the params/fields getting replaced + // are pointers or not + if (currentType.StartsWith("uint") || currentType.StartsWith("int")) + { + int starIndex = currentType.IndexOf('*'); + if (starIndex != -1 && newType.IndexOf('*') == -1) + { + newType += currentType.Substring(starIndex); + } + } + } + + return ret; } listAttributes = null; diff --git a/sources/PartitionUtilsLib/ConstantWriter.cs b/sources/PartitionUtilsLib/ConstantWriter.cs index 58dd19d1d..f08c462c5 100644 --- a/sources/PartitionUtilsLib/ConstantWriter.cs +++ b/sources/PartitionUtilsLib/ConstantWriter.cs @@ -33,6 +33,37 @@ private StreamWriter Writer } } + public void AddPropKey(string name, string args) + { + if (this.namesToValues.ContainsKey(name)) + { + return; + } + + this.namesToValues[name] = args; + + this.Writer.WriteLine( +$@" [PropertyKey({args})] + public static readonly PROPERTYKEY {name};"); + + this.Writer.WriteLine(); + } + + public void AddGuid(string name, string args) + { + if (this.namesToValues.ContainsKey(name)) + { + return; + } + + this.namesToValues[name] = args; + + this.Writer.WriteLine( +$@" public static readonly Guid {name}__scanned__ = new Guid({args});"); + + this.Writer.WriteLine(); + } + public void AddValue(string type, string name, string valueText) { this.namesToValues[name] = valueText; @@ -45,6 +76,17 @@ public void AddValue(string type, string name, string valueText) public static string FixIntValueText(bool forceUnsigned, ref string type, string valueText) { + if (valueText.Length > 0 && char.IsLetter(valueText[0])) + { + // This means our value is probably using an enum or some other expresssion, + // to don't mess with the valueText + + // Set the type to something + type = "uint"; + + return valueText; + } + bool signed = false; bool is64Bit = false; @@ -141,7 +183,9 @@ private void EnsureStarted() { this.writer = new StreamWriter(this.path); this.writer.WriteLine( -@$"using Windows.Win32.Interop; +@$"using System; +using Windows.Win32.Interop; +using Windows.Win32.WindowsPropertiesSystem; // For PROPERTYKEY namespace {this.@namespace} {{ diff --git a/sources/PartitionUtilsLib/ConstantsScraper.cs b/sources/PartitionUtilsLib/ConstantsScraper.cs index d04067bec..8d2f13645 100644 --- a/sources/PartitionUtilsLib/ConstantsScraper.cs +++ b/sources/PartitionUtilsLib/ConstantsScraper.cs @@ -26,12 +26,16 @@ private class ConstantsScraperImpl : IDisposable { private static readonly Regex DefineRegex = new Regex( - @"^#define\s+([A-Z][\dA-Z_]+)\s+(.+)"); + @"^#define\s+([A-Z][\dA-Za-z_]+)\s+(.+)"); private static readonly Regex DefineConstantRegex = new Regex( @"^((_HRESULT_TYPEDEF_|_NDIS_ERROR_TYPEDEF_)\(((?:0x)?[\da-f]+L?)\)|(\(HRESULT\)((?:0x)?[\da-f]+L?))|(-?\d+\.\d+(?:e\+\d+)?f?)|((?:0x[\da-f]+|\-?\d+)(?:UL|L)?)|((\d+)\s*(<<\s*\d+))|(MAKEINTRESOURCE\(\s*(\-?\d+)\s*\))|(\(HWND\)(-?\d+)))$", RegexOptions.IgnoreCase); + private static readonly Regex DefineGuidConstRegex = + new Regex( + @"^\s*(DEFINE_GUID|DEFINE_DEVPROPKEY|DEFINE_KNOWN_FOLDER)\s*\((.*)"); + private Dictionary namespacesToEnumWriters = new Dictionary(); private Dictionary namespacesToConstantWriters = new Dictionary(); private WildcardDictionary requiredNamespaces; @@ -228,6 +232,31 @@ private void AddConstantValue(string originalNamespace, string type, string name this.writtenConstants[name] = valueText; } + + private void AddConstantGuid(string defineGuidKeyword, string originalNamespace, string line) + { + int firstComma = line.IndexOf(','); + string name = line.Substring(0, firstComma).Trim(); + if (this.writtenConstants.ContainsKey(name)) + { + return; + } + + string args = line.Substring(firstComma + 1).Trim(); + int closeParen = args.IndexOf(')'); + args = args.Substring(0, closeParen); + + var writer = this.GetConstantWriter(originalNamespace, name); + + if (defineGuidKeyword == "DEFINE_DEVPROPKEY") + { + writer.AddPropKey(name, args); + } + else + { + writer.AddGuid(name, args); + } + } private void AddConstantInteger(string originalNamespace, string nativeTypeName, string name, string valueText) { @@ -351,6 +380,8 @@ private void ScrapeConstantsFromTraversedFiles( } string continuation = null; + bool processingGuidMultiLine = false; + string defineGuidKeyword = null; foreach (string currentLine in File.ReadAllLines(header)) { string line = continuation == null ? currentLine : continuation + currentLine; @@ -360,8 +391,40 @@ private void ScrapeConstantsFromTraversedFiles( continue; } + if (processingGuidMultiLine) + { + continuation = StripComments(line).Trim(); + if (continuation.EndsWith(';')) + { + processingGuidMultiLine = false; + this.AddConstantGuid(defineGuidKeyword, currentNamespace, continuation); + continuation = null; + } + + continue; + } + continuation = null; + var defineGuidMatch = DefineGuidConstRegex.Match(line); + if (defineGuidMatch.Success) + { + defineGuidKeyword = defineGuidMatch.Groups[1].Value; + line = defineGuidMatch.Groups[2].Value; + line = StripComments(line).Trim(); + if (line.EndsWith(';')) + { + this.AddConstantGuid(defineGuidKeyword, currentNamespace, line); + } + else + { + continuation = line; + processingGuidMultiLine = true; + } + + continue; + } + var defineMatch = DefineRegex.Match(line); // Skip if not #define ... @@ -372,11 +435,6 @@ private void ScrapeConstantsFromTraversedFiles( string name = defineMatch.Groups[1].Value; - if (name == "REG_DWORD_BIG_ENDIAN") - { - - } - // If it's in the exclusion list see if we should ignore it based on the // current partition if (exclusionNamesToPartitions.TryGetValue(name, out var partitions)) @@ -549,10 +607,6 @@ private void ScrapeConstantsFromTraversedFiles( { this.AddConstantInteger(currentNamespace, nativeTypeName, name, valueText); } - else - { - - } } } } @@ -574,11 +628,6 @@ private void WriteEnumsAndRemaps( // For each enum object... foreach (var obj in enumObjectsFromJsons) { - if (obj.name.StartsWith("CREDUIWIN")) - { - - } - // Skip if no members if (obj.members.Count == 0) { @@ -683,10 +732,6 @@ private void WriteEnumsAndRemaps( addedEnum = enumWriter.AddEnum(obj); } } - else - { - - } if (addedEnum || existsAsManualEnum || obj != objectForRemap) { diff --git a/sources/PartitionUtilsLib/EnumWriter.cs b/sources/PartitionUtilsLib/EnumWriter.cs index 682a639b3..c86b019d4 100644 --- a/sources/PartitionUtilsLib/EnumWriter.cs +++ b/sources/PartitionUtilsLib/EnumWriter.cs @@ -79,6 +79,7 @@ private void EnsureStarted() this.writer.WriteLine( @$"using System; using Windows.Win32.Interop; +using Windows.Win32.SystemServices; using static {this.@namespace}.Apis; namespace {this.@namespace} diff --git a/sources/Win32MetadataInterop/GuidConstAttribute.cs b/sources/Win32MetadataInterop/GuidConstAttribute.cs deleted file mode 100644 index 81e08596a..000000000 --- a/sources/Win32MetadataInterop/GuidConstAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace Windows.Win32.Interop -{ - public class GuidConstAttribute : Attribute - { - } -} diff --git a/sources/Win32MetadataInterop/PropertyKeyAttribute.cs b/sources/Win32MetadataInterop/PropertyKeyAttribute.cs new file mode 100644 index 000000000..1b9d0d2a1 --- /dev/null +++ b/sources/Win32MetadataInterop/PropertyKeyAttribute.cs @@ -0,0 +1,11 @@ +using System; + +namespace Windows.Win32.Interop +{ + public class PropertyKeyAttribute : Attribute + { + public PropertyKeyAttribute(uint a, ushort b, ushort c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k, uint pid) + { + } + } +} From bfba2d959873aa4b5bdb7915a0f789e1e5aeb2a1 Mon Sep 17 00:00:00 2001 From: Steve Otteson Date: Fri, 12 Mar 2021 17:09:56 -0800 Subject: [PATCH 2/2] Fix namespace for named pipe APIs --- generation/emitter/requiredNamespacesForNames.rsp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/generation/emitter/requiredNamespacesForNames.rsp b/generation/emitter/requiredNamespacesForNames.rsp index d66bdf816..40635a577 100644 --- a/generation/emitter/requiredNamespacesForNames.rsp +++ b/generation/emitter/requiredNamespacesForNames.rsp @@ -13957,8 +13957,10 @@ SORTIDFROMLCID=Windows.Win32.Intl SORTVERSIONFROMLCID=Windows.Win32.Intl SUBLANGID=Windows.Win32.Intl TEXT=Windows.Win32.Intl -CreateNamedPipeA=Windows.Win32.Ipc -WaitNamedPipeA=Windows.Win32.Ipc +CreateNamedPipeA=Windows.Win32.SystemServices +CreateNamedPipeW=Windows.Win32.SystemServices +WaitNamedPipeA=Windows.Win32.SystemServices +WaitNamedPipeW=Windows.Win32.SystemServices Icmp6CreateFile=Windows.Win32.IpHelper Icmp6ParseReplies=Windows.Win32.IpHelper Icmp6SendEcho2=Windows.Win32.IpHelper