yck1509 / ConfuserEx

An open-source, free protector for .NET applications
http://yck1509.github.io/ConfuserEx/
Other
3.55k stars 1.62k forks source link

ConfuserEx integration for Xamarin Android application #508

Open KathirveluM opened 8 years ago

KathirveluM commented 8 years ago

Hi,

Could you please provide the sample/example on implementing the ConfuserEx with Xamarin Android application?

Note: As we have already deployed our app to Google Store and we need to do Obfuscator as client requirement.

Kindly provide your values inputs and samples on impelmenting the same.

timnboys commented 8 years ago

Well I am not sure how this will work for you but I use this post build event command to automatically run confuserex on release config on build. if /I "$(ConfigurationName)" == "Release" C:\PathToConfuserex\Confuser.CLI.exe "path_to_your_crproject_file" replace the variables above with the actual paths and it will automatically obfuscate the code on post-build event in vs.(note it must be put in as a post-build event though.)

LaraSQP commented 8 years ago

There are also some restrictions regarding which protections you can use with Xamarin. Search, this is all described somewhere.

ghost commented 8 years ago

I try to obfuscate Xamarin.Android dlls using ConfuserEx, but i get only error: [ERROR] Failed to resolve dependency of 'app.dll'. Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null w dnlib.DotNet.Extensions.ResolveThrow(IAssemblyResolver self, IAssembly assembly, ModuleDef sourceModule) w E:\Source\Public\Confuser2\dnlib\src\DotNet\IAssemblyResolver.cs:wiersz 113 w Confuser.Core.ConfuserEngine.Inspection(ConfuserContext context) w e:\Source\Public\Confuser2\Confuser.Core\ConfuserEngine.cs:wiersz 264 Failed at 20:23, 0:01 elapsed. My confuserEx project file:

`

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0

` How can i add dependency for project? What do i need add to project? I can't find any information about that.

Thanks in advance

alexmurari commented 8 years ago

Hi, take a look at this: https://github.com/yck1509/ConfuserEx/wiki/Working-with-Xamarin.Android

ghost commented 8 years ago

I added this paths, but today i created again confuser project using dll for obfuscating from bin/Release directory instead of obj/release. Everything is ok. Problem solved.

MichaelRumpler commented 7 years ago

Did anybody obfuscate multiple dll's successfully?

My solution has 11 projects and I want to obfuscate 7 of them. When I try that, then after the obfuscation, the linker always tries to load an assembly which does not exist.

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'UEyojWTNmtkvWzjwiottBwPIvlfL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Mono.Linker.Steps.LoadReferencesStep.ProcessAssembly(AssemblyDefinition assembly)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Mono.Linker.Steps.BaseStep.Process(LinkContext context)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Mono.Linker.Pipeline.Process(LinkContext context)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute()\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1572,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

The name of the assembly is always a different one.

I added an Obfuscate task to my Android csproj file to run AfterTargets="_CopyIntermediateAssemblies". The obfuscation runs without problems. I just activated rename with mode=debug for now to see if it does anything. It writes .dll and .pdb files to a separate folder. After it completed, I copy those files to the bin\Release directories of the respective projects. Other tasks pick the files up from there and copy them to obj\Release\linksrc. I saw that when I ran MSBuild with verbosity=diagnostic.

MichaelRumpler commented 7 years ago

I checked the obfuscated dll's with dotPeek and five of them do seem to reference assemblies with such a name. Although each project references one such assembly and I couldn't find the one mentioned in the error message.

gitopthar commented 7 years ago

@MichaelRumpler I have the exact same issue trying to obfuscate multiple DLLs. Did you figure out the problem?

FWIW if you set an explicit seed value in the ConfuserEx project file, the bogus assembly name (the one that doesn't exist and fails to link) will always be the same.

MichaelRumpler commented 7 years ago

I think the problem here was that I used a preset="normal" which activated some protections which didn't work. I changed it to none and activated one protection after the other to test which really works.

I ended up with this + deactivating rename for some classes with Adapters:

<rule pattern="true" preset="none" inherit="false">
    <protection id="anti debug" />
    <protection id="anti ildasm" />
    <protection id="constants" />
    <protection id="ctrl flow" />
    <protection id="ref proxy" />
    <protection id="rename">
        <argument name="mode" value="letters" />
<!--        <argument name="renPublic" value="true" />  does not work   -->
    </protection>
<!--    <protection id="resources" />               does not work   -->
</rule>

I would really like to get renPublic running, but this created some ambiguous references.

gitopthar commented 7 years ago

Confirmed. preset="none" followed by explicit enabling of the features does the trick. Thanks @MichaelRumpler.

I also found that moving the ConfuserEx configuration into source code helped a lot. Means that it's much easier to (e.g.) exclude methods from being renamed.

The documentation is pretty poor but here's a great post on that: http://drizin.io/How-to-use-ConfuserEx-Obfuscator/

jzeferino commented 7 years ago

Any thoughts on const string obfuscation with ConfuserEx? Can't managed to do it.

Neither using any of the presets different from none and minimum.

ghost commented 6 years ago

Hello! Is there any full tutorial about how to obfuscate Xamarin.Android program?

XAS-712 commented 6 years ago

emmm. This works great with C# running in desktop environment but maybe this isn't designed for Xamarin.

ghost commented 6 years ago

Yep! Confuser.EX is great tool but not for Xamarin, I will try Dotfuscator.

MichaelRumpler commented 6 years ago

@Enter03 As others already mentioned, the official documentation is very poor. I summed up everything I had to do for Xamarin.Android in the Xamarin forum.

Delvint commented 5 years ago

Recently upgraded from PCL to Class Library. Had to reference most of my nuget packages as from C:\Users\MY_USER.nuget\packages