查找另一个线程的线程信息块
有没有办法找到进程中运行的另一个线程的线程信息块(TIB)?
我需要为另一个线程构造一个异常处理程序,但我无法在线程本身中执行此操作。因此我需要找到它的 TIB 并从另一个线程内部构造它。我怎样才能实现这个目标?
Is there a way to find the Thread Information Block (TIB) of another thread running in your process?
I need to construct an exception handler for another thread but I can't do it in the thread itself. Therefore I need to find it's TIB and construct it from inside another thread. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以直接从 FS 寄存器访问 TIB 的地址(检查 http://www. microsoft.com/msj/archive/S2CE.aspx)。
因此,要获取另一个线程的 TIB,也许可以使用 GetThreadContext() 来获取 FS 的值,从而获取 TIB 的地址? (只是猜测,我没有尝试过!)
You can access the address of the TIB directly from the FS register (check http://www.microsoft.com/msj/archive/S2CE.aspx).
So to get the TIB for another thread maybe can use GetThreadContext() to get the value of FS and therefore the address of the TIB? (just a guess, I didn't try this!)
参考文献:
http://recxltd.blogspot.de /2012/02/from-archives-printing-seh-chain-from.html
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679362(v=vs.85).aspx
完整示例程序:http://pastebin.com/gSTcPz1y
References:
http://recxltd.blogspot.de/2012/02/from-archives-printing-seh-chain-from.html
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679362(v=vs.85).aspx
Complete sample program: http://pastebin.com/gSTcPz1y
这可能不起作用,但请尝试对用户模式 APC 进行排队 到设置异常处理程序的目标线程。
This may not work, but try queueing a user-mode APC to the target thread which sets up your exception handler.
您可以获得线程的 TIB,但更改它我非常怀疑您是否可以做到。
正如 Paul 正确指出的那样,这只会获取它所使用的线程的 TIB,因此我建议在需要此数据的线程中调用它,然后将其移动到需要使用它的线程。
要获得它,您可以使用类似的东西,如此处所述:
You can get the TIB of a thread, but altering it I doubt very much you can do.
As correctly pointed out by Paul, this only gets the TIB for the thread it's used it, so I suggest calling it in the thread from which you need this data and then moving it to the thread where you need to use it.
To get it you can use something like this, described here: