int main (int argc, char *argv[]) { FILE *fp; char *filename; // if (argc < 2) { usage (argc, argv); exit(1); } filename = argv[1]; fp = fopen (filename, "rb"); if (!fp) { fprintf (stderr, "Error: Failed opening %s\n", argv[1]); return 1; } // file checks if (checkFile (fp) < 0) { fprintf(stderr, "Error: File analysis failed\n"); exit(1); } // dump file :) if (PeCheck(fp)) { pe_dump(fp); } else if (ElfCheck(fp)) { elf_dump(fp); } fclose(fp); return 0; }
// Gets the cfg from the command line, reads it, updates the registers, // reads the MIPS instructions from the elf file and inserts them into // memory. Lastly, main initializes the stackpointer, // interprets the instructions and shows the status of the registers // after completing them. int main(int argc, char *argv[]) { int read; if (argc == 3) { read = read_config(argv[1]); } else { printf(ERROR_INVALID_ARGS); return -1; } if (read == 0) { int retElfDump = elf_dump(argv[2], &PC, &mem[0], MEMSZ); if(retElfDump != 0) { printf(ERROR_ELF_DUMP); return -2; } SP = MIPS_RESERVE + MEMSZ; int retInterp = interp(); if (retInterp != SAW_SYSCALL && retInterp != 0) { printf(ERROR_INTERP); return -3; } show_status(); } else { printf(ERROR_READ_CONFIG); return -4; } return 0; }
void read_MIPS(MIPS_t *mips, const char *fname) { switch (elf_dump(fname, &(mips->pc), &(*mips->mem)[0], mips->mem_sz)) { case ELF_ERROR_IO_ERROR : errorf("ERROR: read_MIPS - problems reading file `%s'.\n", fname); case ELF_ERROR_OUT_OF_MEM : errorf("ERROR: read_MIPS - ELF file larger than allocated memory buffer.\n"); case ELF_ERROR_NOT_ELF : errorf("ERROR: read_MIPS - not an ELF file.\n"); case ELF_ERROR_NOT_SUPPORTED : errorf("ERROR: read_MIPS - unsupported ELF features detected.\n"); } }