• Stars
    star
    173
  • Rank 213,156 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Various tools and helpers to read assembly metadata.

MetadataTools

Included features:

  • BinaryCompatChecker - a tool that given a set of managed assemblies will detect binary incompatibilities, such as types missing from referenced assemblies, missing methods, etc.

  • RefDump - given an assembly prints a list of all types from all referenced assemblies used by the current assembly. Can also dump both typerefs and memberrefs to an Xml file. image

  • Pdb

    • extract .pdb information from a .dll/.exe debug directory (Pdb Guid, age, path to .pdb)
    • download the .pdb from symbol server
    • determine if a .dll matches a .pdb
    • find a matching .pdb in a folder for a given .dll
  • IsManagedAssembly.cs - a single .cs file to very quickly determine if a .dll or .exe represents a managed assembly.

  • ReadAssemblyVersion - quickly read an assembly's version

  • LargeAddressAware - sets the LargeAddressAware bit in a 32-bit executable to unlock 4GB memory space

  • MVID - Quickly read an assembly's MVID

Reading an assembly MVID

Mono.Cecil stripped down to a single file to read assembly MVID without dependencies.

Here are the various ways to retrieve the MVID of an assembly:

ImageReader

Just embed this file: https://github.com/KirillOsenkov/MetadataTools/blob/master/src/PEFile/ImageReader.cs

var mvid = ImageReader.ReadAssemblyMvid(filePath);

Cold run on a warm file: 7ms

Or see this sample from Roslyn: https://github.com/dotnet/roslyn/blob/1c98fe1fc6ef122cb3bb436aa90a0ea729fdcf37/src/Compilers/Core/MSBuildTask/MvidReader.cs#L13

Mono.Cecil

https://www.nuget.org/packages/Mono.Cecil

var module = Mono.Cecil.ModuleDefinition.ReadModule(filePath);
var mvid = module.Mvid;

Cold run on a warm file: 16ms

Reflection

This has the downside that it loads the assembly:

var assemblyName = AssemblyName.GetAssemblyName(filePath);
var assembly = Assembly.Load(assemblyName);
var mvid = assembly.ManifestModule.ModuleVersionId;

Cold run on a warm file: 33ms

System.Reflection.Metadata

https://www.nuget.org/packages/System.Reflection.Metadata

Sample in Roslyn: https://github.com/dotnet/roslyn/blob/1c98fe1fc6ef122cb3bb436aa90a0ea729fdcf37/src/Compilers/Core/Portable/AssemblyUtilities.cs#L84

using (var stream = File.OpenRead(filePath))
{
    PEReader reader = new PEReader(stream);
    var metadataReader = reader.GetMetadataReader();
    var mvidHandle = metadataReader.GetModuleDefinition().Mvid;
    var mvid = metadataReader.GetGuid(mvidHandle);
}

Cold run on a warm file: 76ms

BenchmarkDotNet paints quite a different performance picture:

               Method |        Mean |    StdDev |
--------------------- |------------ |---------- |
  ReadUsingReflection | 208.2023 us | 0.4036 us |
         ReadUsingSRM |  98.9620 us | 0.3674 us |
       ReadUsingCecil | 153.1947 us | 0.3085 us |
 ReadUsingImageReader | 147.0230 us | 1.2618 us |

More Repositories

1

MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
C#
1,393
star
2

SourceBrowser

Source browser website generator that powers http://referencesource.microsoft.com and http://sourceroslyn.io
C#
1,026
star
3

RoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree
C#
822
star
4

XmlParser

A Roslyn-inspired full-fidelity XML parser with no dependencies and a simple Visual Studio XML language service
C#
316
star
5

QuickInfo

http://quickinfo.io - a search textbox with extensible "answers" (calculator, unit-converter, colors, ascii/unicode, etc). See demo at http://quickinfo.io/?demo
C#
172
star
6

CodeCleanupTools

A set of command-line tools to cleanup C# and VB source code.
C#
121
star
7

Undo

Simple .NET Undo/Redo framework with merging and transactions
C#
102
star
8

ContentSync

Directory copy/sync/mirror tool that uses file contents (not timestamps) to avoid touching identical files
C#
61
star
9

LargeAddressAware

A build tools package that adds support for making 32-bit exes LARGEADDRESSAWARE
C#
51
star
10

StructuredEditor

An experimental structured code editor prototype for a subset of C#
C#
48
star
11

LayoutDesigner

A prototype Silverlight UI layout designer. Works with basic panels (StackPanel and Grid). Built entirely using drag-n-drop. XAML can be copied to clipboard. Built with Silverlight 4 and runs in the browser.
C#
47
star
12

LiveGeometry

Interactive geometry CAD-like educational software
Visual Basic 6.0
30
star
13

Bliki

Blog/Wiki/Notes
30
star
14

MathParser

Parser for arithmetic expressions
C#
21
star
15

MEFMetadata

Metadata-based part discovery for MEF, uses the Roslyn metadata reader and is faster than reflection.
C#
18
star
16

MSBuildLog

Source code for http://msbuildlog.com
HTML
16
star
17

NuGetTools

C#
15
star
18

dotfiles

My dotfiles and Mac config
Shell
13
star
19

Benchmarks

My collection of benchmarks for random pieces of code
C#
13
star
20

WpfSendKeys

SendKeys for WPF
C#
10
star
21

Misc

Various small and one-off projects just barely too big to throw away
C#
8
star
22

DumpTools

Tools to analyze managed .dmp files using ClrMd
C#
8
star
23

MEFTools

Tools to help working with MEF
C#
7
star
24

Dia2Dump

Taken from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\DIA SDK\Samples\DIA2Dump
C++
6
star
25

MyOwnSearchEngine

This repo has moved to https://github.com/KirillOsenkov/QuickInfo
JavaScript
3
star
26

DiagnosticMargin

C#
3
star
27

VSInstanceFinder

Finds the locations of all installed VS 2017 instances
C#
2
star
28

ColorTools

JavaScript
2
star
29

MagicSquare

Simple addition/multiplication table for kids
C#
2
star
30

ApplyPatch

Simple utility to apply a patch to a set of files
C#
1
star
31

MefHost

Test MEF host to repro a bug
C#
1
star
32

guilabs

Source code for http://guilabs.net
HTML
1
star
33

BeachballPoker

C#
1
star