【发布时间】:2016-07-29 08:13:09
【问题描述】:
我使用一些用 C# 编写的 DLL 测试了 Dotfuscator。 看起来它在 .NET 环境下运行得非常好,所以这次我用 Unity3D 尝试了它们。那些简单的 DLL 仅使用简单的标准 C# 类和方法进行编码,没有反射,没有 LINQ,没有其他自定义或 3rd 方 API,包括 Unity 的。但未能使它们在我的 Unity3d 项目中工作,而未混淆的原始纯 DLL 工作正常。 挣扎了几个小时后,我决定用新的简单项目进行测试。以下是我在 C# 中得到的所有内容,没有其他代码,根本没有其他参考。
[System.Reflection.Obfuscation(Feature = "renaming", Exclude = true)]
public class Class1
{
[System.Reflection.Obfuscation(Feature = "renaming", Exclude = true)]
public static int Get()
{
return 123;
}
}
把它编译成DLL后,我把它放在Unity3D Editor的一个EMPTY项目中播放,效果很好。但是当我在使用 Dotfuscator 混淆 DLL 后再次尝试时,它停止显示“InvalidProgramException: Invalid IL code in Class1:Get (): IL_000c: pop”。
正如您在上面看到的,我添加了防止代码被重命名的属性,当然,我可以在 Reflector 中看到,类和方法的名称实际上都没有被重命名。
昨天我从 PreEmptive 的网站新注册并下载了最新的 Dotfuscator Professional Edition 4.21.0 的评估版。我使用 .NET 3.5 在 Visual Studio 2008 和 2015 上进行了编译,还尝试了所有不同的解决方案平台。 Unity 的版本是 5.3.4f1。
我现在的猜测是 Dotfuscator 只适用于 MSIL,而不是 Unity3D 内部使用的 Mono 2.X。
我说的对吗?有没有人很好地使用带有 Unity3D 或 Mono 的 Dotfuscator?
[编辑] 我用ILDasm检查了IL代码,不明白是怎么回事,但是看到一堆代码被修改很有趣。
在应用 Dotfuscator 之前
.method public hidebysig static int32 Get() cil managed
{
.custom instance void [mscorlib]System.Reflection.ObfuscationAttribute::.ctor() = ( 01 00 02 00 54 0E 07 46 65 61 74 75 72 65 08 72 // ....T..Feature.r
65 6E 61 6D 69 6E 67 54 02 07 45 78 63 6C 75 64 // enamingT..Exclud
65 01 ) // e.
// Code Size 6 (0x6)
.maxstack 8
IL_0000: ldc.i4 0x75bcd15
IL_0005: ret
} // end of method Class1::Get
应用Dotfuscator后
.method public hidebysig static int32 Get() cil managed
{
// Code Size 127 (0x7f)
.maxstack 2
.locals init (int32 V_0)
IL_0000: ldc.i4 0x993
IL_0005: stloc V_0
IL_0009: ldloca V_0
IL_000d: ldind.i4
IL_000e: ldc.i4 0x993
IL_0013: stloc V_0
IL_0017: ldloca V_0
IL_001b: ldind.i4
IL_001c: ceq
IL_001e: switch (
IL_002f,
IL_004c,
IL_002f)
IL_002f: br.s IL_003e
IL_0031: ldc.i4.0
IL_0032: stloc V_0
IL_0036: ldloca V_0
IL_003a: ldind.i4
IL_003b: pop
IL_003c: br.s IL_004a
IL_003e: ldc.i4.0
IL_003f: stloc V_0
IL_0043: ldloca V_0
IL_0047: ldind.i4
IL_0048: br.s IL_003b
IL_004a: nop
IL_004b: nop
IL_004c: ldc.i4 0x1
IL_0051: stloc V_0
IL_0055: ldloca V_0
IL_0059: ldind.i4
IL_005a: br.s IL_0068
IL_005c: ldc.i4.0
IL_005d: stloc V_0
IL_0061: ldloca V_0
IL_0065: ldind.i4
IL_0066: br.s IL_0068
IL_0068: brfalse.s IL_006a
IL_006a: ldc.i4.0
IL_006b: stloc V_0
IL_006f: ldloca V_0
IL_0073: ldind.i4
IL_0074: brfalse IL_0079
IL_0079: ldc.i4 0x75bcd15
IL_007e: ret
} // end of method Class1::Get
【问题讨论】:
-
您是否尝试在 MonoDevelop(与 Unity 一起使用)中创建新的 Mono 2 项目,并在那里测试您的 dll?如果它可以工作,那么问题出在 Unity 如果没有,问题出在 Mono 和/或 Mono 版本的统一使用。
-
@JerrySwitalski 谢谢。正如你所说,我认为值得一试,我回家后会检查它:) 顺便说一句,Mono 2.X 版本现在可用吗? Unity 使用旧版本的 Mono,所以如果不是,它可能会有所不同..
标签: c# unity3d mono obfuscation dotfuscator