1b6cee71dSXin LI 2b6cee71dSXin LI#------------------------------------------------------------------------------ 3*898496eeSXin LI# $File: mathematica,v 1.17 2023/06/16 19:33:58 christos Exp $ 4b6cee71dSXin LI# mathematica: file(1) magic for mathematica files 5b6cee71dSXin LI# "H. Nanosecond" <aldomel@ix.netcom.com> 6b6cee71dSXin LI# Mathematica a multi-purpose math program 7b6cee71dSXin LI# versions 2.2 and 3.0 8b6cee71dSXin LI 9*898496eeSXin LI0 name wolfram 10*898496eeSXin LI>0 string x Mathematica notebook version 2.x 11*898496eeSXin LI!:ext mb 12*898496eeSXin LI!:mime application/vnd.wolfram.mathematica 13*898496eeSXin LI 14b6cee71dSXin LI#mathematica .mb 15*898496eeSXin LI0 string \064\024\012\000\035\000\000\000 16*898496eeSXin LI>0 use wolfram 17*898496eeSXin LI0 string \064\024\011\000\035\000\000\000 18*898496eeSXin LI>0 use wolfram 19*898496eeSXin LI 20*898496eeSXin LI# 21*898496eeSXin LI0 search/1000 Content-type:\040application/mathematica Mathematica notebook version 2.x 22*898496eeSXin LI!:ext nb 23*898496eeSXin LI!:mime application/mathematica 24*898496eeSXin LI 25b6cee71dSXin LI 26b6cee71dSXin LI# .ma 2743a5ec4eSXin LI# multiple possibilities: 28b6cee71dSXin LI 29*898496eeSXin LI0 string (*^\n\n::[\011frontEndVersion\ = 30b6cee71dSXin LI#>41 string >\0 %s 31*898496eeSXin LI>0 use wolfram 32b6cee71dSXin LI 33*898496eeSXin LI#0 string (*^\n\n::[\011palette 34b6cee71dSXin LI 35*898496eeSXin LI#0 string (*^\n\n::[\011Information 36b6cee71dSXin LI#>675 string >\0 %s #doesn't work well 37b6cee71dSXin LI 3843a5ec4eSXin LI# there may be 'cr' instead of 'nl' in some does this matter? 39b6cee71dSXin LI 40b6cee71dSXin LI# generic: 41*898496eeSXin LI0 string (*^\r\r::[\011 42*898496eeSXin LI>0 use wolfram 43*898496eeSXin LI0 string (*^\r\n\r\n::[\011 44*898496eeSXin LI>0 use wolfram 45*898496eeSXin LI0 string (*^\015 46*898496eeSXin LI>0 use wolfram 47*898496eeSXin LI0 string (*^\n\r\n\r::[\011 48*898496eeSXin LI>0 use wolfram 49*898496eeSXin LI0 string (*^\r::[\011 50*898496eeSXin LI>0 use wolfram 51*898496eeSXin LI0 string (*^\r\n::[\011 52*898496eeSXin LI>0 use wolfram 53*898496eeSXin LI0 string (*^\n\n::[\011 54*898496eeSXin LI>0 use wolfram 55*898496eeSXin LI0 string (*^\n::[\011 56*898496eeSXin LI>0 use wolfram 57b6cee71dSXin LI 58b6cee71dSXin LI 59b6cee71dSXin LI# Mathematica .mx files 60b6cee71dSXin LI 61b6cee71dSXin LI#0 string (*This\ is\ a\ Mathematica\ binary\ dump\ file.\ It\ can\ be\ loaded\ with\ Get.*) Mathematica binary file 62b6cee71dSXin LI0 string (*This\ is\ a\ Mathematica\ binary\ Mathematica binary file 63b6cee71dSXin LI#>71 string \000\010\010\010\010\000\000\000\000\000\000\010\100\010\000\000\000 64b6cee71dSXin LI# >71... is optional 65b6cee71dSXin LI>88 string >\0 from %s 66b6cee71dSXin LI 67b6cee71dSXin LI 68b6cee71dSXin LI# Mathematica files PBF: 69b6cee71dSXin LI# 115 115 101 120 102 106 000 001 000 000 000 203 000 001 000 70b6cee71dSXin LI0 string MMAPBF\000\001\000\000\000\203\000\001\000 Mathematica PBF (fonts I think) 71b6cee71dSXin LI 72b6cee71dSXin LI# .ml files These are menu resources I think 73b6cee71dSXin LI# these start with "[0-9][0-9][0-9]\ A~[0-9][0-9][0-9]\ 74b6cee71dSXin LI# how to put that into a magic rule? 75b6cee71dSXin LI4 string \ A~ MAthematica .ml file 76b6cee71dSXin LI 77b6cee71dSXin LI# .nb files 78b6cee71dSXin LI#too long 0 string (***********************************************************************\n\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Mathematica-Compatible Notebook Mathematica 3.0 notebook 79b6cee71dSXin LI0 string (*********************** Mathematica 3.0 notebook 80b6cee71dSXin LI 81b6cee71dSXin LI# other (* matches it is a comment start in these langs 82b6cee71dSXin LI# GRR: Too weak; also matches other languages e.g. ML 83b6cee71dSXin LI#0 string (* Mathematica, or Pascal, Modula-2 or 3 code text 84b6cee71dSXin LI 85b6cee71dSXin LI######################### 86b6cee71dSXin LI# MatLab v5 8743a5ec4eSXin LI# URL: http://fileformats.archiveteam.org/wiki/MAT 8843a5ec4eSXin LI# Reference: https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf 8943a5ec4eSXin LI# first 116 bytes of header contain text in human-readable form 9043a5ec4eSXin LI0 string MATLAB Matlab v 9143a5ec4eSXin LI#>11 string/T x \b, at 11 "%.105s" 9243a5ec4eSXin LI#!:mime application/octet-stream 9343a5ec4eSXin LI!:mime application/x-matlab-data 9443a5ec4eSXin LI!:ext mat 9543a5ec4eSXin LI# https://de.mathworks.com/help/matlab/import_export/mat-file-versions.html 9643a5ec4eSXin LI# level of the MAT-file like: 5.0 7.0 or maybe 7.3 9743a5ec4eSXin LI#>7 string x LEVEL "%.3s" 9843a5ec4eSXin LI>7 ubyte =0x35 \b5 mat-file 9943a5ec4eSXin LI>7 ubyte !0x35 10043a5ec4eSXin LI>>7 string x \b%.3s mat-file 101b6cee71dSXin LI>126 short 0x494d (big endian) 10243a5ec4eSXin LI>>124 beshort x version %#04x 103b6cee71dSXin LI>126 short 0x4d49 (little endian) 10443a5ec4eSXin LI# 0x0100 for level 5.0 and 0x0200 for level 7.0 10543a5ec4eSXin LI>>124 leshort x version %#04x 10643a5ec4eSXin LI# test again so that default clause works 10743a5ec4eSXin LI>126 short x 10843a5ec4eSXin LI# created by MATLAB include Platform sometimes without leading comma (0x2C) or missing 10943a5ec4eSXin LI# like: GLNX86 PCWIN PCWIN64 SOL2 Windows\0407 nt posix 11043a5ec4eSXin LI>>20 search/2 Platform:\040 \b, platform 11143a5ec4eSXin LI>>>&0 string x %-0.2s 11243a5ec4eSXin LI>>>&2 ubyte !0x2C \b%c 11343a5ec4eSXin LI>>>>&0 ubyte !0x2C \b%c 11443a5ec4eSXin LI>>>>>&0 ubyte !0x2C \b%c 11543a5ec4eSXin LI>>>>>>&0 ubyte !0x2C \b%c 11643a5ec4eSXin LI>>>>>>>&0 ubyte !0x2C \b%c 11743a5ec4eSXin LI>>>>>>>>&0 ubyte !0x2C \b%c 11843a5ec4eSXin LI>>>>>>>>>&0 ubyte !0x2C \b%c 11943a5ec4eSXin LI# examples without Platform tag like one_by_zero_char.mat 12043a5ec4eSXin LI>>20 default x 12143a5ec4eSXin LI>>>11 string x "%s" 12243a5ec4eSXin LI# created by MATLAB include time like: Fri Feb 20 15:26:59 2009 12343a5ec4eSXin LI>34 search/9/c created\040on:\040 \b, created 12443a5ec4eSXin LI>>&0 string x %-.24s 12543a5ec4eSXin LI# MatLab v4 12643a5ec4eSXin LI# From: Joerg Jenderek 12743a5ec4eSXin LI# check for valid imaginary flag of Matlab matrix version 4 12843a5ec4eSXin LI13 ushort 0 12943a5ec4eSXin LI# check for valid ASCII matrix name 13043a5ec4eSXin LI>20 ubyte >0x1F 131a4d6d3b8SXin LI# skip PreviousEntries.dat with "invalid high" name \304P\344@\001 132a4d6d3b8SXin LI>>20 ubyte <0304 133a4d6d3b8SXin LI# skip some Netwfw*.dat and $I3KREPH.dat by checking for non zero number of rows 134a4d6d3b8SXin LI>>>4 ulong !0 13543a5ec4eSXin LI# skip some CD-ROM filesystem like test-hfs.iso by looking for valid big endian type flag 136a4d6d3b8SXin LI>>>>0 ubelong&0xFFffFF00 0x00000300 137a4d6d3b8SXin LI>>>>>0 use matlab4 13843a5ec4eSXin LI# no example for 8-bit and 16-bit integers matrix 139a4d6d3b8SXin LI>>>>0 ubelong&0xFFffFF00 0x00000400 140a4d6d3b8SXin LI>>>>>0 use matlab4 141a4d6d3b8SXin LI# branch for Little-Endian variant of Matlab MATrix version 4 14243a5ec4eSXin LI# skip big endian variant by looking for valid low lttle endian type flag 143a4d6d3b8SXin LI>>>>0 ulelong <53 144a4d6d3b8SXin LI# skip tokens.dat and some Netwfw*.dat by check for valid imaginary flag value of MAT version 4 145a4d6d3b8SXin LI>>>>>12 ulelong <2 146*898496eeSXin LI# no misidentified little endian MATrix example with "short" matrix name 147a4d6d3b8SXin LI>>>>>>16 ulelong <3 148*898496eeSXin LI# skip radeon firmware BONAIRE_sdma.bin HAWAII_sdma.bin KABINI_sdma.bin KAVERI_sdma.bin MULLINS_sdma.bin 149*898496eeSXin LI# by check for non zero matrix name length 150*898496eeSXin LI>>>>>>>16 ubelong >0 151*898496eeSXin LI>>>>>>>>0 use \^matlab4 152a4d6d3b8SXin LI# little endian MATrix with "long" matrix name or some misidentified samples 153a4d6d3b8SXin LI>>>>>>16 ulelong >2 154a4d6d3b8SXin LI# skip TileCacheLogo-*.dat with invalid 2nd character \001 of matrix name with length 96 155a4d6d3b8SXin LI>>>>>>>21 ubyte >0x1F 156a4d6d3b8SXin LI>>>>>>>>0 use \^matlab4 157*898496eeSXin LI# Note: called "MATLAB Mat File" with version "Level 4" by DROID via PUID fmt/1550 15843a5ec4eSXin LI# display information of Matlab v4 mat-file 15943a5ec4eSXin LI0 name matlab4 Matlab v4 mat-file 16043a5ec4eSXin LI#!:mime application/octet-stream 16143a5ec4eSXin LI!:mime application/x-matlab-data 16243a5ec4eSXin LI!:ext mat 16343a5ec4eSXin LI# 20-byte header with 5 long integers that contains information describing certain attributes of the Matrix 16443a5ec4eSXin LI# type flag decimal MOPT; maximal 4052=FD4h; maximal 52=34h for little endian 16543a5ec4eSXin LI#>0 ubelong x \b, type flag %u 16643a5ec4eSXin LI#>0 ubelong x (%#x) 16743a5ec4eSXin LI# M: 0~little endian 1~Big Endian 2~VAX D-float 3~VAX G-float 4~Cray 16843a5ec4eSXin LI#>0 ubelong/1000 x \b, M=%u 16943a5ec4eSXin LI>0 ubelong/1000 0 (little endian) 17043a5ec4eSXin LI>0 ubelong/1000 1 (big endian) 17143a5ec4eSXin LI>0 ubelong/1000 2 (VAX D-float) 17243a5ec4eSXin LI>0 ubelong/1000 3 (VAX G-float) 17343a5ec4eSXin LI>0 ubelong/1000 4 (Cray) 17443a5ec4eSXin LI# namlen; the length of the matrix name 17543a5ec4eSXin LI#>16 ubelong x \b, name length %u 176a4d6d3b8SXin LI#>(16.L+19) ubyte x \b, TERMINATING NAME CHARACTER=%#x 17743a5ec4eSXin LI# nul terminated matrix name like: fit_params testmatrix testsparsecomplex teststringarray 17843a5ec4eSXin LI#>20 string x \b, MATRIX NAME="%s" 179a4d6d3b8SXin LI#>21 ubyte x \b, MAYBE 2ND CHAR=%c 18043a5ec4eSXin LI>16 pstring/L x %s 18143a5ec4eSXin LI# T indicates the matrix type: 0~numeric 1~text 2~sparse 18243a5ec4eSXin LI#>0 ubelong%10 x \b, T=%u 18343a5ec4eSXin LI>0 ubelong%10 0 \b, numeric 18443a5ec4eSXin LI>0 ubelong%10 1 \b, text 18543a5ec4eSXin LI>0 ubelong%10 2 \b, sparse 18643a5ec4eSXin LI# mrows; number of rows in the matrix like: 1 3 8 18743a5ec4eSXin LI>4 ubelong x \b, rows %u 18843a5ec4eSXin LI# ncols; number of columns in the matrix like: 1 3 4 5 9 43 18943a5ec4eSXin LI>8 ubelong x \b, columns %u 19043a5ec4eSXin LI# imagf; imaginary flag; 1~matrix has an imaginary part 0~only real data 191a4d6d3b8SXin LI>12 ubelong !0 \b, imaginary (%u) 19243a5ec4eSXin LI# real; Real part of the matrix consists of mrows * ncols numbers 193