加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Dotfuscator访问器重命名get和set

发布时间:2020-12-15 22:08:06 所属栏目:百科 来源:网络整理
导读:我的问题是Dotfuscator配置重命名.想象一个看起来像这样的类: Class MyClass{ private int _propertyA; private int _propertyB; public int PropertyA { get{return _propertyA;} set{_propertyA = value;} } [Obfuscation(Feature = "renaming",Exclude =
我的问题是Dotfuscator配置重命名.想象一个看起来像这样的类:

Class MyClass
{
    private int _propertyA;
    private int _propertyB;

    public int PropertyA
    {
        get{return _propertyA;}
        set{_propertyA = value;}
    }

    [Obfuscation(Feature = "renaming",Exclude = true)]
    public int DestinationReference
    {
        get{return _propertyB;}
    }
}

混淆的类将写成这样的东西

Class a
{

    int s()
    void z(int a)

    public int DestinationReference
    {
        get{return _propertyB;}
    }
}

这是我从使用.Net Reflector看到的假设

我的问题如下:
– 在我们的代码中,我们实现了一个方法,该方法使用反射查找类的所有属性,以便查找特定参数
– 此方法在混淆代码中不起作用,因为我的访问者PropertyA已被替换为get访问器和set访问器的两种不同方法.
– 我知道如果我将一个访问者排除在重命名之外它会在msil代码中保留一个访问者,并且可以通过我的方法查找访问者

我的问题是:
– 不是重命名唯一的选择吗?
– Dotfuscator中是否有一个参数允许重命名访问者,而不将其分成两个不同的方法并丢失访问者?

我对混淆很新,所以原谅我的不完美之处,这就是我所能看到的类似于上面反射器中所描述的类的东西.

如您所见,从重命名中排除的属性将保留具有get访问器的属性.但对于另一个被混淆的人,我可以看到两个不同的方法s和z

我试图看看是否有办法获得单个访问器,例如使用底层的getter和setter重命名为“s”

解决方法

我在查看这篇文章后首先找到了一些问题的答案: http://vicky4147.wordpress.com/2007/10/23/exploring-msil-properties/

我看到MSIL生成了get_XXX()方法和set_XXX(int)方法以及添加属性. Dotfuscator负责重命名get和set方法(这是我们想要的),但也用于删除属性本身(我不想要)

解决方案是为混淆的DLL启用“库模式”,如果启用了库模式,则文档说明:

  • Names of public classes and nested public classes are not renamed. Members (fields and methods) of these classes are also not renamed if they have public,family,or famorassem access.
  • In addition,no virtual methods are renamed,regardless of access specifier. This allows clients of your library to override private virtual methods if need be (this is allowed behavior in the .NET architecture).
  • Any user-specified custom renaming exclusions are applied in addition to the exclusions implied by the above rules.
  • Property and Event metadata are always preserved.

这可以在反射器中进行模糊处理后看到,顶部库模式被禁用,底部库模式被启用

可以看出,没有公共类/方法/字段被重命名,更重要的是我保留了属性元数据.

现在我的下一个问题是,如何保留属性元数据但允许重命名属性本身.我想找到一个令人满意的解决方案,而无需使用自定义混淆属性定义手动装饰每个属性.

我会继续寻找另一天,如果我找不到任何东西,就会将这个答案标记为问题的解决方案.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读