diff options
author | B. Watson <urchlay@slackware.uk> | 2024-05-31 17:51:52 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-05-31 17:51:52 -0400 |
commit | b7661fd2bb461e68493014c1406ace0281d899d0 (patch) | |
tree | f4035aafc03c7bd4ceaff3951014463ac7d8ff64 | |
parent | 434248ed2110460688b6c409fe5ec97677b646c7 (diff) | |
download | bw-atari8-tools-b7661fd2bb461e68493014c1406ace0281d899d0.tar.gz |
unprotbas: detect truncated files, count invalid offsets.
-rw-r--r-- | unprotbas.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/unprotbas.c b/unprotbas.c index 2961f1c..2290f47 100644 --- a/unprotbas.c +++ b/unprotbas.c @@ -79,6 +79,7 @@ unsigned short starp; /* positions where various parts of the file start, derived from the header vars above. */ unsigned short codestart; +unsigned short code_end; unsigned short vnstart; unsigned short vvstart; int filelen; @@ -131,7 +132,7 @@ void setword(int addr, int value) { void dump_header_vars(void) { fprintf(stderr, "LOMEM $%04x VNTP $%04x VNTD $%04x VVTP $%04x\n", lomem, vntp, vntd, vvtp); fprintf(stderr, "STMTAB $%04x STMCUR $%04x STARP $%04x\n", stmtab, stmcur, starp); - fprintf(stderr, "vnstart $%04x, vvstart $%04x, codestart $%04x\n", vnstart, vvstart, codestart); + fprintf(stderr, "vnstart $%04x, vvstart $%04x, codestart $%04x, code_end $%04x\n", vnstart, vvstart, codestart, code_end); } void read_header(void) { @@ -145,6 +146,12 @@ void read_header(void) { codestart = stmtab - TBL_OFFSET - (vntp - 256); vnstart = vntp - TBL_OFFSET; vvstart = vvtp - TBL_OFFSET; + code_end = starp - TBL_OFFSET; + + if(filelen < code_end) { + fprintf(stderr, "Warning: file is truncated: %d bytes, should be %d.\n", filelen, code_end); + } + if(verbose) dump_header_vars(); } @@ -248,6 +255,9 @@ int fixcode(void) { fprintf(stderr, ", %s.\n", (keepgarbage ? "keeping" : "removing")); } if(!keepgarbage) filelen = pos; + } else { + if(verbose) + fprintf(stderr, "No trailing garbage at EOF.\n"); } return result; } @@ -835,7 +845,7 @@ void parse_args(int argc, char **argv) { } int main(int argc, char **argv) { - int outbytes; + int outbytes, invoffs = 0; parse_args(argc, argv); filelen = readfile(); @@ -872,8 +882,11 @@ int main(int argc, char **argv) { } } - if(fixcode()) { - if(verbose) fprintf(stderr, "Fixed invalid offset in code.\n"); + invoffs = fixcode(); + if(invoffs) { + if(verbose) + fprintf(stderr, "Fixed %d invalid offset%s in code.\n", + invoffs, (invoffs == 1 ? "" : "s")); was_protected = 1; } else { if(verbose) fprintf(stderr, "No invalid offsets.\n"); |