26 define(
'OLE_PPS_TYPE_ROOT', 5);
27 define(
'OLE_PPS_TYPE_DIR', 1);
28 define(
'OLE_PPS_TYPE_FILE', 2);
29 define(
'OLE_DATA_SIZE_SMALL', 0x1000);
30 define(
'OLE_LONG_INT_SIZE', 4);
31 define(
'OLE_PPS_SIZE', 0x80);
33 require_once
'PEAR.php';
101 $this->_list = array();
112 fclose($this->_file_handle);
124 $fh = @fopen(
$file,
"r");
126 return $this->
raiseError(
"Can't open file $file");
128 $this->_file_handle = $fh;
130 $signature = fread($fh, 8);
131 if (
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
132 return $this->
raiseError(
"File doesn't seem to be an OLE container.");
135 if (fread($fh, 2) !=
"\xFE\xFF") {
137 return $this->
raiseError(
"Only Little-Endian encoding is supported.");
140 $this->bigBlockSize = pow(2, $this->
_readInt2($fh));
141 $this->smallBlockSize = pow(2, $this->
_readInt2($fh));
149 $directoryFirstBlockId = $this->
_readInt4($fh);
154 $this->bigBlockThreshold = $this->
_readInt4($fh);
156 $sbatFirstBlockId = $this->
_readInt4($fh);
158 $sbbatBlockCount = $this->
_readInt4($fh);
160 $mbatFirstBlockId = $this->
_readInt4($fh);
162 $mbbatBlockCount = $this->
_readInt4($fh);
163 $this->bbat = array();
167 $mbatBlocks = array();
168 for ($i = 0; $i < 109; $i++) {
174 for ($i = 0; $i < $mbbatBlockCount; $i++) {
176 for ($j = 0; $j < $this->bigBlockSize / 4 - 1; $j++) {
185 for ($i = 0; $i < $bbatBlockCount; $i++) {
188 for ($j = 0 ; $j < $this->bigBlockSize / 4; $j++) {
194 $this->sbat = array();
195 $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
196 $sbatFh = $this->
getStream($sbatFirstBlockId);
197 for ($blockId = 0; $blockId < $shortBlockCount; $blockId++) {
198 $this->sbat[$blockId] = $this->
_readInt4($sbatFh);
225 include_once
'OLE/ChainedBlockStream.php';
226 static $isRegistered =
false;
227 if (!$isRegistered) {
228 stream_wrapper_register(
'ole-chainedblockstream',
229 'OLE_ChainedBlockStream');
230 $isRegistered =
true;
236 $GLOBALS[
'_OLE_INSTANCES'][] = $this;
237 $instanceId = end(array_keys(
$GLOBALS[
'_OLE_INSTANCES']));
239 $path =
'ole-chainedblockstream://oleInstanceId=' . $instanceId;
240 if (is_a($blockIdOrPps,
'OLE_PPS')) {
241 $path .=
'&blockId=' . $blockIdOrPps->_StartBlock;
242 $path .=
'&size=' . $blockIdOrPps->Size;
244 $path .=
'&blockId=' . $blockIdOrPps;
246 return fopen(
$path,
'r');
257 list(, $tmp) = unpack(
"c", fread($fh, 1));
269 list(, $tmp) = unpack(
"v", fread($fh, 2));
281 list(, $tmp) = unpack(
"V", fread($fh, 4));
296 for ($pos = 0; ; $pos += 128) {
297 fseek($fh, $pos, SEEK_SET);
298 $nameUtf16 = fread($fh, 64);
300 $nameUtf16 = substr($nameUtf16, 0, $nameLength - 2);
302 $name = str_replace(
"\x00",
"", $nameUtf16);
306 require_once
'OLE/PPS/Root.php';
311 $pps =
new OLE_PPS(null, null, null, null, null,
312 null, null, null, null, array());
315 require_once
'OLE/PPS/File.php';
321 fseek($fh, 1, SEEK_CUR);
327 fseek($fh, 20, SEEK_CUR);
330 $pps->_StartBlock = $this->
_readInt4($fh);
332 $pps->No = count($this->_list);
333 $this->_list[] = $pps;
336 if (isset($this->root) &&
345 foreach ($this->_list as $pps) {
347 $nos = array($pps->DirPps);
348 $pps->children = array();
350 $no = array_pop($nos);
352 $childPps = $this->_list[$no];
353 $nos[] = $childPps->PrevPps;
354 $nos[] = $childPps->NextPps;
355 $pps->children[] = $childPps;
374 return isset($this->_list[$index]) &&
375 ($pps = $this->_list[$index]) &&
376 ($pps->PrevPps == -1 ||
377 $this->_ppsTreeComplete($pps->PrevPps)) &&
378 ($pps->NextPps == -1 ||
379 $this->_ppsTreeComplete($pps->NextPps)) &&
380 ($pps->DirPps == -1 ||
381 $this->_ppsTreeComplete($pps->DirPps));
393 if (isset($this->_list[$index])) {
408 if (isset($this->_list[$index])) {
421 return count($this->_list);
438 if (!isset($this->_list[$index]) ||
439 $position >= $this->_list[$index]->Size ||
444 $fh = $this->
getStream($this->_list[$index]);
445 $data = stream_get_contents($fh, $length, $position);
459 if (isset($this->_list[$index])) {
460 return $this->_list[$index]->Size;
476 for ($i = 0; $i < strlen($ascii); $i++) {
477 $rawname .= $ascii{$i} .
"\x00";
494 return "\x00\x00\x00\x00\x00\x00\x00\x00";
498 $factor = pow(2, 32);
503 $big_date = $days * 24 * 3600 +
504 gmmktime(date(
"H",$date),date(
"i",$date),date(
"s",$date),
505 date(
"m",$date),date(
"d",$date),date(
"Y",$date));
507 $big_date *= 10000000;
509 $high_part = floor($big_date / $factor);
511 $low_part = floor((($big_date / $factor) - $high_part) * $factor);
516 for ($i = 0; $i < 4; $i++) {
517 $hex = $low_part % 0x100;
518 $res .= pack(
'c', $hex);
521 for ($i = 0; $i < 4; $i++) {
522 $hex = $high_part % 0x100;
523 $res .= pack(
'c', $hex);
538 if (strlen($string) != 8) {
539 return new PEAR_Error(
"Expecting 8 byte string");
545 for ($i = 0; $i < 4; $i++) {
546 list(, $high_part) = unpack(
'C', $string{(7 - $i)});
552 for ($i = 4; $i < 8; $i++) {
553 list(, $low_part) = unpack(
'C', $string{(7 - $i)});
558 $big_date = ($high_part * $factor) + $low_part;
560 $big_date /= 10000000;
566 $big_date -= $days * 24 * 3600;
567 return floor($big_date);