campctf2023-chall-tis256

Zachtronics TIS100-inspired reversing challenge for CampCTF 2023
git clone https://git.sinitax.com/sinitax/campctf2023-chall-tis256
Log | Files | Refs | Submodules | README | sfeed.txt

tis256.c (1014B)


      1#include "asm.h"
      2#include "tpu.h"
      3#include "util.h"
      4
      5#include <signal.h>
      6#include <stdarg.h>
      7#include <stdio.h>
      8#include <string.h>
      9#include <stdint.h>
     10#include <stdbool.h>
     11#include <stdlib.h>
     12
     13static struct tis tis;
     14static FILE *tis_stdin = NULL;
     15static FILE *tis_stdout = NULL;
     16
     17int (*cleanup)(void) = NULL;
     18const char *progname = "tis-as";
     19
     20int
     21main(int argc, const char **argv)
     22{
     23	if (argc < 2 || argc > 4) {
     24		fprintf(stderr, "Usage: tis-as FILE [STDIN] [STDOUT]\n");
     25		exit(1);
     26	}
     27
     28	if (argc >= 3) {
     29		tis_stdin = fopen(argv[2], "r");
     30		if (!tis_stdin) die("fopen '%s':", argv[2]);
     31	} else {
     32		tis_stdin = stdin;
     33	}
     34	setvbuf(tis_stdin, NULL, _IONBF, 0);
     35
     36	if (argc >= 4) {
     37		tis_stdout = fopen(argv[3], "w+");
     38		if (!tis_stdout) die("fopen '%s':", argv[3]);
     39	} else {
     40		tis_stdout = stdout;
     41	}
     42	setvbuf(tis_stdout, NULL, _IONBF, 0);
     43
     44	tis_init(&tis, NULL, NULL);
     45
     46	tis_load(&tis, argv[1], tis_stdin, tis_stdout);
     47
     48	while (tis_step(&tis));
     49
     50	tis_deinit(&tis);
     51
     52	fprintf(stderr, "steps: %lu\n", tis.steps);
     53}
     54