GCC 汇编语言编译器错误

GCC assembly language compiler errors

void main()
{
    __asm__
        (
         "jmp   0x2a    
         popl   %esi
         movl   %esi, 0x8(%esi)
         movb   [=10=]x0, 0x7(%esi)
         movl   [=10=]x0, 0xc(%esi)
         movl   [=10=]xb, %eax
         movl   %esi, %ebx
         leal   0x8(%esi), %ecx
         leal   0xc(%esi), %edx
         int    [=10=]x80
         movl   [=10=]x1, %eax
         movl   [=10=]x0, %ebx
         int    [=10=]x80
         call   -0x2f 
         .string \"/bin/sh\"
         ");
}

我遵循了 shellcode 教程,但是当我使用 gcc shellcodeasm.c 编译它时,出现以下错误:

shellcodeasm.c: In function ‘main’:
shellcodeasm.c:5:4: warning: missing terminating " character [enabled by default]
    "jmp 0x2a  
    ^
shellcodeasm.c:5:4: error: missing terminating " character
shellcodeasm.c:6:4: error: expected string literal before ‘popl’
    popl %esi
    ^
shellcodeasm.c:19:4: error: stray ‘\’ in program
    .string \"/bin/sh\"
    ^
shellcodeasm.c:19:13: warning: missing terminating " character [enabled by default]
    .string \"/bin/sh\"
             ^
shellcodeasm.c:19:4: error: missing terminating " character
    .string \"/bin/sh\"
    ^
shellcodeasm.c:20:4: warning: missing terminating " character [enabled by default]
    ");
    ^
shellcodeasm.c:20:4: error: missing terminating " character

我是这方面的新手。

虽然我已经确定这是另一个问题的重复,但您可以通过在内联汇编的每一行的开头和结尾放置一个引号并在每个字符串的末尾嵌入一个换行符来解决这个问题:

void main()
{
    __asm__
        (
         "jmp   0x2a\n"
         "popl   %esi\n"
         "movl   %esi, 0x8(%esi)\n"
         "movb   [=10=]x0, 0x7(%esi)\n"
         "movl   [=10=]x0, 0xc(%esi)\n"
         "movl   [=10=]xb, %eax\n"
         "movl   %esi, %ebx\n"
         "leal   0x8(%esi), %ecx\n"
         "leal   0xc(%esi), %edx\n"
         "int    [=10=]x80\n"
         "movl   [=10=]x1, %eax\n"
         "movl   [=10=]x0, %ebx\n"
         "int    [=10=]x80\n"
         "call   -0x2f\n"
         ".string \"/bin/sh\"\n"
         );
}