Unity代码混淆方案
内容提要:Unity引擎下的代码保护,由于Unity引擎的一些特殊性,实行起来较为复杂,在国内外业界并没有现成的方案。笔者通过在《QQ乐团》项目上的实际尝试,得出了一种具体可行,能够有效保护代码逻辑的方案。特此分享给关注Unity引擎的项目,希望能提供一些的参考。
背景
Unity引擎上的程序执行在Mono运行时上,使用Mono编译出的程序集格式与.NET标准一致。C#是Unity引擎下主要的开发语言,它具备不少高级语言特性,如反射、元数据、内置序列化等。但C#同时也是很容易被反编译的语言,如果不采用任何保护措施,使用常用的工具(.NET Reflector)便能很容易得到可二次编译的代码。对项目运营带来了比较大的风险。
.NET平台下通常的保护手段是混淆编译出的程序集。VisualStudio自带了一个混淆工具Dotfuscator可以对程序集进行混淆。功能包括名称修改,流程混淆,字符串加密等。经过Dotfuscator混淆后的程序集,能够避免被常用反编译工具破解。变量的表意性被破坏,同时函数的内部流程也被混淆(如下[B1] )。能有效起到保护源代码的效果。
publicclass181: 218
{
// Fields
publicuint0;
publicushort1;
publicstaticreadonlyuint2;
publicstaticreadonlyuint3;
// Methods
static181();
public181();
public95.02();
public95.02(ref515A_0, uintA_1);
public95.02(79A_0, refuintA_1);
public95.02(ref79A_0, uintA_1);
public95.02(byte[] A_0, intA_1, refuintA_2);
public95.02(ref481A_0, intA_1, charA_2);
public95.02(refstringA_0, intA_1, charA_2);
public95.02(