当前位置: 首页 > news >正文

网站等级保护测评必须做吗/搜索网

网站等级保护测评必须做吗,搜索网,建网站卖阀门,淘宝客网站推广位怎么做2019独角兽企业重金招聘Python工程师标准>>> 在研究Angry Birds的过程中了解到其部分lua脚本文件被进行了加密,关于如何解密以及如何找到解密key的方法见前一篇博客。游戏资源文件加密是pc上的游戏必做的一件事,虽然无论何种加密方法都无法阻…

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

在研究Angry Birds的过程中了解到其部分lua脚本文件被进行了加密,关于如何解密以及如何找到解密key的方法见前一篇博客。游戏资源文件加密是pc上的游戏必做的一件事,虽然无论何种加密方法都无法阻止别人的破解,但是加密至少能够提高应用被破解的门槛,说白了就是不能让随便一个人都能看到里面的一切。

Andgry Birds对lua文件的加密采用的是AES加密算法,使用CBC模式,另外原始文件内容还进行了7z压缩。为了能够解密,AES加密的key必然会保存在应用的某个地方,所以别人还是能够找到破解的方法,能够还原出原始的资源文件,具体用到的方法就是前一篇博客里说到的。

在学习如何解密的过程中找到了一篇不错的文章,介绍如何使用Python的PyCrypto模块来对文件进行AES加密,并且提供了python编写的加密解密源代码,在后面的评论中有人将其进行了改造,支持streamio模式的加密解密,也就是可以操作内存数据。

代码具有很高的实用价值,如果需要在自己的应用中添加一个加密模块,这是个不错的开始,虽然不一定会采用python来实现。

代码如下:

#!/usr/bin/env python
#
# Code adapted from: http://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/
#
#import os, random, struct
from Crypto.Cipher import AES
from StringIO import StringIO
import hashlib
import base64## def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024):
## ( This is an adaptation from using filenames in order that StringIO can be used to encrypt a string. )
## Note: If in_file / out_file is provided, open with +b!def encrypt_file(key, in_file, out_file=None, chunksize=64*1024):""" Encrypts a file using AES (CBC mode) with thegiven key.key:The encryption key - a string that must beeither 16, 24 or 32 bytes long. Longer keysare more secure.in_file:Input fileout_file:If None, a StringIO will be returned.chunksize:Sets the size of the chunk which the functionuses to read and encrypt the file. Larger chunksizes can be faster for some files and machines.chunksize must be divisible by 16."""if not out_file:out_file = StringIO()iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))encryptor = AES.new(key, AES.MODE_CBC, iv)in_file.seek(0,2)filesize=in_file.tell()in_file.seek(0)# filesize = os.path.getsize(in_file)infile=in_fileoutfile=out_fileoutfile.seek(0)outfile.write(struct.pack('<Q', filesize))outfile.write(iv)while True:chunk = infile.read(chunksize)if len(chunk) == 0:breakelif len(chunk) % 16 != 0:chunk += ' ' * (16 - len(chunk) % 16)outfile.write(encryptor.encrypt(chunk))outfile.seek(0)return outfile## def decrypt_file(key, in_filename, out_filename=None, chunksize=24*1024):
## ( This is an adaptation from using filenames in order that StringIO can be used to encrypt a string. )
## Note: If in_file / out_file is provided, open with +b!def decrypt_file(key, in_file, out_file=None, chunksize=24*1024):""" Decrypts a file using AES (CBC mode) with thegiven key. Parameters are similar to encrypt_file."""if not out_file:out_file = StringIO()infile=in_fileinfile.seek(0)outfile=out_fileoutfile.seek(0)origsize = struct.unpack('<Q', infile.read(struct.calcsize('Q')))[0]iv = infile.read(16)decryptor = AES.new(key, AES.MODE_CBC, iv)while True:chunk = infile.read(chunksize)if len(chunk) == 0:breakoutfile.write(decryptor.decrypt(chunk))outfile.truncate(origsize)outfile.seek(0)return outfile# Method suggested by Eli by turn mnemonic password into 32 byte key.
def getHashKey(aKey):return hashlib.sha256(aKey).digest()# My ( J. Norment's ) Additions
def getInFile(aFileName=None):if not aFileName:return StringIO()else:return open(aFileName,'rb')def getOutFile(aFileName=None):if not aFileName:return StringIO()else:return open(aFileName,'wb')def getB64encoded(aString):return base64.b64encode(aString)def getB64decoded(aString):return base64.b64decode(aString)

原创文章,转载请注明: 转载自All-iPad.net

本文链接地址: 使用AES加密游戏资源文件

转载于:https://my.oschina.net/u/184773/blog/70283

http://www.lbrq.cn/news/1566055.html

相关文章:

  • 北京b2c网站建设/自动引流推广app
  • 贵阳网站建设技术托管/短视频seo排名
  • 曲靖网站建设/百度竞价ocpc投放策略
  • 怎么建免费网站/百度权重查询爱站网
  • 收到一张网站服务费怎么做凭证/品牌策划方案怎么写
  • 深圳网域官网/手机网络优化软件
  • 杭州互联网公司排名/广州网站优化公司排名
  • 做网站熊掌号/上海牛巨微网络科技有限公司
  • 百合网网站建设与策划/seo优化服务价格
  • 国际交友网站怎么建设/建立网站的步骤
  • 网站制作top/山东seo优化
  • 做外贸的网站有那些/资源网站优化排名软件公司
  • 肇庆网站建设制作公司/女性广告
  • 怎么做网站推广六安/北京疫情最新新闻
  • 仓山网站建设/网站首页快速收录
  • 现在还做自适应网站/你对网络营销的理解
  • 网站建设与网页设计总结/职业培训机构资质
  • 住房和城乡建设厅网站青海省/seo优化排名教程
  • 网站和网页不同吗/墨子学院seo
  • 高校后勤网站建设要求/今日热搜榜前十名
  • wordpress主页定制/seo排名优化软件价格
  • 合肥哪里有建站公司/百度下载安装到桌面
  • wordpress无法使用api/seo北京网站推广
  • 网站域名备案资料/目前最好的引流推广方法
  • 怎么建设网站规划/千度seo
  • apache 创建网站/企业网站seo平台
  • seo流量/如何提高网站排名seo
  • 网站被别人域名绑定/中国十大电商平台
  • 贵州省建设厅网站造价工程信息网/怎么查百度竞价关键词价格
  • 为什么要建设个人网站/今日郑州头条最新新闻
  • 如何使用 Ollama 在本地设置并运行 Qwen3
  • 【科研绘图系列】R语言绘制特定区域颜色标记散点图
  • Seata深度剖析:微服务分布式事务解决方案
  • 北京-4年功能测试2年空窗-报培训班学测开-第七十四天-线下面试-聊的很满意但可能有风险-等信吧
  • java面试题储备4: 谈谈对es的理解
  • CSS预处理器之Sass全面解析与实战指南