Definición de Bytes en GCC Inline Assembly en Dev-C ++ (. Ascii en la sintaxis de AT & T en Windows)

StackOverflow https://stackoverflow.com/questions/3712062

Pregunta

El código de abajo solo se muestra un cuadro de mensaje en la pantalla.
Las direcciones están codificados para facilitar:

int main ()
{
    asm("xorl %eax, %eax        \n"
        "xorl %ebx, %ebx        \n"
        "xorl %ecx, %ecx        \n"
        "xorl %edx, %edx        \n"
        "pushl %ecx             \n" //$0x0
        "pushl $0x20206c6c      \n" //"  ll"
        "pushl $0x642e3233      \n" //"d.23"
        "pushl $0x72657375      \n" //"resu"
        "movl %esp, %ecx        \n" //store "user32.dll" address in %ecx
        "movl $0x7c801d7b, %ebx \n" //store address of LoadLibraryA in %ebx
        "pushl %ecx             \n"
        "call *%ebx             \n"
        "movl $0xef30675e, %ecx \n"
        "addl $0x11111111, %ecx \n"
        "pushl %ecx             \n"
        "pushl $0x42656761      \n"
        "pushl $0x7373654d      \n"
        "movl %esp, %ecx        \n"
        "pushl %ecx             \n"
        "pushl %eax             \n"
        "movl $0x7c80ae40, %ebx \n"
        "call *%ebx             \n"
        "movl %esp, %ecx        \n"
        "xorl %edx, %edx        \n"
        "pushl %edx             \n"
        "pushl %ecx             \n"
        "pushl %ecx             \n"
        "pushl %edx             \n"
        "call *%eax             \n"
        "xorl %eax, %eax        \n"
        "pushl %eax             \n"
        "movl $0x7c81cb12, %eax \n"
        "call *%eax             \n"
    );
}

(I no hizo ningún comentario todo el código, porque mi pregunta no es realmente sobre el código)

Mi pregunta es: ¿Hay una manera de escribir la cadena "user32.dll" en ensamblador en línea sin empujar manualmente a la pila? Me refiero a como esta en NASM: db 'Hello'

Sé que en la sintaxis de AT & T que podía hacer .ascii 'Hello' o .string 'Hello' pero ¿qué hay en la línea de gcc?

Tenga en cuenta que estoy usando Dev-C ++ en Windows XP SP3

Gracias!

¿Fue útil?

Solución

Yes, by making use of assembler directives inside your inline assembler. The trick is in putting the string in the right place (the data section), which you can do by switching using .section .data, and then switching back again with .section .text.

You must give the data a label so that you can refer to it; I would recommend using the local label syntax here (where the label is a number, e.g. 1:, and you reference it as either 1b for the first 1: label backwards, or 1f for the first 1: label forwards - see the GNU assembler documentation for more details).

Like this:

int main(void)
{
  asm(".section .data      \n"
      "1: .asciz \"Hello\" \n"
      ".section .text      \n"
      "pushl $1b           \n"
      "call _puts          \n"
      "add $4, %esp        \n"
     );
  return 0;
}

I don't have a Windows system handy to test this on, but it compiles OK and looks like it should be doing the right thing using a MinGW cross-compiler on Linux (I believe Dev-C++ is based on MinGW).

Note: this technique is generally applicable when using a GNU toolchain. If you're building ELF binaries (e.g. native Linux), there is a neater way to switch back to the text section, which is to use .previous, which means "whatever the section before the previous .section was". (The above example works on Linux if you change _puts to puts to account for different symbol prefixing conventions.)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top