最近我开始使用 Frida 并尝试使用一些本地方法。但是我在读取 basic_string
这是我正在使用的方法:
这是我用来 Hook 方法的 JavaScript 代码:
Interceptor.attach(Module.getExportByName('libsigning.so', '_ZN8Security4signEP7_JNIEnvP6rsa_stRKNSt6__ndk112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEE'), {
onEnter: function (args) {
console.log("RSA.sign()")
console.log(Memory.readCString(args[2]))
},
onLeave: function (retval) {
// simply replace the value to be returned with 0
return retval
}
});
在输出中我得到了!字符而不是实际值
这样做的正确方法是什么?
最佳答案
使用这个 frida 代码解决了问题:
function readStdString (str) {
const isTiny = (str.readU8() & 1) === 0;
if (isTiny) {
return str.add(1).readUtf8String();
}
return str.add(2 * Process.pointerSize).readPointer().readUtf8String();
}
来源:https://codeshare.frida.re/@oleavr/read-std-string/
最终工作代码:
Interceptor.attach(Module.getExportByName('libsigning.so', '_ZN8Security4signEP7_JNIEnvP6rsa_stRKNSt6__ndk112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEE'), {
onEnter: function (args) {
console.log("RSA.sign()")
console.log(readStdString(args[2]))
},
onLeave: function (retval) {
// simply replace the value to be returned with 0
return retval
}
});
关于javascript - 从 frida hook 本地方法 basic_string 参数中读取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68243063/