Skip to content

Instantly share code, notes, and snippets.

@garvinhicking
Created October 9, 2023 13:32
Show Gist options
  • Save garvinhicking/0846b5565f4c45fb08f276b33e395a65 to your computer and use it in GitHub Desktop.
Save garvinhicking/0846b5565f4c45fb08f276b33e395a65 to your computer and use it in GitHub Desktop.
TYPO3 T3D uncompress / extract / deflate / extrahieren / entpacken
<?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