Unity3D项目程序加密2——对dll进行混淆

原文地址


之前一篇文章阿赵已经简单的介绍了怎样把自己写的代码打包成dll动态链接库,然后在Unity3D里面用。那么接下来的事情似乎就很简单了,我们在Unity3D里面写脚本,到最后完成时,把核心的代码剪切出去打包成dll文件再放回项目里面。这样似乎别人就不能直接修改你的代码了。事实真的是这样吗?


这里假设我们在Unity3D里面写的代码抽象成这样一个Test类,里面包含了公开和私有的变量,有自带的Start方法、Update方法和OnGUI方法,还有public、private和protected方法。虽然说用抽象类代表了项目里面实际的类,但为了可以看得到代码效果,所以在方法里面大概写了一些简单的打印的命令。
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
把这个Test类放到上次的类库项目里面,然后生成dll,放到Unity3D项目里面:
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
其实要看到dll里面的内容,很多软件都可以,我们这里就拿Unity3D自带的MonoDevelop来看。找到引用里面的dll文件,这里是AzhaoDll.dll。
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
可以直接浏览到dll里面的内容,看看刚才那个Test类,是不是每一个变量、每一个方法都一字不缺的显示出来了?
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 还有上次写的Math3D方法,也能直接看得到。
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
dll就是这么不保险的一个东西,所以我们要引入这一篇文章的内容:对Dll进行混淆。
.Net的代码混淆器有好几种,比如VS自带的DotFuscator、小巧的Reactor,或者相对比较专业的xeoncode。
这里我使用了xeoncode 2010版本。
界面如下:
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
来到Application,可以添加dll文件:
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
选择需要混淆的dll:
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵

然后在Project可以看到dll里面的类、变量和方法。看到某些变量和方法前面打了勾,这是需要混淆的意思,这个可以自己调整,后面再说:
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
  
在Output里面选择一个输出的路径:
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
然后点击右下角的Build Application,就可以发布混淆好的dll。
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 
把混淆好的dll放回Unity3D项目,就可以看到,这次的dll里面出现了很多随机数字和字母组成的变量名称和方法名称:
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵
 仔细的看,可以看出,刚才打钩了的方法和变量都变成乱码名称,然后在方法调用里面也会发生一些变化,除了名称改变以后,代码本身也会发生一些变化,没有之前那么直接的显示出调用的情况,如果是复杂的调用,将会出现goto来代替了。
这样一来,就算是写代码的人自己也很难看得明白这些代码了。当然如果真的非常有心的逐个变量方法名称去对应,逐个goto调用去查找,也还是可以还原的,但估计很少人会话这个功夫去做这种事情。到这里,混淆的目的就达到了。

不过现在拿这个dll去实际运行,会发现出现很多问题的,比如Unity3D自带的方法Start、Update之类的是不会执行的。这是因为混淆的时候把一些不应该混的东西给混淆了。

那么接下来就说一下注意的事项:
1、public和protected的变量和方法,默认是不会混淆的,你也可以手动的把勾打上,让它混淆,不过由于这些是被外部调用的变量和方法,你混淆了它的名称,那么外部调用的时候是必然出错的。
2、像Unity3D的Start、Update、OnGUI等MonoBehaviour自带的方法,都是具有特定含义的,虽然是私有方法,但也不应该混淆,不然到了该执行的时候就不会执行了。
3、某些有特定含义的名称,或者有用到使用字符串来识别变量或者方法名称时,这些方法和字符串都不应该混淆,不然也会出现调用不到的情况。
 
Unity3D项目程序加密2——对dll进行混淆 - 阿赵 - 穷到掉渣的超级奶爸阿赵

以上是简单的使用方法,具体的情况可能要到真正用的时候才会出现,所以就随机应变了。

六一节快乐!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
淘宝花钱买的最新版!需要的拿去! 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
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、付费专栏及课程。

余额充值