Convert AT&T syntax to Intel Syntax (ASM)

你。 提交于 2019-12-24 00:57:07

问题


I've been trying to access the peb information of an executable as seen here: Access x64 TEB C++ & Assembly

The code works only in AT&T syntax for some odd reason but when I try to use Intel syntax, it fails to give the same value. There's of course an error on my part. So I'm asking..

How can I convert:

int main()
{
    void* ptr = 0; //0x7fff5c4ff3c0
    asm volatile
    (
        "movq %%gs:0x30, %%rax\n\t"
        "movq 0x60(%%rax), %%rax\n\t"
        "movq 0x18(%%rax), %%rax\n\t"
        "movq %%rax, %0\n"
        : "=r" (ptr) ::
    );
}

to Intel Syntax?

I tried:

asm volatile
(
    "movq rax, gs:[0x30]\n\t"
    "movq rax, [rax + 0x60]\n\t"
    "movq rax, [rax + 0x18]\n\t"
    "movq rax, %0\n"
    : "=r" (ptr) ::
);

and:

asm volatile
(
    "mov rax, QWORD PTR gs:[0x30]\n\t"
    "mov rax, QWORD PTR [rax + 0x60]\n\t"
    "mov rax, QWORD PTR [rax + 0x18]\n\t"
    "movq rax, %0\n"                     //mov rax, QWORD PTR [%0]\n
    : "=r" (ptr) ::
);

They do not print the same value as the AT&T syntax: 0x7fff5c4ff3c0

Any ideas?


回答1:


You forgot to reverse operand order on the last line. That said, the only instruction you need to have in asm is the first one due to the gs segment override, the rest could be done in C.



来源:https://stackoverflow.com/questions/21974224/convert-att-syntax-to-intel-syntax-asm

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