-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obfuscate .NET dlls #4202
Comments
@jonathanpeppers did we change anything on the targets that could cause that? |
We have some new extension points you can use now documented here: An example of some of the recent changes and how we worked around it: |
The missing linksrc folder will also be a problem. I always ran the obfuscator in that directory so that it could find all dependencies. If you don't copy them all to one folder anymore, in which variable can I find a list of all dependencies? Is that ResolvedAssemblies? And how do I remove the merged assemblies from the list? Do I remove them from ResolvedUserAssemblies? Currently I also get an "System.IO.FileNotFoundException: Could not load assembly" for the merged dlls in GenerateJavaStubs. When is the best time to run the obfuscator? My old approach was to run it after everything had been copied to linksrc, but if that is not done anymore... I also attach my diagnostic log here - should've done that before. |
I would review the change for AndroidX.Migration as this specifically worked around the |
I did that and changed the obfuscation task to use all the directories from
But when the build process continues, it still uses the merged assemblies afterwards. I also had to remove the merged assemblies from I don't know how I can check my main assembly with an .so extension from that directory, but I also found it in the .aab in base/root/assemblies. And unfortunately that version was not obfuscated !!! In the projects bin\Release folder the dll did get obfuscated. What else do I have to do in order to include the right file in the .aab? |
AndroidX is running the target earlier: So you are probably obfuscating the assemblies after they are used by some steps. You might try running your target: <PropertyGroup>
<BeforeGenerateAndroidManifest>
$(BeforeGenerateAndroidManifest);
YourTarget;
</BeforeGenerateAndroidManifest>
</PropertyGroup> Then try just changing the two item groups: I don't know if this is an option, but I would have argued not to obfuscate at all -- obfuscated IL (or AOT'd assembly) is still readable and able to be reverse engineered. |
If I run it BeforeGenerateAndroidManifest and only remove the merged dlls from ResolvedAssemblies and ResolvedUserAssemblies, then it builds, but the .aab still contains the merged dlls. If I also remove them from the other properties I listed above, then I get a I also tried actually deleting the merged dlls from the harddisk and copying the obfuscated dlls to obj\Release\90 and obj\Release\90\android\assets, but then I got an Obfuscation does help. Although I expect AOT to revert most of the control flow obfuscation simply renaming all the symbols (classes, method names, ...) makes it almost impossible to get back to readable code. |
@MichaelRumpler can you share a sample app with your custom target? |
Thanks! I hope you can test it. Unfortunately the feature which merges several dlls together is a premium feature of the Babel Obfuscator (http://www.babelfor.net/products/obfuscator). I needed to buy the enterprise version of it. I tried to keep the project structure as it is in my real solution. So the names, target frameworks and dependencies are from my real app. But most of the projects only contain a Class1.cs which holds references to the dependencies so that no whole dll is linked out. The interesting stuff can be found in the folder RoyalMobileApps.XF\RoyalMobileApps.XF.Android. I usually start building the release version with Build_APK.bat and the file Obfuscate.targets does all the obfuscation stuff. |
Do you know how to get a trial key for this?
|
I sent them an email on Friday but didn't get a reply yet. |
I tried your sample, and it seemed like I needed to add: <_BeforeLinkAssemblies>
$(_BeforeLinkAssemblies);
Obfuscate;
</_BeforeLinkAssemblies> Since, it looks like we had to use this private property in AndroidX.Migration, we might need to rename this to |
Yes, that was the key! Thank you very much. Now everything works as expected. Here is again what I did: In my .csproj I load a Obfuscate.targets file only in Release mode:
In the beginning I had this stuff in my .csproj directly, but as it got too much, I didn't want to litter the .csproj with it. The Obfuscate.targets file is something like this:
As Jonathan pointed out above,
I could've also hardcoded the
This gets the files with complete path to the merged assemblies. The obfuscator merges them directly into the
Now call the obfuscator. I use BabelFor.Net, but I won't list all the parameters for calling it here, as it is not relevant for any other obfuscators.
After the obfuscation, the merged assemblies must be removed from |
I have a Xamarin.Forms solution with multiple projects. Several of them need to be obfuscated (I use Babel.NET) before the app bundle is built. In order to make it a bit more complicated, the obfuscator also merges some dlls together into one and has to delete the merged, unobfuscated dlls which must not be included in the final aab anymore.
This all used to work a few months ago in some older Xamarin.Android version. I included an Obfuscate.targets file from my csproj file:
And in that .targets file I declared two targets which did the work:
and
Unfortunately those targets starting with underline I depend upon are internal and may change with every new Xamarin version. But I couldn't make it work with anything other.
This is exactly my problem now. The new build process does not contain the target _CopyIntermediateAssemblies anymore and I get an error.
So my question is:
Everything should of course use the new shiny features like d8, r8 and app bundles.
I can build the aab without problem if I disable obfuscation, but this is a requirement for my app.
Version Information
Microsoft Visual Studio Professional 2019
Version 16.4.3
VisualStudio.16.Release/16.4.3+29709.97
Microsoft .NET Framework
Version 4.8.03752
Xamarin 16.4.000.308 (d16-4@4755fb3)
Xamarin Designer 16.4.0.475 (remotes/origin/d16-4@ac250f5aa)
Xamarin Templates 16.4.25 (579ee62)
Xamarin.Android SDK 10.1.3.7 (d16-4/d66aed0)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: fd9f379
Java.Interop: xamarin/java.interop/d16-4@c4e569f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b
The text was updated successfully, but these errors were encountered: