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');
34 require_once
'classes/OLE/PPS.php';
64 $this->_list = array();
77 $big_block_size_offset = 30;
79 $bd_start_offset = 68;
81 $fh = @fopen(
$file,
"r");
83 return $this->raiseError(
"Can't open file $file");
85 $this->_file_handle = $fh;
89 $signature = fread($fh, 8);
90 if (
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
91 return $this->raiseError(
"File doesn't seem to be an OLE container.");
93 fseek($fh, $big_block_size_offset);
94 $packed_array = unpack(
"v", fread($fh, 2));
95 $big_block_size = pow(2, $packed_array[
'']);
97 $packed_array = unpack(
"v", fread($fh, 2));
98 $small_block_size = pow(2, $packed_array[
'']);
101 fseek($fh, $iBdbCnt_offset);
102 $packed_array = unpack(
"V", fread($fh, 4));
103 $iBdbCnt = $packed_array[
''];
105 $packed_array = unpack(
"V", fread($fh, 4));
106 $pps_wk_start = $packed_array[
''];
108 fseek($fh, $bd_start_offset);
109 $packed_array = unpack(
"V", fread($fh, 4));
110 $bd_start = $packed_array[
''];
111 $packed_array = unpack(
"V", fread($fh, 4));
112 $bd_count = $packed_array[
''];
113 $packed_array = unpack(
"V", fread($fh, 4));
114 $iAll = $packed_array[
''];
117 if (PEAR::isError(
$ret)) {
131 fclose($this->_file_handle);
145 $pointer = ($pps_wk_start + 1) * $big_block_size;
148 fseek($this->_file_handle, $pointer);
154 $name_length = unpack(
"c", substr($pps_wk, 64, 2));
155 $name_length = $name_length[
''] - 2;
156 $name = substr($pps_wk, 0, $name_length);
157 $type = unpack(
"c", substr($pps_wk, 66, 1));
162 return $this->raiseError(
"PPS at $pointer has unknown type: {$type['']}");
164 $prev = unpack(
"V", substr($pps_wk, 68, 4));
165 $next = unpack(
"V", substr($pps_wk, 72, 4));
166 $dir = unpack(
"V", substr($pps_wk, 76, 4));
169 $time_1st = substr($pps_wk, 100, 8);
170 $time_2nd = substr($pps_wk, 108, 8);
171 $start_block = unpack(
"V", substr($pps_wk, 116, 4));
172 $size = unpack(
"V", substr($pps_wk, 120, 4));
175 $this->_list[] =
new OLE_PPS(null,
'', $type[
''], $prev[
''], $next[
''],
178 ($start_block[
''] + 1) * $big_block_size, array());
180 $this->_list[count($this->_list) - 1]->Size =
$size[
''];
199 if ($this->_list[$index]->NextPps != -1) {
200 if (!isset($this->_list[$this->_list[$index]->NextPps])) {
207 if ($this->_list[$index]->DirPps != -1) {
208 if (!isset($this->_list[$this->_list[$index]->DirPps])) {
228 if (isset($this->_list[$index])) {
244 if (isset($this->_list[$index])) {
258 return count($this->_list);
275 if (!isset($this->_list[$index]) or ($position >= $this->_list[$index]->Size) or ($position < 0)) {
279 fseek($this->_file_handle, $this->_list[$index]->_data + $position);
280 return fread($this->_file_handle, $length);
293 if (isset($this->_list[$index])) {
294 return $this->_list[$index]->Size;
310 for ($i = 0; $i < strlen($ascii); $i++) {
311 $rawname .= $ascii{$i}.
"\x00";
328 return "\x00\x00\x00\x00\x00\x00\x00\x00";
337 $big_date = $days*24*3600 + gmmktime(date(
"H",$date),date(
"i",$date),date(
"s",$date),
338 date(
"m",$date),date(
"d",$date),date(
"Y",$date));
340 $big_date *= 10000000;
342 $high_part = floor($big_date/$factor);
344 $low_part = floor((($big_date/$factor) - $high_part)*$factor);
349 for ($i=0; $i<4; $i++)
351 $hex = $low_part % 0x100;
352 $res .= pack(
'c', $hex);
355 for ($i=0; $i<4; $i++)
357 $hex = $high_part % 0x100;
358 $res .= pack(
'c', $hex);
374 if (strlen($string) != 8) {
375 return new PEAR_Error(
"Expecting 8 byte string");
381 for ($i=0; $i<4; $i++)
383 $al = unpack(
'C', $string{(7 - $i)});
384 $high_part += $al[
''];
390 for ($i=4; $i<8; $i++)
392 $al = unpack(
'C', $string{(7 - $i)});
393 $low_part += $al[
''];
398 $big_date = ($high_part*$factor) + $low_part;
400 $big_date /= 10000000;
406 $big_date -= $days*24*3600;
407 return floor($big_date);