ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Shared\OLERead Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Shared\OLERead:

Public Member Functions

 read (string $pFilename)
 Read the file. More...
 
 getStream ($stream)
 Extract binary stream data. More...
 

Data Fields

const BIG_BLOCK_SIZE = 0x200
 
const SMALL_BLOCK_SIZE = 0x40
 
const PROPERTY_STORAGE_BLOCK_SIZE = 0x80
 
const SMALL_BLOCK_THRESHOLD = 0x1000
 
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c
 
const ROOT_START_BLOCK_POS = 0x30
 
const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c
 
const EXTENSION_BLOCK_POS = 0x44
 
const NUM_EXTENSION_BLOCK_POS = 0x48
 
const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c
 
const SIZE_OF_NAME_POS = 0x40
 
const TYPE_POS = 0x42
 
const START_BLOCK_POS = 0x74
 
const SIZE_POS = 0x78
 
 $wrkbook
 
 $summaryInformation
 
 $documentSummaryInformation
 

Private Member Functions

 readData ($bl)
 Read a standard stream (by joining sectors using information from SAT). More...
 
 readPropertySets ()
 Read entries in the directory stream. More...
 

Static Private Member Functions

static getInt4d ($data, $pos)
 Read 4 bytes of data at specified position. More...
 

Private Attributes

 $data = ''
 
 $numBigBlockDepotBlocks
 
 $rootStartBlock
 
 $sbdStartBlock
 
 $extensionBlock
 
 $numExtensionBlocks
 
 $bigBlockChain
 
 $smallBlockChain
 
 $entry
 
 $rootentry
 
 $props = []
 

Detailed Description

Definition at line 7 of file OLERead.php.

Member Function Documentation

◆ getInt4d()

static PhpOffice\PhpSpreadsheet\Shared\OLERead::getInt4d (   $data,
  $pos 
)
staticprivate

Read 4 bytes of data at specified position.

Parameters
string$data
int$pos
Returns
int

Definition at line 323 of file OLERead.php.

References PhpOffice\PhpSpreadsheet\Shared\OLERead\$data.

324  {
325  if ($pos < 0) {
326  // Invalid position
327  throw new ReaderException('Parameter pos=' . $pos . ' is invalid.');
328  }
329 
330  $len = strlen($data);
331  if ($len < $pos + 4) {
332  $data .= str_repeat("\0", $pos + 4 - $len);
333  }
334 
335  // FIX: represent numbers correctly on 64-bit system
336  // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
337  // Changed by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
338  $_or_24 = ord($data[$pos + 3]);
339  if ($_or_24 >= 128) {
340  // negative number
341  $_ord_24 = -abs((256 - $_or_24) << 24);
342  } else {
343  $_ord_24 = ($_or_24 & 127) << 24;
344  }
345 
346  return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $_ord_24;
347  }

◆ getStream()

PhpOffice\PhpSpreadsheet\Shared\OLERead::getStream (   $stream)

Extract binary stream data.

Parameters
int$stream
Returns
null|string

Definition at line 193 of file OLERead.php.

References GuzzleHttp\Psr7\$stream, data, and PhpOffice\PhpSpreadsheet\Shared\OLERead\readData().

194  {
195  if ($stream === null) {
196  return null;
197  }
198 
199  $streamData = '';
200 
201  if ($this->props[$stream]['size'] < self::SMALL_BLOCK_THRESHOLD) {
202  $rootdata = $this->readData($this->props[$this->rootentry]['startBlock']);
203 
204  $block = $this->props[$stream]['startBlock'];
205 
206  while ($block != -2) {
207  $pos = $block * self::SMALL_BLOCK_SIZE;
208  $streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
209 
210  $block = self::getInt4d($this->smallBlockChain, $block * 4);
211  }
212 
213  return $streamData;
214  }
215  $numBlocks = $this->props[$stream]['size'] / self::BIG_BLOCK_SIZE;
216  if ($this->props[$stream]['size'] % self::BIG_BLOCK_SIZE != 0) {
217  ++$numBlocks;
218  }
219 
220  if ($numBlocks == 0) {
221  return '';
222  }
223 
224  $block = $this->props[$stream]['startBlock'];
225 
226  while ($block != -2) {
227  $pos = ($block + 1) * self::BIG_BLOCK_SIZE;
228  $streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
229  $block = self::getInt4d($this->bigBlockChain, $block * 4);
230  }
231 
232  return $streamData;
233  }
readData($bl)
Read a standard stream (by joining sectors using information from SAT).
Definition: OLERead.php:242
$stream
PHP stream implementation.
$this data['403_header']
+ Here is the call graph for this function:

◆ read()

PhpOffice\PhpSpreadsheet\Shared\OLERead::read ( string  $pFilename)

Read the file.

Definition at line 96 of file OLERead.php.

References $i, PhpOffice\PhpSpreadsheet\Shared\OLERead\$numBigBlockDepotBlocks, PhpOffice\PhpSpreadsheet\Shared\OLERead\$numExtensionBlocks, PhpOffice\PhpSpreadsheet\Shared\OLERead\$rootStartBlock, PhpOffice\PhpSpreadsheet\Shared\OLERead\$sbdStartBlock, PhpOffice\PhpSpreadsheet\Shared\File\assertFile(), data, PhpOffice\PhpSpreadsheet\Shared\OLERead\readData(), and PhpOffice\PhpSpreadsheet\Shared\OLERead\readPropertySets().

96  : void
97  {
98  File::assertFile($pFilename);
99 
100  // Get the file identifier
101  // Don't bother reading the whole file until we know it's a valid OLE file
102  $this->data = file_get_contents($pFilename, false, null, 0, 8);
103 
104  // Check OLE identifier
105  $identifierOle = pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1);
106  if ($this->data != $identifierOle) {
107  throw new ReaderException('The filename ' . $pFilename . ' is not recognised as an OLE file');
108  }
109 
110  // Get the file data
111  $this->data = file_get_contents($pFilename);
112 
113  // Total number of sectors used for the SAT
114  $this->numBigBlockDepotBlocks = self::getInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
115 
116  // SecID of the first sector of the directory stream
117  $this->rootStartBlock = self::getInt4d($this->data, self::ROOT_START_BLOCK_POS);
118 
119  // SecID of the first sector of the SSAT (or -2 if not extant)
120  $this->sbdStartBlock = self::getInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
121 
122  // SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
123  $this->extensionBlock = self::getInt4d($this->data, self::EXTENSION_BLOCK_POS);
124 
125  // Total number of sectors used by MSAT
126  $this->numExtensionBlocks = self::getInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
127 
128  $bigBlockDepotBlocks = [];
129  $pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
130 
131  $bbdBlocks = $this->numBigBlockDepotBlocks;
132 
133  if ($this->numExtensionBlocks != 0) {
134  $bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS) / 4;
135  }
136 
137  for ($i = 0; $i < $bbdBlocks; ++$i) {
138  $bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
139  $pos += 4;
140  }
141 
142  for ($j = 0; $j < $this->numExtensionBlocks; ++$j) {
143  $pos = ($this->extensionBlock + 1) * self::BIG_BLOCK_SIZE;
144  $blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
145 
146  for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
147  $bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
148  $pos += 4;
149  }
150 
151  $bbdBlocks += $blocksToRead;
152  if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
153  $this->extensionBlock = self::getInt4d($this->data, $pos);
154  }
155  }
156 
157  $pos = 0;
158  $this->bigBlockChain = '';
159  $bbs = self::BIG_BLOCK_SIZE / 4;
160  for ($i = 0; $i < $this->numBigBlockDepotBlocks; ++$i) {
161  $pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
162 
163  $this->bigBlockChain .= substr($this->data, $pos, 4 * $bbs);
164  $pos += 4 * $bbs;
165  }
166 
167  $pos = 0;
168  $sbdBlock = $this->sbdStartBlock;
169  $this->smallBlockChain = '';
170  while ($sbdBlock != -2) {
171  $pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
172 
173  $this->smallBlockChain .= substr($this->data, $pos, 4 * $bbs);
174  $pos += 4 * $bbs;
175 
176  $sbdBlock = self::getInt4d($this->bigBlockChain, $sbdBlock * 4);
177  }
178 
179  // read the directory stream
180  $block = $this->rootStartBlock;
181  $this->entry = $this->readData($block);
182 
183  $this->readPropertySets();
184  }
readData($bl)
Read a standard stream (by joining sectors using information from SAT).
Definition: OLERead.php:242
readPropertySets()
Read entries in the directory stream.
Definition: OLERead.php:259
$this data['403_header']
$i
Definition: disco.tpl.php:19
static assertFile($filename)
Assert that given path is an existing file and is readable, otherwise throw exception.
Definition: File.php:143
+ Here is the call graph for this function:

◆ readData()

PhpOffice\PhpSpreadsheet\Shared\OLERead::readData (   $bl)
private

Read a standard stream (by joining sectors using information from SAT).

Parameters
int$blSector ID where the stream starts
Returns
string Data for standard stream

Definition at line 242 of file OLERead.php.

References PhpOffice\PhpSpreadsheet\Shared\OLERead\$data, and data.

Referenced by PhpOffice\PhpSpreadsheet\Shared\OLERead\getStream(), and PhpOffice\PhpSpreadsheet\Shared\OLERead\read().

243  {
244  $block = $bl;
245  $data = '';
246 
247  while ($block != -2) {
248  $pos = ($block + 1) * self::BIG_BLOCK_SIZE;
249  $data .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
250  $block = self::getInt4d($this->bigBlockChain, $block * 4);
251  }
252 
253  return $data;
254  }
$this data['403_header']
+ Here is the caller graph for this function:

◆ readPropertySets()

PhpOffice\PhpSpreadsheet\Shared\OLERead::readPropertySets ( )
private

Read entries in the directory stream.

Definition at line 259 of file OLERead.php.

References $d, $name, $size, and $type.

Referenced by PhpOffice\PhpSpreadsheet\Shared\OLERead\read().

259  : void
260  {
261  $offset = 0;
262 
263  // loop through entires, each entry is 128 bytes
264  $entryLen = strlen($this->entry);
265  while ($offset < $entryLen) {
266  // entry data (128 bytes)
267  $d = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
268 
269  // size in bytes of name
270  $nameSize = ord($d[self::SIZE_OF_NAME_POS]) | (ord($d[self::SIZE_OF_NAME_POS + 1]) << 8);
271 
272  // type of entry
273  $type = ord($d[self::TYPE_POS]);
274 
275  // sectorID of first sector or short sector, if this entry refers to a stream (the case with workbook)
276  // sectorID of first sector of the short-stream container stream, if this entry is root entry
277  $startBlock = self::getInt4d($d, self::START_BLOCK_POS);
278 
279  $size = self::getInt4d($d, self::SIZE_POS);
280 
281  $name = str_replace("\x00", '', substr($d, 0, $nameSize));
282 
283  $this->props[] = [
284  'name' => $name,
285  'type' => $type,
286  'startBlock' => $startBlock,
287  'size' => $size,
288  ];
289 
290  // tmp helper to simplify checks
291  $upName = strtoupper($name);
292 
293  // Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
294  if (($upName === 'WORKBOOK') || ($upName === 'BOOK')) {
295  $this->wrkbook = count($this->props) - 1;
296  } elseif ($upName === 'ROOT ENTRY' || $upName === 'R') {
297  // Root entry
298  $this->rootentry = count($this->props) - 1;
299  }
300 
301  // Summary information
302  if ($name == chr(5) . 'SummaryInformation') {
303  $this->summaryInformation = count($this->props) - 1;
304  }
305 
306  // Additional Document Summary information
307  if ($name == chr(5) . 'DocumentSummaryInformation') {
308  $this->documentSummaryInformation = count($this->props) - 1;
309  }
310 
311  $offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
312  }
313  }
$size
Definition: RandomTest.php:84
$type
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the caller graph for this function:

Field Documentation

◆ $bigBlockChain

PhpOffice\PhpSpreadsheet\Shared\OLERead::$bigBlockChain
private

Definition at line 71 of file OLERead.php.

◆ $data

PhpOffice\PhpSpreadsheet\Shared\OLERead::$data = ''
private

◆ $documentSummaryInformation

PhpOffice\PhpSpreadsheet\Shared\OLERead::$documentSummaryInformation

Definition at line 41 of file OLERead.php.

◆ $entry

PhpOffice\PhpSpreadsheet\Shared\OLERead::$entry
private

Definition at line 81 of file OLERead.php.

◆ $extensionBlock

PhpOffice\PhpSpreadsheet\Shared\OLERead::$extensionBlock
private

Definition at line 61 of file OLERead.php.

◆ $numBigBlockDepotBlocks

PhpOffice\PhpSpreadsheet\Shared\OLERead::$numBigBlockDepotBlocks
private

Definition at line 46 of file OLERead.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\OLERead\read().

◆ $numExtensionBlocks

PhpOffice\PhpSpreadsheet\Shared\OLERead::$numExtensionBlocks
private

Definition at line 66 of file OLERead.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\OLERead\read().

◆ $props

PhpOffice\PhpSpreadsheet\Shared\OLERead::$props = []
private

Definition at line 91 of file OLERead.php.

◆ $rootentry

PhpOffice\PhpSpreadsheet\Shared\OLERead::$rootentry
private

Definition at line 86 of file OLERead.php.

◆ $rootStartBlock

PhpOffice\PhpSpreadsheet\Shared\OLERead::$rootStartBlock
private

Definition at line 51 of file OLERead.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\OLERead\read().

◆ $sbdStartBlock

PhpOffice\PhpSpreadsheet\Shared\OLERead::$sbdStartBlock
private

Definition at line 56 of file OLERead.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\OLERead\read().

◆ $smallBlockChain

PhpOffice\PhpSpreadsheet\Shared\OLERead::$smallBlockChain
private

Definition at line 76 of file OLERead.php.

◆ $summaryInformation

PhpOffice\PhpSpreadsheet\Shared\OLERead::$summaryInformation

Definition at line 39 of file OLERead.php.

◆ $wrkbook

PhpOffice\PhpSpreadsheet\Shared\OLERead::$wrkbook

Definition at line 37 of file OLERead.php.

◆ BIG_BLOCK_DEPOT_BLOCKS_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c

Definition at line 29 of file OLERead.php.

◆ BIG_BLOCK_SIZE

const PhpOffice\PhpSpreadsheet\Shared\OLERead::BIG_BLOCK_SIZE = 0x200

Definition at line 12 of file OLERead.php.

◆ EXTENSION_BLOCK_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::EXTENSION_BLOCK_POS = 0x44

Definition at line 27 of file OLERead.php.

◆ NUM_BIG_BLOCK_DEPOT_BLOCKS_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c

Definition at line 24 of file OLERead.php.

◆ NUM_EXTENSION_BLOCK_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::NUM_EXTENSION_BLOCK_POS = 0x48

Definition at line 28 of file OLERead.php.

◆ PROPERTY_STORAGE_BLOCK_SIZE

const PhpOffice\PhpSpreadsheet\Shared\OLERead::PROPERTY_STORAGE_BLOCK_SIZE = 0x80

Definition at line 18 of file OLERead.php.

◆ ROOT_START_BLOCK_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::ROOT_START_BLOCK_POS = 0x30

Definition at line 25 of file OLERead.php.

◆ SIZE_OF_NAME_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::SIZE_OF_NAME_POS = 0x40

Definition at line 32 of file OLERead.php.

◆ SIZE_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::SIZE_POS = 0x78

Definition at line 35 of file OLERead.php.

◆ SMALL_BLOCK_DEPOT_BLOCK_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c

Definition at line 26 of file OLERead.php.

◆ SMALL_BLOCK_SIZE

const PhpOffice\PhpSpreadsheet\Shared\OLERead::SMALL_BLOCK_SIZE = 0x40

Definition at line 15 of file OLERead.php.

◆ SMALL_BLOCK_THRESHOLD

const PhpOffice\PhpSpreadsheet\Shared\OLERead::SMALL_BLOCK_THRESHOLD = 0x1000

Definition at line 21 of file OLERead.php.

◆ START_BLOCK_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::START_BLOCK_POS = 0x74

Definition at line 34 of file OLERead.php.

◆ TYPE_POS

const PhpOffice\PhpSpreadsheet\Shared\OLERead::TYPE_POS = 0x42

Definition at line 33 of file OLERead.php.


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