1
0
Fork 0

Decompiler: escape 8bit and control chars and \t

This commit is contained in:
Xuefer 2015-06-30 03:59:03 +08:00
parent 8c23a1d08c
commit 3aed197bd3
1 changed files with 14 additions and 2 deletions

View File

@ -222,7 +222,8 @@ class Decompiler_Value extends Decompiler_Object // {{{
{
$code = var_export($this->value, true);
if (gettype($this->value) == 'string') {
$code = preg_replace_callback("![\r\n]+!", array(&$this, 'convertNewline'), $code);
$code = preg_replace_callback("![\t\r\n]+!", array(&$this, 'convertNewline'), $code);
$code = preg_replace_callback("![\\x01-\\x1f\\x7f-\\xff]+!", array(&$this, 'escape8BitString'), $code);
$code = preg_replace("!^'' \\. \"|\" \\. ''\$!", '"', $code);
}
return $code;
@ -230,7 +231,18 @@ class Decompiler_Value extends Decompiler_Object // {{{
function convertNewline($m)
{
return "' . \"". strtr($m[0], array("\r" => "\\r", "\n" => "\\n")) . "\" . '";
return "' . \"" . strtr($m[0], array("\t" => "\\t", "\r" => "\\r", "\n" => "\\n")) . "\" . '";
}
function escape8BitString($m)
{
// TODO: recognize $encoding
$s = $m[0];
$escaped = '';
for ($i = 0, $c = strlen($s); $i < $c; ++$i) {
$escaped .= "\\x" . dechex(ord($s[$i]));
}
return "' . \"" . $escaped . "\" . '";
}
}
// }}}