views:

91

answers:

4

I don't know much about the CIL, except that there is metadata in assemblies that record the type information.
Would it be possible to create some reflecting tool that is able to read a C# or VB.NET assembly and change its metadata so that all class members become public?
Would it be straightforward (e.g. change one or two bytes for each method in CIL)?

A: 

Yes. See this article:

http://msdn.microsoft.com/en-us/magazine/cc188743.aspx

bbudge
+3  A: 

Yes, it is possible, but it is not always safe. There is code out there in the wild that uses the Reflection API to find types, methods, fields, etc. If the code explicitly looks for non-public ones, making them public will break the code. Similarly, if the code looks for the public ones and expects that the non-public ones are not included, once again making those public will break the code.

The best tool to do this that I know of is Mono.Cecil, which is an open-source library that can read, manipulate, and write .NET assemblies.

Timwi
Microsoft is also (slowly) developing the [Common Compiler Infrastructure](http://ccimetadata.codeplex.com/), which is very similar to `Mono.Cecil`.
Stephen Cleary
A: 

If the assembly has a strong name, then you won't be able to substitute your modified assembly for the original.

Kristopher Johnson
A: 

Proof by example: When you are using a debugger, you can see the private members of objects, including those imported from other assemblies.

Jon Hanna