Can I see the contents of the String Table in a running process?

256 Views Asked by At

Is there any way I can see the contents of the string table in a running .NET application?

I want to compare a console application with vanilla string concatinations and one using the string builder.

1

There are 1 best solutions below

0
Jonathan Dickinson On

You can use ClrMD to attach to a process and retrieve information from it. Something along the lines of the following should work:

var proc = Process.GetProcessesByName("myapp.exe").FirstOrDefault();
using (var target = DataTarget.AttachToProcess(proc.Id, 1000))
{
    var runtime = target.ClrVersions[0].CreateRuntime();
    var heap = runtime.GetHeap();
    foreach (var obj in heap.EnumerateObjectAddresses())
    {
        var type = heap.GetObjectType(obj);
        if (type.Name == "System.String")
        {
            var value = (string)type.GetValue(obj);
            // Write value to disk or something.
        }
    }
}