vb.net - 将友元类添加到混淆的排除列表中

标签 vb.net obfuscation dotfuscator

我使用 Dotfuscator CE 和 Visual Studio 2015 Update 3 来混淆我的 .Net 程序集。 我们知道公共(public)类型和成员默认情况下不会被混淆。 我很想知道如何在排除列表中添加友元类,以便这些类不被混淆?

这是我用来混淆 DLL 的配置文件。

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE dotfuscator SYSTEM "http://www.preemptive.com/dotfuscator/dtd/dotfuscator_v2.3.dtd">
<dotfuscator version="2.3">
  <propertylist>
    <property name="SourceDirectory" value="This Path Will Be Replaced By Visual Studio" />
    <property name="SourceFile" value="This Filename Will Be Replaced By Visual Studio" />
  </propertylist>
  <global>
    <option>quiet</option>
  </global>
  <input>
    <asmlist>
      <inputassembly refid="e4ca1ab5-26cb-4ab7-9621-87063f75a38f">
        <option>honoroas</option>
        <option>stripoa</option>
        <option>library</option>
        <option>transformxaml</option>
        <file dir="${SourceDirectory}" name="${SourceFile}" />
      </inputassembly>
    </asmlist>
  </input>
  <output>
    <file dir="${SourceDirectory}" />
  </output>
  <renaming>
    <option>xmlserialization</option>
    <mapping>
      <mapoutput overwrite="true">
        <file dir="${SourceDirectory}\Dotfuscated" name="Map.xml" />
      </mapoutput>
    </mapping>
    <referencerulelist>
      <referencerule rulekey="{6655B10A-FD58-462d-8D4F-5B1316DFF0FF}" />
      <referencerule rulekey="{7D9C8B02-2383-420f-8740-A9760394C2C1}" />
      <referencerule rulekey="{229FD6F8-5BCC-427b-8F72-A7A413ECDF1A}" />
      <referencerule rulekey="{2B7E7C8C-A39A-4db8-9DFC-6AFD38509061}" />
      <referencerule rulekey="{494EA3BA-B947-44B5-BEE8-A11CC85AAF9B}" />
      <referencerule rulekey="{89769974-93E9-4e71-8D92-BE70E855ACFC}" />
      <referencerule rulekey="{4D81E604-A545-4631-8B6D-C3735F793F80}" />
    </referencerulelist>
  </renaming>
  <sos mergeruntime="true">
    <option>version:v4</option>
    <option>sendanalytics</option>
    <option>dontsendtamper</option>
  </sos>
  <smartobfuscation>
    <smartobfuscationreport verbosity="all" overwrite="false" />
  </smartobfuscation>
</dotfuscator>

实际上我有一个带有好友访问说明符的模型类。我通过 PostAsJsonAsync 方法发布其对象,例如

Dim result As HttpResponseMessage = client.PostAsJsonAsync(APIEndPoints.LOGIN, _LoginModel).Result

这是 friend 类:

Friend Class LoginModel

    Public AccessKey As String

    Public Password As String
End Class

接收请求的API方法和模型:

[HttpPost]
        [Route("authenticate")]
        public async Task<JsonResult> Authenticate([FromBody] LoginViewModel lvm)
// Here lvm.Accesskey is null

当API收到请求和LoginModel时,其字段为空。如果我公开我的 LoginModel 那么它就可以工作。 注意:只有当我混淆 DLL 时才会发生这种情况,否则该实现也适用于 Friend 类。

另请注意:友元类在 VB.Net 中很常见。在程序集中访问时,它们的工作方式类似于公共(public)类,但在程序集外部它们是私有(private)的。

最佳答案

根据您的说明,听起来您不仅要排除 Friend 类型的名称,还要排除这些类型中的公共(public)字段的名称。我将您最初的问题解释为想要排除任何标记为“ friend ”的内容,无论上下文如何。

这里重要的一点是,根据 Dotfuscator 的规则,排除类型不会自动排除其成员

以下是排除顶级好友类型以及这些类型的公共(public)和好友字段的排除规则集:

<excludelist>
  <type name=".*" regex="true" speclist="+notpublic">
    <comment>Exclude top-level types that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "private" in IL).</comment>
    <field name=".*" speclist="+public" regex="true">
      <comment>Exclude public fields of types the parent rule matches</comment>
    </field>
  </type>
</excludelist>

您还可以只排除您知道重命名时会造成麻烦的类型和成员,而不是使用基于可访问性的规则排除大量名称。下面是一个示例,假设 LoginModel 在程序集 YourAssembly 和命名空间 YourNamespace.Here 中定义:

<excludelist>
  <type name="YourAssembly.YourNamespace.Here.LoginModel">
    <field name="AccessKey" signature="string" />
    <field name="Password" signature="string" />
  </type>
</excludelist>

(我注意到您对多个输入程序集使用了相同的配置,但此规则仍然安全,因为如果输入程序集不包含指定的类型,则该规则将被忽略。)

仅供引用,the Professional Edition documentation on Exclusion Rules (以及该页面的子主题)可能有用 - 社区版和专业版共享相同的配置文件格式,以实现两个版本都支持的功能。

披露:我在 PreEmptive Solutions 的 Dotfuscator 团队工作。

关于vb.net - 将友元类添加到混淆的排除列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42230913/

相关文章:

php - 有没有人见过像这样混淆的代码?这是什么意思?

javascript - 从 uglifyjs 源映射中恢复 javascript 源代码

.net-core - dotfuscator 为 "dotnet build"或 "dotnet publish"- 无法加载 "FindProjectAssemblies"任务 PreEmptive.Dotfuscator.Internal.Tasks.dll

vb.net - VB6 DLL 将回调作为 Integer,VB.NET 需要委托(delegate)引用类型

C# 替代 Visual Basic .NET 命名空间 My

.net - 挣扎于枚举标志

java - Proguard 输出 JAR 文件无法执行

c# - Dotfuscator 和 ILMerge 可以协同工作吗?

c# - Xamarin C# xaml混淆数据绑定(bind)冲突

c# - SQL Server 查询 : get the sum conditionally