如何防止在Unity3d IL2CPP中剥离托管dll

时间:2015-04-16 04:53:08

标签: xcode encoding unity3d mono il2cpp

我使用System.Text.Encoding的1252编码进行扩展ASCII支持,以充分利用字节的第8位,到目前为止,当使用Mono作为Scripting Backend时,I&#lll;能够阻止通过Assets/link.xml文件剥离代码,如下所示:

<assembly fullname="I18N">
    <type fullname="I18N.Common" preserve="all"/>
    <type fullname="I18N.Common.ByteEncoding" preserve="all"/>
    <type fullname="I18N.Common.Handlers" preserve="all"/>
    <type fullname="I18N.Common.Manager" preserve="all"/>
    <type fullname="I18N.Common.MonoEncoder" preserve="all"/>
    <type fullname="I18N.Common.MonoEncoding" preserve="all"/>
    <type fullname="I18N.Common.Strings" preserve="all"/>
</assembly>

<assembly fullname="I18N.West">
    <type fullname="I18N.West" preserve="all"/>
    <type fullname="I18N.West.ENCwindows_1252" preserve="all"/>
    <type fullname="I18N.West.CP1252" preserve="all"/>
</assembly>

但是,当我切换到IL2CPP时,由于某些功能在构建期间被剥离,我得到了崩溃。即使我在Unity的播放器设置中禁用了Stripping Level ..

这是我的运行时崩溃日志:

IL2CPP崩溃:

NotSupportedException: CodePage 1252 not supported
  at System.Security.Cryptography.TripleDESCryptoServiceProvider.CreateEncryptor (System.Byte[] rgbKey, System.Byte[] rgbIV) [0x00000] in <filename unknown>:0 
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 

当我删除link.xml中的preserve语句时,与Mono中的相同:

NotSupportedException: CodePage 1252 not supported
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 

以下是我使用违规代码的方法:

byte[] bytes = System.Text.Encoding.GetEncoding(1252).GetBytes(str); // exactly 8-bit

string str = System.Text.Encoding.GetEncoding(1252).GetString(bytes);

非常感谢你!

1 个答案:

答案 0 :(得分:2)

实际上,您可能会在IL2CPP运行时看到一个与代码剥离无关的错误。使用4.6.4p3版本的Unity,我可以看到同样的问题,并且我已经跟踪了它。我们应该能够在下一个补丁版本中修复此问题。

事实证明,libil2cpp运行时中的icall与mscorlib中的托管代码交互不正确,因此mscorlib中的代码被发送到IL2CPP脚本后端的不同路径。