ffi.toString(pointer)


从本地内存读取以 NUL 结尾的 UTF-8 字符串。

🌐 Reads a NUL-terminated UTF-8 string from native memory.

如果 pointer0n,则返回 null

🌐 If pointer is 0n, null is returned.

此函数不会验证 pointer 是否指向可读内存,也不会验证所指向的数据是否以 \0 结尾。传递无效指针、指向已释放内存的指针或指向没有终止 NUL 的字节的指针,可能会读取无关的内存、导致进程崩溃,或产生截断或乱码输出。

🌐 This function does not validate that pointer refers to readable memory or that the pointed-to data is terminated with \0. Passing an invalid pointer, a pointer to freed memory, or a pointer to bytes without a terminating NUL can read unrelated memory, crash the process, or produce truncated or garbled output.

const { toString } = require('node:ffi');

const value = toString(ptr);