MediaWiki  1.34.0
MSCompoundFileReader Class Reference

Read the directory of a Microsoft Compound File Binary file, a.k.a. More...

Static Public Member Functions

static readFile ( $fileName)
 Read a file by name. More...
 
static readHandle ( $fileHandle)
 Read from an open seekable handle. More...
 

Public Attributes

const ERROR_FILE_OPEN = 1
 
const ERROR_INVALID_FORMAT = 6
 
const ERROR_INVALID_SIGNATURE = 4
 
const ERROR_READ = 3
 
const ERROR_READ_PAST_END = 5
 
const ERROR_SEEK = 2
 
const TYPE_ROOT = 5
 
const TYPE_STORAGE = 1
 
const TYPE_STREAM = 2
 
const TYPE_UNALLOCATED = 0
 

Private Member Functions

 __construct ( $fileHandle)
 
 bin2dec ( $str, $offset, $length)
 
 decodeClsid ( $binaryClsid)
 
 error ( $message, $code)
 
 fseek ( $offset)
 
 getFatSector ( $fatSectorId)
 
 getNextSectorIdFromFat ( $sectorId)
 
 init ()
 
 readDifat ()
 
 readDirectory ()
 
 readOffset ( $offset, $length)
 
 readSector ( $sectorId)
 
 sectorOffset ( $sectorId)
 
 unpack ( $block, $offset, $struct)
 
 unpackOffset ( $offset, $struct)
 

Private Attributes

 $difat
 
 $error
 
 $errorCode
 
 $fat = []
 
 $file
 
 $fileLength
 
 $header
 
 $mime
 
 $mimeFromClsid
 
 $sectorLength
 
 $valid = false
 

Static Private Attributes

static $mimesByClsid
 

Detailed Description

Read the directory of a Microsoft Compound File Binary file, a.k.a.

an OLE file, and detect the MIME type.

References:

Since
1.33

Definition at line 32 of file MSCompoundFileReader.php.

Constructor & Destructor Documentation

◆ __construct()

MSCompoundFileReader::__construct (   $fileHandle)
private

Definition at line 116 of file MSCompoundFileReader.php.

References $fileHandle, error(), and init().

Member Function Documentation

◆ bin2dec()

MSCompoundFileReader::bin2dec (   $str,
  $offset,
  $length 
)
private

Definition at line 210 of file MSCompoundFileReader.php.

Referenced by getFatSector(), readDifat(), and unpack().

◆ decodeClsid()

MSCompoundFileReader::decodeClsid (   $binaryClsid)
private

Definition at line 164 of file MSCompoundFileReader.php.

References unpack().

Referenced by readDirectory().

◆ error()

MSCompoundFileReader::error (   $message,
  $code 
)
private

◆ fseek()

MSCompoundFileReader::fseek (   $offset)
private

Definition at line 243 of file MSCompoundFileReader.php.

References error().

Referenced by readOffset().

◆ getFatSector()

MSCompoundFileReader::getFatSector (   $fatSectorId)
private

Definition at line 282 of file MSCompoundFileReader.php.

References $fat, bin2dec(), error(), and readSector().

Referenced by getNextSectorIdFromFat().

◆ getNextSectorIdFromFat()

MSCompoundFileReader::getNextSectorIdFromFat (   $sectorId)
private

Definition at line 275 of file MSCompoundFileReader.php.

References getFatSector().

Referenced by readDirectory().

◆ init()

MSCompoundFileReader::init ( )
private

Definition at line 127 of file MSCompoundFileReader.php.

References error(), readDifat(), readDirectory(), and unpackOffset().

Referenced by __construct().

◆ readDifat()

MSCompoundFileReader::readDifat ( )
private

Definition at line 252 of file MSCompoundFileReader.php.

References bin2dec(), and readSector().

Referenced by init().

◆ readDirectory()

MSCompoundFileReader::readDirectory ( )
private

Definition at line 298 of file MSCompoundFileReader.php.

References $type, decodeClsid(), error(), getNextSectorIdFromFat(), readSector(), and unpack().

Referenced by init().

◆ readFile()

static MSCompoundFileReader::readFile (   $fileName)
static

Read a file by name.

Parameters
string$fileNameThe full path to the file
Returns
array An associative array of information about the file:
  • valid: true if the file is valid, false otherwise
  • error: An error message in English, should be present if valid=false
  • errorCode: One of the self::ERROR_* constants
  • mime: The MIME type detected from the directory contents
  • mimeFromClsid: The MIME type detected from the CLSID on the root directory entry

Definition at line 78 of file MSCompoundFileReader.php.

References ERROR_FILE_OPEN, and readHandle().

◆ readHandle()

static MSCompoundFileReader::readHandle (   $fileHandle)
static

Read from an open seekable handle.

Parameters
resource$fileHandleThe file handle
Returns
array An associative array of information about the file:
  • valid: true if the file is valid, false otherwise
  • error: An error message in English, should be present if valid=false
  • errorCode: One of the self::ERROR_* constants
  • mime: The MIME type detected from the directory contents
  • mimeFromClsid: The MIME type detected from the CLSID on the root directory entry

Definition at line 102 of file MSCompoundFileReader.php.

References $fileHandle.

Referenced by MimeAnalyzer\detectMicrosoftBinaryType(), and readFile().

◆ readOffset()

MSCompoundFileReader::readOffset (   $offset,
  $length 
)
private

Definition at line 219 of file MSCompoundFileReader.php.

References error(), and fseek().

Referenced by readSector(), and unpackOffset().

◆ readSector()

MSCompoundFileReader::readSector (   $sectorId)
private

Definition at line 234 of file MSCompoundFileReader.php.

References readOffset(), and sectorOffset().

Referenced by getFatSector(), readDifat(), and readDirectory().

◆ sectorOffset()

MSCompoundFileReader::sectorOffset (   $sectorId)
private

Definition at line 160 of file MSCompoundFileReader.php.

Referenced by readSector().

◆ unpack()

MSCompoundFileReader::unpack (   $block,
  $offset,
  $struct 
)
private
Parameters
string$block
int$offset
int[]$struct
Returns
array

Definition at line 197 of file MSCompoundFileReader.php.

References bin2dec().

Referenced by decodeClsid(), readDirectory(), and unpackOffset().

◆ unpackOffset()

MSCompoundFileReader::unpackOffset (   $offset,
  $struct 
)
private
Parameters
int$offset
int[]$struct
Returns
array

Definition at line 186 of file MSCompoundFileReader.php.

References readOffset(), and unpack().

Referenced by init().

Member Data Documentation

◆ $difat

MSCompoundFileReader::$difat
private

Definition at line 42 of file MSCompoundFileReader.php.

◆ $error

MSCompoundFileReader::$error
private

Definition at line 37 of file MSCompoundFileReader.php.

◆ $errorCode

MSCompoundFileReader::$errorCode
private

Definition at line 38 of file MSCompoundFileReader.php.

◆ $fat

MSCompoundFileReader::$fat = []
private

Definition at line 43 of file MSCompoundFileReader.php.

Referenced by getFatSector().

◆ $file

MSCompoundFileReader::$file
private

Definition at line 33 of file MSCompoundFileReader.php.

◆ $fileLength

MSCompoundFileReader::$fileLength
private

Definition at line 44 of file MSCompoundFileReader.php.

◆ $header

MSCompoundFileReader::$header
private

Definition at line 34 of file MSCompoundFileReader.php.

◆ $mime

MSCompoundFileReader::$mime
private

Definition at line 35 of file MSCompoundFileReader.php.

◆ $mimeFromClsid

MSCompoundFileReader::$mimeFromClsid
private

Definition at line 36 of file MSCompoundFileReader.php.

◆ $mimesByClsid

MSCompoundFileReader::$mimesByClsid
staticprivate
Initial value:
= [
'00020810-0000-0000-C000-000000000046' => 'application/vnd.ms-excel',
'00020820-0000-0000-C000-000000000046' => 'application/vnd.ms-excel',
'00020906-0000-0000-C000-000000000046' => 'application/msword',
'64818D10-4F9B-11CF-86EA-00AA00B929E8' => 'application/vnd.ms-powerpoint',
]

Definition at line 58 of file MSCompoundFileReader.php.

◆ $sectorLength

MSCompoundFileReader::$sectorLength
private

Definition at line 41 of file MSCompoundFileReader.php.

◆ $valid

MSCompoundFileReader::$valid = false
private

Definition at line 39 of file MSCompoundFileReader.php.

◆ ERROR_FILE_OPEN

const MSCompoundFileReader::ERROR_FILE_OPEN = 1

Definition at line 51 of file MSCompoundFileReader.php.

Referenced by readFile().

◆ ERROR_INVALID_FORMAT

const MSCompoundFileReader::ERROR_INVALID_FORMAT = 6

Definition at line 56 of file MSCompoundFileReader.php.

◆ ERROR_INVALID_SIGNATURE

const MSCompoundFileReader::ERROR_INVALID_SIGNATURE = 4

Definition at line 54 of file MSCompoundFileReader.php.

◆ ERROR_READ

const MSCompoundFileReader::ERROR_READ = 3

Definition at line 53 of file MSCompoundFileReader.php.

◆ ERROR_READ_PAST_END

const MSCompoundFileReader::ERROR_READ_PAST_END = 5

Definition at line 55 of file MSCompoundFileReader.php.

◆ ERROR_SEEK

const MSCompoundFileReader::ERROR_SEEK = 2

Definition at line 52 of file MSCompoundFileReader.php.

◆ TYPE_ROOT

const MSCompoundFileReader::TYPE_ROOT = 5

Definition at line 49 of file MSCompoundFileReader.php.

◆ TYPE_STORAGE

const MSCompoundFileReader::TYPE_STORAGE = 1

Definition at line 47 of file MSCompoundFileReader.php.

◆ TYPE_STREAM

const MSCompoundFileReader::TYPE_STREAM = 2

Definition at line 48 of file MSCompoundFileReader.php.

◆ TYPE_UNALLOCATED

const MSCompoundFileReader::TYPE_UNALLOCATED = 0

Definition at line 46 of file MSCompoundFileReader.php.


The documentation for this class was generated from the following file: