Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Code obfuscation

Discussion in 'Editor & General Support' started by pep_dj, Oct 11, 2017.

  1. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    178
    I'm almost ready to release my new game for iOS and Android. I want to protect some parts of the code, so it's harder to decompile. But before buy some obfuscator from asset store, I would like to know how code is seen when someone decompiles it.

    I see that people uses il2spy to see the code inside dlls. But, for an Android apk, where can I find these dll files? I used apktool to extract files, but I cannot find them.

    So, questions are:
    • Do I need an obfuscator because it's relatively easy to decompile and see code?
    • If answer to previous question is "yes": how can I see it?
     
  2. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    626
    You can extract .apk files like archive files and see the content, just go to assets/bin/ and here you go, there are the binaries and DLLs, use IL2Spy to see the code.
    • Yes, you need obfuscator, because it is really easy to decompile code.
    • Just open the DLL binary using IL2Spy.
    Hope this helps.
    Thanks.
     
    pep_dj likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Since APK's are just JAR files, and JAR files are just ZIP files with an extra manifest file included, you can open APK's in WinZip, winrar, or whatever your favorite archive application is. Windows even has built in ZIP support, but you might have to rename the file extension to .zip first.
     
    pep_dj likes this.
  4. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    178
    Thanks for your answer. I used ilspy to see my code in assets/bin/Data/Managed/Assembly-CSharp.dll. I can see it exactly as I wrote it! :eek: I think Unity should obfuscate the code...

    Do yo know a good obfuscator?
     
    mikejm_ likes this.
  5. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    626
    I don't have any experience with Obfuscation because I don't use it.

    As the other articles states, it seems the IL2CPP is secure if you are compiling to Android, Give it a try and check if it can be decompiled or not.

    But the right answer is you can't protect your project from pirates and hackers, these such tasks just take a bit more time from them.

    Anyway, you can search for Unity obfuscation in asset store or Google to find good resources.
     
    mikejm_ and pep_dj like this.
  6. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Obligatory (if they want it bad enough they will get it) post. Your best bet is a paid asset.
     
    pep_dj likes this.
  7. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    iOS and Android both support IL2CPP builds, just use it.

    IL gets converted to C++ which is then compiled to object code. The object code is not intentionally obfuscated, but is practically obfuscated.
     
    pep_dj likes this.
  8. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    178
    I'm receiving an error when compiling for Android using IL2CPP... don't know why :(
     
  9. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    626
    What is the error message?
     
  10. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    178
    This one:

    Code (CSharp):
    1. Fatal error in Unity CIL Linker
    2. System.NullReferenceException: Object reference not set to an instance of an object
    3.   at UnityLinker.AddUnresolvedStubsStep.GetTypeModule (Mono.Cecil.TypeReference type, Mono.Cecil.AssemblyDefinition[] assemblies) [0x00001] in <81b71c29c35449f8a666455c78a2dcfb>:0
    4.   at UnityLinker.AddUnresolvedStubsStep.GetTypeModule (Mono.Cecil.TypeReference type) [0x00001] in <81b71c29c35449f8a666455c78a2dcfb>:0
    5.   at UnityLinker.AddUnresolvedStubsStep.Process () [0x000b5] in <81b71c29c35449f8a666455c78a2dcfb>:0
    6.   at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00018] in <09bca01fd71241c7a07af8c71eb6ae1a>:0
    7.   at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00020] in <09bca01fd71241c7a07af8c71eb6ae1a>:0
    8.   at UnityLinker.UnityDriver.Run () [0x00086] in <81b71c29c35449f8a666455c78a2dcfb>:0
    9.   at UnityLinker.UnityDriver.RunDriverWithoutErrorHandling () [0x00001] in <81b71c29c35449f8a666455c78a2dcfb>:0
    10.   at UnityLinker.UnityDriver.RunDriver () [0x00002] in <81b71c29c35449f8a666455c78a2dcfb>:0
     
  11. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    626
    It is a bit strange for me.

    Try some googling, you might find useful resources.

    Excuse me, i can't help you in this case, but i saw a similar problem that was related to Stripping, and they solved it by adding some link.xml file.

    Hope this helps.
    Thanks.
     
    pep_dj likes this.
  12. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    189
    Should I open a new thread or can I revive this one ?
    Is there a good option for obfuscation ? I tried obfuscator but it breaks a lot of things by default
     
  13. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    178
    I think using IL2CPP will be enough. C++ code is not as easy to decompile as Mono.
     
    rbitard likes this.
  14. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    189
    Good Idea I should try to see what it does on my projects