[File] [PATCH] of Magdir/map for Garmin update *.rgn, *.exe

Jörg Jenderek joerg.jen.der.ek at gmx.net
Sun Dec 1 20:14:06 UTC 2019


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

Hello,

some weeks ago i send patches to recognize maps found on garmin
navigation devices. After updating firmware of garmin device i
run file command version 5.37 on garmin device. There exist some
files with name extension exe and rgn. These are recognized only as
"data".

Luckily i find a file format documentation by Herbert Oppmann. So i
add the PDF-URL by comment line to  Magdir/map like:
 # Ref.: www.memotech.franken.de/FileFormats/Garmin_RGN_Format.pdf

According to reference such Garmin firmware Update start with
specific magic keyword. So first test line looks like:
 0	string		KpGr		Garmin update

To keep out put columns low, i display additional information if not
standard. So next show header format version if not 1.0 (That is
0064h as 2 byte little endian integer) by lines:
 >0x4	uleshort	!0x0064
 >>4	uleshort/100	x		\b, version %u
 >>4	uleshort%100	x		\b.%u

After the header comes some RGN records. To display information of
Garmin RGN record i introduce a subroutine by lines like
 0	name	garmin-entry
For debugging purpose the record length can be shown by line like
 >0	ulelong		x		\b, length 0x%x
This is 2 for Data record, for Application often this value is 1Bh
sometimes 1Dh and for Region record this value is "big". Furthermore
this values can be used to jump from record to record.

After the record length comes a record identifying byte. Usual values
are D, A or R. So at end of sub routine show unusual values by
lines like
 >4	default		x		\b; other
 >>4	ubyte		x		ID '%c'

The data record (ID='D'=44h) with version content like 1.0
(hexadecimal 0064h) are handled by branch with lines
 >4	ubyte		=0x44
 >>5	uleshort	!0x0064		\b; Data
 >>>5	uleshort/100	x		\b, version %u
 >>>5	uleshort%100	x		\b.%u

The Application Record (ID='A'=41h) has a varying size, because
builder name like "SQA" or "hales" are different. There standard
version is 2.0 ( hexadecimal 00c8h). So show version, builder name,
date and time by lines like:
 >4	ubyte		=0x41		\b; App
 >>5	uleshort	!0x00C8
 >>>5	uleshort/100	x		\b, version %u
 >>>5	uleshort%100	x		\b.%u
 >>7	string		x		\b, build by %s
 >>>&1	string		x		%s
 >>>>&1	string		x		%s

Third branch is for region record (ID='R'=52h). There first i show
region id by lines starting like:
 >4	ubyte		=0x52		\b; Region
 >>5	uleshort	x		ID=%u
This id is different and characteristic for region record content. So
i show first bytes of content by line like
 >>15	ubequad		x		\b, content 0x%llx...

When interpreting the content as string, we get "KpGr" for recursive
embedded updates, "GARMIN BITMAP" for Garmin Bitmap images (*.srf),
"PK" for ZIP/JAR archive and others.
I tried to inspect content by calling file command again, but i
failed at that position.

So at the end i inspect region content by looking for specific
content magic. To use default clause i look again at version by line
 >0x4	uleshort	x
First test for region content with Garmin images *.srf by specific
magic and using test lines of Magdir/images like
 >>0x3a	search/5/s	GARMIN\ BITMAP	\b=
 !:mime	image/x-garmin-exe
 !:ext	exe
 >>>&0	indirect	x
The updates with embedded garmin bitmap images of vehicles have file
name extension exe like example Vehicle_Compact-Purple_220.exe. I
also add a user defined mime type. For test purpose i extract Garmin
Bitmap (*.srf) and convert this by tool srftopam of NetPBM package to
Netpbm PAM image (*.pam) that can be viewed/converted by ImageMagick.

If update does not contain bitmap *.srf then it is a "region" with
file name extension rgn. These example are handled by other branch
starting with lines like:
 >>0x3a	default		x		\b=
 !:mime	application/x-garmin-rgn
 !:ext	rgn
Recursive embedded garmin updates are handled by
 >>>0x3a	search/5/s	KpGrd
 >>>>&0		indirect	x

Regions with ZIP or JAR archive content are handled by last branch by
magic lines inside Magdir/archive and Magdir/zip like:
 >>>0x3a	search/5/s	PK\003\004
 >>>>&0		indirect	x

After header handle first and second garmin RGN record by lines like
 >6	use	garmin-entry
 >(0x6.l+10)	ubyte		x
 >>&0		use		garmin-entry

After applying the above mentioned modifications by patch
file-5.37-map-rgn.diff then i get an output like:
a.rgn:                                Garmin update; App,
	build by hales Oct 25 1999 11:52:30;
	Region ID=7, 13579 ms, content 0x48656c6c6f000000...=
B1907,ANT_250_USB.rgn:                Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=250, content 0xb8210020ad940100...=
c.rgn:                                Garmin update; App,
	build by hales Oct 25 1999 11:52:30;
	Region ID=6, 24680 ms, content 0x424865790e000000...=
Fenix3,Wi-Fi_200.rgn:                 Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=251, content 0xacd94e2e2135f570...=
Fenix3_650.rgn:                       Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=14, content 0x4b70477264000200...=
	Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=14, content 0x4ff000004ff00001...=
fenix3HR,Display_370.rgn:             Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=249, content 0x4a14f103c80dc70c...=
IndexSmartScale_310.rgn:              Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=1, content 0x2c1102002e535546...=
nuvi25x9LanguageText_260.rgn:         Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=255, content 0x504b030414000200...=
	Zip archive data, at least v2.0 to extract
nuvi25x9LanguageText_260.zip:
	Zip archive data, at least v2.0 to extract
nuvi4692_CHN_regionfileonly__590.jar:
	Java archive data (JAR)
nuvi4692_CHN_regionfileonly__590.rgn: Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=148, content 0x504b030414000800...=
	Java archive data (JAR)
nuvi900T_update.rgnfile__360.rgn:     Garmin update; App,
	build by sqa Feb 23 2009 18:23:01;
	Region ID=80, content 0x0...=
test-versions.rgn:                    Garmin update,
	version 1.2; Data, version 1.3; App, version 2.3,
	build by joerg Oct 25 1999 11:52:30;
	Region ID=7, 13579 ms, content 0x48656c6c6f000000...=
test-year2018.rgn:                    Garmin update; App,
	build by joerg Mar 13 2018 12:34:56;
	Region ID=7, 13579 ms, content 0x4248657900000000...=
Vehicle_Compact-Purple_220.exe:       Garmin update; App,
	build by SQA Oct 25 1999 14:16:13;
	Region ID=78, content 0x4741524d494e2042...=
	Garmin Bitmap file, version 2.20, 2880x80
Vehicle_Compact-Purple_220.pam:
	Netpbm PAM image file
Vehicle_Compact-Purple_220.srf:
	Garmin Bitmap file, version 2.20, 2880x80

I hope my diff file can be applied in a 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+v8rHJQhrU1gUCXeQe8gAKCRCv8rHJQhrU
1gBgAJ9kb5to2No1ihDSpYvnpuNNjKDRwgCfeSUPiriVflesxK6dyvigF+0yc5k=
=0OqQ
-----END PGP SIGNATURE-----
-------------- next part --------------
--- file-5.37/magic/Magdir/map.old	2019-04-30 04:02:04 +0000
+++ file-5.37/magic/Magdir/map	2019-12-01 19:57:54 +0000
@@ -316,6 +316,83 @@
 # LBL:2A9h,SRT:1Dh 25h 27h,TRE:CFh 135h,TRF:5Ah,TYP:5Bh 6Eh 7Ch AEh,RGN:7Dh
 >>0	uleshort	x		\b, header length 0x%x
 
+# URL:		https://www.memotech.franken.de/FileFormats/
+# Reference:	https://www.memotech.franken.de/FileFormats/Garmin_RGN_Format.pdf
+# From:		Joerg Jenderek
+0	string		KpGr		Garmin update
+# format version like: 0064h~1.0
+>0x4	uleshort	!0x0064
+>>4	uleshort/100	x		\b, version %u
+>>4	uleshort%100	x		\b.%u
+# 1st Garmin entry
+>6	use	garmin-entry
+# 2nd Garmin entry
+>(0x6.l+10)	ubyte		x
+>>&0		use		garmin-entry
+# 3rd entry
+>(0x6.l+10)	ubyte		x
+>>&(&0.l+4)	ubyte		x
+>>>&0		use		garmin-entry
+# look again at version to use default clause
+>0x4	uleshort	x
+# test for region content by looking for
+# Garmin *.srf by ./images with normal builder name "SQA" or longer "hales"
+# 1 space after equal sign
+>>0x3a	search/5/s	GARMIN\ BITMAP	\b= 
+!:mime	image/x-garmin-exe
+!:ext	exe
+>>>&0	indirect	x
+# if not bitmap *.srf then region; 1 space after equal sign
+>>0x3a	default		x		\b= 
+!:mime	application/x-garmin-rgn
+!:ext	rgn
+# recursiv embedded
+>>>0x3a	search/5/s	KpGrd
+>>>>&0	indirect	x
+# look for ZIP or JAR archive by ./archive and ./zip
+>>>0x3a	search/5/s	PK\003\004
+>>>>&0	indirect	x
+# TODO: other garmin RGN record content like foo
+#>>0x3a	search/5/s	bar		BAR
+#		display information of Garmin RGN record
+0	name	garmin-entry
+# record length: 2 for Data, for Application often 1Bh sometimes 1Dh, "big" for Region
+#>0	ulelong		x		\b, length 0x%x
+# data record (ID='D') with version content like 0064h~1.0
+>4	ubyte		=0x44
+>>5	uleshort	!0x0064		\b; Data
+>>>5	uleshort/100	x		\b, version %u
+>>>5	uleshort%100	x		\b.%u
+# Application Record (ID='A')
+>4	ubyte		=0x41		\b; App
+# version content like 00c8h~2.0
+>>5	uleshort	!0x00C8
+>>>5	uleshort/100	x		\b, version %u
+>>>5	uleshort%100	x		\b.%u
+# builder name like: SQA sqa build hales
+>>7	string		x		\b, build by %s
+# build date like: Oct 25 1999, Oct 1 2008, Feb 23 2009, Dec 15 2009
+>>>&1	string		x		%s
+# build time like: 11:26:12, 11:45:54, 14:16:13, 18:23:01
+>>>>&1	string		x		%s
+# region record (ID='R')
+>4	ubyte		=0x52		\b; Region
+# region ID:14~fw_all.bin: 78~ZIP, RGN or SRF bitmap; 148~ZIP or JAR; 249~display firmware; 251~WiFi or GCD firmware; 255~ZIP
+>>5	uleshort	x		ID=%u
+# delay in ms: like 0, 500
+>>7	ulelong		!0		\b, %u ms
+# region size (is record length - 10)
+#>>11	ulelong		x		\b, length 0x%x
+# region content like:
+# "KpGr"~recursiv embedded,"GARMIN BITMAP"~Garmin Bitmap *.srf, "PK"~ZIP archive
+#>>15	string		x		\b, content "%s"
+>>15	ubequad		x		\b, content 0x%llx...
+# This does NOT WORK!
+#>>15	indirect	x		\b; contains 
+>4	default		x		\b; other
+# garmin Record ID Identifies the record content like: D A R
+>>4	ubyte		x		ID '%c'
+
 # TOM TOM GPS watches ttbin files:
 # https://github.com/ryanbinns/ttwatch/tree/master/ttbin
 # From: Daniel Lenski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file-5.37-map-rgn.diff.sig
Type: application/octet-stream
Size: 95 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20191201/35b73fae/attachment.obj>


More information about the File mailing list