MediaWiki REL1_33
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.
 
static readHandle ( $fileHandle)
 Read from an open seekable handle.
 

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)
 
 unpackSector ( $sectorNumber, $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 $e, $fileHandle, and init().

Member Function Documentation

◆ bin2dec()

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

Definition at line 203 of file MSCompoundFileReader.php.

References $value, and and().

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

◆ decodeClsid()

MSCompoundFileReader::decodeClsid ( $binaryClsid)
private

Definition at line 163 of file MSCompoundFileReader.php.

References and(), and unpack().

Referenced by readDirectory().

◆ error()

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

Definition at line 231 of file MSCompoundFileReader.php.

References $code.

◆ fseek()

MSCompoundFileReader::fseek ( $offset)
private

Definition at line 235 of file MSCompoundFileReader.php.

References and(), error, and fseek().

Referenced by fseek(), and readOffset().

◆ getFatSector()

MSCompoundFileReader::getFatSector ( $fatSectorId)
private

Definition at line 274 of file MSCompoundFileReader.php.

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

Referenced by getNextSectorIdFromFat().

◆ getNextSectorIdFromFat()

MSCompoundFileReader::getNextSectorIdFromFat ( $sectorId)
private

Definition at line 267 of file MSCompoundFileReader.php.

References and(), and getFatSector().

Referenced by readDirectory().

◆ init()

MSCompoundFileReader::init ( )
private

Definition at line 127 of file MSCompoundFileReader.php.

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

Referenced by __construct().

◆ readDifat()

MSCompoundFileReader::readDifat ( )
private

Definition at line 244 of file MSCompoundFileReader.php.

References and(), bin2dec(), and readSector().

Referenced by init().

◆ readDirectory()

MSCompoundFileReader::readDirectory ( )
private

Definition at line 290 of file MSCompoundFileReader.php.

References $type, and(), 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 and(), ERROR_FILE_OPEN, and readHandle().

Referenced by MSCompoundFileReaderTest\testReadFile(), and MSCompoundFileReaderTest\testReadFileInvalid().

◆ 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 readFile().

◆ readOffset()

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

Definition at line 212 of file MSCompoundFileReader.php.

References and(), error, and fseek().

Referenced by readSector(), and unpackOffset().

◆ readSector()

MSCompoundFileReader::readSector ( $sectorId)
private

Definition at line 227 of file MSCompoundFileReader.php.

References readOffset(), and sectorOffset().

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

◆ sectorOffset()

MSCompoundFileReader::sectorOffset ( $sectorId)
private

Definition at line 159 of file MSCompoundFileReader.php.

Referenced by readSector(), and unpackSector().

◆ unpack()

MSCompoundFileReader::unpack ( $block,
$offset,
$struct )
private

Definition at line 190 of file MSCompoundFileReader.php.

References $data, and(), and bin2dec().

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

◆ unpackOffset()

MSCompoundFileReader::unpackOffset ( $offset,
$struct )
private

Definition at line 180 of file MSCompoundFileReader.php.

References and(), readOffset(), and unpack().

Referenced by init(), and unpackSector().

◆ unpackSector()

MSCompoundFileReader::unpackSector ( $sectorNumber,
$struct )
private

Definition at line 185 of file MSCompoundFileReader.php.

References and(), sectorOffset(), and unpackOffset().

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: