|
@@ -11,7 +11,7 @@
|
|
// #include <signal.h> // handle Ctrl-C/SIGINT
|
|
// #include <signal.h> // handle Ctrl-C/SIGINT
|
|
|
|
|
|
#include <strings.h> // strcasecmp
|
|
#include <strings.h> // strcasecmp
|
|
-#include <time.h> // usleep(), nanonsleep() ?
|
|
|
|
|
|
+#include <time.h>
|
|
|
|
|
|
#include <ctype.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h> // random()
|
|
#include <stdlib.h> // random()
|
|
@@ -72,15 +72,16 @@ static void file_output_open(const char *const log_path) {
|
|
zf_log_set_output_v(ZF_LOG_PUT_STD, 0, file_output_callback);
|
|
zf_log_set_output_v(ZF_LOG_PUT_STD, 0, file_output_callback);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// END LOGGING
|
|
|
|
+
|
|
#include "terminal.h"
|
|
#include "terminal.h"
|
|
|
|
|
|
struct console_details console;
|
|
struct console_details console;
|
|
|
|
|
|
-#include "utils.h"
|
|
|
|
-
|
|
|
|
-// END LOGGING
|
|
|
|
-
|
|
|
|
|
|
+#include "images.h"
|
|
#include "lastseen.h"
|
|
#include "lastseen.h"
|
|
|
|
+#include "render.h"
|
|
|
|
+#include "utils.h"
|
|
|
|
|
|
/*
|
|
/*
|
|
What is the name of the actual, real Mystic executable
|
|
What is the name of the actual, real Mystic executable
|
|
@@ -91,32 +92,6 @@ that we'll be executing and mangling?
|
|
// Size of our input and output buffers.
|
|
// Size of our input and output buffers.
|
|
#define BSIZE 1024
|
|
#define BSIZE 1024
|
|
|
|
|
|
-/*
|
|
|
|
- * string_insert()
|
|
|
|
- * Inserts a string into a given position.
|
|
|
|
- * This safely checks to make sure the buffer isn't overrun.
|
|
|
|
- */
|
|
|
|
-int string_insert(char *buffer, int max_length, int pos, const char *insert) {
|
|
|
|
- assert(max_length > pos);
|
|
|
|
- assert(buffer != NULL);
|
|
|
|
- assert(insert != NULL);
|
|
|
|
-
|
|
|
|
- if (strlen(buffer) + strlen(insert) >= max_length) {
|
|
|
|
- ZF_LOGD("string_insert() failed inserting [%s]", repr(insert));
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- memmove(buffer + pos + strlen(insert), buffer + pos,
|
|
|
|
- strlen(buffer + pos) + 1);
|
|
|
|
- // cp + strlen(display), cp, strlen(cp) + 1);
|
|
|
|
- strncpy(buffer + pos, insert, strlen(insert));
|
|
|
|
- // (cp, display, strlen(display));
|
|
|
|
- return 1; // success
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// Should this be passed around to the functions that use it?
|
|
|
|
-
|
|
|
|
-#include "render.h"
|
|
|
|
-
|
|
|
|
/*
|
|
/*
|
|
These are harry "timeout" events.
|
|
These are harry "timeout" events.
|
|
|
|
|
|
@@ -201,17 +176,6 @@ connections.
|
|
const char *username = NULL;
|
|
const char *username = NULL;
|
|
const char *fullname = NULL;
|
|
const char *fullname = NULL;
|
|
|
|
|
|
-/*
|
|
|
|
-Pascal String Copy. Copy from pascal string, to C String.
|
|
|
|
-
|
|
|
|
-First char is pascal string length. (Max 255).
|
|
|
|
- */
|
|
|
|
-void pcopy(char *pstring, char *str) {
|
|
|
|
- int len = (int)*pstring;
|
|
|
|
- strncpy(str, pstring + 1, len);
|
|
|
|
- str[len] = 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/*
|
|
/*
|
|
This only works for those few idiots that use the
|
|
This only works for those few idiots that use the
|
|
horribly broken SSH crap that Mystic uses.
|
|
horribly broken SSH crap that Mystic uses.
|
|
@@ -490,7 +454,7 @@ int mangle(int fd, const char *buffer, int len) {
|
|
int need_render = 0; // changing word case around doesn't need the render
|
|
int need_render = 0; // changing word case around doesn't need the render
|
|
int mangled = 0;
|
|
int mangled = 0;
|
|
int mangled_chars = 0;
|
|
int mangled_chars = 0;
|
|
- char play[BSIZE * 2];
|
|
|
|
|
|
+ char play[BSIZE * 2]; // The main buffer to send.
|
|
const char *cp;
|
|
const char *cp;
|
|
|
|
|
|
// Make a copy of buffer, since it can no longer be changed
|
|
// Make a copy of buffer, since it can no longer be changed
|
|
@@ -500,7 +464,13 @@ int mangle(int fd, const char *buffer, int len) {
|
|
|
|
|
|
// NEVER reference buffer from this point on!
|
|
// NEVER reference buffer from this point on!
|
|
|
|
|
|
- char work[BSIZE * 2];
|
|
|
|
|
|
+ char work[BSIZE * 2]; // The mess with buffer.
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ We use the work buffer to blank out the ANSI
|
|
|
|
+ before trying to locate words. (So we don't
|
|
|
|
+ grab part of the ANSI codes and mangle those!)
|
|
|
|
+ */
|
|
|
|
|
|
// Use terminal - clean out ANSI
|
|
// Use terminal - clean out ANSI
|
|
|
|
|
|
@@ -552,28 +522,34 @@ int mangle(int fd, const char *buffer, int len) {
|
|
int slen;
|
|
int slen;
|
|
int needs_cls = 0;
|
|
int needs_cls = 0;
|
|
|
|
|
|
- struct file_need {
|
|
|
|
- const char *filename;
|
|
|
|
|
|
+ struct image {
|
|
|
|
+ const char **lines;
|
|
|
|
+ int size;
|
|
int cls;
|
|
int cls;
|
|
- int rand_pos;
|
|
|
|
- } possibles[] = {
|
|
|
|
- {"goofy_head", 1, 0}, {"bat", 1, 0}, {"panther", 1, 0},
|
|
|
|
- {"wolf", 1, 0}, {"skull", 0, 1}, {"skull2", 0, 1},
|
|
|
|
- {"guy", 0, 1}, {"blinkman", 0, 1}, {"ghost", 1, 0}};
|
|
|
|
|
|
+ int width; // height = size
|
|
|
|
+ } images[] = {{ghost, sizeof(ghost) / sizeof(char *), 1, 0},
|
|
|
|
+ {ghead, sizeof(ghead) / sizeof(char *), 1, 0},
|
|
|
|
+ {wolf, sizeof(wolf) / sizeof(char *), 1, 0},
|
|
|
|
+ {panther, sizeof(panther) / sizeof(char *), 1, 0},
|
|
|
|
+ {bat, sizeof(bat) / sizeof(char *), 1, 0},
|
|
|
|
+ {skull, sizeof(skull) / sizeof(char *), 0, 19},
|
|
|
|
+ {skullblink, sizeof(skullblink) / sizeof(char *), 0, 19}};
|
|
|
|
|
|
static LastSeen last_files(2);
|
|
static LastSeen last_files(2);
|
|
int r;
|
|
int r;
|
|
|
|
|
|
do {
|
|
do {
|
|
- r = randint((sizeof(possibles) / sizeof(file_need)));
|
|
|
|
|
|
+ r = randint((sizeof(images) / sizeof(image)));
|
|
} while (last_files.seen_before(r));
|
|
} while (last_files.seen_before(r));
|
|
|
|
|
|
- int x, y;
|
|
|
|
- x = randint(50) + 1;
|
|
|
|
- y = randint(12) + 1;
|
|
|
|
- char fgoto[10];
|
|
|
|
|
|
+ char fgoto[10] = "";
|
|
|
|
+
|
|
|
|
+ if (!images[r].cls) {
|
|
|
|
+ int x = 0, y = 0;
|
|
|
|
+
|
|
|
|
+ x = randint(79 - images[r].width);
|
|
|
|
+ y = randint(24 - images[r].size);
|
|
|
|
|
|
- if (possibles[r].rand_pos) {
|
|
|
|
int slen;
|
|
int slen;
|
|
slen = snprintf(fgoto, sizeof(fgoto), "^f%02d%02d", x, y);
|
|
slen = snprintf(fgoto, sizeof(fgoto), "^f%02d%02d", x, y);
|
|
if (slen >= sizeof(fgoto)) {
|
|
if (slen >= sizeof(fgoto)) {
|
|
@@ -585,7 +561,7 @@ int mangle(int fd, const char *buffer, int len) {
|
|
}
|
|
}
|
|
|
|
|
|
// (2); // (sizeof(possibles) / sizeof(file_need)) - 1);
|
|
// (2); // (sizeof(possibles) / sizeof(file_need)) - 1);
|
|
- needs_cls = possibles[r].cls;
|
|
|
|
|
|
+ needs_cls = images[r].cls;
|
|
|
|
|
|
// I get what's happening. Mystic moves cursor to home, CLS, cursor
|
|
// I get what's happening. Mystic moves cursor to home, CLS, cursor
|
|
// home. When we get here, we're ALWAYS at the top of the screen...
|
|
// home. When we get here, we're ALWAYS at the top of the screen...
|
|
@@ -595,9 +571,12 @@ int mangle(int fd, const char *buffer, int len) {
|
|
// I tried a ^P2 before doing this .. but I'd rather have the picture up
|
|
// I tried a ^P2 before doing this .. but I'd rather have the picture up
|
|
// right away I think.
|
|
// right away I think.
|
|
|
|
|
|
- slen = snprintf(display, sizeof(display), "%s%s%s.^P3%s",
|
|
|
|
|
|
+ // Ok, yes, there's no filename being sent. :P
|
|
|
|
+ render_image(images[r].lines, images[r].size);
|
|
|
|
+
|
|
|
|
+ slen = snprintf(display, sizeof(display), "%s%s^P3%s",
|
|
needs_cls ? "\x1b[2J" : "", fgoto,
|
|
needs_cls ? "\x1b[2J" : "", fgoto,
|
|
- possibles[r].filename, restore_color);
|
|
|
|
|
|
+ restore_color);
|
|
if (slen >= sizeof(display)) {
|
|
if (slen >= sizeof(display)) {
|
|
ZF_LOGE("snprintf %d > size %d", slen, (int)sizeof(display));
|
|
ZF_LOGE("snprintf %d > size %d", slen, (int)sizeof(display));
|
|
display[0] = 0;
|
|
display[0] = 0;
|
|
@@ -658,9 +637,7 @@ int mangle(int fd, const char *buffer, int len) {
|
|
|
|
|
|
// Add in random text, plus color!
|
|
// Add in random text, plus color!
|
|
do {
|
|
do {
|
|
- r = random() % ((sizeof(phrasing) / sizeof(char *)) - 1);
|
|
|
|
- // Does this drop the last element in phrasing? (Seems like it takes
|
|
|
|
- // awhile to get Seg Fault spoof, might be why)
|
|
|
|
|
|
+ r = randint(sizeof(phrasing) / sizeof(char *));
|
|
} while (last_phrasing.seen_before(r));
|
|
} while (last_phrasing.seen_before(r));
|
|
|
|
|
|
int color = random() % 15 + 1;
|
|
int color = random() % 15 + 1;
|
|
@@ -685,7 +662,8 @@ int mangle(int fd, const char *buffer, int len) {
|
|
"^G%02d%02d^S3^C%02d^P1%s^S0^R0%s^P1^G0101", x, y,
|
|
"^G%02d%02d^S3^C%02d^P1%s^S0^R0%s^P1^G0101", x, y,
|
|
color, phrasing[r], restore_color);
|
|
color, phrasing[r], restore_color);
|
|
if (slen >= sizeof(display)) {
|
|
if (slen >= sizeof(display)) {
|
|
- ZF_LOGE("snprintf %d > size %d", slen, (int)sizeof(display));
|
|
|
|
|
|
+ ZF_LOGE("snprintf %d > size %d (Phrase: %d, %s)", slen,
|
|
|
|
+ (int)sizeof(display), r, phrasing[r]);
|
|
display[0] = 0;
|
|
display[0] = 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -820,7 +798,7 @@ int mangle(int fd, const char *buffer, int len) {
|
|
if (need_render) {
|
|
if (need_render) {
|
|
render(fd, play, len);
|
|
render(fd, play, len);
|
|
} else {
|
|
} else {
|
|
- write(fd, play, len); // strlen(buffer));
|
|
|
|
|
|
+ write(fd, play, len);
|
|
};
|
|
};
|
|
return need_render && mangled;
|
|
return need_render && mangled;
|
|
}
|
|
}
|
|
@@ -948,7 +926,7 @@ int main(int argc, char *argv[]) {
|
|
ZF_LOGI("Username: [%s]", username);
|
|
ZF_LOGI("Username: [%s]", username);
|
|
};
|
|
};
|
|
if (strncmp("-SL", argv[x], 3) == 0) {
|
|
if (strncmp("-SL", argv[x], 3) == 0) {
|
|
- node = argv[x][3] - '0' + 1;
|
|
|
|
|
|
+ node = atoi(argv[x] + 3) + 1;
|
|
ZF_LOGI("Node: %d", node);
|
|
ZF_LOGI("Node: %d", node);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -995,7 +973,7 @@ int main(int argc, char *argv[]) {
|
|
tios.c_lflag &= ~(ECHO | ECHONL | ICANON);
|
|
tios.c_lflag &= ~(ECHO | ECHONL | ICANON);
|
|
/*
|
|
/*
|
|
tios.c_iflag &= ~(ICRNL | IXON | BRKINT);
|
|
tios.c_iflag &= ~(ICRNL | IXON | BRKINT);
|
|
- tios.c_iflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
|
|
|
|
|
+ tios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
|
tios.c_oflag &= ~(OPOST);
|
|
tios.c_oflag &= ~(OPOST);
|
|
*/
|
|
*/
|
|
tcsetattr(master, TCSAFLUSH, &tios);
|
|
tcsetattr(master, TCSAFLUSH, &tios);
|
|
@@ -1067,9 +1045,6 @@ int main(int argc, char *argv[]) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /*
|
|
|
|
- static char output[(BSIZE * 4) + 1];
|
|
|
|
- */
|
|
|
|
int total;
|
|
int total;
|
|
|
|
|
|
// read_fd esta atribuido com read_fd?
|
|
// read_fd esta atribuido com read_fd?
|
|
@@ -1079,20 +1054,20 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
if ((total = read(master, buffer + size, BSIZE - size)) != -1) {
|
|
if ((total = read(master, buffer + size, BSIZE - size)) != -1) {
|
|
// Ok, we've read more into the buffer.
|
|
// Ok, we've read more into the buffer.
|
|
-
|
|
|
|
- ZF_LOGV_MEM(buffer + size, total, "Read %d bytes:", total);
|
|
|
|
|
|
+ ZF_LOGV("Read %d bytes", total);
|
|
|
|
+ // ZF_LOGV_MEM(buffer + size, total, "Read %d bytes:", total);
|
|
size += total;
|
|
size += total;
|
|
- ZF_LOGV_MEM(buffer, size, "Buffer now:");
|
|
|
|
|
|
+ // ZF_LOGV_MEM(buffer, size, "Buffer now:");
|
|
int pos = rstrnstr(buffer, size, "\r\n");
|
|
int pos = rstrnstr(buffer, size, "\r\n");
|
|
if (pos >= 0) {
|
|
if (pos >= 0) {
|
|
// found something!
|
|
// found something!
|
|
pos += 2;
|
|
pos += 2;
|
|
- ZF_LOGD_MEM(buffer, pos, "mangle buffer %d bytes:", pos);
|
|
|
|
|
|
+ // ZF_LOGD_MEM(buffer, pos, "mangle buffer %d bytes:", pos);
|
|
mangle(STDOUT_FILENO, buffer, pos);
|
|
mangle(STDOUT_FILENO, buffer, pos);
|
|
memmove(buffer, buffer + pos, size - pos);
|
|
memmove(buffer, buffer + pos, size - pos);
|
|
size -= pos;
|
|
size -= pos;
|
|
- } else {
|
|
|
|
- ZF_LOGV("position of /r/n not found.");
|
|
|
|
|
|
+ // } else {
|
|
|
|
+ // ZF_LOGV("position of /r/n not found.");
|
|
}
|
|
}
|
|
|
|
|
|
} else
|
|
} else
|