Unity5.X实现混淆

本文详细介绍如何在Unity5.6.x中自定义混淆文件,包括在不同版本中实现混淆的方法差异。在Unity5.6.1中,只能修改全局混淆文件;而在Unity5.6.5中,可以通过创建proguard-user.txt和调整mainTemplate.gradle来实现项目级别的混淆。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Unity5.6.1中,无法对特定工程指定混淆文件,只能去修改Unity目录下的Editor\Data\PlaybackEngines\AndroidPlayer\Tools\UnityProGuardTemplate.txt文件。

这是一个全局的混淆文件,也就是你所有使用Unity5.6.1的工程,都会受到这个文件的影响。

 

在Unity5.6.5中,已经开始支持自定义混淆文件,不过Unity官方并未提到这一点,是博主自己测试出来的。我们在工程的Plugins\Android目录下,新建一个文件proguard-user.txt,注意文件名不能错,否则Unity识别不了。这个文件就是混淆文件。

为了让Unity能识别这个文件,还需要在同级目录下新建一个mainTemplate.gradle文件,或者找到全局的mainTemplate文件——Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates\mainTemplate.gradle。将其中的

buildTypes {
        debug {
            jniDebuggable true
        }
        release {
            // Set minifyEnabled to true if you want to run ProGuard on your project
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
            **SIGNCONFIG**
        }
    }

修改为:

buildTypes {
        debug {
            jniDebuggable true
        }
        release {
            // Set minifyEnabled to true if you want to run ProGuard on your project
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-user.txt'
            **SIGNCONFIG**
        }
    }

这段话是什么意思呢?

其中debug、release分别是代表develop模式和release模式的包,我们可以分别控制这两种模式的混淆。一般来说,为了加密代码和优化性能、减小包体积,release打开混淆即可,debug不开。

minifyEnabled就是混淆开关,true代表开,false代表关。

getDefaultProguardFile(‘proguard-android.txt') 是获取默认的 ProGuard 设置。proguard-android.txt描述了系统提供的基础混淆配置信息,文件所在路径为:\sdk\tools\proguard\proguard-android.txt。后面的'proguard-user.txt'是我们指定的混淆文件,通过这个文件,我们可以去对Unity工程中的代码进行混淆。

 

 

参考链接:

https://www.jianshu.com/p/1b76e4c10495


 

淘宝花钱买的最新版!需要的拿去! 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
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、付费专栏及课程。

余额充值