Forms project and obfuscation

FrancMoralesFrancMorales JPMember ✭✭

I have some experience obfuscating Xamarin Android projects but I'm hitting a wall with Xamarin Forms. The linker does not accept the obfuscated DLL.

Has anyone gotten an obfuscator to work with Xamarin Forms? If so, which?

Thank you all.

Answers

  • FrancMoralesFrancMorales JPMember ✭✭

    I should add that this is a problem with PCL projects only. The linker accepts obfuscated dll's in shared projects (it throws a warning but not an error).

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    You should mention which obfuscator you use, how you configured the obfuscator and linker and what the exact error is.

    Unfortunately I cannot help you there. Obfuscation is a requirement for my current app (on Android), but I didn't try it yet. So I am interested in your findings in this area.

  • FrancMoralesFrancMorales JPMember ✭✭

    I've used several obfuscators and I would use any one that works.

    The LinkAssemblies error is:

    Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item...
    

    The problem is a combination of naming protections and when/how to insert the obfuscated dll in the archiving process.

  • codemaster007codemaster007 USMember ✭✭

    I can do the obfuscation in xamarin android but in xamarin forms how do you obfuscate too dlls ? Any suggestions or hint?

  • codemaster007codemaster007 USMember ✭✭

    thanks for the answer.

  • huangjinshehuangjinshe USMember ✭✭✭

    Did you guys tied .NET Reactor? Looks like it support for Xamarin, And they have a tools for Visual Studio for one click protect your assembly.

  • knottydevknottydev USMember ✭✭

    I had no issues using dotfuscator and following this guide: https://www.preemptive.com/dotfuscator/pro/userguide/en/getting_started_xamarin.html

    ... using the community edition and Visual Studio 2017 CE

  • devcatdevcat Member ✭✭

    Michael,

    Thanks so much for posting your full process to get obfuscation working! I followed everything step-by-step, and finally my files are being properly obfuscated, with no extra hassle when deploying.

  • TonyCeliaTonyCelia USMember ✭✭

    I just finished evaluating BabelFor.NET 9.0 with Visual Studio 2017 / Xamarin on Mac OS High Sierra. I'm using Xamarin Forms to develop a PCL project for Android and iOS. After adding AfterBuild task to the .csproj, use of the tool is very easy. My trial version was limited with some features being crippled, but it provided enough functionality for review. Inspection of the resulting DLLs with ILSpy shows that Babel does what it claims.

    I'll be evaluating ConfuserEx next.

  • TonyCeliaTonyCelia USMember ✭✭

    Has anyone successfully integrated ConfuserEx with Visual Studio 2017 for Mac / Xamarin? I was hoping to apply the build task methodology that I employed for BabelFor.Net (adding the AfterBuild task to .csproj. If so, do you have a sample csproj (or just the relevant part of the csproj) that you could post? Thank you.

  • TonyCeliaTonyCelia USMember ✭✭
    edited November 2018

    I'm about to give up on ConfuserEX for my Xamarin.Forms PCL (Android and iOS) project, but thought I'd give it one more try. Below are the steps that I've followed so far to obfuscate a dll. The result is a process that starts to execute but then fails with

    [ERROR] Unknown error occurred 
    Exception: dnlib.DotNet.Pdb.Managed.PdbException: Failed to read PDB: Invalid signature.
    

    My steps to build and use ConfuserEx on OSX High Sierra are as follows:

    1. Get ConfuserEx 1.0: git clone https://github.com/yck1509/ConfuserEx.git ConfuserEx
    2. Update dnlib: git submodule init; git submodule update;
    3. Build Confuser2.mono: Confuser.CLI (I used Visual Studio Community for Mac). 2 build warnings that looked harmless.
    4. Create my crproj file (similar @MichaelRumpler above but with Mac probePaths)
    5. Execute ConfuserEx: mono Confuser.CLI.exe -n app.crproj

    Confuser.CLI starts and fails with the output below:

     [INFO] ConfuserEx v1.0.0-2-g778190f Copyright (C) Ki 2014
     [INFO] Running on Unix 17.7.0.0, 5.12.0.309 (2018-02/39d89a335c8 Thu Sep 27 06:54:53 EDT 2018), 64 bits
     [DEBUG] Discovering plugins...
     [INFO] Discovered 10 protections, 1 packers.
     [DEBUG] Resolving component dependency...
     [INFO] Loading input modules...
     [INFO] Loading 'App.dll'...
     [INFO] Initializing...
    [DEBUG] Building pipeline...
    [INFO] Resolving dependencies...
    [DEBUG] Checking Strong Name...
    [DEBUG] Creating global .cctors...
    [DEBUG] Watermarking...
    [DEBUG] Executing 'Name analysis' phase...
    [DEBUG] Building VTables & identifier list...
    [DEBUG] Analyzing...
    [INFO] Processing module 'App.dll'...
    [DEBUG] Executing 'Invalid metadata addition' phase...
    [DEBUG] Executing 'Renaming' phase...
    [DEBUG] Renaming...
    [DEBUG] Executing 'Anti-debug injection' phase...
    [DEBUG] Executing 'Anti-dump injection' phase...
    [ERROR] Unknown error occurred.
    Exception: dnlib.DotNet.Pdb.Managed.PdbException: Failed to read PDB: Invalid signature
    at dnlib.DotNet.Pdb.Managed.PdbReader.ReadInternal (dnlib.IO.IImageStream stream) [0x00030] in        <7872a884084e4681935d37638bb723a0>:0 
    

    at dnlib.DotNet.Pdb.Managed.PdbReader.Read (dnlib.IO.IImageStream stream) [0x00007] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.Pdb.Managed.SymbolReaderCreator.Create (dnlib.IO.IImageStream pdbStream) [0x0000b] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.Pdb.Managed.SymbolReaderCreator.Create (System.String pdbFileName) [0x00006] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.Pdb.Managed.SymbolReaderCreator.CreateFromAssemblyFile (System.String assemblyFileName) [0x0000b] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.Pdb.SymbolReaderCreator.Create (dnlib.DotNet.Pdb.PdbImplType pdbImpl, System.String assemblyFileName) [0x00010] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.ModuleDefMD.CreateSymbolReader (dnlib.DotNet.ModuleCreationOptions options) [0x000b0] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.ModuleDefMD.InitializePdb (dnlib.DotNet.ModuleCreationOptions options) [0x00004] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.ModuleDefMD..ctor (dnlib.DotNet.MD.MetaData metaData, dnlib.DotNet.ModuleCreationOptions options) [0x0014e] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.ModuleDefMD.Load (dnlib.DotNet.MD.MetaData metaData, dnlib.DotNet.ModuleCreationOptions options) [0x00000] in <7872a884084e4681935d37638bb723a0>:0
    at dnlib.DotNet.ModuleDefMD.Load (System.String fileName, dnlib.DotNet.ModuleCreationOptions options) [0x00006] in <7872a884084e4681935d37638bb723a0>:0
    at Confuser.Core.Services.RuntimeService.GetRuntimeType (System.String fullName) [0x00053] in :0
    at Confuser.Protections.AntiDumpProtection+AntiDumpPhase.Execute (Confuser.Core.ConfuserContext context, Confuser.Core.ProtectionParameters parameters) [0x0000b] in <7b854044badf49fbb8fbaf090be38916>:0
    at Confuser.Core.ProtectionPipeline.ExecuteStage (Confuser.Core.PipelineStage stage, System.Action1[T] func, System.Func1[TResult] targets, Confuser.Core.ConfuserContext context) [0x0005f] in
    :0
    at Confuser.Core.ConfuserEngine.RunPipeline (Confuser.Core.ProtectionPipeline pipeline, Confuser.Core.ConfuserContext context) [0x00106] in
    :0
    at Confuser.Core.ConfuserEngine.RunInternal (Confuser.Core.ConfuserParameters parameters, System.Threading.CancellationToken token) [0x0044c] in
    :0
    Failed at 4:48 PM, 0:00 elapsed.

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @TonyCelia
    The .pdb files contain debugging information. You don't want that in your release build.

    I have these lines in my .csproj:

      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DebugType>none</DebugType>
        <DebugSymbols>False</DebugSymbols>
        ...
    

    I never tried it on the Mac.

    You can try to debug ConfuserEx too. The source seems very complicated to me, but at least you may find out a better reason for the exception than the stack trace provides.

  • TonyCeliaTonyCelia USMember ✭✭

    @MichaelRumpler
    Thank you for your reply. My .csproj contains the same for DebugType and DebugSymbols (for my release build), so I'm not sure why it appears that ConfuserEx is trying to read PDB (on Mac). Babel support has been good, helping me to automate obfuscation of my iOS and Android DLLs as part of my build process, so Babel may be my only viable option.

  • ChdoulaChdoula JPMember ✭✭
    edited January 3

    @MichaelRumpler (Thank you for your post), I need some help please

    I can't figure out whats is the project.csproject !!!!!!! you mean the android csproj ???? I'm lost

Sign In or Register to comment.