访问64 TEB C ++&放大器;部件 [英] Access x64 TEB C++ & Assembly

查看:777
本文介绍了访问64 TEB C ++&放大器;部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在32位汇编​​,我可以访问 ProcessEnvironmentBlock 的TEB 结构。从那里,我访问中队长 TEB 结构。

In 32-bit assembly, I can access the ProcessEnvironmentBlock of the TEB structure. From there I access Ldr of the TEB structure.

此技术说明如下: http://en.wikipedia.org/wiki/Win32_Thread_Information_Block

在code在32位汇编​​要做到这一点:

The code to do this in 32-bit assembly is:

void* ptr = NULL;

__asm
{
    mov eax, FS:[0x18]
    mov eax, [eax + 0x30]  //Offset of PEB
    mov eax, [eax + 0x0C]  //Offset of LDR in PEB structure
    mov eax, _ptr
};

std::cout<<ptr<<"\n";

的TEB结构可以在这里看到: http://msdn.moonsols.com/win7rtm_x64/ TEB.html
和PEB结构可以看这里: http://msdn.moonsols.com/win7rtm_x64/PEB。 HTML

以上作品的32位code。

The above works for 32-bit code.

不过,我还想写code到x64机器上工作。我看到的结构x64版本写道:

However, I want to also write code to work on x64 machines. I viewed the x64 version of the structures and wrote:

__asm
{
    mov rax, GS:[0x30]
    mov rax, [rax + 0x60]
    mov rax, [rax + 0x18]
    mov rax, _ptr
};

这是可以做到用 WINNT.H NtCurrentTeb(),但我想使用汇编。

This can be done using Winnt.h NtCurrentTeb() but I want to use assembly.

但是,它不能在所有工作。任何想法,为什么?

However, it fails to work at all. Any ideas why?

推荐答案

Visual Studio中不允许的内联汇编为X64 C ++。不支持__asm​​关键字。你可以写你的汇编在一个单独的文件和链接它,也可以使用内部函数做你需要做的事情。

Visual studio doesn't allow inline assembler for X64 C++. The __asm keyword isn't supported. You can write your assembler in a separate file and link it in or you can use intrinsics do what you need to do.

这篇关于访问64 TEB C ++&放大器;部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆