开发者

Would it theoretically be possible to manipulate a .NET assembly so that everything becomes public?

I don't know much about the CIL, except that there is metadata in assemblies that record the type information开发者_如何学Go.

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)?


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜