[File] [PATCH] of Magdir/c64 Commodore 64 cartridge misidentfies DROID CRT

Jörg Jenderek joerg.jen.der.ek at gmx.net
Wed May 24 21:47:41 UTC 2023


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
some days ago i enabled secure boot on an installation and the
machine crashed. I am no expert in that field but i believed that
something went wrong when "enrolling" security certificates. So i
looked for such samples on my systems. Sometimes these have suffix
crt. Unfortunately this suffix is also used for other files types
like Commodore 64 cartridges.

When running file command version 5.44 on such Commodore CRT samples
and related files, i get an output like:

Archon Cartridge v1.1.crt:     Commodore 64 cartridge:
       		 	       "Magic Desk",
			       Magic Desk,
			       Domark, HES Australia
DaffyDuck.crt:                 Commodore 64 cartridge:
			       "DAFFY DUCK",
			       EasyFlash
Disk Utilities 1c.crt:         Commodore 64 cartridge:
     	       		       "ndefpack 1.0.1",
			       EasyFlash
boxymoxy_v11.crt:              Commodore 64 cartridge:
			       "VICE CART",
			       GMod2
c64gscar.crt:                  Commodore 64 cartridge:
			       "C64GS Cartridge",
			       C64 Game System, System 3
fc3-geos.crt:                  Commodore 64 cartridge:
			       "FINAL CARTRIDGE 3",
			       Final Cartridge III
fmt-822-signature-id-1179.crt: Commodore 64 cartridge:
			       "\253\253\253\253\253\253\253\253",
fmt-822.crt:                   Commodore 64 cartridge
			       , 16 KB game
maniac.crt:                    Commodore 64 cartridge:
			       "EASYFLASH",
			       EasyFlash
pop.crt:                       Commodore 64 cartridge:
			       "EasyFlash",
			       EasyFlash
sales.crt:                     Commodore 64 cartridge:
			       "sales",
			       16 KB game

Furthermore only generic mime type application/octet-stream
or text/plain is shown with -i. With option --extension
only 3 byte sequence ??? is shown.

For comparison reason i also run the file format identification
utility DROID ( See https://sourceforge.net/projects/droid/).
The samples are described as "CRT C64 Cartridge Image Format"
by PUID fmt/822.

For comparison reason i run the file format identification utility
TrID ( See https://mark0.net/soft-trid-e.html). The cartridge samples
are described as here with high priority as "C64 Cartridge image"
with suffix CRT by crt-c64.trid.xml. But the samples are also
described with low priority as "CCS64 Cartridge" with wrong suffix
CAR by car-ccs64.trid.xml (See appended trid-v-cdr_c64.txt.gz).

TrID list the used file name extension and often with -v option the
related URL pointing to used file format information. With the help
of these tools i found a page about CaRTridge Images. So this is
now expressed inside Magdir/c64 by additional comment lines like:
# Reference: https://vice-emu.sourceforge.io/vice_17.html#SEC391
#		http://ist.uwaterloo.ca/~schepers/formats/CRT.TTX
#		http://mark0.net/download/triddefs_xml.7z
#		defs/c/crt-c64.trid.xml

The DROID samples like fmt-822-signature-id-1179.crt are not real
Commodore 64 cartridge. These are used by DROID to recognise
such cartridges and contain just some leading bytes.

The description happens inside Magdir/c64 and test the first 13
bytes. This looks like:
 0	string		C64\40CARTRIDGE	Commodore 64 cartridge
The DROID tool also test if the next 3 bytes of 16-byte cartridge
signature are spaces. TrID also use this additional characteristic
for variant "C64 Cartridge image", but for "C64 Cartridge image"
variant only 1 appended space is checked. In my inspected samples i
also get 3 spaces but just in case for "exotic" variant show this
information by additional line like:
 >14	ubeshort	!0x2020	\b, at 14 %#x

Afterwards the 32-byte null padded cartridge names are shown if
available by lines like:
 >0x20	ubyte	0	\b,
 >0x20	ubyte	!0
 >>0x20	string/T	x	\b: "%.32s",
For real samples i get strings like "BUGS BUNNY" "CART64"
"EasyFlash" "FINAL CARTRIDGE" "Magic Desk" "VICE CART". For the
DROID samples i get "\253\253\253\253\253\253\253\253" for variant
filled with 0xAB values or nothing for variant with nil bytes.

Afterwards the cartridge hardware types is shown. For some types
like 0 there a next level sub classification is done by displaying
cartridge Hardware Revision/Subtype at offset 0x18. In current
version hardware types in range 0-77 are listed. This is done by
lines like:
 >0x16	beshort	0
 >>0x18	beshort	0x0000	16 KB game
 >>0x18	beshort	0x0001	8 KB game
 >>0x18	beshort	0x0100	UltiMax mode
 >>0x18	beshort	0x0101	RAM/disabled
 >0x16	beshort	1	Action Replay
 >0x16	beshort	2	KCS Power Cartridge
 ...
 >0x16	beshort	75	IEEE Flash! 64
 >0x16	beshort	76	Turtle Graphics II
 >0x16	beshort	77	Freeze Frame MK2

In one of the documents an additional type with higher number 78
for "Partner 64" is listed. For cases of accident or future
expansion now show higher types number by additional lines like:
 >0x16	beshort	78	Partner 64
 >0x16	ubeshort >78	Unknown type %#x
 >>0x1A	ubyte	>0	revision %#x
For the DROID samples i get "unknown type 0xabab revision 0xab" for
for variant filled with 0xAB values or "16 KB game" for variant
with nil bytes.

I want to distinguish DROID samples from real CRT samples. So i
look at other fields in header and display unusual values. After
the signature the file header length is stored. Typical and minimum
value is 40h, but some times wrong 20h appear in some samples, but
i myself found no such samples. So report this field by additional
line after last displaying like:
 >0x10	ubelong	!0x40	\b, header length %#x
Afterwards the cartridge version is stored. Typical version are
1.0 1.1 (adds CRT sub type/hardware revision) 2.0 (introduces
VIC20, PLUS4, C128, CBM2). In my samples the version was 1.0. So
show other values by lines like:
 >0x14	ubeshort	!0x0100
 >>0x14	ubyte		x	\b, version %u
 >>0x15	ubyte		x	\b.%u
For the DROID samples i get "version 171.171" for variant filled
with 0xAB values or "version 0.0" for variant with nil bytes.

After the header the cartridge content begins which start with ROM
signature which must be CHIP according to DROID. So for damaged CRT
show unusual values by additional lines like:
 >0x40	ubelong	!0x43484950	\b, invalid ROM signature
 >>0x40	string	x		"%0.4s"
For the DROID samples this ROM signature is valid.

Afterwards the total packet length is stored. This is shown by line
like:
 >0x44	ubelong	x	\b, packet length %#x
For real CRT samples i get values like 2010h 4010h. For the DROID
samples i get here nothing because that offset is beyond the end of
file size limit.

So i choose this criterium as second test to skip DROID samples
because this is the most significant proofing test. I done this by
putting the displaying part in sub routine c64-crt. One advantage
is that i can keep many magic lines. Another advantage is that the
routine can be also used for other cartridge variants which start
with other starting signature. So the start now becomes like:
 0	string		C64\40CARTRIDGE
 >0x44	ubelong		>0x10
 >>0	use		c64-crt
 0	name		c64-crt
 >0	string		x		Commodore 64 cartridge
 !:mime	application/x-commodore-crt
 !:ext	crt
Instead of generic mime type application/octet-stream i show an
user defined one. The file name suffix is CRT, but according to
TrID CAR is used for "CCS64 Cartridge" variant, but i have and
found no such samples.

After applying the above mentioned modifications by patch
file-5.44-c64-crt.diff then misidentification of DROID samples vanish
and now i get an output with more details like:

Archon Cartridge v1.1.crt:     Commodore 64 cartridge:
       		 	       "Magic Desk",
			       Magic Desk, Domark, HES Australia
			       , packet length 0x2010
DaffyDuck.crt:                 Commodore 64 cartridge:
			       "DAFFY DUCK",
			       EasyFlash
			       , packet length 0x2010
Disk Utilities 1c.crt:         Commodore 64 cartridge:
     	       		       "ndefpack 1.0.1",
			       EasyFlash
			       , packet length 0x2010
boxymoxy_v11.crt:              Commodore 64 cartridge:
			       "VICE CART",
			       GMod2
			       , packet length 0x2010
c64gscar.crt:                  Commodore 64 cartridge:
			       "C64GS Cartridge",
			       C64 Game System, System 3
			       , packet length 0x2010
fc3-geos.crt:                  Commodore 64 cartridge:
			       "FINAL CARTRIDGE 3",
			       Final Cartridge III
			       , packet length 0x4010
fmt-822-signature-id-1179.crt: ISO-8859 text
			       , with no line terminators
fmt-822.crt:                   data
maniac.crt:                    Commodore 64 cartridge:
			       "EASYFLASH",
			       EasyFlash
			       , packet length 0x2010
pop.crt:                       Commodore 64 cartridge:
			       "EasyFlash",
			       EasyFlash
			       , packet length 0x2010
sales.crt:                     Commodore 64 cartridge:
			       "sales",
			       16 KB game
			       , packet length 0x4010

I hope my diff file can be applied in future version of
file utility.

With best wishes
Jörg Jenderek
- --
Jörg Jenderek


-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iF0EARECAB0WIQS5/qNWKD4ASGOJGL+v8rHJQhrU1gUCZG6F/QAKCRCv8rHJQhrU
1n+1AKDaYbwozhIdo7GMw9Zf+mBwR1z95ACfUM4geiUNG+bCzMWO5ltmHTGe0ZE=
=7XQT
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trid-v-crt_c64.txt.gz
Type: application/x-gzip
Size: 547 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20230524/4af14a2f/attachment.bin>
-------------- next part --------------
--- file-5.44/magic/Magdir/c64.old	2022-11-30 00:04:06.000000000 +0100
+++ file-5.44/magic/Magdir/c64	2023-05-24 23:29:06.119043500 +0200
@@ -13,11 +13,30 @@
 # C64 (and other CBM) cartridges
 # Extended by David Korth <gerbilsoft at gerbilsoft.com>
+# Update:	Joerg Jenderek
 # Reference: https://vice-emu.sourceforge.io/vice_17.html#SEC391
+#		http://ist.uwaterloo.ca/~schepers/formats/CRT.TTX
+#		http://mark0.net/download/triddefs_xml.7z/defs/c/crt-c64.trid.xml
+# Note:		called "C64 Cartridge image" by TrID and
+#		"CRT C64 Cartridge Image Format" by DROID via PUID fmt/822
 
-0	string		C64\40CARTRIDGE	Commodore 64 cartridge
+0	string		C64\40CARTRIDGE
+# skip DROID fmt-822-signature-id-1179.crt with missing packet length
+>0x44	ubelong		>0x10
+>>0	use		c64-crt
+#	display Commodore 64 cartridge information
+0	name		c64-crt
+>0	string		x		Commodore 64 cartridge
+#!:mime	application/octet-stream
+!:mime	application/x-commodore-crt
+!:ext	crt
+#		http://mark0.net/download/triddefs_xml.7z/defs/c/car-ccs64.trid.xml
+#!:ext	crt/car
 >0x20	ubyte	0	\b,
 >0x20	ubyte	!0
+# 32-byte null padded cartridge name like: "BUGS BUNNY" "CART64" "EasyFlash" "FINAL CARTRIDGE" "Magic Desk" "VICE CART"
 >>0x20	string/T	x	\b: "%.32s",
+# cartridge hardware type
 >0x16	beshort	0
+# cartridge port EXROM line status
 >>0x18	beshort	0x0000	16 KB game
 >>0x18	beshort	0x0001	8 KB game
@@ -60,4 +79,5 @@
 >0x16	beshort	35	Action Replay 3
 >0x16	beshort	36
+# cartridge Hardware Revision/Subtype (usually 0) (added in v1.01)
 >>0x1A	ubyte	1	Nordic Replay
 >>0x1A	ubyte	!1	Retro Replay
@@ -105,4 +125,22 @@
 >0x16	beshort	76	Turtle Graphics II
 >0x16	beshort	77	Freeze Frame MK2
+>0x16	beshort	78	Partner 64
+# cartridge hardware type: (0-78)
+>0x16	ubeshort >78	unknown type %#x
+# Cartridge Hardware Revision/Subtype (usually 0 added in v1.01)
+>>0x1A	ubyte	>0	revision %#x
+# padded with 3 space characters for CRT but for CCS64 Cartridge (*.CAR) maybe different according to TrID
+>14	ubeshort	!0x2020	\b, at 14 %#x
+# file header length like: 20h (reported wrong) 40h (default and minimum)
+>0x10	ubelong	!0x40	\b, header length %#x
+# cartridge version like: 1.0 1.1 (adds CRT sub type/hardware revision) 2.0 (introduces VIC20, PLUS4, C128, CBM2)
+>0x14	ubeshort	!0x0100
+>>0x14	ubyte		x	\b, version %u
+>>0x15	ubyte		x	\b.%u
+# cartridge content start with ROM signature which must be CHIP
+>0x40	ubelong	!0x43484950	\b, invalid ROM signature
+>>0x40	string	x		"%0.4s"
+# total packet length (length of ROM image size and header combined) like: 2010h 4010h
+>0x44	ubelong	x	\b, packet length %#x
 
 0	string		C128\40CARTRIDGE	Commodore 128 cartridge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file-5.44-c64-crt.diff.sig
Type: application/octet-stream
Size: 1474 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20230524/4af14a2f/attachment.obj>


More information about the File mailing list