file = $file; if ( empty( self::$binary_characters ) ) { self::$binary_characters .= "\x00\x01\x02\x03\x04\x05\x06\x07\0x08\x0B\x0E\x0F\x10\x11"; self::$binary_characters .= "\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1C\x1D\x1E\x1F"; } if ( empty( self::$whitespace_characters ) ) { self::$whitespace_characters .= "\x09\x0A\x0C\x0D\x20"; } if ( empty( self::$tag_terminating_characters ) ) { self::$tag_terminating_characters .= "\x20\x3E"; } if ( is_null( self::$image ) ) { $image = &self::$image; $image = array(); // Windows Icon $image[] = array ( 'mime' => 'image/vnd.microsoft.icon', 'pattern' => "\x00\x00\x01\x00", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '', // none ); // "BM" - BMP signature $image[] = array ( 'mime' => 'image/bmp', 'pattern' => "\x42\x4D", 'mask' => "\xFF\xFF", 'ignore' => '' ); // "GIF87a" - GIF signature $image[] = array ( 'mime' => 'image/gif', 'pattern' => "\x47\x49\x46\x38\x37\x61", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "GIF89a" - GIF signature $image[] = array ( 'mime' => 'image/gif', 'pattern' => "\x47\x49\x46\x38\x39\x61", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "RIFF" followed by 4 bytes followed by "WEBPVP" $image[] = array ( 'mime' => 'image/webp', 'pattern' => "\x52\x49\x46\x46\x00\x00\x00\x00\x57\x45\x42\x50\x56\x50", 'mask' => "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); // A byte with only the highest bit set followed by the string "PNG" followed by CR LF SUB LF - PNG signature $image[] = array ( 'mime' => 'image/png', 'pattern' => "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); // JPEG start of image marker followed by another marker $image[] = array ( 'mime' => 'image/jpeg', 'pattern' => "\xFF\xD8\xFF", 'mask' => "\xFF\xFF\xFF", 'ignore' => '' ); // PSD signature $image[] = array ( 'mime' => 'application/psd', 'pattern' => "\x38\x42\x50\x53", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); } if ( is_null( self::$media ) ) { $media = &self::$media; $media = array(); // The WebM signature $media[] = array ( 'mime' => 'video/webm', 'pattern' => "\x1A\x45\xDF\xA3", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); // The .snd signature $media[] = array ( 'mime' => 'audio/basic', 'pattern' => "\x2E\x73\x6E\x64", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "FORM" followed by 4 bytes followed by "AIFF" - the AIFF signature $media[] = array ( 'mime' => 'audio/aiff', 'pattern' => "\x46\x4F\x52\x4D\x00\x00\x00\x00\x41\x49\x46\x46", 'mask' => "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF", 'ignore' => '' ); // MP3 without ID3 tag /****** UNTESTED ******/ $media[] = array ( 'mime' => 'audio/mpeg', 'pattern' => "\xFF\xFB", 'mask' => "\xFF\xFF", 'ignore' => '' ); // "ID3" and the ID3v2-tagged MP3 signature $media[] = array ( 'mime' => 'audio/mpeg', 'pattern' => "\x49\x44\x33", 'mask' => "\xFF\xFF\xFF", 'ignore' => '' ); // "OggS" followed by NUL - The OGG signature $media[] = array ( 'mime' => 'application/ogg', 'pattern' => "\x4F\x67\x67\x53\x00", 'mask' => "\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "MThd" followed by 4 bytes representing the number 6 in 32 bits (big endian) - MIDI signature $media[] = array ( 'mime' => 'audio/midi', 'pattern' => "\x4D\x54\x68\x64\x00\x00\x00\x06", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "RIFF" followed by 4 bytes followed by "AVI" - AVI signature $media[] = array ( 'mime' => 'video/avi', 'pattern' => "\x52\x49\x46\x46\x00\x00\x00\x00\x41\x56\x49\x20", 'mask' => "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "RIFF" followed by 4 bytes followed by "WAVE" - WAVE signature $media[] = array ( 'mime' => 'audio/wave', 'pattern' => "\x52\x49\x46\x46\x00\x00\x00\x00\x57\x41\x56\x45", 'mask' => "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF", 'ignore' => '' ); } if ( is_null( self::$fonts ) ) { $fonts = &self::$fonts; $fonts = array(); // 34 bytes followed by "LP" - Opentype signature $fonts[] = array ( 'mime' => 'application/vnd.ms-fontobject', 'pattern' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" . "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4C\x50", 'mask' => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" . "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF", 'ignore' => '' ); // 4 bytes representing version type 1 of true type font $fonts[] = array ( 'mime' => 'application/font-ttf', 'pattern' => "\x00\x01\x00\x00", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "OTTO" - Opentype signature $fonts[] = array ( 'mime' => 'application/font-off', // application/vnd.ms-opentype 'pattern' => "\x4F\x54\x54\x4F", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "ttcf" - Truetype Collection signature $fonts[] = array ( 'mime' => 'application/x-font-truetype-collection', 'pattern' => "\x74\x74\x63\x66", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); // 'wOFF' - Web Open Font Format signature $fonts[] = array ( 'mime' => 'application/font-woff', 'pattern' => "\x77\x4F\x46\x46", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); } if ( is_null( self::$archive ) ) { $archive = &self::$archive; $archive = array(); // GZIP signature $archive[] = array ( 'mime' => 'application/x-gzip', 'pattern' => "\x1F\x8B\x08", 'mask' => "\xFF\xFF\xFF", 'ignore' => '' ); // "PK" followed by ETX, EOT - ZIP signature $archive[] = array ( 'mime' => 'application/zip', 'pattern' => "\x50\x4B\x03\x04", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); // "Rar " followed by SUB, BEL, NUL - RAR signature $archive[] = array ( 'mime' => 'application/x-rar-compressed', 'pattern' => "\x52\x61\x72\x20\x1A\x07\x00", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); } if ( is_null( self::$text ) ) { $text = &self::$text; $text = array(); // "%!PS-Adobe-" - Postscript signature $text[] = array ( 'mime' => 'application/postscript', 'pattern' => "\x25\x50\x53\x2D\x41\x64\x6F\x62\x65", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => '' ); // UTF-16 Big Endian BOM text $text[] = array ( 'mime' => 'text/plain', 'pattern' => "\xFF\xFE", 'mask' => "\xFF\xFF", 'ignore' => '' ); // UTF-16 Little Endian BOM text $text[] = array ( 'mime' => 'text/plain', 'pattern' => "\xFE\xFF", 'mask' => "\xFF\xFF", 'ignore' => '' ); // UTF-8 BOM text $text[] = array ( 'mime' => 'text/plain', 'pattern' => "\xEF\xBB\xBF", 'mask' => "\xFF\xFF\xFF", 'ignore' => '' ); } if ( is_null( self::$others ) ) { $others = &self::$others; $others = array(); $others[] = array ( 'mime' => 'WINDOWS EXECUTABLE', 'pattern' => "\x4D\x5A", 'mask' => "\xFF\xFF", 'ignore' => '' ); $others[] = array ( 'mime' => 'EXEC_LINKABLE', 'pattern' => "\x7F\x45\x4C\x46", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => '' ); } if ( is_null( self::$unknown ) ) { $unknown = &self::$unknown; $unknown = array(); // " 'text/html', 'pattern' => "\x3C\x21\x44\x4F\x43\x54\x59\x50\x45\x20\x48\x54\x4D\x4C", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x48\x54\x4D\x4C", 'mask' => "\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x48\x45\x41\x44", 'mask' => "\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x53\x43\x52\x49\x50\x54", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x49\x46\x52\x41\x4D\x45", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x48\x31", 'mask' => "\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x44\x49\x56", 'mask' => "\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x46\x4F\x4E\x54", 'mask' => "\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x54\x41\x42\x4C\x45", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x41", 'mask' => "\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x53\x54\x59\x4C\x45", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x54\x49\x54\x4C\x45", 'mask' => "\xFF\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x42", 'mask' => "\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x42\x4F\x44\x59", 'mask' => "\xFF\xFF\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x42\x52", 'mask' => "\xFF\xFF\xFF", 'ignore' => self::$whitespace_characters ); // " 'text/html', 'pattern' => "\x3C\x50", 'mask' => "\xFF\xFF", 'ignore' => self::$whitespace_characters ); // "