GCC汇编语言编译错误

时间:2015-10-12 08:50:35

标签: linux gcc compiler-errors inline-assembly 32-bit

void main()
{
    __asm__
        (
         "jmp   0x2a    
         popl   %esi
         movl   %esi, 0x8(%esi)
         movb   $0x0, 0x7(%esi)
         movl   $0x0, 0xc(%esi)
         movl   $0xb, %eax
         movl   %esi, %ebx
         leal   0x8(%esi), %ecx
         leal   0xc(%esi), %edx
         int    $0x80
         movl   $0x1, %eax
         movl   $0x0, %ebx
         int    $0x80
         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

我是这方面的新手。

1 个答案:

答案 0 :(得分:2)

虽然我已将此识别为另一个问题的副本,但您可以通过在每行内联汇编的开头和结尾放置引号并在每个字符串的末尾嵌入换行符来解决此问题:

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