手游之u3d之global-metadata.dat解密
本帖最后由 wesleyxu 于 2020-12-30 18:10 编辑文章来自“安全客”
链接:https://www.anquanke.com/post/id/226685
作者:灯-等灯等灯~
https://p4.ssl.qhimg.com/t01d593118c22070bdb.jpg
所需工具:010editor
frida
js脚本
Il2CppDumper
ida一款国外的游戏,u3d引擎,没有mono,使用Il2CppDumper一番操作
https://p3.ssl.qhimg.com/t01e24edeae1d30233e.png
Dump失败,好吧,
ida打开libil2cpp.so,能正常打开,应该没加密
010editor打开global-metadata.dat
https://p1.ssl.qhimg.com/t0130d77ac7036e8dee.png
global-metadata.dat头部信息,正常是AF 1B B1 FA 18,
应该就是加密了,
使用模块跑一下
下载地址:
https://www.sweetscape.com/010editor/repository/templates/
https://p0.ssl.qhimg.com/t0183f1b6bad5932ff2.png
导入后,跑一下
https://p3.ssl.qhimg.com/t01fca6c08baa3d764f.png
出错,绝逼是加密了,如果没加密正常是能跑通的,找个没加密的跑一下,正常是这样的,如下图
https://p4.ssl.qhimg.com/t01a917dd6b151b1661.png
这里说一下如何计算global-metadata.dat大小的,
查看metadataHeader段
https://p1.ssl.qhimg.com/t0131b1f625fdc8d2d7.png
有各种偏移和大小,计算整个文件大小就在这里面,
直接查看最后一个
https://p3.ssl.qhimg.com/t01e32d7dd2e8e3bbcf.png
大小和偏移加起来就是0x55c118 + 0xf0c = 0x55D024
Ctrl+G,直接跳转到该偏移,刚好是文件末尾
https://p1.ssl.qhimg.com/t0180b6dfdf6dae2dfa.png
看了很多文件,最后一个属性都是在0x108,0x10C,有个注意点就是如果最后一个属性的值比倒数第二个小的话,就取倒数第二个的属性值。
基于以上两点,我们祭出frida,写下js脚本
解释如下:
https://p1.ssl.qhimg.com/t012ee4a120c68de721.png
代码如下:
/*
获取解密后的global-metadata.dat
github:https://github.com/350030173/global-metadata_dump
用法:
frida -U -l global-metadata_dump.js packagename
导出的文件在/data/data/yourPackageName/global-metadata.dat
*/
//
//get_self_process_name()获取当前运行进程包名
//参考:https://github.com/lasting-yang/frida_dump/blob/master/dump_dex_class.js
function get_self_process_name()
{
var openPtr = Module.getExportByName('libc.so', 'open');
var open = new NativeFunction(openPtr, 'int', ['pointer', 'int']);
var readPtr = Module.getExportByName("libc.so", "read");
var read = new NativeFunction(readPtr, "int", ["int", "pointer", "int"]);
var closePtr = Module.getExportByName('libc.so', 'close');
var close = new NativeFunction(closePtr, 'int', ['int']);
var path = Memory.allocUtf8String("/proc/self/cmdline");
var fd = open(path, 0);
if (fd != -1)
{
var buffer = Memory.alloc(0x1000);
var result = read(fd, buffer, 0x1000);
close(fd);
result = ptr(buffer).readCString();
return result;
}
return "-1";
}
function frida_Memory(pattern)
{
Java.perform(function ()
{
console.log("头部标识:" + pattern);
var addrArray = Process.enumerateRanges("r--");
for (var i = 0; i < addrArray.length; i++)
{
var addr = addrArray;
Memory.scan(addr.base, addr.size, pattern,
{
onMatch: function (address, size)
{
console.log('搜索到 ' + pattern + " 地址是:" + address.toString());
console.log(hexdump(address,
{
offset: 0,
length: 64,
header: true,
ansi: true
}
));
//0x108,0x10C如果不行,换0x100,0x104
var DefinitionsOffset = parseInt(address, 16) + 0x108;
var DefinitionsOffset_size = Memory.readInt(ptr(DefinitionsOffset));
var DefinitionsCount = parseInt(address, 16) + 0x10C;
var DefinitionsCount_size = Memory.readInt(ptr(DefinitionsCount));
//根据两个偏移得出global-metadata大小
var global_metadata_size = DefinitionsOffset_size + DefinitionsCount_size
console.log("大小:", global_metadata_size);
var file = new File("/data/data/" + get_self_process_name() + "/global-metadata.dat", "wb");
file.write(Memory.readByteArray(address, global_metadata_size));
file.flush();
file.close();
console.log('导出完毕...');
},
onComplete: function ()
{
//console.log("搜索完毕")
}
}
);
}
}
);
}
setImmediate(frida_Memory("AF 1B B1 FA 18")); //global-metadata.dat头部特征
安装游戏后,游戏启动,attach上
https://p3.ssl.qhimg.com/t01fc9d50127e8a3cdd.png
导出的文件在你的游戏的私有目录下,/data/data/yourpackagename/global-metadata.dat
之后导出放在电脑上,使用010查看
https://p2.ssl.qhimg.com/t01a724131e2e49bd12.png
嗯,正常了,最后在使用Il2CppDumper导出dump.cs,
那就可以愉快的分析了。。。
以上仅供学习,切勿用于非法用途,文章如有侵犯,请联系文章对应版主删除
本帖最后由 JMBQ 于 2021-1-1 13:36 编辑
这招能治三崩子?
改了几次,100104也试了,头也换了,貌似不行,还是谢谢楼主分享
C:\Users\Administrator>frida -U -l global-metadata_dump.js com.miHoYo.bh3.huawei
____
/ _| Frida 14.2.2 - A world-class dynamic instrumentation toolkit
| (_| |
> _| Commands:
/_/ |_| help -> Displays the help system
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at https://www.frida.re/docs/home/
Attaching...
头部标识:AF 1B B1 FA
TypeError: cannot read property 'apply' of undefined
at <anonymous> (frida/runtime/core.js:45)
->
楼主你好,最近试了两个软件都是dump错误{:301_1008:}
需要输入什么口令,具体的内容如下
Initializing metadata...
Metadata Version: 24.2
Initializing il2cpp file...
Applying relocations...
Il2Cpp Version: 24.2
Searching...
CodeRegistration : 0
MetadataRegistration : 0
ERROR: No symbol is detected
ERROR: Can't use auto mode to process file, try manual mode.
Input CodeRegistration:
是什么原因呢? 谢谢分享:victory: 不明觉历!感谢分享! 顶一个顶一个顶一个 用心讨论,共获提升! 感谢楼主分享 好厉害,学习了 厉害,晚上回去试试 遇到魔改的就报废了, 建议直接dump maps的地址