3

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

Sahil Khanna
  • 4,262
  • 8
  • 47
  • 72
  • 1
    Does obfuscation log file mapping.txt is generated? I have not used Obfuscar but similar tool I have used. That tool will generate obfuscation report. If report generated then only obfuscation is success. So, obfuscar also may follow similar approach. Please check. – Ranjit Feb 24 '21 at 15:51

1 Answers1

0

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.

Sahil Khanna
  • 4,262
  • 8
  • 47
  • 72