<Website>

getID3

PHK Home

File: /lib/module.misc.iso.php

Size:19597
Storage flags:strip

<?php
















class getid3_iso extends getid3_handler
{

public function 
Analyze() {
$info = &$this->getid3->info;

$info['fileformat'] = 'iso';

for (
$i 16$i <= 19$i++) {
$this->fseek(2048 $i);
$ISOheader $this->fread(2048);
if (
substr($ISOheader15) == 'CD001') {
switch (
ord($ISOheader{0})) {
case 
1:
$info['iso']['primary_volume_descriptor']['offset'] = 2048 $i;
$this->ParsePrimaryVolumeDescriptor($ISOheader);
break;

case 
2:
$info['iso']['supplementary_volume_descriptor']['offset'] = 2048 $i;
$this->ParseSupplementaryVolumeDescriptor($ISOheader);
break;

default:

 break;
}
}
}

$this->ParsePathTable();

$info['iso']['files'] = array();
foreach (
$info['iso']['path_table']['directories'] as $directorynum => $directorydata) {
$info['iso']['directories'][$directorynum] = $this->ParseDirectoryRecord($directorydata);
}

return 
true;
}


public function 
ParsePrimaryVolumeDescriptor(&$ISOheader) {

 


 
$info = &$this->getid3->info;
$info['iso']['primary_volume_descriptor']['raw'] = array();
$thisfile_iso_primaryVD = &$info['iso']['primary_volume_descriptor'];
$thisfile_iso_primaryVD_raw = &$thisfile_iso_primaryVD['raw'];

$thisfile_iso_primaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader01));
$thisfile_iso_primaryVD_raw['standard_identifier'] = substr($ISOheader15);
if (
$thisfile_iso_primaryVD_raw['standard_identifier'] != 'CD001') {
$info['error'][] = 'Expected "CD001" at offset ('.($thisfile_iso_primaryVD['offset'] + 1).'), found "'.$thisfile_iso_primaryVD_raw['standard_identifier'].'" instead';
unset(
$info['fileformat']);
unset(
$info['iso']);
return 
false;
}


$thisfile_iso_primaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader61));

 
$thisfile_iso_primaryVD_raw['system_identifier'] = substr($ISOheader832);
$thisfile_iso_primaryVD_raw['volume_identifier'] = substr($ISOheader4032);

 
$thisfile_iso_primaryVD_raw['volume_space_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader804));

 
$thisfile_iso_primaryVD_raw['volume_set_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader1202));
$thisfile_iso_primaryVD_raw['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($ISOheader1242));
$thisfile_iso_primaryVD_raw['logical_block_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader1282));
$thisfile_iso_primaryVD_raw['path_table_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader1324));
$thisfile_iso_primaryVD_raw['path_table_l_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1402));
$thisfile_iso_primaryVD_raw['path_table_l_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1442));
$thisfile_iso_primaryVD_raw['path_table_m_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1482));
$thisfile_iso_primaryVD_raw['path_table_m_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1522));
$thisfile_iso_primaryVD_raw['root_directory_record'] = substr($ISOheader15634);
$thisfile_iso_primaryVD_raw['volume_set_identifier'] = substr($ISOheader190128);
$thisfile_iso_primaryVD_raw['publisher_identifier'] = substr($ISOheader318128);
$thisfile_iso_primaryVD_raw['data_preparer_identifier'] = substr($ISOheader446128);
$thisfile_iso_primaryVD_raw['application_identifier'] = substr($ISOheader574128);
$thisfile_iso_primaryVD_raw['copyright_file_identifier'] = substr($ISOheader70237);
$thisfile_iso_primaryVD_raw['abstract_file_identifier'] = substr($ISOheader73937);
$thisfile_iso_primaryVD_raw['bibliographic_file_identifier'] = substr($ISOheader77637);
$thisfile_iso_primaryVD_raw['volume_creation_date_time'] = substr($ISOheader81317);
$thisfile_iso_primaryVD_raw['volume_modification_date_time'] = substr($ISOheader83017);
$thisfile_iso_primaryVD_raw['volume_expiration_date_time'] = substr($ISOheader84717);
$thisfile_iso_primaryVD_raw['volume_effective_date_time'] = substr($ISOheader86417);
$thisfile_iso_primaryVD_raw['file_structure_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader8811));

 
$thisfile_iso_primaryVD_raw['application_data'] = substr($ISOheader883512);


$thisfile_iso_primaryVD['system_identifier'] = trim($thisfile_iso_primaryVD_raw['system_identifier']);
$thisfile_iso_primaryVD['volume_identifier'] = trim($thisfile_iso_primaryVD_raw['volume_identifier']);
$thisfile_iso_primaryVD['volume_set_identifier'] = trim($thisfile_iso_primaryVD_raw['volume_set_identifier']);
$thisfile_iso_primaryVD['publisher_identifier'] = trim($thisfile_iso_primaryVD_raw['publisher_identifier']);
$thisfile_iso_primaryVD['data_preparer_identifier'] = trim($thisfile_iso_primaryVD_raw['data_preparer_identifier']);
$thisfile_iso_primaryVD['application_identifier'] = trim($thisfile_iso_primaryVD_raw['application_identifier']);
$thisfile_iso_primaryVD['copyright_file_identifier'] = trim($thisfile_iso_primaryVD_raw['copyright_file_identifier']);
$thisfile_iso_primaryVD['abstract_file_identifier'] = trim($thisfile_iso_primaryVD_raw['abstract_file_identifier']);
$thisfile_iso_primaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_primaryVD_raw['bibliographic_file_identifier']);
$thisfile_iso_primaryVD['volume_creation_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_creation_date_time']);
$thisfile_iso_primaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_modification_date_time']);
$thisfile_iso_primaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_expiration_date_time']);
$thisfile_iso_primaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_effective_date_time']);

if ((
$thisfile_iso_primaryVD_raw['volume_space_size'] * 2048) > $info['filesize']) {
$info['error'][] = 'Volume Space Size ('.($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)';
}

return 
true;
}


public function 
ParseSupplementaryVolumeDescriptor(&$ISOheader) {

 


 
$info = &$this->getid3->info;
$info['iso']['supplementary_volume_descriptor']['raw'] = array();
$thisfile_iso_supplementaryVD = &$info['iso']['supplementary_volume_descriptor'];
$thisfile_iso_supplementaryVD_raw = &$thisfile_iso_supplementaryVD['raw'];

$thisfile_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader01));
$thisfile_iso_supplementaryVD_raw['standard_identifier'] = substr($ISOheader15);
if (
$thisfile_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') {
$info['error'][] = 'Expected "CD001" at offset ('.($thisfile_iso_supplementaryVD['offset'] + 1).'), found "'.$thisfile_iso_supplementaryVD_raw['standard_identifier'].'" instead';
unset(
$info['fileformat']);
unset(
$info['iso']);
return 
false;
}

$thisfile_iso_supplementaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader61));

 
$thisfile_iso_supplementaryVD_raw['system_identifier'] = substr($ISOheader832);
$thisfile_iso_supplementaryVD_raw['volume_identifier'] = substr($ISOheader4032);

 
$thisfile_iso_supplementaryVD_raw['volume_space_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader804));
if (
$thisfile_iso_supplementaryVD_raw['volume_space_size'] == 0) {

 
 
 }


 
$thisfile_iso_supplementaryVD_raw['volume_set_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader1202));
$thisfile_iso_supplementaryVD_raw['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($ISOheader1242));
$thisfile_iso_supplementaryVD_raw['logical_block_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader1282));
$thisfile_iso_supplementaryVD_raw['path_table_size'] = getid3_lib::LittleEndian2Int(substr($ISOheader1324));
$thisfile_iso_supplementaryVD_raw['path_table_l_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1402));
$thisfile_iso_supplementaryVD_raw['path_table_l_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1442));
$thisfile_iso_supplementaryVD_raw['path_table_m_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1482));
$thisfile_iso_supplementaryVD_raw['path_table_m_opt_location'] = getid3_lib::LittleEndian2Int(substr($ISOheader1522));
$thisfile_iso_supplementaryVD_raw['root_directory_record'] = substr($ISOheader15634);
$thisfile_iso_supplementaryVD_raw['volume_set_identifier'] = substr($ISOheader190128);
$thisfile_iso_supplementaryVD_raw['publisher_identifier'] = substr($ISOheader318128);
$thisfile_iso_supplementaryVD_raw['data_preparer_identifier'] = substr($ISOheader446128);
$thisfile_iso_supplementaryVD_raw['application_identifier'] = substr($ISOheader574128);
$thisfile_iso_supplementaryVD_raw['copyright_file_identifier'] = substr($ISOheader70237);
$thisfile_iso_supplementaryVD_raw['abstract_file_identifier'] = substr($ISOheader73937);
$thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier'] = substr($ISOheader77637);
$thisfile_iso_supplementaryVD_raw['volume_creation_date_time'] = substr($ISOheader81317);
$thisfile_iso_supplementaryVD_raw['volume_modification_date_time'] = substr($ISOheader83017);
$thisfile_iso_supplementaryVD_raw['volume_expiration_date_time'] = substr($ISOheader84717);
$thisfile_iso_supplementaryVD_raw['volume_effective_date_time'] = substr($ISOheader86417);
$thisfile_iso_supplementaryVD_raw['file_structure_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader8811));

 
$thisfile_iso_supplementaryVD_raw['application_data'] = substr($ISOheader883512);


$thisfile_iso_supplementaryVD['system_identifier'] = trim($thisfile_iso_supplementaryVD_raw['system_identifier']);
$thisfile_iso_supplementaryVD['volume_identifier'] = trim($thisfile_iso_supplementaryVD_raw['volume_identifier']);
$thisfile_iso_supplementaryVD['volume_set_identifier'] = trim($thisfile_iso_supplementaryVD_raw['volume_set_identifier']);
$thisfile_iso_supplementaryVD['publisher_identifier'] = trim($thisfile_iso_supplementaryVD_raw['publisher_identifier']);
$thisfile_iso_supplementaryVD['data_preparer_identifier'] = trim($thisfile_iso_supplementaryVD_raw['data_preparer_identifier']);
$thisfile_iso_supplementaryVD['application_identifier'] = trim($thisfile_iso_supplementaryVD_raw['application_identifier']);
$thisfile_iso_supplementaryVD['copyright_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['copyright_file_identifier']);
$thisfile_iso_supplementaryVD['abstract_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['abstract_file_identifier']);
$thisfile_iso_supplementaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier']);
$thisfile_iso_supplementaryVD['volume_creation_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_creation_date_time']);
$thisfile_iso_supplementaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_modification_date_time']);
$thisfile_iso_supplementaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']);
$thisfile_iso_supplementaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_effective_date_time']);

if ((
$thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']) > $info['filesize']) {
$info['error'][] = 'Volume Space Size ('.($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)';
}

return 
true;
}


public function 
ParsePathTable() {
$info = &$this->getid3->info;
if (!isset(
$info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) {
return 
false;
}
if (isset(
$info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) {
$PathTableLocation $info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'];
$PathTableSize $info['iso']['supplementary_volume_descriptor']['raw']['path_table_size'];
$TextEncoding 'UTF-16BE'
 } else {
$PathTableLocation $info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'];
$PathTableSize $info['iso']['primary_volume_descriptor']['raw']['path_table_size'];
$TextEncoding 'ISO-8859-1'
 }

if ((
$PathTableLocation 2048) > $info['filesize']) {
$info['error'][] = 'Path Table Location specifies an offset ('.($PathTableLocation 2048).') beyond the end-of-file ('.$info['filesize'].')';
return 
false;
}

$info['iso']['path_table']['offset'] = $PathTableLocation 2048;
$this->fseek($info['iso']['path_table']['offset']);
$info['iso']['path_table']['raw'] = $this->fread($PathTableSize);

$offset 0;
$pathcounter 1;
while (
$offset $PathTableSize) {

 
$info['iso']['path_table']['directories'][$pathcounter] = array();
$thisfile_iso_pathtable_directories_current = &$info['iso']['path_table']['directories'][$pathcounter];

$thisfile_iso_pathtable_directories_current['length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset1));
$offset += 1;
$thisfile_iso_pathtable_directories_current['extended_length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset1));
$offset += 1;
$thisfile_iso_pathtable_directories_current['location_logical'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset4));
$offset += 4;
$thisfile_iso_pathtable_directories_current['parent_directory'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset2));
$offset += 2;
$thisfile_iso_pathtable_directories_current['name'] = substr($info['iso']['path_table']['raw'], $offset$thisfile_iso_pathtable_directories_current['length']);
$offset += $thisfile_iso_pathtable_directories_current['length'] + ($thisfile_iso_pathtable_directories_current['length'] % 2);

$thisfile_iso_pathtable_directories_current['name_ascii'] = getid3_lib::iconv_fallback($TextEncoding$info['encoding'], $thisfile_iso_pathtable_directories_current['name']);

$thisfile_iso_pathtable_directories_current['location_bytes'] = $thisfile_iso_pathtable_directories_current['location_logical'] * 2048;
if (
$pathcounter == 1) {
$thisfile_iso_pathtable_directories_current['full_path'] = '/';
} else {
$thisfile_iso_pathtable_directories_current['full_path'] = $info['iso']['path_table']['directories'][$thisfile_iso_pathtable_directories_current['parent_directory']]['full_path'].$thisfile_iso_pathtable_directories_current['name_ascii'].'/';
}
$FullPathArray[] = $thisfile_iso_pathtable_directories_current['full_path'];

$pathcounter++;
}

return 
true;
}


public function 
ParseDirectoryRecord($directorydata) {
$info = &$this->getid3->info;
if (isset(
$info['iso']['supplementary_volume_descriptor'])) {
$TextEncoding 'UTF-16BE'
 } else {
$TextEncoding 'ISO-8859-1'
 }

$this->fseek($directorydata['location_bytes']);
$DirectoryRecordData $this->fread(1);

while (
ord($DirectoryRecordData{0}) > 33) {

$DirectoryRecordData .= $this->fread(ord($DirectoryRecordData{0}) - 1);

$ThisDirectoryRecord['raw']['length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData01));
$ThisDirectoryRecord['raw']['extended_attribute_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData11));
$ThisDirectoryRecord['raw']['offset_logical'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData24));
$ThisDirectoryRecord['raw']['filesize'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData104));
$ThisDirectoryRecord['raw']['recording_date_time'] = substr($DirectoryRecordData187);
$ThisDirectoryRecord['raw']['file_flags'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData251));
$ThisDirectoryRecord['raw']['file_unit_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData261));
$ThisDirectoryRecord['raw']['interleave_gap_size'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData271));
$ThisDirectoryRecord['raw']['volume_sequence_number'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData282));
$ThisDirectoryRecord['raw']['file_identifier_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData321));
$ThisDirectoryRecord['raw']['file_identifier'] = substr($DirectoryRecordData33$ThisDirectoryRecord['raw']['file_identifier_length']);

$ThisDirectoryRecord['file_identifier_ascii'] = getid3_lib::iconv_fallback($TextEncoding$info['encoding'], $ThisDirectoryRecord['raw']['file_identifier']);

$ThisDirectoryRecord['filesize'] = $ThisDirectoryRecord['raw']['filesize'];
$ThisDirectoryRecord['offset_bytes'] = $ThisDirectoryRecord['raw']['offset_logical'] * 2048;
$ThisDirectoryRecord['file_flags']['hidden'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x01);
$ThisDirectoryRecord['file_flags']['directory'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x02);
$ThisDirectoryRecord['file_flags']['associated'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x04);
$ThisDirectoryRecord['file_flags']['extended'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x08);
$ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10);
$ThisDirectoryRecord['file_flags']['multiple'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80);
$ThisDirectoryRecord['recording_timestamp'] = $this->ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']);

if (
$ThisDirectoryRecord['file_flags']['directory']) {
$ThisDirectoryRecord['filename'] = $directorydata['full_path'];
} else {
$ThisDirectoryRecord['filename'] = $directorydata['full_path'].$this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']);
$info['iso']['files'] = getid3_lib::array_merge_clobber($info['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/'$ThisDirectoryRecord['filesize']));
}

$DirectoryRecord[] = $ThisDirectoryRecord;
$DirectoryRecordData $this->fread(1);
}

return 
$DirectoryRecord;
}

public function 
ISOstripFilenameVersion($ISOfilename) {

 if (!
strstr($ISOfilename';')) {
return 
$ISOfilename;
} else {
return 
substr($ISOfilename0strpos($ISOfilename';'));
}
}

public function 
ISOtimeText2UNIXtime($ISOtime) {

$UNIXyear = (int) substr($ISOtime04);
$UNIXmonth = (int) substr($ISOtime42);
$UNIXday = (int) substr($ISOtime62);
$UNIXhour = (int) substr($ISOtime82);
$UNIXminute = (int) substr($ISOtime102);
$UNIXsecond = (int) substr($ISOtime122);

if (!
$UNIXyear) {
return 
false;
}
return 
gmmktime($UNIXhour$UNIXminute$UNIXsecond$UNIXmonth$UNIXday$UNIXyear);
}

public function 
ISOtime2UNIXtime($ISOtime) {

 
 
 
 
 
 
 

$UNIXyear ord($ISOtime{0}) + 1900;
$UNIXmonth ord($ISOtime{1});
$UNIXday ord($ISOtime{2});
$UNIXhour ord($ISOtime{3});
$UNIXminute ord($ISOtime{4});
$UNIXsecond ord($ISOtime{5});
$GMToffset $this->TwosCompliment2Decimal(ord($ISOtime{5}));

return 
gmmktime($UNIXhour$UNIXminute$UNIXsecond$UNIXmonth$UNIXday$UNIXyear);
}

public function 
TwosCompliment2Decimal($BinaryValue) {

 
 
 
 
 

if (
$BinaryValue 0x80) {


 return (
- ((~$BinaryValue 0xFF) + 1));
} else {

 return 
$BinaryValue;
}
}


}

For more information about the PHK package format: http://phk.tekwire.net