Browse Source

Add missing tables.

pull/1716/head
Siegfried Pammer 6 years ago
parent
commit
aa4ed6439e
  1. 16
      ILSpy/ILSpy.csproj
  2. 10
      ILSpy/Metadata/CorTables/ClassLayoutTableTreeNode.cs
  3. 4
      ILSpy/Metadata/CorTables/EventMapTableTreeNode.cs
  4. 66
      ILSpy/Metadata/CorTables/FieldLayoutTableTreeNode.cs
  5. 130
      ILSpy/Metadata/CorTables/FieldMarshalTableTreeNode.cs
  6. 130
      ILSpy/Metadata/CorTables/FieldRVATableTreeNode.cs
  7. 154
      ILSpy/Metadata/CorTables/ImplMapTableTreeNode.cs
  8. 4
      ILSpy/Metadata/CorTables/InterfaceImplTableTreeNode.cs
  9. 2
      ILSpy/Metadata/CorTables/MethodImplTableTreeNode.cs
  10. 140
      ILSpy/Metadata/CorTables/NestedClassTableTreeNode.cs
  11. 4
      ILSpy/Metadata/CorTables/PropertyMapTableTreeNode.cs
  12. 1
      ILSpy/Metadata/DataDirectoriesTreeNode.cs
  13. 3
      ILSpy/Metadata/FlagsFilterControl.xaml.cs
  14. 26
      ILSpy/Metadata/Helpers.cs
  15. 5
      ILSpy/Metadata/MetadataTableViews.xaml
  16. 5
      ILSpy/Metadata/MetadataTreeNode.cs

16
ILSpy/ILSpy.csproj

@ -135,6 +135,22 @@ @@ -135,6 +135,22 @@
<Compile Include="Controls\SearchBox.cs" />
<Compile Include="Controls\SortableGridViewColumn.cs" />
<Compile Include="Controls\XamlResourceExtension.cs" />
<Compile Include="Metadata\CorTables\FieldRVATableTreeNode.cs">
<SubType>Code</SubType>
<Generator>MSBuild:Compile</Generator>
</Compile>
<Compile Include="Metadata\CorTables\FieldMarshalTableTreeNode.cs">
<SubType>Code</SubType>
<Generator>MSBuild:Compile</Generator>
</Compile>
<Compile Include="Metadata\CorTables\NestedClassTableTreeNode.cs">
<SubType>Code</SubType>
<Generator>MSBuild:Compile</Generator>
</Compile>
<Compile Include="Metadata\CorTables\ImplMapTableTreeNode.cs">
<SubType>Code</SubType>
<Generator>MSBuild:Compile</Generator>
</Compile>
<Compile Include="Metadata\CorTables\PropertyMapTableTreeNode.cs">
<SubType>Code</SubType>
<Generator>MSBuild:Compile</Generator>

10
ILSpy/Metadata/CorTables/ClassLayoutTableTreeNode.cs

@ -76,11 +76,11 @@ namespace ICSharpCode.ILSpy.Metadata @@ -76,11 +76,11 @@ namespace ICSharpCode.ILSpy.Metadata
public readonly EntityHandle Parent;
public readonly uint ClassSize;
public unsafe ClassLayout(byte *ptr, bool small)
public unsafe ClassLayout(byte *ptr, int typeDefSize)
{
PackingSize = (ushort)(ptr[0] | (ptr[1] << 8));
ClassSize = (uint)(ptr[2] | (ptr[3] << 8) | (ptr[4] << 16) | (ptr[5] << 24));
Parent = MetadataTokens.TypeDefinitionHandle(small ? (int)(ptr[6] | (ptr[7] << 8)) : (int)(ptr[6] | (ptr[7] << 8) | (ptr[8] << 16) | (ptr[9] << 24)));
PackingSize = (ushort)Helpers.GetValue(ptr, 2);
ClassSize = (uint)Helpers.GetValue(ptr + 2, 4);
Parent = MetadataTokens.TypeDefinitionHandle(Helpers.GetValue(ptr + 6, typeDefSize));
}
}
@ -122,7 +122,7 @@ namespace ICSharpCode.ILSpy.Metadata @@ -122,7 +122,7 @@ namespace ICSharpCode.ILSpy.Metadata
var rowOffset = metadata.GetTableMetadataOffset(TableIndex.ClassLayout)
+ metadata.GetTableRowSize(TableIndex.ClassLayout) * (row - 1);
this.Offset = metadataOffset + rowOffset;
this.classLayout = new ClassLayout(ptr + rowOffset, metadata.GetTableRowCount(TableIndex.TypeDef) <= ushort.MaxValue);
this.classLayout = new ClassLayout(ptr + rowOffset, metadata.GetTableRowCount(TableIndex.TypeDef) < ushort.MaxValue ? 2 : 4);
}
}

4
ILSpy/Metadata/CorTables/EventMapTableTreeNode.cs

@ -77,8 +77,8 @@ namespace ICSharpCode.ILSpy.Metadata @@ -77,8 +77,8 @@ namespace ICSharpCode.ILSpy.Metadata
public unsafe EventMap(byte *ptr, int typeDefSize, int eventDefSize)
{
Parent = MetadataTokens.TypeDefinitionHandle(Helpers.GetRowNum(ptr, typeDefSize));
EventList = MetadataTokens.EventDefinitionHandle(Helpers.GetRowNum(ptr + typeDefSize, eventDefSize));
Parent = MetadataTokens.TypeDefinitionHandle(Helpers.GetValue(ptr, typeDefSize));
EventList = MetadataTokens.EventDefinitionHandle(Helpers.GetValue(ptr + typeDefSize, eventDefSize));
}
}

66
ILSpy/Metadata/CorTables/FieldLayoutTableTreeNode.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy.Metadata @@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy.Metadata
public override object Icon => Images.Literal;
public override bool View(ViewModels.TabPageModel tabPage)
public unsafe override bool View(ViewModels.TabPageModel tabPage)
{
tabPage.Title = Text.ToString();
tabPage.SupportsLanguageSwitching = false;
@ -57,10 +57,11 @@ namespace ICSharpCode.ILSpy.Metadata @@ -57,10 +57,11 @@ namespace ICSharpCode.ILSpy.Metadata
var list = new List<FieldLayoutEntry>();
foreach (var row in metadata.GetFieldLayouts()) {
FieldDefinition d = default;
d.GetOffset();
list.Add(new FieldLayoutEntry(module, row));
var length = metadata.GetTableRowCount(TableIndex.FieldLayout);
byte* ptr = metadata.MetadataPointer;
int metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
for (int rid = 1; rid <= length; rid++) {
list.Add(new FieldLayoutEntry(module, ptr, metadataOffset, rid));
}
view.ItemsSource = list;
@ -69,48 +70,55 @@ namespace ICSharpCode.ILSpy.Metadata @@ -69,48 +70,55 @@ namespace ICSharpCode.ILSpy.Metadata
return true;
}
struct FieldLayoutEntry
readonly struct FieldLayout
{
readonly int metadataOffset;
readonly PEFile module;
readonly MetadataReader metadata;
readonly EntityHandle handle;
//readonly fieldDef;
public int RID => MetadataTokens.GetRowNumber(handle);
public readonly int Offset;
public readonly FieldDefinitionHandle Field;
public int Token => MetadataTokens.GetToken(handle);
public int Offset => metadataOffset
+ metadata.GetTableMetadataOffset(TableIndex.FieldLayout)
+ metadata.GetTableRowSize(TableIndex.FieldLayout) * (RID - 1);
public unsafe FieldLayout(byte* ptr, int fieldDefSize)
{
Offset = Helpers.GetValue(ptr, 4);
Field = MetadataTokens.FieldDefinitionHandle(Helpers.GetValue(ptr + 4, fieldDefSize));
}
}
//public int Attributes => (int)fieldDef.Attributes;
unsafe struct FieldLayoutEntry
{
readonly PEFile module;
readonly MetadataReader metadata;
readonly FieldLayout fieldLayout;
//public object AttributesTooltip => new FlagsTooltip((int)eventDef.Attributes, typeof(EventAttributes));
public int RID { get; }
//public int NameStringHandle => MetadataTokens.GetHeapOffset(fieldDef.Name);
public int Token => 0x10000000 | RID;
//public string Name => metadata.GetString(fieldDef.Name);
public int Offset { get; }
//public int Signature => MetadataTokens.GetHeapOffset(fieldDef.Signature);
[StringFormat("X8")]
public int Field => MetadataTokens.GetToken(fieldLayout.Field);
public string SignatureTooltip {
public string FieldTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new Decompiler.Metadata.GenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)handle).WriteTo(module, output, context);
((EntityHandle)fieldLayout.Field).WriteTo(module, output, context);
return output.ToString();
}
}
public FieldLayoutEntry(PEFile module, EntityHandle handle)
[StringFormat("X8")]
public int FieldOffset => fieldLayout.Offset;
public FieldLayoutEntry(PEFile module, byte* ptr, int metadataOffset, int row)
{
this.metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
this.module = module;
this.metadata = module.Metadata;
this.handle = handle;
//this.fieldDef = metadata.GetFieldLayoutinition(handle);
this.RID = row;
var rowOffset = metadata.GetTableMetadataOffset(TableIndex.FieldLayout)
+ metadata.GetTableRowSize(TableIndex.FieldLayout) * (row - 1);
this.Offset = metadataOffset + rowOffset;
int fieldDefSize = metadata.GetTableRowCount(TableIndex.Field) < ushort.MaxValue ? 2 : 4;
this.fieldLayout = new FieldLayout(ptr + rowOffset, fieldDefSize);
}
}

130
ILSpy/Metadata/CorTables/FieldMarshalTableTreeNode.cs

@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy.Metadata
{
internal class FieldMarshalTableTreeNode : ILSpyTreeNode
{
private PEFile module;
public FieldMarshalTableTreeNode(PEFile module)
{
this.module = module;
}
public override object Text => $"0D FieldMarshal ({module.Metadata.GetTableRowCount(TableIndex.FieldMarshal)})";
public override object Icon => Images.Literal;
public unsafe override bool View(ViewModels.TabPageModel tabPage)
{
tabPage.Title = Text.ToString();
tabPage.SupportsLanguageSwitching = false;
var view = Helpers.PrepareDataGrid(tabPage);
var metadata = module.Metadata;
var list = new List<FieldMarshalEntry>();
var length = metadata.GetTableRowCount(TableIndex.FieldMarshal);
byte* ptr = metadata.MetadataPointer;
int metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
for (int rid = 1; rid <= length; rid++) {
list.Add(new FieldMarshalEntry(module, ptr, metadataOffset, rid));
}
view.ItemsSource = list;
tabPage.Content = view;
return true;
}
readonly struct FieldMarshal
{
public readonly BlobHandle NativeType;
public readonly EntityHandle Parent;
public unsafe FieldMarshal(byte* ptr, int hasFieldMarshalRefSize)
{
NativeType = MetadataTokens.BlobHandle(Helpers.GetValue(ptr, 4));
Parent = Helpers.FromHasFieldMarshalTag((uint)Helpers.GetValue(ptr + 4, hasFieldMarshalRefSize));
}
}
unsafe struct FieldMarshalEntry
{
readonly PEFile module;
readonly MetadataReader metadata;
readonly FieldMarshal fieldMarshal;
public int RID { get; }
public int Token => 0x0D000000 | RID;
public int Offset { get; }
[StringFormat("X8")]
public int Parent => MetadataTokens.GetToken(fieldMarshal.Parent);
public string ParentTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new Decompiler.Metadata.GenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)fieldMarshal.Parent).WriteTo(module, output, context);
return output.ToString();
}
}
[StringFormat("X8")]
public int NativeType => (int)MetadataTokens.GetHeapOffset(fieldMarshal.NativeType);
public FieldMarshalEntry(PEFile module, byte* ptr, int metadataOffset, int row)
{
this.module = module;
this.metadata = module.Metadata;
this.RID = row;
var rowOffset = metadata.GetTableMetadataOffset(TableIndex.FieldMarshal)
+ metadata.GetTableRowSize(TableIndex.FieldMarshal) * (row - 1);
this.Offset = metadataOffset + rowOffset;
int hasFieldMarshalRefSize = metadata.ComputeCodedTokenSize(32768, TableMask.Field | TableMask.Param);
this.fieldMarshal = new FieldMarshal(ptr + rowOffset, hasFieldMarshalRefSize);
}
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, "FieldMarshals");
}
}
}

130
ILSpy/Metadata/CorTables/FieldRVATableTreeNode.cs

@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy.Metadata
{
internal class FieldRVATableTreeNode : ILSpyTreeNode
{
private PEFile module;
public FieldRVATableTreeNode(PEFile module)
{
this.module = module;
}
public override object Text => $"1D FieldRVA ({module.Metadata.GetTableRowCount(TableIndex.FieldRva)})";
public override object Icon => Images.Literal;
public unsafe override bool View(ViewModels.TabPageModel tabPage)
{
tabPage.Title = Text.ToString();
tabPage.SupportsLanguageSwitching = false;
var view = Helpers.PrepareDataGrid(tabPage);
var metadata = module.Metadata;
var list = new List<FieldRVAEntry>();
var length = metadata.GetTableRowCount(TableIndex.FieldRva);
byte* ptr = metadata.MetadataPointer;
int metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
for (int rid = 1; rid <= length; rid++) {
list.Add(new FieldRVAEntry(module, ptr, metadataOffset, rid));
}
view.ItemsSource = list;
tabPage.Content = view;
return true;
}
readonly struct FieldRVA
{
public readonly int Offset;
public readonly FieldDefinitionHandle Field;
public unsafe FieldRVA(byte* ptr, int fieldDefSize)
{
Offset = Helpers.GetValue(ptr, 4);
Field = MetadataTokens.FieldDefinitionHandle(Helpers.GetValue(ptr + 4, fieldDefSize));
}
}
unsafe struct FieldRVAEntry
{
readonly PEFile module;
readonly MetadataReader metadata;
readonly FieldRVA fieldLayout;
public int RID { get; }
public int Token => 0x1D000000 | RID;
public int Offset { get; }
[StringFormat("X8")]
public int Field => MetadataTokens.GetToken(fieldLayout.Field);
public string FieldTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new Decompiler.Metadata.GenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)fieldLayout.Field).WriteTo(module, output, context);
return output.ToString();
}
}
[StringFormat("X8")]
public int FieldOffset => fieldLayout.Offset;
public FieldRVAEntry(PEFile module, byte* ptr, int metadataOffset, int row)
{
this.module = module;
this.metadata = module.Metadata;
this.RID = row;
var rowOffset = metadata.GetTableMetadataOffset(TableIndex.FieldRva)
+ metadata.GetTableRowSize(TableIndex.FieldRva) * (row - 1);
this.Offset = metadataOffset + rowOffset;
int fieldDefSize = metadata.GetTableRowCount(TableIndex.Field) < ushort.MaxValue ? 2 : 4;
this.fieldLayout = new FieldRVA(ptr + rowOffset, fieldDefSize);
}
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, "FieldRVAs");
}
}
}

154
ILSpy/Metadata/CorTables/ImplMapTableTreeNode.cs

@ -0,0 +1,154 @@ @@ -0,0 +1,154 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Metadata
{
class ImplMapTableTreeNode : ILSpyTreeNode
{
private PEFile module;
public ImplMapTableTreeNode(PEFile module)
{
this.module = module;
}
public override object Text => $"1C ImplMap ({module.Metadata.GetTableRowCount(TableIndex.ImplMap)})";
public override object Icon => Images.Literal;
public unsafe override bool View(ViewModels.TabPageModel tabPage)
{
tabPage.Title = Text.ToString();
tabPage.SupportsLanguageSwitching = false;
var view = Helpers.PrepareDataGrid(tabPage);
var metadata = module.Metadata;
var list = new List<ImplMapEntry>();
var length = metadata.GetTableRowCount(TableIndex.ImplMap);
byte* ptr = metadata.MetadataPointer;
int metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
for (int rid = 1; rid <= length; rid++) {
list.Add(new ImplMapEntry(module, ptr, metadataOffset, rid));
}
view.ItemsSource = list;
tabPage.Content = view;
return true;
}
readonly struct ImplMap
{
public readonly PInvokeAttributes MappingFlags;
public readonly EntityHandle MemberForwarded;
public readonly StringHandle ImportName;
public readonly ModuleReferenceHandle ImportScope;
public unsafe ImplMap(byte *ptr, int moduleRefSize, int memberForwardedTagRefSize, int stringHandleSize)
{
MappingFlags = (PInvokeAttributes)Helpers.GetValue(ptr, 2);
MemberForwarded = Helpers.FromMemberForwardedTag((uint)Helpers.GetValue(ptr + 2, memberForwardedTagRefSize));
ImportName = MetadataTokens.StringHandle(Helpers.GetValue(ptr + 2 + memberForwardedTagRefSize, stringHandleSize));
ImportScope = MetadataTokens.ModuleReferenceHandle(Helpers.GetValue(ptr + 2 + memberForwardedTagRefSize + stringHandleSize, moduleRefSize));
}
}
unsafe struct ImplMapEntry
{
readonly PEFile module;
readonly MetadataReader metadata;
readonly ImplMap implMap;
public int RID { get; }
public int Token => 0x1C000000 | RID;
public int Offset { get; }
public PInvokeAttributes MappingFlags => implMap.MappingFlags;
public object MappingFlagsTooltip => new FlagsTooltip((int)implMap.MappingFlags, typeof(PInvokeAttributes));
[StringFormat("X8")]
public int MemberForwarded => MetadataTokens.GetToken(implMap.MemberForwarded);
public string MemberForwardedTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new GenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)implMap.MemberForwarded).WriteTo(module, output, context);
return output.ToString();
}
}
[StringFormat("X8")]
public object ImportScope => MetadataTokens.GetToken(implMap.ImportScope);
public string ImportScopeTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new GenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)implMap.ImportScope).WriteTo(module, output, context);
return output.ToString();
}
}
public string ImportName => metadata.GetString(implMap.ImportName);
public string ImportNameTooltip => $"{MetadataTokens.GetHeapOffset(implMap.ImportName):X} \"{ImportName}\"";
public unsafe ImplMapEntry(PEFile module, byte* ptr, int metadataOffset, int row)
{
this.module = module;
this.metadata = module.Metadata;
this.RID = row;
var rowOffset = metadata.GetTableMetadataOffset(TableIndex.ImplMap)
+ metadata.GetTableRowSize(TableIndex.ImplMap) * (row - 1);
this.Offset = metadataOffset + rowOffset;
int moduleRefSize = metadata.GetTableRowCount(TableIndex.ModuleRef) < ushort.MaxValue ? 2 : 4;
int memberForwardedTagRefSize = metadata.ComputeCodedTokenSize(32768, TableMask.MethodDef | TableMask.Field);
int stringHandleSize = metadata.GetHeapSize(HeapIndex.String) < ushort.MaxValue ? 2 : 4;
this.implMap = new ImplMap(ptr + rowOffset, moduleRefSize, memberForwardedTagRefSize, stringHandleSize);
}
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, "ImplMap");
}
}
}

4
ILSpy/Metadata/CorTables/InterfaceImplTableTreeNode.cs

@ -77,8 +77,8 @@ namespace ICSharpCode.ILSpy.Metadata @@ -77,8 +77,8 @@ namespace ICSharpCode.ILSpy.Metadata
public unsafe InterfaceImpl(byte *ptr, int classSize, int interfaceSize)
{
Class = MetadataTokens.TypeDefinitionHandle(Helpers.GetRowNum(ptr, classSize));
Interface = Helpers.FromTypeDefOrRefTag((uint)Helpers.GetRowNum(ptr + classSize, interfaceSize));
Class = MetadataTokens.TypeDefinitionHandle(Helpers.GetValue(ptr, classSize));
Interface = Helpers.FromTypeDefOrRefTag((uint)Helpers.GetValue(ptr + classSize, interfaceSize));
}
}

2
ILSpy/Metadata/CorTables/MethodImplTableTreeNode.cs

@ -126,7 +126,7 @@ namespace ICSharpCode.ILSpy.Metadata @@ -126,7 +126,7 @@ namespace ICSharpCode.ILSpy.Metadata
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, "MethodDefs");
language.WriteCommentLine(output, "MethodImpls");
}
}
}

140
ILSpy/Metadata/CorTables/NestedClassTableTreeNode.cs

@ -0,0 +1,140 @@ @@ -0,0 +1,140 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Metadata
{
class NestedClassTableTreeNode : ILSpyTreeNode
{
private PEFile module;
public NestedClassTableTreeNode(PEFile module)
{
this.module = module;
}
public override object Text => $"29 NestedClass ({module.Metadata.GetTableRowCount(TableIndex.NestedClass)})";
public override object Icon => Images.Literal;
public unsafe override bool View(ViewModels.TabPageModel tabPage)
{
tabPage.Title = Text.ToString();
tabPage.SupportsLanguageSwitching = false;
var view = Helpers.PrepareDataGrid(tabPage);
var metadata = module.Metadata;
var list = new List<NestedClassEntry>();
var length = metadata.GetTableRowCount(TableIndex.NestedClass);
byte* ptr = metadata.MetadataPointer;
int metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
for (int rid = 1; rid <= length; rid++) {
list.Add(new NestedClassEntry(module, ptr, metadataOffset, rid));
}
view.ItemsSource = list;
tabPage.Content = view;
return true;
}
readonly struct NestedClass
{
public readonly TypeDefinitionHandle Nested;
public readonly TypeDefinitionHandle Enclosing;
public unsafe NestedClass(byte *ptr, int typeDefSize)
{
Nested = MetadataTokens.TypeDefinitionHandle(Helpers.GetValue(ptr, typeDefSize));
Enclosing = MetadataTokens.TypeDefinitionHandle(Helpers.GetValue(ptr + typeDefSize, typeDefSize));
}
}
unsafe struct NestedClassEntry
{
readonly PEFile module;
readonly MetadataReader metadata;
readonly NestedClass nestedClass;
public int RID { get; }
public int Token => 0x29000000 | RID;
public int Offset { get; }
[StringFormat("X8")]
public int NestedClass => MetadataTokens.GetToken(nestedClass.Nested);
public string NestedClassTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new Decompiler.Metadata.GenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)nestedClass.Nested).WriteTo(module, output, context);
return output.ToString();
}
}
[StringFormat("X8")]
public int EnclosingClass => MetadataTokens.GetToken(nestedClass.Enclosing);
public string EnclosingClassTooltip {
get {
ITextOutput output = new PlainTextOutput();
var context = new Decompiler.Metadata.GenericContext(default(TypeDefinitionHandle), module);
((EntityHandle)nestedClass.Enclosing).WriteTo(module, output, context);
return output.ToString();
}
}
public unsafe NestedClassEntry(PEFile module, byte* ptr, int metadataOffset, int row)
{
this.module = module;
this.metadata = module.Metadata;
this.RID = row;
var rowOffset = metadata.GetTableMetadataOffset(TableIndex.NestedClass)
+ metadata.GetTableRowSize(TableIndex.NestedClass) * (row - 1);
this.Offset = metadataOffset + rowOffset;
int typeDefSize = metadata.GetTableRowCount(TableIndex.TypeDef) < ushort.MaxValue ? 2 : 4;
this.nestedClass = new NestedClass(ptr + rowOffset, typeDefSize);
}
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, "NestedClass");
}
}
}

4
ILSpy/Metadata/CorTables/PropertyMapTableTreeNode.cs

@ -77,8 +77,8 @@ namespace ICSharpCode.ILSpy.Metadata @@ -77,8 +77,8 @@ namespace ICSharpCode.ILSpy.Metadata
public unsafe PropertyMap(byte *ptr, int typeDefSize, int propertyDefSize)
{
Parent = MetadataTokens.TypeDefinitionHandle(Helpers.GetRowNum(ptr, typeDefSize));
PropertyList = MetadataTokens.PropertyDefinitionHandle(Helpers.GetRowNum(ptr + typeDefSize, propertyDefSize));
Parent = MetadataTokens.TypeDefinitionHandle(Helpers.GetValue(ptr, typeDefSize));
PropertyList = MetadataTokens.PropertyDefinitionHandle(Helpers.GetValue(ptr + typeDefSize, propertyDefSize));
}
}

1
ILSpy/Metadata/DataDirectoriesTreeNode.cs

@ -51,7 +51,6 @@ namespace ICSharpCode.ILSpy.Metadata @@ -51,7 +51,6 @@ namespace ICSharpCode.ILSpy.Metadata
//dataGrid.Columns.Add(new DataGridTextColumn { IsReadOnly = true, Header = "Size", Binding = new Binding("Size") { StringFormat = "X8" } });
//dataGrid.Columns.Add(new DataGridTextColumn { IsReadOnly = true, Header = "Section", Binding = new Binding("Section") });
var headers = module.Reader.PEHeaders;
var reader = module.Reader.GetEntireImage().GetReader(headers.PEHeaderStartOffset, 128);
var header = headers.PEHeader;
var entries = new DataDirectoryEntry[] {

3
ILSpy/Metadata/FlagsFilterControl.xaml.cs

@ -5,6 +5,7 @@ using System.Reflection; @@ -5,6 +5,7 @@ using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using DataGridExtensions;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.ILSpy.Metadata
{
@ -57,7 +58,7 @@ namespace ICSharpCode.ILSpy.Metadata @@ -57,7 +58,7 @@ namespace ICSharpCode.ILSpy.Metadata
foreach (var item in flagsType.GetFields(BindingFlags.Static | BindingFlags.Public)) {
if (item.Name.EndsWith("Mask", StringComparison.Ordinal))
continue;
int value = (int)item.GetRawConstantValue();
int value = (int)CSharpPrimitiveCast.Cast(TypeCode.Int32, item.GetRawConstantValue(), false);
yield return new Flag($"{item.Name} ({value:X4})", value);
}
}

26
ILSpy/Metadata/Helpers.cs

@ -32,6 +32,7 @@ using System.Windows.Controls; @@ -32,6 +32,7 @@ using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using DataGridExtensions;
using ICSharpCode.Decompiler.Util;
using ICSharpCode.ILSpy.Controls;
using ICSharpCode.ILSpy.ViewModels;
@ -101,6 +102,7 @@ namespace ICSharpCode.ILSpy.Metadata @@ -101,6 +102,7 @@ namespace ICSharpCode.ILSpy.Metadata
case "Flags":
case "Attributes":
case "ImplAttributes":
case "MappingFlags":
binding.Converter = new UnderlyingEnumValueConverter();
binding.StringFormat = "X4";
e.Column.SetTemplate((ControlTemplate)MetadataTableViews.Instance[e.PropertyType.Name + "Filter"]);
@ -129,7 +131,7 @@ namespace ICSharpCode.ILSpy.Metadata @@ -129,7 +131,7 @@ namespace ICSharpCode.ILSpy.Metadata
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int GetRowNum(byte* ptr, int size)
public static unsafe int GetValue(byte* ptr, int size)
{
int result = 0;
for (int i = 0; i < size; i += 2) {
@ -148,11 +150,29 @@ namespace ICSharpCode.ILSpy.Metadata @@ -148,11 +150,29 @@ namespace ICSharpCode.ILSpy.Metadata
fromTypeDefOrRefTag = typeof(TypeDefinitionHandle).Assembly
.GetType("System.Reflection.Metadata.Ecma335.TypeDefOrRefTag")
.GetMethod("ConvertToHandle", BindingFlags.Static | BindingFlags.NonPublic);
fromHasFieldMarshalTag = typeof(TypeDefinitionHandle).Assembly
.GetType("System.Reflection.Metadata.Ecma335.HasFieldMarshalTag")
.GetMethod("ConvertToHandle", BindingFlags.Static | BindingFlags.NonPublic);
fromMemberForwardedTag = typeof(TypeDefinitionHandle).Assembly
.GetType("System.Reflection.Metadata.Ecma335.MemberForwardedTag")
.GetMethod("ConvertToHandle", BindingFlags.Static | BindingFlags.NonPublic);
}
readonly static FieldInfo rowCounts;
readonly static MethodInfo computeCodedTokenSize;
readonly static MethodInfo fromTypeDefOrRefTag;
readonly static MethodInfo fromHasFieldMarshalTag;
readonly static MethodInfo fromMemberForwardedTag;
public static EntityHandle FromHasFieldMarshalTag(uint tag)
{
return (EntityHandle)fromHasFieldMarshalTag.Invoke(null, new object[] { tag });
}
public static EntityHandle FromMemberForwardedTag(uint tag)
{
return (EntityHandle)fromMemberForwardedTag.Invoke(null, new object[] { tag });
}
public static EntityHandle FromTypeDefOrRefTag(uint tag)
{
@ -170,9 +190,7 @@ namespace ICSharpCode.ILSpy.Metadata @@ -170,9 +190,7 @@ namespace ICSharpCode.ILSpy.Metadata
{
var t = value.GetType();
if (t.IsEnum) {
var u = t.GetEnumUnderlyingType();
if (u == typeof(int))
return (int)value;
return (int)CSharpPrimitiveCast.Cast(TypeCode.Int32, value, false);
}
return value;
}

5
ILSpy/Metadata/MetadataTableViews.xaml

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
xmlns:local="clr-namespace:ICSharpCode.ILSpy.Metadata"
xmlns:reflection="clr-namespace:System.Reflection;assembly=mscorlib"
xmlns:cecil="clr-namespace:Mono.Cecil;assembly=Mono.Cecil"
xmlns:srm="clr-namespace:System.Reflection;assembly=System.Reflection.Metadata"
xmlns:dgx="urn:tom-englert.de/DataGridExtensions">
@ -79,6 +80,10 @@ @@ -79,6 +80,10 @@
<local:FlagsFilterControl FlagsType="{x:Type reflection:GenericParameterAttributes}" Filter="{Binding Path=Filter, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=dgx:DataGridFilterColumnControl}}" />
</ControlTemplate>
<ControlTemplate x:Key="PInvokeAttributesFilter">
<local:FlagsFilterControl FlagsType="{x:Type cecil:PInvokeAttributes}" Filter="{Binding Path=Filter, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=dgx:DataGridFilterColumnControl}}" />
</ControlTemplate>
<Style x:Key="ItemContainerStyle" TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>

5
ILSpy/Metadata/MetadataTreeNode.cs

@ -77,8 +77,10 @@ namespace ICSharpCode.ILSpy.Metadata @@ -77,8 +77,10 @@ namespace ICSharpCode.ILSpy.Metadata
this.Children.Add(new MemberRefTableTreeNode(module));
this.Children.Add(new ConstantTableTreeNode(module));
this.Children.Add(new CustomAttributeTableTreeNode(module));
this.Children.Add(new FieldMarshalTableTreeNode(module));
this.Children.Add(new DeclSecurityTableTreeNode(module));
this.Children.Add(new ClassLayoutTableTreeNode(module));
this.Children.Add(new FieldLayoutTableTreeNode(module));
this.Children.Add(new StandAloneSigTableTreeNode(module));
this.Children.Add(new EventMapTableTreeNode(module));
this.Children.Add(new EventTableTreeNode(module));
@ -88,11 +90,14 @@ namespace ICSharpCode.ILSpy.Metadata @@ -88,11 +90,14 @@ namespace ICSharpCode.ILSpy.Metadata
this.Children.Add(new MethodImplTableTreeNode(module));
this.Children.Add(new ModuleRefTableTreeNode(module));
this.Children.Add(new TypeSpecTableTreeNode(module));
this.Children.Add(new ImplMapTableTreeNode(module)); ;
this.Children.Add(new FieldRVATableTreeNode(module));
this.Children.Add(new AssemblyTableTreeNode(module));
this.Children.Add(new AssemblyRefTableTreeNode(module));
this.Children.Add(new FileTableTreeNode(module));
this.Children.Add(new ExportedTypeTableTreeNode(module));
this.Children.Add(new ManifestResourceTableTreeNode(module));
this.Children.Add(new NestedClassTableTreeNode(module));
this.Children.Add(new GenericParamTableTreeNode(module));
this.Children.Add(new MethodSpecTableTreeNode(module));
this.Children.Add(new GenericParamConstraintTableTreeNode(module));

Loading…
Cancel
Save