From 92400e0f1a55162ba60a79cdce7b4b798543ffe5 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 1 Mar 2012 00:13:04 +0100 Subject: [PATCH] Add support for 'windowsruntime' IL keyword. --- .../Disassembler/ReflectionDisassembler.cs | 11 +++++++++-- ILSpy/Languages/Language.cs | 2 +- ILSpy/LoadedAssembly.cs | 2 +- ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs | 2 +- Mono.Cecil/Mono.Cecil/AssemblyFlags.cs | 1 + Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs | 5 +++++ Mono.Cecil/Mono.Cecil/TypeAttributes.cs | 1 + Mono.Cecil/Mono.Cecil/TypeDefinition.cs | 5 +++++ 8 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs index 413234e77..675d9e28a 100644 --- a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs @@ -809,6 +809,7 @@ namespace ICSharpCode.Decompiler.Disassembler { TypeAttributes.SpecialName, "specialname" }, { TypeAttributes.Import, "import" }, { TypeAttributes.Serializable, "serializable" }, + { TypeAttributes.WindowsRuntime, "windowsruntime" }, { TypeAttributes.BeforeFieldInit, "beforefieldinit" }, { TypeAttributes.HasSecurity, null }, }; @@ -1075,7 +1076,10 @@ namespace ICSharpCode.Decompiler.Disassembler public void WriteAssemblyHeader(AssemblyDefinition asm) { - output.Write(".assembly " + DisassemblerHelpers.Escape(asm.Name.Name)); + output.Write(".assembly "); + if (asm.Name.IsWindowsRuntime) + output.Write("windowsruntime "); + output.Write(DisassemblerHelpers.Escape(asm.Name.Name)); OpenBlock(false); WriteAttributes(asm.CustomAttributes); WriteSecurityDeclarations(asm); @@ -1103,7 +1107,10 @@ namespace ICSharpCode.Decompiler.Disassembler output.WriteLine(".module extern {0}", DisassemblerHelpers.Escape(mref.Name)); } foreach (var aref in module.AssemblyReferences) { - output.Write(".assembly extern {0}", DisassemblerHelpers.Escape(aref.Name)); + output.Write(".assembly extern "); + if (aref.IsWindowsRuntime) + output.Write("windowsruntime "); + output.Write(DisassemblerHelpers.Escape(aref.Name)); OpenBlock(false); if (aref.PublicKeyToken != null) { output.Write(".publickeytoken = "); diff --git a/ILSpy/Languages/Language.cs b/ILSpy/Languages/Language.cs index 45cfa8c6d..901ca8af5 100644 --- a/ILSpy/Languages/Language.cs +++ b/ILSpy/Languages/Language.cs @@ -89,7 +89,7 @@ namespace ICSharpCode.ILSpy { WriteCommentLine(output, assembly.FileName); var name = assembly.AssemblyDefinition.Name; - if ((name.Attributes & (AssemblyAttributes)0x0200) != 0) { + if (name.IsWindowsRuntime) { WriteCommentLine(output, name.Name + " [WinRT]"); } else { WriteCommentLine(output, name.FullName); diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index ffdc1270e..30a98ded0 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -181,7 +181,7 @@ namespace ICSharpCode.ILSpy { if (name == null) throw new ArgumentNullException("name"); - if ((name.Attributes & (AssemblyAttributes)0x0200) != 0) { + if (name.IsWindowsRuntime) { return assemblyList.winRTMetadataLookupCache.GetOrAdd(name.Name, LookupWinRTMetadata); } else { return assemblyList.assemblyLookupCache.GetOrAdd(name.FullName, LookupReferencedAssemblyInternal); diff --git a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs index f84a47323..c9596d47a 100644 --- a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs @@ -83,7 +83,7 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - if ((r.Attributes & (AssemblyAttributes)0x0200) != 0) { + if (r.IsWindowsRuntime) { language.WriteCommentLine(output, r.Name + " [WinRT]"); } else { language.WriteCommentLine(output, r.FullName); diff --git a/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs b/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs index e466e7844..72a0eb06c 100644 --- a/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs +++ b/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs @@ -35,6 +35,7 @@ namespace Mono.Cecil { PublicKey = 0x0001, SideBySideCompatible = 0x0000, Retargetable = 0x0100, + WindowsRuntime = 0x0200, DisableJITCompileOptimizer = 0x4000, EnableJITCompileTracking = 0x8000, } diff --git a/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs b/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs index 9697634f1..063bc5b62 100644 --- a/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs +++ b/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs @@ -92,6 +92,11 @@ namespace Mono.Cecil { set { attributes = attributes.SetAttributes ((uint) AssemblyAttributes.Retargetable, value); } } + public bool IsWindowsRuntime { + get { return attributes.GetAttributes ((uint) AssemblyAttributes.WindowsRuntime); } + set { attributes = attributes.SetAttributes ((uint) AssemblyAttributes.WindowsRuntime, value); } + } + public byte [] PublicKey { get { return public_key; } set { diff --git a/Mono.Cecil/Mono.Cecil/TypeAttributes.cs b/Mono.Cecil/Mono.Cecil/TypeAttributes.cs index bc4e18f33..86fbc4dba 100644 --- a/Mono.Cecil/Mono.Cecil/TypeAttributes.cs +++ b/Mono.Cecil/Mono.Cecil/TypeAttributes.cs @@ -62,6 +62,7 @@ namespace Mono.Cecil { // Implementation attributes Import = 0x00001000, // Class/Interface is imported Serializable = 0x00002000, // Class is serializable + WindowsRuntime = 0x00004000, // Windows Runtime type // String formatting attributes StringFormatMask = 0x00030000, // Use this mask to retrieve string information for native interop diff --git a/Mono.Cecil/Mono.Cecil/TypeDefinition.cs b/Mono.Cecil/Mono.Cecil/TypeDefinition.cs index 1cfda2ee2..e19c7d8f4 100644 --- a/Mono.Cecil/Mono.Cecil/TypeDefinition.cs +++ b/Mono.Cecil/Mono.Cecil/TypeDefinition.cs @@ -389,6 +389,11 @@ namespace Mono.Cecil { set { attributes = attributes.SetAttributes ((uint) TypeAttributes.Serializable, value); } } + public bool IsWindowsRuntime { + get { return attributes.GetAttributes ((uint) TypeAttributes.WindowsRuntime); } + set { attributes = attributes.SetAttributes ((uint) TypeAttributes.WindowsRuntime, value); } + } + public bool IsAnsiClass { get { return attributes.GetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass); } set { attributes = attributes.SetMaskedAttributes ((uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass, value); }