The x86 MSRs can be read with the RDMSR instruction, which is privileged (Ring 0) .
(可以使用特权(Ring 0)的RDMSR指令读取x86 MSR 。)
In Linux there are system calls that a user thread can invoke to read FS_BASE and GS_BASE. (在Linux中,用户线程可以调用一些系统调用来读取FS_BASE和GS_BASE。)
There are no library wrappers for them, so you have to write code to invoke them yourself. (它们没有库包装器,因此您必须编写代码以自己调用它们。)
Here's one way to do it in C++, you add these global function definitions to your program:
(这是在C ++中执行此操作的一种方法,可以将这些全局函数定义添加到程序中:)
#include <cstdint>
#include <asm/prctl.h>
#include <sys/syscall.h>
namespace x86 {
uint64_t fs_base() {
uint64_t fs_base;
syscall(SYS_arch_prctl,ARCH_GET_FS,&fs_base);
return fs_base;
}
uint64_t gs_base() {
uint64_t gs_base;
syscall(SYS_arch_prctl,ARCH_GET_GS,&gs_base);
return gs_base;
}
}
Now you can call these functions from gdb and print their return value in hex, like this:
(现在,您可以从gdb调用这些函数,并以十六进制打印其返回值,如下所示:)
(gdb) p/x x86::fs_base()
$1 = 0x7ffff5e01780
(gdb) p/x x86::gs_base()
$2 = 0x0
(gdb)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…