-
-
[分享]frida 主动调用系统api,获取文件长度
-
发表于: 2025-5-28 14:17 345
-
环境:frida12.8.0 安卓7.1
在frida主动调用so的函数时,遇到arg2需要存入arg1(文件路径)的长度
一开始使用js的原生Path进行处理,但是老是失败(希望大佬可以指出问题)。
var file = new File(path, "rb");
var size = 0;
var chunk;
while (chunk == file.read(4096)) {
size += chunk.length;
}
file.close();
return size;后来想想,会不会是不兼容,后来就想到能不能主动调用安卓相关api,来实现。
手动调用 libc 函数(fopen/fseek/ftell)
var fopen = Module.findExportByName(null, "fopen");
var fseek = Module.findExportByName(null, "fseek");
var ftell = Module.findExportByName(null, "ftell");
var fclose = Module.findExportByName(null, "fclose");
if (fopen && fseek && ftell) {
var open = new NativeFunction(fopen, 'pointer', ['pointer', 'pointer']);
var seek = new NativeFunction(fseek, 'int', ['pointer', 'int', 'int']);
var tell = new NativeFunction(ftell, 'int', ['pointer']);
var close = new NativeFunction(fclose, 'int', ['pointer']);
var pathPtr = Memory.allocUtf8String(path);
var modePtr = Memory.allocUtf8String("rb");
var file = open(pathPtr, modePtr);
if (!file.isNull()) {
seek(file, 0, 2); // SEEK_END = 2
var size = tell(file);
close(file);
return size;
}ok,一下子就调用成功了
记录下来供大家参考。
最后于 2025-5-28 14:30
被mb_ogvnfpfi编辑
,原因:
赞赏
他的文章
赞赏
雪币:
留言: