【问题标题】:right i have this code and the system command keeps coming up with errors [closed]对,我有这段代码,系统命令不断出现错误[关闭]
【发布时间】:2018-04-30 14:59:43
【问题描述】:

我正在尝试使用蛮力

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
        int i;
        while (i <= 999999 ) {
                system("./lock", i); 
                i++;
        }
        printf("Error. Unable to crack file.\n");
        return 0;
}

我正在尝试将值“i”放入系统命令中,这样当我对我的文件运行它时,它就会得到 pin。但我不断收到系统命令错误,我希望它在 Linux 终端中运行。

喜欢这个

./lock 1
./lock 2
./lock 3
etc.

但是,如果您知道检测它是否已被破解的方法,请同时添加。如果可以的话。

【问题讨论】:

  • 编译器应该警告你你正在使用一个未初始化变量i,并且system()有太多参数。
  • 我用的是 man 3 系统。它并没有帮助所有人。我在谷歌上搜索了 5 个小时才找到问题,但我仍然看不到问题。
  • 我明白了,prog.c:9:17: error: too many arguments to function ‘system’。那个错误信息是不是不够清楚?
  • 5小时,你没发现system不能带两个参数??它只需要一个参数。 负责将所有输入合并到一个参数中。 (见我的回答,以及sprintf的使用)

标签: c


【解决方案1】:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i = 0;
    while (i <= 999999 )
    {
        char cmd[100];
        sprintf(cmd, "./lock %d", i);
        if (system(cmd) == 0)
        {
            printf("Success with i = %d\n", i);
            exit(0);
        }
        ++i;
    }
    return !printf("Error. Unable to crack file.\n");
}

【讨论】:

  • 我想知道sprintf 是否与sprintf_s 混淆了。
  • 它成功了,但在第一次尝试时就停止了。我正在尝试找到解决此问题的方法。
  • 那你没有足够详细地描述lock程序做了什么,或者它什么时候成功,或者它做了什么。
猜你喜欢
  • 2012-03-24
  • 2018-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-26
  • 2019-01-26
相关资源
最近更新 更多