2017-02-14 59 views
1

我正在使用Dotfuscator CE與Visual Studio 2015更新3混淆我的.Net程序集。 我們知道公共類型和成員默認情況下不會被混淆。 我很想知道如何在排除列表中添加朋友類,以便這些不應該被混淆?添加朋友類排除列表混淆

這是我用來混淆我的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> 

其實我和朋友訪問符一個Model類。我通過PostAsJsonAsync方法發佈它的對象,例如

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

這裏是朋友類:接收該請求和模型

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中很常見。它們在集合中訪問時像公共類一樣工作,但它們在集合之外是私有的。

回答

2

根據您的說明,聽起來您不僅要排除Friend類型的名稱,還要排除這些類型中Public字段的名稱。無論上下文如何,我都將原來的問題解釋爲希望排除標記爲Friend的任何內容。

這裏重要的一點是,根據Dotfuscator的規則,不包括類型不會自動排除其成員

這裏的排除規則集排除頂層朋友類型和這些類型的公共及朋友字段:

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

(我注意到您使用的是多輸入組件相同的配置,但這個規則仍是安全的,因爲如果輸入組件沒有按」 t包含指定的類型,則該規則將被忽略。)

作爲參考,the Professional Edition documentation on Exclusion Rules(和該頁面的子主題)可能會有用 - Community Edition和Professional Edition共享相同的配置文件格式,受到兩個版本的支持。

披露:我在PreEmptive Solutions的Dotfuscator團隊工作。

1

如果你想排除您輸入組件的朋友類型和成員,因爲你的組件具有Friend Assembly,然後注意Dotfuscator的將自動重命名(唯一一種由Dotfuscator的CE提供模糊的)排除這樣的代碼元素和意志發出以下警告:

警告:NameOfYourInputAsssembly有非輸入朋友組件,並在圖書館模式;內部成員不會被重新命名或修剪。考慮添加Friend Assemblies作爲增加混淆的輸入。

(這裏的術語「internal」是VB的「Friend」關鍵字的C#等價物)。

正如警告所示,您可以將Friend Assembly作爲Dotfuscator的另一個輸入。 如果這樣做,Dotfuscator可以重命名好友類型和成員,並更新好友大會以使用新名稱引用這些類型和成員。


如果你仍想排除朋友類型和成員,你可以用下面的重命名排除規則集做到這一點,添加爲<renaming>標籤在配置文件中的孩子:

<excludelist> 
    <type name=".*" regex="true" speclist="+notpublic"> 
    <comment>Exclude types that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "private" in IL).</comment> 
    </type> 
    <type name=".*" regex="true" speclist="+nestedassembly"> 
    <comment>Exclude nested types that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "private" in IL).</comment> 
    </type> 
    <type name=".*" regex="true" excludetype="false"> 
    <comment>Select, but do not exclude, all types.</comment> 
    <method name=".*" speclist="+assembly" regex="true"> 
     <comment>Exclude methods that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment> 
    </method> 
    <field name=".*" speclist="+assembly" regex="true"> 
     <comment>Exclude fields that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment> 
    </field> 
    <propertymember name=".*" speclist="+assembly" regex="true"> 
     <comment>Exclude properties that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment> 
    </propertymember> 
    <eventmember name=".*" speclist="+assembly" regex="true"> 
     <comment>Exclude events that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment> 
    </eventmember> 
    </type> 
</excludelist> 

編輯:我錯過了此答案的以前版本中的嵌套類型。

披露:我在PreEmptive Solutions的Dotfuscator團隊工作。

+0

感謝@Joe的詳細信息,但解決方案無法正常工作。我正在更新我的問題以提供更多詳細信息。簡而言之,您的答案中提到的排除規則並不排除Friend Classes被混淆。 –

+0

當我在Idasm中看到混淆的DLL時,它顯示Friend類的公共數據成員已被混淆爲名稱a&b。 –

+0

@AzazulHaq我根據你的澄清發布了一個單獨的答案。 –