开发者

Workaround for Reflection Bug in Dotfuscator?

开发者 https://www.devze.com 2023-03-09 15:36 出处:网络
Greetings all, I am calling Type.GetProperties(), but after running Dotfuscator, it is returning zero items, when it returned more than zero before.

Greetings all,

I am calling Type.GetProperties(), but after running Dotfuscator, it is returning zero items, when it returned more than zero before.

public class Test
{
    public int Number { get; set; }

    public void ShowInfo()
    {
        Type type = this.GetType();

        PropertyInfo[] props = type.GetProperties();
        Console.WriteLine("type [" + type.Name开发者_StackOverflow + "] props count: " + props.Length);
    }
}

If I exclude the "Number" property from renaming within Dotfuscator, then it works, but otherwise it doesn't. However, it is not possible for me to do this for all properties in my project, as it would lead to possible bugs.

Are there any workarounds for this method? Or even other "free" obfuscation applications I could use?

I have already tried looking on their website to submit a bug, but I am only using the community edition so there doesn't seem to be as much support for it.


Dotfuscator automatically strips properties (which are just metadata anyway - the real work is done by the get/set pair of methods that are automatically created) during renaming. It also renames the underlying get/set methods as well. Depending on what you are trying to do, you'll need to exclude either the property metadata itself, or the get/set methods (or possibly both) from renaming.

If you need to keep the property metadata intact (for example, to simply list the properties in a Type), you can instruct Dotfuscator to exclude properties from renaming by checking them in the tree view on the Renaming Exclusions tab or using a custom regex property rule. This will only exclude the property metadata - the get/set methods will still be renamed.

If you need to keep the get/set methods (because, for example, you are trying to get or set a property's value by reflection), you can instruct Dotfuscator to exclude those methods from renaming by expanding the property in the tree view and checking the get/set methods underneath, or by using a custom regex method rule.


As the process of obfuscation is not limited to renaming your class members, you can't be sure of that. That's the problem with obfuscation: You basically can't make any assumptions about your class anymore regarding the result of reflection. The only way I can think of is to not use reflection but expressions.

Have a look at this question and its answer to know, what I mean with "expressions": How to raise PropertyChanged event without using string name

0

精彩评论

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