Since Unity uses C # as the primary language, the code is compiled and executed as a DLL in the execution file, which poses a big problem for us, which is very easy to decompile.
How to decompile the Code of the Unity game:
Unity Package generated install package, we randomly download a game, unzip apk, come to
Assets\bin\data\managed
This directory.
Assembly-csharp.dllassembly-csharp-firstpass.dll
The code you write in the game is stored in these two DLLs.
Drag and drop the DLL into the monodevelop, and wait a few moments to see the code in the DLL.
If there are some more important code do not want others to see, it is written in C + +, C + + compiled so file, after the anti-compilation can only become assembly language, undoubtedly increased the difficulty of cracking (of course, can not hundred hundred anti-cracking, the compilation of a lot of Daniel)
We create a new folder, create a new JNI folder inside, create a new C file, the contents are as follows:
#include <string.h> #include <jni.h> int Share () {return 1234561;}
Just a function, for C # to call.
Then create a new Android.mk file, which is a Mk file that the NDK compiles so needs and specifies how to compile it.
Local_path: = $ (call My-dir) include $ (clear_vars) local_module: = Share local_src_files: = share.c Include $ (build_shared_library)
Then create a new Application.mk file, specifying the build platform and other dependencies.
App_abi: =armeabi-v7aapp_platform:=android-8app_stl:=gnustl_staticapp_cflags + =-wno-error=format-security
Then execute the command in the JNI folder:
Ndk-build
The so file is compiled and stored in the Lib at the top level.
Create a new Unity3d project, and then write the code to invoke the function in so.
Using unityengine;using system.collections;using system.io;using system.runtime.interopservices;using System;public Class Test:monobehaviour {[DllImport ("Share")]private static extern int Share ();//Use this for initializationvoid Start () {Debug.Log ("Shared =" +share ());} Update is called once per framevoid update () {}}
Note that if you want to invoke the function in so you must write according to the rules specified by unity:
[DllImport ("Share")]private static extern int Share ();
Create a new catalog in the Unity project
Plugins\android
Copy so file here
Then we export the APK installation test
Demo Project Download:
http://download.csdn.net/detail/cp790621656/8430985
Unity3d call C + + function to implement encryption anti-cracking (Android)