Question

During the process of obfuscating a .NET assembly (using Dotfuscator), I have found myself tweaking how things are renamed. This often involves looking at the assembly in ILDASM and tracing a Type back to the source code file that it is defined in.

Usually this is a simple process. But I have found that locating an Anonymous Type is very difficult -- especially in a large assembly.

If I am trying to find the location of an anonymous type, such as the following line of code:

new { Name = 'Gene', Age = 30 }

Which is compiled as:

<>f__AnonymousType0`2'<'<Name>j__TPar','<Age>j__TPar'>`

And appears as the root of the assembly in the ILDASM tree.

If I want to locate the anonymous type in the source code, I am left without much help:

  • No Namespace
  • No symbols to search on
  • Nothing in the Solution Navigator
  • Nothing in the Class View
  • Nothing in the Object Browser

Am I missing something? Are there any tools to help locate an Anonymous Type in code files?

Était-ce utile?

La solution

Obviously the code for the anonymous class itself isn't present in the original source code, but there's source code which leads to the creation of the anonymous class, and I assume that's what you're trying to find. However, There may be multiple source files involved.

For example, in your example, there could be:

Class1.cs:
    var x = new { Name = "Jon", Age = 10 };

Class2.cs:
    var y = new { Name = 100, Age = 10m };

// And potentially many other source files

Both of those would use the same generic type, but with different type arguments. Basically you'd need to find every anonymous-object-creation-expression expression using the same property names in the same order. I wouldn't be surprised if the metadata contained nothing to help you here directly.

EDIT: The generated code will contain a reference to the constructor of the anonymous type, of course - so you could look for that. It's not clear what tools you're using, but searching for the name of the anonymous type within the IL would fine the uses.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top