#include #include #include #include void getFlag(); void output_line(FILE *outfile, unsigned long line, char *s); // int gets(char *s); int main(int argc, char **argv) { setbuf(stdout, NULL); // turn off output buffering FILE *outfile = fopen("/tmp/prog.bas", "w"); unsigned long line_no; struct { char buffer[32]; unsigned long *line_pointer; } locals; line_no = 100; locals.buffer[0] = ' '; locals.line_pointer = &line_no; printf("Ready for some BASIC programming?\n"); while (locals.buffer[0] != '\0') { printf("%lu ", *locals.line_pointer); if(!gets(locals.buffer)) // reads line, with newline replaced by '\0' break; output_line(outfile, line_no, locals.buffer); line_no = line_no + 10; } if (outfile) { fclose(outfile); system("python ctf.py run /tmp/prog.bas"); } return 0; } void output_line(FILE *outfile, unsigned long line, char *s) { static int state = 1; if (outfile && state) { fprintf(outfile, "%lu ", line); if (*s < ' ' || strncmp(s, "END", 4) == 0 || strncmp(s, "end", 4) == 0) { fprintf(outfile, "END\n"); *s = '\0'; state = 0; } else { while (*s >= ' ') fputc(toupper(*(s++)), outfile); fputc('\n', outfile); } } } void getFlag() { if (getenv("TASK_NAME")) { system("python ctf.py success"); exit(0); } else { printf("Success!"); exit(0); } }