admin管理员组文章数量:1318572
Recently I started using Frida and playing with some native methods. But i have a problem with reading value of basic_string
Here is method which I'm hooking:
Here is JavaScript code which I'm using to hook method:
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
}
});
In output I'm getting ! character instead of real value
What is a proper way of doing this?
Recently I started using Frida and playing with some native methods. But i have a problem with reading value of basic_string
Here is method which I'm hooking:
Here is JavaScript code which I'm using to hook method:
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
}
});
In output I'm getting ! character instead of real value
What is a proper way of doing this?
Share Improve this question edited Jul 7, 2021 at 7:05 Robert 42.8k18 gold badges109 silver badges172 bronze badges asked Jul 4, 2021 at 8:50 KaspekKaspek 3754 silver badges19 bronze badges 2-
2
Seems like
basic_string
is not a pointer to achar[]
but to a C++ object. Therefore when directly using that pointer you interpret the c++ instance data as string which does not work. See en.cppreference./w/cpp/string/basic_string and stek29.rocks/2017/08/07/frida-stdstring.html and codeshare.frida.re/@oleavr/read-std-string – Robert Commented Jul 4, 2021 at 10:59 - Robert thanks for your answer, you solved my problem <3 – Kaspek Commented Jul 4, 2021 at 11:37
1 Answer
Reset to default 6Problem was resolved using this frida code:
function readStdString (str) {
const isTiny = (str.readU8() & 1) === 0;
if (isTiny) {
return str.add(1).readUtf8String();
}
return str.add(2 * Process.pointerSize).readPointer().readUtf8String();
}
source: https://codeshare.frida.re/@oleavr/read-std-string/
final working code:
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
}
});
本文标签: javascriptRead value from frida hooked native method basicstring parameterStack Overflow
版权声明:本文标题:javascript - Read value from frida hooked native method basic_string parameter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742047978a2417903.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论