int loadTD0(Computer* comp, const char* name, int drv) { Floppy* flp = comp->dif->fdc->flop[drv & 3]; FILE* file = fopen(name, "rb"); if (!file) return ERR_CANT_OPEN; int err = ERR_OK; td0Head hd; fread(&hd, sizeof(td0Head), 1, file); if (strncmp(hd.sign, "td", 2) && strncmp(hd.sign, "TD", 2)) { err = ERR_TD0_SIGN; } else if ((hd.dens != 0) || (hd.sides > 2)) { err = ERR_TD0_TYPE; } else if (hd.ver < 0x14) { err = ERR_TD0_VERSION; } else { if (strncmp(hd.sign,"TD",2)) { // 1 on td (packed) LHADecoderType* decType; LHADecoder* dec = NULL; decType = lha_decoder_for_name("-lh1-"); dec = lha_decoder_new(decType, fGetData, file, -1); doTD0(flp, lhaDepack, dec, hd.flag & 0x80); lha_decoder_free(dec); } else { doTD0(flp, fGetData, file, hd.flag & 0x80); } flp->path = (char*)realloc(flp->path,sizeof(char) * (strlen(name) + 1)); strcpy(flp->path,name); flp->insert = 1; flp->changed = 0; } fclose(file); return err; }
LHADecoder *lha_basic_reader_decode(LHABasicReader *reader) { LHADecoderType *dtype; if (reader->curr_file == NULL) { return NULL; } // Look up the decoder to use for this compression method. dtype = lha_decoder_for_name(reader->curr_file->compress_method); if (dtype == NULL) { return NULL; } // Create decoder. return lha_decoder_new(dtype, decoder_callback, reader, reader->curr_file->length); }
int main(int argc, char *argv[]) { LHADecoderType *dtype; unsigned int i; time_t now; char timestr[32]; if (argc < 2) { printf("Usage: %s <decoder-type> [filename]\n", argv[0]); exit(-1); } algorithm = argv[1]; dtype = lha_decoder_for_name(algorithm); if (dtype == NULL) { fprintf(stderr, "Unknown decoder type '%s'\n", algorithm); exit(-1); } if (argc >= 3) { run_from_file(dtype, argv[2]); } else { signal(SIGALRM, alarm_signal); signal(SIGSEGV, crash_signal); srand(time(NULL)); for (i = 0; ; ++i) { now = time(NULL); strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", localtime(&now)); printf("%s - Iteration %i:\n", timestr, i); fuzz_test(dtype, MAX_FUZZ_LEN); } } return 0; }