Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. #define _BSD_SOURCE
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <unistd.h>
  6. #include <mhash.h>
  7.  
  8. /* WARNING: Do not debug this program. Halting on breakpoints at the wrong
  9. * time can be extremely hazardous. YOU HAVE BEEN WARNED. */
  10.  
  11. /* Structures used to define our layout. Note the careful use of volatile;
  12. * we don't want the compiler optimising away part of the invocation. */
  13.  
  14. typedef struct
  15. {
  16. const char name[7]; /* sigil at focus */
  17. volatile int target; /* summoning point */
  18. volatile char invocation; /* current char of invocation */
  19. } focus_t;
  20.  
  21. typedef struct node
  22. {
  23. const char name[4]; /* name of node */
  24. focus_t* center; /* points to the evocation focus */
  25. struct node* cw; /* clockwise binding ring */
  26. struct node* ccw; /* counterclockwise binding ring */
  27. struct node* star; /* next node of star */
  28. const char* linkname; /* name of star linkage */
  29. volatile uint32_t angel; /* protective angel for this node */
  30. } node_t;
  31.  
  32. /* The pentacle nodes are circularly linked in both directions to form
  33. * a binding perimeter. In addition, they are singly linked to form a
  34. * classic 'daemon trap' five-pointed star. Each node points towards the
  35. * evocation focus (but not the other way around!) to enforce the geometry
  36. * we want. The design is based heavily on the Pentagram of Solomon. */
  37.  
  38. struct
  39. {
  40. focus_t focus;
  41. node_t node[5];
  42. }
  43. S =
  44. {
  45. /* None of the symbols for the pentacle are in Unicode. So we have to make
  46. * do with Latin transcriptions. */
  47. .focus = { "SOLUZEN", 0 },
  48. .node = {
  49. [0] = { "TE", &S.focus, &S.node[1], &S.node[4], &S.node[2], "BELLONY" },
  50. [1] = { "TRA", &S.focus, &S.node[2], &S.node[0], &S.node[3], "HALLIY" },
  51. [2] = { "GRAM", &S.focus, &S.node[3], &S.node[1], &S.node[4], "HALLIZA" },
  52. [3] = { "MA", &S.focus, &S.node[4], &S.node[2], &S.node[0], "ABDIA" },
  53. [4] = { "TON", &S.focus, &S.node[0], &S.node[3], &S.node[1], "BALLATON" }
  54. }
  55. };
  56.  
  57. /* Name of spirit to summon --- rot13'd for safety.
  58. * (#65 from Crowley's translation of SHEMHAMPHORASH.)
  59. * This is Andrealphus, he that has dominion over menusuration, astronomy and
  60. * geometry. He seems fairly non-threatening. */
  61.  
  62. const char spiritname[] = "NAQERNYCUHF";
  63. int rot13(int c) { return 'A' + (((c - 'A') + 13) % 26); }
  64.  
  65. /* We invoke the following names around the circle as a protective measure.
  66. * Strictly these should be in Hebrew script, but as the computer is a dumb
  67. * instrument we're relying on the symbolism rather than the actual literal
  68. * meaning themselves. Plus, working in RTL is a pain. */
  69.  
  70. const char* angels[] = {
  71. "Kether", "Eheieh", "Metatron", "Chaioth ha-Qadesh",
  72. "Rashith ha-Gilgalim", "Chokmah", "Jah", "Ratziel", "Auphanim",
  73. "Masloth", "Binah", "Jehovah Elohim", "Tzaphkiel", "Aralim",
  74. "Shabbathai", "Chesed", "El", "Tzadkiel", "Chasmalim", "Tzadekh",
  75. "Geburah", "Elohim Gibor", "Khamael", "Seraphim", "Madim",
  76. "Tiphareth", "Eloah Va-Daath", "Raphael", "Malachim", "Shemesh",
  77. "Netzach", "Jehovah Sabaoth", "Haniel", "Elohim", "Nogah", "Hod",
  78. "Elohim Sabaoth", "Michael", "Beni Elohim", "Kokab", "Yesod",
  79. "Shaddai El Chai", "Gabriel", "Cherubim", "Levanah"
  80. };
  81. const int angelcount = sizeof(angels)/sizeof(*angels);
  82.  
  83. /* Place the next angel on the pentacle. */
  84.  
  85. static void updatepentacle()
  86. {
  87. static int angelnode = 0;
  88. static int angelindex = 0;
  89.  
  90. const char* angel = angels[angelindex++];
  91. angelindex %= angelcount;
  92.  
  93. /* Hash the angel's name to reduce its essence to 32 bits (which lets us
  94. * copy the angel bodily into the pentacle node. */
  95.  
  96. uint32_t angelhash;
  97. MHASH td = mhash_init(MHASH_CRC32);
  98. mhash(td, angel, strlen(angel));
  99. mhash_deinit(td, &angelhash);
  100.  
  101. S.node[angelnode].angel = angelhash;
  102. angelnode = (angelnode + 1) % 5;
  103. }
  104.  
  105. int main(int argc, const char* argv[])
  106. {
  107. /* Lock the evocation into memory, to prevent it from being paged out
  108. * while the spirit has manifested --- which would be bad. */
  109.  
  110. int e = mlock(&S, sizeof(S));
  111. if (e != 0)
  112. {
  113. fprintf(stderr, "Unable to lock evocation, refusing to runn");
  114. exit(1);
  115. }
  116.  
  117. /* Actually perform the invocation: continually cycle the spirit's
  118. * name into the evocation focus (while maintaining our pentacle
  119. * integrity!) until something shows up in the target of the
  120. * evocation focus. */
  121.  
  122. printf("Summoning...n");
  123. do
  124. {
  125. for (int i = 0; i < sizeof(spiritname)-1; i++)
  126. {
  127. S.focus.invocation = rot13(spiritname[i]);
  128. updatepentacle();
  129. usleep(100); /* don't CPU-starve our spirit */
  130. }
  131. }
  132. while (S.focus.target == 0);
  133. printf("Summoning successful! %dn", S.focus.target);
  134.  
  135. /* Our spirit's arrived! Dismiss it immediately by using a null
  136. * invocation. Keep going until the evocation focus remains empty.
  137. * FIXME: a particularly mean spirit might find a way to hide. Until
  138. * we can sort this out, only summon relatively benign ones. This is
  139. * probably safe anyway, as when the process terminates the spirit's
  140. * address space will be nuked, taking the spirit with it. */
  141.  
  142. printf("Dismissing...n");
  143. do
  144. {
  145. S.focus.target = 0;
  146. for (int i = 0; i < 1000; i++)
  147. {
  148. S.focus.invocation = 0;
  149. updatepentacle();
  150. }
  151. }
  152. while (S.focus.target != 0);
  153.  
  154. printf("Done.n");
  155. return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement