mkaring / ConfuserEx

An open-source, free protector for .NET applications
https://mkaring.github.io/ConfuserEx/
MIT License
2.31k stars 350 forks source link

Skip obfuscation for *.winmd library #455

Closed ashahabov closed 2 years ago

ashahabov commented 2 years ago

*.csproj v1

Here is my initial *.csproj file:

<project baseDir="obj\Release" outputDir="..\Release" xmlns="http://confuser.codeplex.com">
    <rule pattern="true" preset="aggressive" />
    <module path="MyProduct.exe">
        <rule pattern="true" preset="aggressive" inherit="false"></rule>
    </module>
</project>

Build fails with:

Confuser.MSBuild.targets(69, 5): Could not resolve method: System.Void Windows.Storage.Streams.InMemoryRandomAccessStream::Dispose() (Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime)

My application uses Windows.winmd library.

image

*.csproj v2

Now I am trying to avoid Windows.winmd obfuscation with the following updates:

<project baseDir="obj\Release" outputDir="..\Release" xmlns="http://confuser.codeplex.com">
    <rule pattern="true" preset="aggressive" />
    <module path="MyProduct.exe">
        <rule pattern="true" preset="aggressive" inherit="false"></rule>
    </module>
    <module path="..\..\..\libs\Windows.winmd">
        <rule pattern="true" preset="none" inherit="false"></rule>
    </module>
</project>

This also failed, but this time on the other type:

Confuser.MSBuild.targets(69, 5): Could not resolve method: System.Object Windows.Foundation.Collections.IMapView`2<System.String,System.Object>::Lookup(System.String) (Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime)

Since Windows.winmd does not relate to my business code, I would like to avoid obfuscation for that. Is it possible? Or how I can resolve the latest issue?

mkaring commented 2 years ago

You can always declare a library as external. You can do that by adding external="true" in the module tag. Those attributes are considered dependencies and will not get obfuscated. The second error still points to confuserex being unable to find a specific type. Where is Windows.Foundation.Collections.IMapView2` located? You may need to add that library as well to the project.

ashahabov commented 2 years ago

Windows.Foundation.Collections.IMapView also in the same Windows.winmd library.


Regard external=true attribute, if I use it:

<project baseDir="obj\Release" outputDir="..\Release" xmlns="http://confuser.codeplex.com">
    <rule pattern="true" preset="aggressive" />
    <module path="MyProduct.exe">
        <rule pattern="true" preset="aggressive" inherit="false"></rule>
    </module>
    <module path="..\..\..\libs\Windows.winmd" external="true"></module>
</project>

it does not affect — it still throws initial exception about Windows.Storage.Streams.InMemoryRandomAccessStream::Dispose():

Confuser.MSBuild.targets(69, 5): Could not resolve method: System.Void Windows.Storage.Streams.InMemoryRandomAccessStream::Dispose() (Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime)

mkaring commented 2 years ago

There is a bug in 1.5 that may cause this. Could you give the 1.6 RC version a try. This should sort it out.

ashahabov commented 2 years ago

I was able to resolve this issue with "ref proxy".mode=strong setting. Here is my work .crproj:

<project baseDir="obj\Release" outputDir="..\Release" xmlns="http://confuser.codeplex.com">
    <rule pattern="true" preset="aggressive" inherit="false" />
    <module path="MyProduct.exe">
        <rule pattern="true" preset="aggressive" inherit="false">
            <protection id="ref proxy">
                <argument name="mode" value="strong" />
            </protection>
        </rule>
    </module>
</project>
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.