Obfuscar for Xamarin Forms

1.1k Views Asked by At

I'm developing a Xamarin.Forms app using Visual Studio for Mac (Community Edition). I'm able to decompile the source code of the Android application using ILSpy

In order to obfuscate the source code, I used Obfuscar and followed the steps in https://docs.obfuscar.com/tutorials/xamarin.html

  • Below is the Xamarin.Android project structure

enter image description here

  • Below is the configuration in obfuscar.xml
    <Obfuscator>
        <Var name="RenameProperties" value="true" />
        <Var name="RenameEvents" value="true" />
        <Var name="RenameFields" value="true" />
        <Var name="KeepPublicApi" value="false" />
        <Var name="HidePrivateApi" value="true" />
        <Var name="HideStrings" value="true" />
        <Var name="UseUnicodeNames" value="true" />
        <Var name="OptimizeMethods" value="true" />
        <Var name="InPath" value="./bin/Release" />
        <Var name="OutPath" value="./bin/Release/Obfuscator_Output" />
        <Module file="$(InPath)/Sample.dll" />
    </Obfuscator>
  • Below changes are done in the Android.csproj

enter image description here

When the project is built in the Release mode, Archived, and Decompiled, the source code is still visible in plain text using ILSpy.

enter image description here

I need help in configuring Obfuscator correctly for the Xamarin.Forms project

1

There are 1 best solutions below

0
On BEST ANSWER

Everything worked fine with the below Obfuscar configuration

<Obfuscator>
    <Var name="RenameProperties" value="true" />
    <Var name="RenameEvents" value="true" />
    <Var name="RenameFields" value="true" />
    <Var name="KeepPublicApi" value="false" />
    <Var name="HidePrivateApi" value="true" />
    <Var name="HideStrings" value="true" />
    <Var name="UseUnicodeNames" value="true" />
    <Var name="OptimizeMethods" value="true" />
    <Var name="InPath" value="/Users/sahil.khanna/path_to_xamarin_project/Sample.Android/bin/Release" />
    <Var name="OutPath" value="$(InPath)/Obfuscator_Output" />
    <Module file="$(InPath)/Sample.dll" />
</Obfuscator>

Strangely, InPath and OutPath worked with an absolute path instead of a relative path on a Mac. The only changes I did were in the InPath and OutPath to make it work.