Get linear address of FS:[0] in 32-bit protected mode / MSVC inline asm

别来无恙 提交于 2019-12-10 18:22:07

问题


I used this instruction in Visual C++ inline assembly

lea eax, FS:[0]

Why did eax get a zero?

And how do I get the linear address of FS:[0]?


回答1:


Assuming FS points to the Windows Thread Information Block (TIB), also known as the Thread Environment Block (TEB), you get the linear address of the TIB by reading the 32-bit value at fs:[0x18]. The best way to do this in Visual C++ is to use the __readfsdword intrinsic:

TEB *teb = (TEB *) __readfsdword(0x18);



回答2:


The LEA instruction ("Load Effective Address") is badly named (e.g. should probably be called LEO/"Load Effective Offset") because it only calculates the offset within a segment.



来源:https://stackoverflow.com/questions/47589280/get-linear-address-of-fs0-in-32-bit-protected-mode-msvc-inline-asm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!