map 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. #------------------------------------------------------------------------------
  2. # $File: map,v 1.10 2023/02/03 20:41:57 christos Exp $
  3. # map: file(1) magic for Map data
  4. #
  5. # Garmin .FIT files https://pub.ks-and-ks.ne.jp/cycling/edge500_fit.shtml
  6. 8 string .FIT FIT Map data
  7. >15 byte 0
  8. >>35 belong x \b, unit id %d
  9. >>39 lelong x \b, serial %u
  10. # https://pub.ks-and-ks.ne.jp/cycling/edge500_fit.shtml
  11. # 20 years after unix epoch
  12. # TZ=GMT date -d '1989-12-31 0:00' +%s
  13. >>43 leldate+631065600 x \b, %s
  14. >>47 leshort x \b, manufacturer %d
  15. >>47 leshort 1 \b (garmin)
  16. >>49 leshort x \b, product %d
  17. >>53 byte x \b, type %d
  18. >>53 byte 1 \b (Device)
  19. >>53 byte 2 \b (Settings)
  20. >>53 byte 3 \b (Sports/Cycling)
  21. >>53 byte 4 \b (Activity)
  22. >>53 byte 8 \b (Elevations)
  23. >>53 byte 10 \b (Totals)
  24. # Summary: Garmin map
  25. # From: Joerg Jenderek
  26. # URL: https://en.wikipedia.org/wiki/Garmin_.img
  27. # Reference: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/IMG_File_Format
  28. # sourceforge.net/projects/garmin-img/files/IMG%20File%20Format/1.0/imgformat-1.0.pdf
  29. # GRR: similar to MBR boot sector handled by ./filesystems
  30. 0x1FE leshort =0xAA55
  31. # look for valid map signature
  32. >0x13 string =IMG\0
  33. >>0 use garmin-map
  34. 0 name garmin-map
  35. >0 ubyte x Garmin
  36. !:mime application/x-garmin-map
  37. # If non-zero, every byte of the entire .img file is to be XORed with this value
  38. >0 ubyte !0 \b, %#x XORed
  39. # goto block before FAT
  40. >(0x40.b*512) ubyte x
  41. # 1st fat name "DLLINFO TXT" only found for vpm
  42. >>&512 string =DLLINFO\ TXT map (Voice Processing)
  43. # there exist 2 other Garmin VPM formats; see ./audio
  44. !:ext vpm
  45. # Deutsch__Yannick_D4481-00_0210.vpm
  46. #>>>512 search/0x0116da60/s RIFF \b; with
  47. # determine type voice type by ./riff
  48. #>>>>&0 indirect x \b
  49. >>&512 string !DLLINFO\ TXT map
  50. !:ext img
  51. # 9 zeros
  52. >1 ubelong !0 \b, zeroes %#x
  53. # Map's version major
  54. >8 ubyte x v%u
  55. # Map's version minor
  56. >9 ubyte x \b.%.2u
  57. # Map description[20], 0x20 padded
  58. >0x49 string x %.20s
  59. # Map name, continued (0x20 padded, \0 terminated)
  60. >0x65 string >\ \b%.31s
  61. # Update year (+1900 for val >= 0x63, +2000 for val <= 0x62)
  62. >0xB ubyte x \b, updated
  63. >>0xB ubyte >0x62
  64. >>>0xB ubyte-100 x 20%.2u
  65. >>0xB ubyte <0x63
  66. >>>0xB ubyte x 20%.2u
  67. # Update month (0-11)
  68. >0xA ubyte x \b-%.2u
  69. # All zeroes
  70. >0xc uleshort !0 \b, zeroes %#x
  71. # Mapsource flag, 1 - file created by Mapsource, 0 - Garmin map visible in Basecamp and Homeport
  72. #>0xE ubyte !0 \b, Mapsource flag %#x
  73. >0xE ubyte 1 \b, Mapsource
  74. # Checksum, sum of all bytes modulo 256 should be 0
  75. #>0xF ubyte x \b, Checksum %#x
  76. # Signature: DSKIMG 0x00 or DSDIMG 0x00 for demo map
  77. >0x10 string !DSKIMG \b, signature "%.7s"
  78. >0x39 use garmin-date
  79. # Map file identifier like GARMIN\0
  80. >0x41 string !GARMIN \b, id "%.7s"
  81. # Block size exponent, E1; appears to always be 0x09; minimum block size 512 bytes
  82. >0x61 ubyte !0x09 \b, E1=%u
  83. # Block size exponent, E2 ; file blocksize=2**(E1+E2)
  84. >>0x62 ubyte x \b, E2=%u
  85. >0x61 ubyte =0x09 \b, blocksize
  86. >>0x62 ubyte 0 512
  87. >>0x62 ubyte 1 1024
  88. >>0x62 ubyte 2 2048
  89. >>0x62 ubyte 3 4096
  90. >>0x62 ubyte 4 8192
  91. >>0x62 ubyte 5 16384
  92. >>0x62 default x
  93. >>>0x62 ubyte x E2=%u
  94. # MBR signature
  95. >0x1FE leshort !0xAA55 \b, invalid MBR
  96. # 512 zeros
  97. >0x200 uquad !0 \b, zeroes %#llx
  98. # First sub-file offset (absolute); sometimes NO/UNKNOWN sub file!
  99. >0x40C ulelong >0 \b, at %#x
  100. # sub-file Header length
  101. #>>(0x40C.l) uleshort x \b, header len %#x
  102. >>(0x40C.l) uleshort x %u bytes
  103. # sub-file Type[10] like "GARMIN RGN" "GARMIN TRE", "GARMIN TYP", etc.
  104. >>(0x40C.l+2) ubyte >0x1F
  105. >>>(0x40C.l+2) ubyte <0xFF
  106. >>>>(0x40C.l+2) string x "%.10s"
  107. # 0x00 for most maps, 0x80 for locked maps (City Nav, City Select, etc.)
  108. >>>>(0x40C.l+13) ubyte >0 \b, locked %#x
  109. # Block sequence numbers like 0000 0100 0200 ... FFFF
  110. # >0x420 ubequad >0 \b, seq. %#16.16llx
  111. # >>0x428 ubequad >0 \b%16.16llx
  112. # >>>0x430 ubequad >0 \b%16.16llx
  113. # >>>>0x438 ubequad >0 \b%16.16llx
  114. # >>>>>0x440 ubequad >0 \b%16.16llx
  115. # >>>>>>0x448 ubequad >0 \b%16.16llx
  116. # >>>>>>>0x450 ubequad >0 \b%16.16llx
  117. # >>>>>>>>0x458 ubequad >0 \b%16.16llx
  118. # >>>>>>>>>0x460 ubequad >0 \b%16.16llx
  119. # >>>>>>>>>>0x468 ubequad >0 \b%16.16llx
  120. # >>>>>>>>>>>0x470 ubequad >0 \b%16.16llx
  121. # >>>>>>>>>>>>0x478 ubequad >0 \b%16.16llx
  122. # >>>>>>>>>>>>>0x480 ubequad >0 \b%16.16llx
  123. # >>>>>>>>>>>>>>0x488 ubequad >0 \b%16.16llx
  124. # >>>>>>>>>>>>>>>0x490 ubequad >0 \b%16.16llx
  125. # >>>>>>>>>>>>>>>>0x498 ubequad >0 \b%16.16llx
  126. # >>>>>>>>>>>>>>>>>0x4A0 ubequad >0 \b%16.16llx
  127. # >>>>>>>>>>>>>>>>>>0x4A8 ubequad >0 \b%16.16llx
  128. # look for end of FAT
  129. #>>0x420 search/512/s \xff\xff FAT END
  130. # Physical block number of FAT header
  131. #>0x40 ubyte x \b, FAT at phy. block %u
  132. >0x40 ubyte x
  133. >>(0x40.b*512) ubyte x
  134. # 1st FAT block
  135. >>>&511 use garmin-fat
  136. # 2nd FAT block
  137. >>>&1023 use garmin-fat
  138. # 3th FAT block
  139. >>>&1535 use garmin-fat
  140. # 4th FAT block
  141. >>>&2047 use garmin-fat
  142. # ... xth FAT block
  143. #
  144. # 314 zeros but not in vpm and also gmaptz.img
  145. >0x84 uquad !0 \b, at 0x84 %#llx
  146. # display FileAllocationTable block entry in garmin map
  147. 0 name garmin-fat
  148. >0 ubyte x \b;
  149. # sub file part; 0x0003 seems to be garbage
  150. >0x10 uleshort !0 next %#4.4x
  151. >0x10 uleshort =0
  152. # fat flag 0~dummy block 1~true sub file
  153. >>0 ubyte !1 flag %u
  154. >>0 ubyte =1
  155. # sub-file name like MAKEGMAP 12345678
  156. >>>0x1 string x %.8s
  157. # sub-file typ like RGN TRE MDR LBL
  158. >>>0x9 string x \b.%.3s
  159. # size of sub file
  160. >>>0xC ulelong x \b, %u bytes
  161. # 32-bit block sequence numbers
  162. #>>>0x20 ubequad x \b, seq. %#16.16llx
  163. # display date stored inside Garmin maps like yyyy-mm-dd h:mm:ss
  164. 0 name garmin-date
  165. # year like 2018
  166. >0 uleshort x \b, created %u
  167. # month (0-11)
  168. >2 ubyte x \b-%.2u
  169. # day (1-31)
  170. >3 ubyte x \b-%.2u
  171. # hour (0-23)
  172. >4 ubyte x %u
  173. # minute (0-59)
  174. >5 ubyte x \b:%.2u
  175. # second (0-59)
  176. >6 ubyte x \b:%.2u
  177. # Summary: Garmin Map subfiles
  178. # From: Joerg Jenderek
  179. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/IMG_File_Format
  180. # Garmin Common Header
  181. 2 string GARMIN\
  182. # skip ASCII text by checking for low header length
  183. >0 uleshort <0x1000 Garmin map,
  184. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/GMP_Subfile_Format
  185. >>9 string GMP subtile
  186. !:mime application/x-garmin-gpm
  187. !:ext gmp
  188. # copyright message
  189. >>>(0.s) string x %s
  190. >>>0x0E use garmin-date
  191. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/MDR_Subfile_Format
  192. # This contains the searchable address table used for finding routing destinations
  193. >>9 string MDR address table
  194. !:mime application/x-garmin-mdr
  195. !:ext mdr
  196. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/NOD_Subfile_Format
  197. # http://svn.parabola.me.uk/display/trunk/doc/nod.txt
  198. # This contains the routing information
  199. >>9 string NOD routing
  200. !:mime application/x-garmin-nod
  201. !:ext nod
  202. >>>0x0E use garmin-date
  203. #>>>0x15 ulelong x \b, at %#x
  204. #>>>0x19 ulelong x %#x bytes NOD1
  205. #>>>0x25 ulelong x \b, at %#x
  206. #>>>0x29 ulelong x %#x bytes NOD2
  207. #>>>0x31 ulelong x \b, at %#x
  208. #>>>0x35 ulelong x %#x bytes NOD3
  209. # URL: http://www.pinns.co.uk/osm/net.html
  210. # routable highways (length, direction, allowed speed,house address information)
  211. >>9 string NET highways
  212. !:mime application/x-garmin-net
  213. !:ext net
  214. #>>>0x15 ulelong x \b, at %#x
  215. #>>>0x19 ulelong x %#x bytes NET1
  216. #>>>0x22 ulelong >0
  217. #>>>>0x1E ulelong x \b, at %#x
  218. #>>>>0x22 ulelong x %#x bytes NET2
  219. #>>>0x2B ulelong >0
  220. #>>>>0x27 ulelong x \b, at %#x
  221. #>>>>0x2B ulelong x %#x bytes NET3
  222. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/LBL_Subfile_Format
  223. >>9 string LBL labels
  224. !:mime application/x-garmin-lbl
  225. !:ext lbl
  226. >>>(0.s) string x %s
  227. # Label coding type 6h 9h and ah
  228. >>>0x1E ubyte x \b, coding type %#x
  229. #>>>0x15 ulelong x \b, at %#x
  230. #>>>0x19 ulelong x %#x bytes LBL1
  231. #>>>0x1F ulelong x \b, at %#x
  232. #>>>0x23 ulelong x %#x bytes LBL2
  233. #>>>0x2D ulelong x \b, at %#x
  234. #>>>0x31 ulelong x %#x bytes LBL3
  235. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/SRT_Subfile_Format
  236. # A lookup table of the chars in the map's codepage, and their collating sequence
  237. >>9 string SRT sort table
  238. !:mime application/x-garmin-srt
  239. !:ext srt
  240. >>>0x0E use garmin-date
  241. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/TRE_Subfile_Format
  242. >>9 string TRE tree
  243. !:mime application/x-garmin-tre
  244. !:ext tre
  245. # title like City Nav Europe NTU 2019.2 Basemap
  246. # or OSM Street map
  247. >>>(0.s) string x %s
  248. # 2nd title like Copyright 1995-2018 by GARMIN Corporation.
  249. # or http://www.openstreetmap.org/
  250. >>>>&1 string x %s
  251. >>>0x0E use garmin-date
  252. #>>>0x21 ulelong x \b, at %#x
  253. #>>>0x25 ulelong x %#x bytes TRE1
  254. #>>>0x29 ulelong x \b, at %#x
  255. #>>>0x2D ulelong x %#x bytes TRE2
  256. #>>>0x31 ulelong x \b, at %#x
  257. #>>>0x35 ulelong x %#x bytes TRE3
  258. # Copyright record size
  259. #>>>0x39 uleshort x \b, copyright record size %u
  260. # Map ID
  261. >>>0x74 ulelong x \b, ID %#x
  262. # URL: https://www.gpspower.net/garmin-tutorials/353310-basecamp-installing-free-desktop-map.html
  263. # For road traffic information service (RDS/TMS/TMC). Commonly seen in City Navigator maps
  264. >>9 string TRF traffic,
  265. !:mime application/x-garmin-trf
  266. !:ext trf
  267. # city/region like Preitenegg
  268. >>>(0.s+1) string x 1st %s
  269. # highway part like L606/L148
  270. >>>>&1 string x %s
  271. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/Format
  272. # Reference: http://www.pinns.co.uk/osm/typformat.html
  273. # customize the appearance of objects. For GPS and MapSource/Qlandkarte better looking maps
  274. >>9 string TYP types
  275. !:mime application/x-garmin-typ
  276. !:ext typ
  277. >>>0x0E use garmin-date
  278. # character set 1252 65001~UTF8
  279. >>>0x15 uleshort x \b, code page %u
  280. # POIs
  281. #>>>0x17 ulelong x \b, at %#x
  282. #>>>0x1B ulelong x %#x bytes TYP1
  283. # extra pois
  284. #>>>0x5B ulelong x \b, at %#x
  285. #>>>0x5F ulelong x %#x bytes TYP8
  286. # URL: https://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/RGN_Subfile_Format
  287. # http://www.pinns.co.uk/osm/RGN.html
  288. # region data used by the Garmin software
  289. >>9 string RGN region
  290. !:mime application/x-garmin-rgn
  291. !:ext rgn
  292. # POIs,Indexed POIs,Polylines or Polygons or first map level
  293. #>>>0x15 ulelong x \b, at %#x
  294. #>>>0x19 ulelong x %#x bytes RGN1
  295. # polygons with extended types
  296. #>>>0x21 ulelong >0
  297. #>>>>0x1D ulelong x \b, at %#x
  298. #>>>>0x21 ulelong x %#x bytes RGN2
  299. # polylines with extended types
  300. #>>>0x3D ulelong >0
  301. #>>>>0x39 ulelong x \b, at %#x
  302. #>>>>0x3D ulelong x %#x bytes RGN3
  303. # extended POIs
  304. #>>>0x59 ulelong >0
  305. #>>>>0x55 ulelong x \b, at %#x
  306. #>>>>0x59 ulelong x %#x bytes RGN3
  307. #>>9 default x unknown map type
  308. # Header length; GMP:31h 35h 3Dh,MDR:11Eh 238h 2C4h 310h,NOD:3Fh 7Fh,NET:64h,
  309. # LBL:2A9h,SRT:1Dh 25h 27h,TRE:CFh 135h,TRF:5Ah,TYP:5Bh 6Eh 7Ch AEh,RGN:7Dh
  310. >>0 uleshort x \b, header length %#x
  311. # URL: https://www.memotech.franken.de/FileFormats/
  312. # Reference: https://www.memotech.franken.de/FileFormats/Garmin_RGN_Format.pdf
  313. # From: Joerg Jenderek
  314. 0 string KpGr Garmin update
  315. # format version like: 0064h~1.0
  316. >0x4 uleshort !0x0064
  317. >>4 uleshort/100 x \b, version %u
  318. >>4 uleshort%100 x \b.%u
  319. # 1st Garmin entry
  320. >6 use garmin-entry
  321. # 2nd Garmin entry
  322. >(0x6.l+10) ubyte x
  323. >>&0 use garmin-entry
  324. # 3rd entry
  325. >(0x6.l+10) ubyte x
  326. >>&(&0.l+4) ubyte x
  327. >>>&0 use garmin-entry
  328. # look again at version to use default clause
  329. >0x4 uleshort x
  330. # test for region content by looking for
  331. # Garmin *.srf by ./images with normal builder name "SQA" or longer "hales"
  332. # 1 space after equal sign
  333. >>0x3a search/5/s GARMIN\ BITMAP \b=
  334. !:mime image/x-garmin-exe
  335. !:ext exe
  336. >>>&0 indirect x
  337. # if not bitmap *.srf then region; 1 space after equal sign
  338. >>0x3a default x \b=
  339. !:mime application/x-garmin-rgn
  340. !:ext rgn
  341. # recursiv embedded
  342. >>>0x3a search/5/s KpGrd
  343. >>>>&0 indirect x
  344. # look for ZIP or JAR archive by ./archive and ./zip
  345. >>>0x3a search/5/s PK\003\004
  346. >>>>&0 indirect x
  347. # TODO: other garmin RGN record content like foo
  348. #>>0x3a search/5/s bar BAR
  349. # display information of Garmin RGN record
  350. 0 name garmin-entry
  351. # record length: 2 for Data, for Application often 1Bh sometimes 1Dh, "big" for Region
  352. #>0 ulelong x \b, length %#x
  353. # data record (ID='D') with version content like 0064h~1.0
  354. >4 ubyte =0x44
  355. >>5 uleshort !0x0064 \b; Data
  356. >>>5 uleshort/100 x \b, version %u
  357. >>>5 uleshort%100 x \b.%u
  358. # Application Record (ID='A')
  359. >4 ubyte =0x41 \b; App
  360. # version content like 00c8h~2.0
  361. >>5 uleshort !0x00C8
  362. >>>5 uleshort/100 x \b, version %u
  363. >>>5 uleshort%100 x \b.%u
  364. # builder name like: SQA sqa build hales
  365. >>7 string x \b, build by %s
  366. # build date like: Oct 25 1999, Oct 1 2008, Feb 23 2009, Dec 15 2009
  367. >>>&1 string x %s
  368. # build time like: 11:26:12, 11:45:54, 14:16:13, 18:23:01
  369. >>>>&1 string x %s
  370. # region record (ID='R')
  371. >4 ubyte =0x52 \b; Region
  372. # 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
  373. >>5 uleshort x ID=%u
  374. # delay in ms: like 0, 500
  375. >>7 ulelong !0 \b, %u ms
  376. # region size (is record length - 10)
  377. #>>11 ulelong x \b, length %#x
  378. # region content like:
  379. # "KpGr"~recursiv embedded,"GARMIN BITMAP"~Garmin Bitmap *.srf, "PK"~ZIP archive
  380. #>>15 string x \b, content "%s"
  381. >>15 ubequad x \b, content %#llx...
  382. # This does NOT WORK!
  383. #>>15 indirect x \b; contains
  384. >4 default x \b; other
  385. # garmin Record ID Identifies the record content like: D A R
  386. >>4 ubyte x ID '%c'
  387. # TOM TOM GPS watches ttbin files:
  388. # https://github.com/ryanbinns/ttwatch/tree/master/ttbin
  389. # From: Daniel Lenski
  390. 0 byte 0x20
  391. >1 leshort 0x0007
  392. >>0x76 byte 0x20
  393. >>>0x77 leshort 0x0075 TomTom activity file, v7
  394. >>>>8 leldate x (%s,
  395. >>>>3 byte x device firmware %d.
  396. >>>>4 byte x \b%d.
  397. >>>>5 byte x \b%d,
  398. >>>>6 leshort x product ID %04d)
  399. # Garmin firmware:
  400. # https://www.memotech.franken.de/FileFormats/Garmin_GCD_Format.pdf
  401. # https://www.gpsrchive.com/GPSMAP/GPSMAP%2066sr/Firmware.html
  402. 0 string GARMIN
  403. >6 uleshort 100 GARMIN firmware (version 1.0)