使用 Frida 从钩子方法中读取 uchar 值

Read uchar value from hooked method using Frida

如何读取 uchar* 的值?

我尝试了很多方法,我使用的代码是:

Interceptor.attach(Module.getExportByName('libsigning.so', 'EVP_DigestSignFinal'), {
    onEnter: function (args) {
        console.log("RSA.doFinal() [VALID]")
        console.log("arg0: OpenSSL object")
        console.log("arg1: " + Memory.readUtf8String(args[1]))
        console.log("arg2: " + args[2].readUInt())
    },
    onLeave: function (retval) {
        // simply replace the value to be returned with 0
        return retval
    }
});

我得到了什么:

RSA.doFinal() [VALID]
arg0: RSA object
arg1: 
arg2: 512

它在 ghidra 中的外观:

在输出中我得到的是未知字符而不是真实值

这样做的正确方法是什么?

你hook的方法是documented

int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen);

根据它的文档,第二个参数接收创建的签名:

signs the data in ctx and places the signature in sig. If sig is NULL then the maximum size of the output buffer is written to the siglen parameter. If sig is not NULL then before the call the siglen parameter should contain the length of the sig buffer. If the call is successful the signature is written to sig and the amount of data written to siglen.

(加密)签名是二进制数据,在 C 中,类型 unsigned char 通常用于存储此类二进制数据。因此,即使它包含名称 char,您也不会在其中找到任何可打印的字符或完整的字符串。

因此,如果您想将其打印为字符串,它将失败,因为“实际值”是二进制数据。

要读取二进制数据,您可以使用 NativePointer

中的 Frida readByteArray