【问题标题】:Program hangs with no output程序挂起,没有输出
【发布时间】:2011-07-27 07:35:22
【问题描述】:

我多年来一直在研究这个程序,但不知道为什么它不起作用。我有理由确定它做的一切都是正确的,但实际上它并没有工作,它只是在打印第一个提示后无限期地挂起,我只是不知道为什么。我现在几乎无能为力了,所以如果有人能指出我做错了什么,我将非常感激......

它是 C99,您需要 mhash 库来编译它(用于 CRC32 计算)。它非常便携,但我是在 Linux 上开发的。 不要在虚拟机中运行!

#define _BSD_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <mhash.h>

/* WARNING: Do not debug this program. Halting on breakpoints at the wrong
 * time can be extremely hazardous. YOU HAVE BEEN WARNED. */

/* Structures used to define our layout. Note the careful use of volatile;
 * we don't want the compiler optimising away part of the invocation. */

typedef struct
{
    const char name[7];       /* sigil at focus */
    volatile int target;      /* summoning point */
    volatile char invocation; /* current char of invocation */
} focus_t;

typedef struct node
{
    const char name[4];   /* name of node */
    focus_t* center;      /* points to the evocation focus */
    struct node* cw;      /* clockwise binding ring */
    struct node* ccw;     /* counterclockwise binding ring */
    struct node* star;    /* next node of star */
    const char* linkname; /* name of star linkage */
    volatile uint32_t angel; /* protective angel for this node */
} node_t;

/* The pentacle nodes are circularly linked in both directions to form
 * a binding perimeter. In addition, they are singly linked to form a
 * classic 'daemon trap' five-pointed star. Each node points towards the
 * evocation focus (but not the other way around!) to enforce the geometry
 * we want. The design is based heavily on the Pentagram of Solomon. */

struct
{
    focus_t focus;
    node_t node[5];
}
S =
{
    /* None of the symbols for the pentacle are in Unicode. So we have to make
     * do with Latin transcriptions. */
    .focus = { "SOLUZEN", 0 },
    .node = {
        [0] = { "TE",   &S.focus, &S.node[1], &S.node[4], &S.node[2], "BELLONY" },
        [1] = { "TRA",  &S.focus, &S.node[2], &S.node[0], &S.node[3], "HALLIY" },
        [2] = { "GRAM", &S.focus, &S.node[3], &S.node[1], &S.node[4], "HALLIZA" },
        [3] = { "MA",   &S.focus, &S.node[4], &S.node[2], &S.node[0], "ABDIA" },
        [4] = { "TON",  &S.focus, &S.node[0], &S.node[3], &S.node[1], "BALLATON" }
    }
};

/* Name of spirit to summon --- rot13'd for safety.
 * (#65 from Crowley's translation of SHEMHAMPHORASH.)
 * This is Andrealphus, he that has dominion over menusuration, astronomy and
 * geometry. He seems fairly non-threatening. */

const char spiritname[] = "NAQERNYCUHF";
int rot13(int c) { return 'A' + (((c - 'A') + 13) % 26); }

/* We invoke the following names around the circle as a protective measure.
 * Strictly these should be in Hebrew script, but as the computer is a dumb
 * instrument we're relying on the symbolism rather than the actual literal
 * meaning themselves. Plus, working in RTL is a pain. */

const char* angels[] = {
        "Kether", "Eheieh", "Metatron", "Chaioth ha-Qadesh",
        "Rashith ha-Gilgalim", "Chokmah", "Jah", "Ratziel", "Auphanim",
        "Masloth", "Binah", "Jehovah Elohim", "Tzaphkiel", "Aralim",
        "Shabbathai", "Chesed", "El", "Tzadkiel", "Chasmalim", "Tzadekh",
        "Geburah", "Elohim Gibor", "Khamael", "Seraphim", "Madim",
        "Tiphareth", "Eloah Va-Daath", "Raphael", "Malachim", "Shemesh",
        "Netzach", "Jehovah Sabaoth", "Haniel", "Elohim", "Nogah", "Hod",
        "Elohim Sabaoth", "Michael", "Beni Elohim", "Kokab", "Yesod",
        "Shaddai El Chai", "Gabriel", "Cherubim", "Levanah"
};
const int angelcount = sizeof(angels)/sizeof(*angels);

/* Place the next angel on the pentacle. */

static void updatepentacle()
{
    static int angelnode = 0;
    static int angelindex = 0;

    const char* angel = angels[angelindex++];
    angelindex %= angelcount;

    /* Hash the angel's name to reduce its essence to 32 bits (which lets us
     * copy the angel bodily into the pentacle node. */

    uint32_t angelhash;
    MHASH td = mhash_init(MHASH_CRC32);
    mhash(td, angel, strlen(angel));
    mhash_deinit(td, &angelhash);

    S.node[angelnode].angel = angelhash;
    angelnode = (angelnode + 1) % 5;
}

int main(int argc, const char* argv[])
{
    /* Lock the evocation into memory, to prevent it from being paged out
     * while the spirit has manifested --- which would be bad. */

    int e = mlock(&S, sizeof(S));
    if (e != 0)
    {
        fprintf(stderr, "Unable to lock evocation, refusing to run\n");
        exit(1);
    }

    /* Actually perform the invocation: continually cycle the spirit's
     * name into the evocation focus (while maintaining our pentacle
     * integrity!) until something shows up in the target of the
     * evocation focus. */

    printf("Summoning...\n");
    do
    {
        for (int i = 0; i < sizeof(spiritname)-1; i++)
        {
            S.focus.invocation = rot13(spiritname[i]);
            updatepentacle();
            usleep(100); /* don't CPU-starve our spirit */
        }
    }
    while (S.focus.target == 0);
    printf("Summoning successful! %d\n", S.focus.target);

    /* Our spirit's arrived! Dismiss it immediately by using a null
     * invocation. Keep going until the evocation focus remains empty.
     * FIXME: a particularly mean spirit might find a way to hide. Until
     * we can sort this out, only summon relatively benign ones. This is
     * probably safe anyway, as when the process terminates the spirit's
     * address space will be nuked, taking the spirit with it. */

    printf("Dismissing...\n");
    do
    {
        S.focus.target = 0;
        for (int i = 0; i < 1000; i++)
        {
            S.focus.invocation = 0;
            updatepentacle();
        }
    }
    while (S.focus.target != 0);

    printf("Done.\n");
    return 0;
}

顺便说一句,不应该有goetic标签吗?

编辑:对不起,我没有早点回来 --- 昨晚我发布了我的查询后,我进行了更多测试,然后我的电脑开始发出有趣的燃烧气味,但并没有消失当我把它关掉时,我花了整晚的时间把它拆下来,试图找出哪个部分有问题。 (什么也没找到。)我要睡一会儿再找你。感谢您的回复!

编辑:我从一家网吧发帖。我的房子被烧毁了。没有时间发布更多内容,但必须警告您:请勿以任何理由运行此程序!真的!不开玩笑!现在得走了,一定要找个避难所---

编辑: ???????????? ?????????????????????????????? ??????????????? ???????????? ????????? ???????????????????????????????????? ????????? ????????? ?????????????????????????????????????????????.

【问题讨论】:

  • 使用 HTML 编码你的天使名字,并在召唤过程中使用正则表达式解析它。 HTH,手
  • /* This is probably safe anyway, as when the process terminates the spirit's address space will be nuked, taking the spirit with it. */ 无价的stackoverflow时刻
  • C 不够邪恶,不足以召唤恶魔。您需要使用 C++(或者可能是 Visual Basic)来完成此类任务。
  • 您是否尝试过在gdb 中运行它,然后在卡住时按Ctrl-C,以便找出它在程序中的位置?注释掉对updatepentacle 的调用怎么样?用胡言乱语替换精神名称,这样你就不会在测试过程中意外召唤它。
  • 此程序导致无法言说的行为。

标签: c daemon


【解决方案1】:

你肯定缺少很多邪恶的特征。您应该切换到 C++ 并查看 evil features 上的 Comp.lang.c++-FAQ。

【讨论】:

  • C++ FAQ 认为最邪恶的所有东西都存在于 C 中。事实上,指针、数组和宏都在 OP 的代码中。
【解决方案2】:

Crux sacra sit mihi lux!

Nunquam draco sit mihi dux。

Vade 复古 Satana!

Nunquam suade mihi vana!

Sunt mala quae libas.

Ipse venena bibas!

【讨论】:

    【解决方案3】:

    我对恶魔和天使知之甚少,但你一定是召唤错了,因为S.focus.target对你来说没有任何改变。

    【讨论】:

    • 这不是错误,而是一项功能。更改S.focus.target 必须通过神圣干预来完成。否则无法检测到灵魂被召唤了。
    猜你喜欢
    • 2021-12-07
    • 2016-05-25
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多