aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--whichbas.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/whichbas.c b/whichbas.c
index 9f7f6db..1ed21a4 100644
--- a/whichbas.c
+++ b/whichbas.c
@@ -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);
}