-
-
Save DavidBruchmann/39389a2c65ab66e1bfbbe6ddaf2c4881 to your computer and use it in GitHub Desktop.
TYPO3 T3D uncompress / extract / deflate / extrahieren / entpacken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Execute: | |
# php -d memory_limit=2G t3d.php file.t3d > output.txt | |
$fd = fopen($argv[1], 'rb'); | |
function getNextFilePart($fd, $unserialize = false, $name = '') { | |
$headerLength = 32 + 1 + 1 + 1 + 10 + 1; | |
$headerString = fread($fd, $headerLength); | |
if (empty($headerString)) { | |
echo 'File does not contain data for "' . $name . '"'; | |
return null; | |
} | |
$header = explode(':', $headerString); | |
if (str_contains($header[0], 'Warning')) { | |
echo('File read error: Warning message in file. (' . $headerString . fgets($fd) . ')'); | |
return null; | |
} | |
if ((string)$header[3] !== '') { | |
echo('File read error: InitString had a wrong length. (' . $name . ')'); | |
return null; | |
} | |
$dataString = (string)fread($fd, (int)$header[2]); | |
$isDataCompressed = $header[1] === '1'; | |
fread($fd, 1); | |
if (!hash_equals($header[0], md5($dataString))) { | |
echo ('MD5 check failed (' . $name . ')'); | |
return null; | |
} | |
if ($isDataCompressed) { | |
if (function_exists('gzuncompress')) { | |
$dataString = (string)gzuncompress($dataString); | |
} else { | |
echo('Content read error: This file requires decompression, ' . | |
'but this server does not offer gzcompress()/gzuncompress() functions.'); | |
return null; | |
} | |
} | |
return $unserialize ? unserialize($dataString, ['allowed_classes' => false]) : $dataString; | |
} | |
$dat['header'] = getNextFilePart($fd, true, 'header'); | |
$dat['records'] = getNextFilePart($fd, true, 'records'); | |
$dat['files'] = getNextFilePart($fd, true, 'files'); | |
$dat['files_fal'] = getNextFilePart($fd, true, 'files_fal'); | |
print_r($dat); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment