DynaMD 1.0.9.1

Helper objects to browse complex structures returned by ClrMD

Install-Package DynaMD -Version 1.0.9.1
dotnet add package DynaMD --version 1.0.9.1
<PackageReference Include="DynaMD" Version="1.0.9.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DynaMD --version 1.0.9.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DynaMD, 1.0.9.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install DynaMD as a Cake Addin
#addin nuget:?package=DynaMD&version=1.0.9.1

// Install DynaMD as a Cake Tool
#tool nuget:?package=DynaMD&version=1.0.9.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

DynaMD

About

Helper objects to browse complex structures returned by ClrMD. This is useful to quickly write scripts to analyze memory dumps.

The library leverages the dynamic keyword to give direct access to memory structures.

How to use

Given an address and a ClrMD ClrHeap instance, you can get a dynamic proxy by calling GetProxy:

var proxy = heap.GetProxy(0x00001000);

Or all the instances of a given type:

// Using generics:
var proxies1 = heap.GetProxies<string>();

// Or writing the type name (useful if you don't reference it):
var proxies2 = heap.GetProxies("System.String");

From there, you can access any field like you would with a "real" object:

Console.WriteLine(proxy.Value);
Console.WriteLine((string)proxy.Child.Name);
Console.WriteLine(proxy.Description.Size.Width * proxy.Description.Size.Height);

Only fields are supported, but automatic properties are translated:

class SomeType
{
    private int _backingField;
    public int Field1 => _backingField;
    public int Field2 { get; }
}

var proxy = heap.GetProxies<SomeType>().First();

var value1 = proxy._backingField; // Calling proxy.Field1 is not supported
var value2 = proxy.Field2; // Automatically translated to <Field2>k__BackingField

Primitive types are automatically converted:

class SomeType
{
    public int IntValue;
    public double DoubleValue;
}

var proxy = heap.GetProxies<SomeType>().First();

Console.WriteLine(proxy.IntValue.GetType()); // System.Int32
Console.WriteLine(proxy.DoubleValue.GetType()); // System.Double

Non-primitive proxies can be cast to string or blittable structs:

struct BlittableStruct
{
    public int Value;
}

class SomeType
{
    public BlittableStruct StructValue;
    public DateTime DateTimeValue;
    public string StringValue;
}

var proxy = heap.GetProxies<SomeType>().First();

BlittableStruct structValue = (BlittableStruct)proxy.StructValue;
DateTime dateTimeValue = (DateTime)proxy.DateTimeValue;
string stringValue = (string)proxy.stringValue;

You can also enumerate the contents of arrays, get the length, or use an indexer:


class SomeType
{
    public int[] ArrayValue;
}

var proxy = heap.GetProxies<SomeType>().First();

Console.WriteLine("Length: " + proxy.ArrayValue.Length);
Console.WriteLine("First element: " + proxy.ArrayValue[0]);

foreach (var value in proxy.ArrayValue)
{
    Console.WriteLine(value);
}

To retrieve the address of a proxified object, explicitely cast it to ulong. Also, calling .ToString() on a proxy will return the address encoded in hexadecimal:

var proxy = heap.GetProxy(0x1000);
var address = (ulong)proxy;
Console.WriteLine("{0:x2}", address); // 0x1000
Console.WriteLine(proxy); // 0x1000

To retrieve the instance of ClrType, call GetClrType():

ClrType type = proxy.GetClrType();

Check the unit tests for more examples.

DynaMD

About

Helper objects to browse complex structures returned by ClrMD. This is useful to quickly write scripts to analyze memory dumps.

The library leverages the dynamic keyword to give direct access to memory structures.

How to use

Given an address and a ClrMD ClrHeap instance, you can get a dynamic proxy by calling GetProxy:

var proxy = heap.GetProxy(0x00001000);

Or all the instances of a given type:

// Using generics:
var proxies1 = heap.GetProxies<string>();

// Or writing the type name (useful if you don't reference it):
var proxies2 = heap.GetProxies("System.String");

From there, you can access any field like you would with a "real" object:

Console.WriteLine(proxy.Value);
Console.WriteLine((string)proxy.Child.Name);
Console.WriteLine(proxy.Description.Size.Width * proxy.Description.Size.Height);

Only fields are supported, but automatic properties are translated:

class SomeType
{
    private int _backingField;
    public int Field1 => _backingField;
    public int Field2 { get; }
}

var proxy = heap.GetProxies<SomeType>().First();

var value1 = proxy._backingField; // Calling proxy.Field1 is not supported
var value2 = proxy.Field2; // Automatically translated to <Field2>k__BackingField

Primitive types are automatically converted:

class SomeType
{
    public int IntValue;
    public double DoubleValue;
}

var proxy = heap.GetProxies<SomeType>().First();

Console.WriteLine(proxy.IntValue.GetType()); // System.Int32
Console.WriteLine(proxy.DoubleValue.GetType()); // System.Double

Non-primitive proxies can be cast to string or blittable structs:

struct BlittableStruct
{
    public int Value;
}

class SomeType
{
    public BlittableStruct StructValue;
    public DateTime DateTimeValue;
    public string StringValue;
}

var proxy = heap.GetProxies<SomeType>().First();

BlittableStruct structValue = (BlittableStruct)proxy.StructValue;
DateTime dateTimeValue = (DateTime)proxy.DateTimeValue;
string stringValue = (string)proxy.stringValue;

You can also enumerate the contents of arrays, get the length, or use an indexer:


class SomeType
{
    public int[] ArrayValue;
}

var proxy = heap.GetProxies<SomeType>().First();

Console.WriteLine("Length: " + proxy.ArrayValue.Length);
Console.WriteLine("First element: " + proxy.ArrayValue[0]);

foreach (var value in proxy.ArrayValue)
{
    Console.WriteLine(value);
}

To retrieve the address of a proxified object, explicitely cast it to ulong. Also, calling .ToString() on a proxy will return the address encoded in hexadecimal:

var proxy = heap.GetProxy(0x1000);
var address = (ulong)proxy;
Console.WriteLine("{0:x2}", address); // 0x1000
Console.WriteLine(proxy); // 0x1000

To retrieve the instance of ClrType, call GetClrType():

ClrType type = proxy.GetClrType();

Check the unit tests for more examples.

Release Notes

Added Readme.md

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on DynaMD:

Repository Stars
chrisnas/DebuggingExtensions
Host of debugging-related extensions such as post-mortem tools or WinDBG extensions

Version History

Version Downloads Last updated
1.0.9.1 122 6/5/2021
1.0.9 117 6/5/2021
1.0.8 97 3/25/2021
1.0.7.3 490 7/8/2019
1.0.7.2 384 2/24/2019
1.0.7.1 529 12/3/2018
1.0.7 448 12/3/2018
1.0.6.2 713 7/15/2018
1.0.6.1 622 7/5/2018
1.0.5.2 606 7/1/2018
1.0.4.1 1,122 4/13/2018
1.0.4 639 4/11/2018
1.0.3.1 618 3/25/2018
1.0.2-pre 713 3/30/2017
1.0.1-pre 609 3/24/2017
1.0.0-pre 630 3/23/2017