zoukankan      html  css  js  c++  java
  • 常见的内存加密防破解及安全方案

    最近项目临出包测试时,测试反馈部分敏感数据可以在运行时被八门神器或gg大玩家等工具搜索到并进行修改。

    迫不得已,只能暂停手头的工作重新检查既定的内存加密方案情况。然而,不查不要紧,一查吓一跳:

    1)内存加密的方案最开始的时候推行下去并加到项目中了,但是使用的是网上搜索的插件(也就基本相当于开源了),同时防破解机制不够稳固

    2)项目后续开发的过程中,不断更新提交相关脚本及proto生成的协议时竟然没有对比检查修改的有效性,导致覆盖问题

    3)方案的引入及使用过程有数据定义的遗漏以及使用的不合理导致的Bug

    那么就怪不得我了,祭起工具干起来吧。

    除了3是琐碎的排查,针对前两个问题就写个小工具处理下就OK了:

    	protected static string protobufPath = "/Source/Proto/";
    	[MenuItem("Tools/EncryptProtoScript")]
    	protected static void encryptProtoScript()	//对ProtoBuf中定义的int/float等类型的private field进行加密(有需要可以进行文件导入的监听及自动化处理)
    	{
    		var tArr = Directory.GetFiles(Application.dataPath + protobufPath, "*.cs");
    		foreach(var filePath in tArr)
    		{
    			var tContent = File.ReadAllText(filePath);
    			bool tIntFlag = tContent.Contains("using Int = EncryptInt;");
    			bool tFloatFlag = tContent.Contains("using Float = EncryptFloat;");
    
    			bool tNeedEncrypt = false;
    			if(tContent.Contains("private int ") || tContent.Contains("private int? "))
    			{
    				tNeedEncrypt = true;
    				if(!tIntFlag)
    				{
    					tContent = tContent.Replace("EncryptInt", "Int");
    					tContent = "using Int = EncryptInt;
    " + tContent;
    				}
    				tContent = tContent.Replace("private int ", "private Int ").Replace("private int? ", "private Int? ");
    			}
    
    			if(tContent.Contains("private float ") || tContent.Contains("private float? "))
    			{
    				tNeedEncrypt = true;
    				if(!tFloatFlag)
    				{
    					tContent = tContent.Replace("EncryptFloat", "Float");
    					tContent = "using Float = EncryptFloat;
    " + tContent;
    				}
    				tContent = tContent.Replace("private float ", "private Float ").Replace("private float? ", "private Float? ");
    			}
    
    			if(tNeedEncrypt)
    			{
    				File.WriteAllText(filePath, tContent);
    			}
    		}
    		AssetDatabase.Refresh();
    	}

    最后总结下吧:

    首先,无论何种本地数据安全方案,都基于两个大前提,不然毫无意义:
    1)游戏本身不被破解
    2)游戏代码不被破解

    其次针对各种类型的内存搜索数值修改,都是基于数值变化的原理进行不断缩小范围来定位,不过同样基于两个前提:
    1)数值常驻内存
    2)数值在内存中的地址稳定不变

    因此可以想见,针对内存数据破解的防范或安全方案(需要评估并平衡效率)有以下几种常见方案:
    1)内存中的数据及时清理(实时存盘)
    2)进行实时内存存储位置/地址的修改
    3)进行数据加密(加密算法)/进行数据校验(Hash算法)
    4)加盐/噪音干扰(引入冗余数值,伴随敏感数据一起变化)

  • 相关阅读:
    Oracle使用记录
    UML中类关系表示与Java代码中的对应关系
    Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
    Mysql:The user specified as a definer ('xxx'@'%') does not exist 错误
    Java 从html中提取纯文本
    com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别
    MySQL 查看数据库数据表空间大小
    MySQL 中的 information_schema 数据库
    WARN: Establishing SSL connection without server's identity verification is not recommended.
    Cause: java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
  • 原文地址:https://www.cnblogs.com/wayland/p/11089064.html
Copyright © 2011-2022 走看看