From cd2b5339028ce16dd4da734fa176bc72fa26e1fd Mon Sep 17 00:00:00 2001 From: Banana Date: Mon, 24 Jun 2013 10:56:24 +0200 Subject: [PATCH] new functions and how to added about serialized data and how to try to fix them --- .../repair-serialized-string.php | 77 ++++++++++++++++++ single-functions/var-dump-to-array.php | 79 +++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 methods-and-how-to/repair-serialized-string.php create mode 100644 single-functions/var-dump-to-array.php diff --git a/methods-and-how-to/repair-serialized-string.php b/methods-and-how-to/repair-serialized-string.php new file mode 100644 index 0000000..7898d41 --- /dev/null +++ b/methods-and-how-to/repair-serialized-string.php @@ -0,0 +1,77 @@ +"; + $data2 = preg_replace ( '!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'",$data1 ); + $max = (strlen ( $data1 ) > strlen ( $data2 )) ? strlen ( $data1 ) : strlen ( $data2 ); + + echo $data1 . PHP_EOL; + echo $data2 . PHP_EOL; + + for($i = 0; $i < $max; $i ++) { + + if (@$data1 {$i} !== @$data2 {$i}) { + + echo "Diffrence ", @$data1 {$i}, " != ", @$data2 {$i}, PHP_EOL; + echo "\t-> ORD number ", ord ( @$data1 {$i} ), " != ", ord ( @$data2 {$i} ), PHP_EOL; + echo "\t-> Line Number = $i" . PHP_EOL; + + $start = ($i - 20); + $start = ($start < 0) ? 0 : $start; + $length = 40; + + $point = $max - $i; + if ($point < 20) { + $rlength = 1; + $rpoint = - $point; + } else { + $rpoint = $length - 20; + $rlength = 1; + } + + echo "\t-> Section Data1 = ", substr_replace ( substr ( $data1, $start, $length ), "{$data1 {$i}}", $rpoint, $rlength ), PHP_EOL; + echo "\t-> Section Data2 = ", substr_replace ( substr ( $data2, $start, $length ), "{$data2 {$i}}", $rpoint, $rlength ), PHP_EOL; + } + } +} + +?> \ No newline at end of file diff --git a/single-functions/var-dump-to-array.php b/single-functions/var-dump-to-array.php new file mode 100644 index 0000000..5053f05 --- /dev/null +++ b/single-functions/var-dump-to-array.php @@ -0,0 +1,79 @@ +)#', + '#(string\\(|int\\(|float\\(|array\\(|NULL|object\\(|})#', + ); + $str = preg_replace($regex, "\n\\1", $str); + $str = trim($str); + } + $regex = array( + '#^\\040*NULL\\040*$#m', + '#^\\s*array\\((.*?)\\)\\s*{\\s*$#m', + '#^\\s*string\\((.*?)\\)\\s*(.*?)$#m', + '#^\\s*int\\((.*?)\\)\\s*$#m', + '#^\\s*float\\((.*?)\\)\\s*$#m', + '#^\\s*\[(\\d+)\\]\\s*=>\\s*$#m', + '#\\s*?\\r?\\n\\s*#m', + ); + $replace = array( + 'N', + 'a:\\1:{', + 's:\\1:\\2', + 'i:\\1', + 'd:\\1', + 'i:\\1', + ';' + ); + $serialized = preg_replace($regex, $replace, $str); + $func = create_function( + '$match', + 'return "s:".strlen($match[1]).":\\"".$match[1]."\\"";' + ); + $serialized = preg_replace_callback( + '#\\s*\\["(.*?)"\\]\\s*=>#', + $func, + $serialized + ); + $func = create_function( + '$match', + 'return "O:".strlen($match[1]).":\\"".$match[1]."\\":".$match[2].":{";' + ); + $serialized = preg_replace_callback( + '#object\\((.*?)\\).*?\\((\\d+)\\)\\s*{\\s*;#', + $func, + $serialized + ); + $serialized = preg_replace( + array('#};#', '#{;#'), + array('}', '{'), + $serialized + ); + + return unserialize($serialized); +} +?> \ No newline at end of file -- 2.39.5