How to use .Net Reactor obfuscated dll of Xamarin Android APK

后端 未结 3 952
予麋鹿
予麋鹿 2021-02-10 05:55

I am new to Xamarin Android. I have created an App using Visual Studio 2015 Community Edition. I have set the Solution Configuration to Release.

For obfuscation I used .

相关标签:
3条回答
  • 2021-02-10 06:08

    1) Publish not obfuscated an application .apk, rename it to .zip.

    2) Move from it the file Mono.Android.dll from the folder "assemblies" into the folder YourProjectName\bin\Release.

    3) Create a new .NET Reactor project, set the right settings (uncheck Anti ILDASM, also the obfuscation process renames a fields that is used in reflection or serialization. To avoid crash of app, should set the exclusions for ignore some types or methods.). Save this project file into YourXamarinFolder\YourProjectName\bin\Release.

    4) Create the file obfuscate_android.bat, insert here the code:

     "C:\Program Files (x86)\Eziriz\.NET Reactor\dotNET_Reactor.exe" -project "NET_Reactor_Project_Name.nrproj"
      copy "YourProjectName_Secure\YourProjectName.dll" "YourProjectName.dll"
      DEL "YourProjectName_Secure\*.dll" "YourProjectName_Secure\*.pdb" /q
    

    Move this file into YourProjectName\bin\Release.

    5) Unload your Xamarin project and edit YourProjectName.csproj Find the next block:

    <PropertyGroup Condition = " '$ (Configuration) | $ (Platform)' == 'Release | AnyCPU'">
    <! -- Insert here the link to obfuscate_android.bat -->
    <PostBuildEvent>obfuscate_android.bat </ PostBuildEvent>
     </ PropertyGroup>
    

    6) Save all and Reload project

    7) Run Publish.

    0 讨论(0)
  • 2021-02-10 06:13

    It has come extremely easy to use .net reactor with xamarin today:

    1. from reactor ide install extension for your visual studio appropriate version (menu Visual Studio)

    2. in reactor ide create a project for your xamarin solution. You can use menu "Protection Themes->Xamarin" or play with you own settings. Do not forget to add additional files (your Forms shared project and others needed). save project, note its path.

    3. in Visual Studio ide menu Tools->Reactor Automation set:

    • project file path to your Xamarin Android (or other needed) platform project, check Enabled.
    • configuration to Release,
    • Net Reactor Project file to the one that you created in step 2.

    Click ok, that's it.

    The build process would be MSBuild compiling, then reactor would apply its processing, then VS would pack/aot whatever was set for platform deployment/distribution.

    0 讨论(0)
  • 2021-02-10 06:20

    I got my Xamarin Android project in Xamarin Studio obfuscating fine with .NET Reactor by hooking into MSBuild. Add this markup to the bottom of your csproj file:

      <Target Name="AfterCompile">
        <Exec Command="&quot;C:\Program Files (x86)\Eziriz\.NET Reactor\dotNET_Reactor.exe&quot; -file &quot;$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)&quot; -targetfile &quot;$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)&quot; -suppressildasm 1 -obfuscation 1 -stringencryption 1 -antitamp 1 -control_flow_obfuscation 1 -flow_level 9 -resourceencryption 1 -mono 1 -exception_handling 1" Condition="'$(ConfigurationName)' == 'Release'" />
      </Target>
    </Project>
    

    To note, when I upgraded to Xamarin in Visual Studio 2015 this does not work anymore. Gave me a "error MSB4018: The "LinkAssemblies" task failed unexpectedly."

    **edit I got past the 'LinkAssemblies' task error by setting PostBuild to true and hooking to the 'PostBuildEvent' event instead as Ajit pointed out.

    However, the obfuscated DLL is not getting added to the apk file. I tested this by unzipping the .apk file (just change the file extension to .zip or .rar) and decompiling the DLL file inside. It was not obfuscated.

    I looked in the bin/Release and the obj/Release folders, and the DLL in there is obfuscated. But for some reason, the DLL in the apk is not the obfuscated DLL.

    Perhaps the PostBuildEvent is too late in the process of creating the apk file?

    Here is my current setup:

    Set the PostBuild to true:

      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        ...
        <PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
      </PropertyGroup>
    

    and then hook to the 'PostBuildEvent' event instead 'AfterCompile'

      <Target Name="PostBuildEvent">
        <Exec Command="&quot;C:\Program Files (x86)\Eziriz\.NET Reactor\dotNET_Reactor.exe&quot; -file &quot;$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)&quot; -targetfile &quot;$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)&quot; -suppressildasm 1 -obfuscation 1 -stringencryption 1 -antitamp 1 -control_flow_obfuscation 1 -flow_level 9 -resourceencryption 1 -mono 1 -exception_handling 1" Condition="'$(ConfigurationName)' == 'Release'" />
      </Target>
    </Project>
    

    ** update I created a simple blank Android project in VS 2015 to test if the problem may be caused by the complexity of my project (use of 3rd party controls, common utility library as a 2nd project in solution, etc). The 'LinkAssemblies' error still occurs so it's probably my environment/setup.

    I have a GitHub account but haven't downloaded the app, so I couldn't upload the entire project folder structure, so I just zipped up the whole solution and uploaded that. It's available here:

    https://github.com/nbcruz/TestObfuscate/blob/master/TestObfuscate.zip

    I had to delete the contents of the obj/Debug folder as it had 78MB of files to make the zip file under 25MB for GitHub to allow.

    The .NET Reactor project is inside the bin\Release\ folder. I manually run it and create the obfuscated DLL which is inside the bin\Release\TestObfuscate_Secure folder. The obfuscate.bat file is also inside the bin\Release\ folder and it basically just copies the DLL inside the bin\Release\TestObfuscate_Secure folder into the bin\Release\ folder. This blank simple solution still throws the 'LinkAssemblies' error.

    0 讨论(0)
提交回复
热议问题