Unity3d用户数据保存

0x00 背景

Unity3D的用户数据应该如何正确保存?

0x01 保存方式

这个链接里有三个保存方式,ファイル保存パス,在我的ios上路径稍微有点区别:
1. Application.dataPath:
ios8.3: /private/var/mobile/Containers/Data/Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Data
2. Application.persistentDataPath:
ios8.3: /private/var/mobile/Containers/Data/Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents
3. Application.temporaryCachePath:
ios8.3: /private/var/mobile/Containers/Data/Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches

下面的两个路径是我加的:
1. unity中可以使用AssetBundle来管理安装游戏之后再下载的Assets。它的路径是可以自己设置的,我看过的一个游戏是放在了Application.temporaryCachePath/ab/这个目录下。
2. Unity里有一个PlayerPrefs类,用来管理玩家的用户名,session之类的配置数据,它一般是存在/private/var/mobile/Containers/Data/Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Preferences这个目录下,名字为com.xxxxx.xxx.plist。因为它存储的数据一般也比较重要,可以使用unity anti-cheat toolkitObscuredPrefs来进行加密存储。

0x02 加密

对于存储量重要数据的本地文件,需要加密,我看过的一个加密方式如下:

其中ECAABEKDPFA.KHKNBAPGJPJ这个函数进行了AES解密,说明文件中的内容本身是加密存储的。另外文件的名字为ECAABEKDPFA.MKEBBJCBIDK,我们看一下这个field是什麽:

可以看到文件名为userOid加上一个Save字符串。但是对该文件名还进行了FGCMPVQRFAD.OEIJJBMLKMO操作,我们看一下这个函数:

发现实际上是对文件名进行了hash,并将hash表示为十六进制的字符串,最后生成的文件名的一个例子为:e1227e600b90b8a261c760fbaaaa5c97

0x03 非unity的文件保存路径

参考这个链接:
http://archive.hack.lu/2016/20161020-HackLu-Lightening-Stirparo-iOS_Forensics.pdf

/private/var/mobile/Containers/Bundle/Application/<APP-UUID>/: This
path is the actual path where the application bundle is stored.
/private/var/mobile/Containers/Data/Application/<APP-UUID>/: This path is
the actual path where most of the application data is stored.
/private/var/mobile/Containers/Shared/AppGroup/<APP-UUID>/: As the
name of the folder suggests, this path is the path where applications can store data
with the aim of sharing it with other apps or extensions.