Unity Mono脚本 加密

文章转载自 Unity Mono脚本 加密,感谢原作者提供好文章
个人是用虚拟机mac系统编译的mono,按照雨松大神的教程即可,转载这篇文章主要是讲解全面,可以解除很多困惑。

加密环境
引擎版本:Unity3d 5.3.4 及更高版本 (使用Mono而并非IL2CPP)
操作系统:CentOS 6.2(Final)
加密环境:Android、iOS(暂定)
加密对象:C#源代码(dll文件)
解密方法:libmono.so (重点:加入解密算法并重编译此文件)
加密的目地
.NET Reflector等反编译工具 无法通过对dll反编译得到源码
注意事项
dll的加密算法和libmono.so解密算法一致

思路分析
重点:我们需要对libmono.so重编译,加入我们的解密算法。
准备环境
编译系统:linux或mac os
我的编译环境:centos 6.2 Final,建议在linux或mac os中编译 libmono.so
linux安装运行库
git
在编译过程中,可能需要通过git获取某些运行库。
查看是否安装git:git –version
CentOS7
yum 安装git

其它package
autoconf
automake
bison
gcc
gettext
glib >= 2.0
libtool
make
perl
glib >= 2.0 这个一直安装失败
centos安装软件
在root权限下,通过以下命令来安装软件:

yum install [nginx][php][php-fpm][mariadb][mariadb-server][mysql][mysql-server]...

Unity安装Android模块
确保已安装Unity引擎,并且Android模块已安装,Android SDK已安装并更新,保证可以打包APK
正式/测试工程
使用Unity创建一个加密测试项目或正式项目,用来用加密
Unity mono
unity的mono和原生mono有些不一样,所以需要去github拉取unity的mono库

monobuildtools
unity mono打包工具

Android SDK Tool/Android6.0
我使用Unity5.3.4在windows上打包apk,需要android sdk tool版本为23,Android6.0,所以同样请先准备好环境

Android打包工具
Android Studio
Eclipse
Andmore - Eclipse Android Tooling
android对应的NDK版本
查看路径:external/buildscripts/build_runtime_android.sh
https://github.com/Unity-Technologies/mono/blob/unity-5.3/external/buildscripts/build_runtime_android.sh
在文件的上半部分就可以看到需要的NDK版本,我在2016-06-25 clone的,需要的NDK版本为r10e
android-ndk 下载
根据android和unity的版本不同,需要的ndk版本也不同,我这儿以2016-06-25 clone的仓库为例,需要ndk-r10e
x64
android-ndk-r10e-linux-x86_64.bin
x86
android-ndk-r10e-linux-x86.bin
设置android ndk环境变量
反编译工具测试加密结果.Net反编译工具
主要加密对象是Assembly-CSharp.dll,所以可以准备几款.Net反编译工具来测试加密结果
下面举例.net的反编译工具
.NET Reflector
C语言反编译工具
如果对libmono.so也加密的话,那还需要准备几款C语言反编译工具
下面举例C语言反编译工具
ida pro
官网
libmono.so(解密方法)

加密C#的dll
根据自己的实际情况,对导出的 assets/bin/Data/Managed/Assembly-CSharp.dll 进行加密
在so中解密dll
Mono加载dll的代码的文件位于/mono/metadata/image.c
mono_image_open_from_data_with_name
打开image.c,找到 mono_image_open_from_data_with_name 方法,把解密方法写在这儿。此方法大概在1807行

MonoImage *
mono_image_open_from_data_with_name (char *data, guint32 data_len, gboolean need_copy, MonoImageOpenStatus *status, gboolean refonly, const char *name)
{
    MonoCLIImageInfo *iinfo;
    MonoImage *image;
    char *datac;

    if (!data || !data_len) {
        if (status)
            *status = MONO_IMAGE_IMAGE_INVALID;
        return NULL;
    }
     //在这儿对加密过的dll进行解密
    if (strstr(name, “Assembly-CSharp.dll”) != NULL)
    {
        //这里是解密过程,我们采用的是xxtea加解密算法。
    }

    //.....
    return register_image (image);
}

遇到的问题
AndroidManifest.xml Error
Unity导出Android Project之后,AndroidMainifest.xml中有一行会报Error: android:debuggable=”false” ,无法识别。
解决办法
CentOS安装软件 Error
在CentOS上安装一些软件时遇到:Errno 256] No more mirrors to try
确保系统已连接网络,输入以下命令(作用:重建缓存)
yum clean all
yum makecache
Linux安装ndk.bin?
资料:Linux下安装JDK-(bin版)
安装步骤
以下命令都是ROOT身份运行
1. 安装ndk-文件拷贝

#mkdir /usr/ndk #cd /usr/ndk #cp /xxxx/android-ndk-r10e-linux-x86.bin /usr/ndk
  1. 安装ndk-安装和配置环境变量
  2. ./android-ndk-r10e-linux-x86.bin 成功后终端输出 Everything is OK
  3. 安装ndk-安装成功
Everything is Ok
[root@workstation ndk]# source /etc/bashrc
[root@workstation ndk]# echo $ANDROID_NDK_ROOT
/usr/ndk/android-ndk-r10r
[root@workstation ndk]#

提示要ndk9?
查看参考资料caption的修改
./configure没有那个文件或目录
查看README文件
tar.xz安装
Linux下解压tar.xz格式压缩文件
资料
安装glib
我安装的是glib-2.48.1
1 ./configure 2 make 3 make install
这里configure主要是配置并生成Makefile文件,make主要是对程序进行编译,make install主要是对编译好的程序进行安装
资料
安装glib-提示缺少libffi
不知道大家注意到没有,在configure时,出现缺少相关库时解决方法都可以使用 库-devel 解决,那么这个
devel是什么呢?devel是个开发包,只有在开发程序时才会安装。里面包含了头文件、以及开发用到的相关库和
帮助文件等等。一般安装某些工具的时候就会出现
glib的安装
安装glib依赖库
libffi
下载,解压,执行 ./configure make make install 进行安装
libpcre >=8.13
./configure –with-prce=/usr/local/prec/
tar.bz2安装
命令:tar -xjvf xxx.tar.bz2 来解压,得到解压后的目录再进一步安装
其它错误

  1. 文件格式错误
    /bin/bash^M: bad interpreter: 没有那个文件或目录
    方法二:在windows下用Notepad++修改格式为unix
    PKG_CONFIG_PATH environment
    如果配置 PKG_CONFIG_PATH
    Linux操作知识
    查看系统版本:
    lsb_release –a
    查看linux系统位数:
    getconf LONG_BIT 输出32则是x86,输出64则是x64
    给shell赋于root权限:
  2. 输入 su 2.输入root密码 回车
    执行脚本:chmod 700 hello.sh
    文件拷贝
    cp [选项] 源文件或目录 目标文件或目录
    访问共享文件夹
    1.virtual box设置共享文件夹
  3. 这一步是在mnt下创建share目录,可不创建
    mkdir /mnt/share
    步骤3,有两种方法
    如果你希望把共享目录放在share下,并且mnt也创建 了share目录:
    #sudo mount -t vboxsf 共享文件夹名/mnt/share ,比如我的:
    mount -t vboxsf mono/mnt/share
    你希望直接放在mnt下:
    #sudo mount -t vboxsf 共享文件夹名/mnt,比如我的:
    mount -t vboxsf mono/mnt
  4. 在 文件系统 – mnt 下就可以看到共享内容了
    cd 目录操作
    以root用户登录之后,默认是在当前用户文件夹内,往上跳到文件主目录中:cd ../../
    virtualbox 虚拟和主机粘贴板共享
  5. 从virtualbox官网下载对应版本的增加工具包,进行安装
  6. 在linux中加载工具包 ios镜像,进行安装
  7. 虚拟机和主机可以共享粘贴板内容了
    Centos安装软件
    CentOS6.X安装QQ2012
    终于可以在centos下使用QQ啦!
    Centos YUM更新软件:http://jingyan.baidu.com/article/19020a0ac84c3d529d2842ee.html
    centos安装软件:https://www.centos.org/forums/viewtopic.php?t=871 查找某一类软件:yum list Firefox
    文献资料
    Unity 自动导出 AndroidStudio 项目

Perl语言(*.pl文件)
perl是解释性语言, 可用于linux/unix系统。可以理解为和windows下的bat一样。
*.pl 是perl语言的库文件,通常用 require xx.pl; 来加载
*.pm 是perl语言的模块文件,通常用 use module; 来加载
*.plx 是perl语言的脚本文件
运行: ./路径/文件名 (前面的“./”表示运行命令)
结束: ctrl + c
注释
单行:#开头,有个例外perl程序第一行也是#开头
多行:=pod 注释多行代码块 =cut
参考资料
Captain
Unity3d 加密 Assembly-CSharp.dll (Android平台) 全记录
技术人生
Unity3D-重新编译Mono加密DLL
雨松
Unity3D研究院之Android加密DLL与破解DLL .SO(八十一)
其它
Unity 3d脚本加密方案

淘宝花钱买的最新版!需要的拿去! This asset obfuscates your code to make it harder for bad guys to reverse engineer your projects. Specifically designed for Unity, it seamlessly links in with its build process. The top priority of this package is to work straight out of the box with no extra steps required. While other obfuscators can stop a game from working, Beebyte's obfuscator looks for specific Unity related code that must be protected. The contents of your source files are unchanged, the obfuscation targets the compiled assembly. Features: - Supports IL2CPP - Supports Assembly Definition Files (Unity 2017.3+) - Removes Namespaces without any conflicts - Recognises Unity related code that must not be changed - Renames Classes (including MonoBehaviours) - Renames Methods - Renames Parameters - Renames Fields - Renames Properties - Renames Events - String literal obfuscation - Adds fake methods - Easy and extensive customisation using the Unity inspector window - Consistent name translations are possible across multiple builds and developers - Semantically secure cryptographic naming convention for renamed members The asset works for both Unity Free and Unity Pro version 4.2.0 onwards (including Unity 5 & 2017 & 2018). Build targets include Standalone, Android, iOS, WebGL, UWP. Other platforms are not guaranteed or supported but may become supported at a future date. IL2CPP builds are much harder to reverse engineer but strings and member information (class, method names etc) are visible in the global-metadata.dat file. Obfuscation will apply to this file adding further security. Why not complement your security with the Anti-Cheat Toolkit - a great third party asset. For more information about the Obfuscator, please see the FAQ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值