src/main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include <assert.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "vm.h" #include "rom.h" // automatically generated from rom.bin by `make` char *embedded_msg = "Strings won't save you here...\n"; int main() { char flag_input[21]; uint8_t *memory = NULL; struct CPU cpu; // believe me, I _really_ tried to put the below calloc() in vm_init() memory = calloc(RAM_SIZE, sizeof(uint8_t)); if (memory == NULL) perror("Failed to allocate memory. Aborting..."); // __src_rom_bin* comes from "rom.h", generated by make from rom.bin vm_init(&cpu, memory, __src_rom_bin, __src_rom_bin_len); printf("Fill in the rest of the flag: RS{"); fgets(flag_input, 20, stdin); flag_input[strcspn(flag_input, "\n")] = 0; // trim trailing newline printf("The inputted flag was RS{%s}\n\n", flag_input); for (uint8_t i = 0; i < strlen(flag_input); ++i) memory[128+i] = (uint8_t)flag_input[i]; #ifdef DEBUG printf("[DEBUG MODE]: Running interpreter...\n"); // DEBUG is_being_traced = 1; #endif vm_run(&cpu, memory); uint8_t win = memory[0x30]; // memory test to see if if (win == 7) // flag was correct printf("YAY, you got the flag!\n"); else printf("Sorry, that's not the flag. Try again!\n"); free(memory); return EXIT_SUCCESS; } |