function decompress2($in_data, $out_len) { $pos_max = strlen($in_data) - 1; $pos = -1; $out_data = ''; do { $ctrl = ord($in_data[++$pos]); if ($ctrl > 31) { if ($ctrl < 0xE0) { $len = 2 + ($ctrl >> 5); } else { $len = 2 + ($ctrl >> 5) + ord($in_data[++$pos]); } $backref = (($ctrl & 0x1F) << 8) + 1 + ord($in_data[++$pos]); if ($len < $backref) { $out_data .= substr($out_data, -$backref, $len); } else { /** * If the length of the block is longer than the back ref, it means * that we're going to repeat the same pattern over and over */ $out_data .= str_pad('', $len, substr($out_data, -$backref), STR_PAD_RIGHT); } } else { $out_data .= substr($in_data, ++$pos, $ctrl + 1); $pos += $ctrl; } if (isset($out_data[$out_len])) { die("WTF"); } } while ($pos < $pos_max); return $out_data; }