diff options
author | B. Watson <urchlay@slackware.uk> | 2025-03-10 04:21:46 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2025-03-10 04:21:46 -0400 |
commit | 2b7e4fdff3057bc07ad9f3da813f6a331e0b80f1 (patch) | |
tree | 68ed23df2a119e20c5b4076b12e56cb1fdb6d58f | |
parent | bd92bf5e59e97ebd67aa6309c7012537c41be87a (diff) | |
download | bw-atari8-tools-2b7e4fdff3057bc07ad9f3da813f6a331e0b80f1.tar.gz |
-rw-r--r-- | whichbas.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -969,21 +969,23 @@ CALLBACK(handle_end_stmt) { } /* return true if input_file is Atari MS BASIC. - AMSB files begin with a 3-byte header: 0x00, then 2 byte length + AMSB files begin with a 3-byte header: 0x00 or 0x01, then 2 byte length (LSB/MSB), which is actually 3 bytes less than the full length of the file (or, it's the length of the file minus the 3-byte header). Also, the files always end with 3 0x00 bytes. We check that the header length is 3 bytes less than the file length, - then check for the 3 0x00's at the end. + then check for the 3 0x00's at the end... or, if the first byte was 1, + meaning "locked program", check for 3 "encrypted" 0x00's at the end. */ int detect_amsb(void) { - int len, c; + int trailing_byte_value = 0, len, c; if(verbose) fprintf(stderr, "entering detect_amsb()\n"); rewind(input_file); c = fgetc(input_file); - if(c) return 0; + if(c > 1) return 0; + if(c) trailing_byte_value = 0x54; c = fgetc(input_file); if(c == EOF) return 0; len = (fgetc(input_file) << 8) | c; @@ -1000,9 +1002,9 @@ int detect_amsb(void) { if(verbose) fprintf(stderr, "detect_amsb() file size is correct, checking for 3 nulls\n"); fseek(input_file, -3, SEEK_END); - if(fgetc(input_file)) return 0; - if(fgetc(input_file)) return 0; - if(fgetc(input_file)) return 0; + if(fgetc(input_file) != trailing_byte_value) return 0; + if(fgetc(input_file) != trailing_byte_value) return 0; + if(fgetc(input_file) != trailing_byte_value) return 0; if(verbose) fprintf(stderr, "detect_amsb() found 3 nulls, return 1\n"); @@ -1053,7 +1055,7 @@ void detect_foreign(void) { foreign("ELF executable (not BASIC at all!)", SRET_NOT_BASIC); } - if(c == 0 && detect_amsb()) { + if((c == 0 || c == 1) && detect_amsb()) { foreign("Atari Microsoft BASIC", SRET_AMSB); } |