"sonic_www_php_header", "die" => "sonic_www_php_exit", "exit" => "sonic_www_php_exit", "setcookie" => "sonic_www_php_setcookie", "setrawcookie" => "sonic_www_php_setrawcookie", "session_start" => "sonic_www_php_session_start", ); global $pcode_plain; /* //test phpcode $pcode_plain =<<< EOF EOF; */ $pcode_plain =<<< EOF EOF; function main() { global $pcode_plain, $oin_func_replace; // if ($pc_mode = $_REQUEST["pc_mode"]); else $pc_mode = "straight"; $pc_shift_funcs = $_REQUEST["pc_shift_funcs"]; $pc_shift_globs = $_REQUEST["pc_shift_globs"]; $pc_shift_space = $_REQUEST["pc_shift_space"]; $download = $_REQUEST["download"]; $pc_opts["mode"] = $pc_mode; $pc_opts["shift_funcs"] = $pc_shift_funcs; $pc_opts["shift_globs"] = $pc_shift_globs; $pc_opts["shift_space"] = $pc_shift_space; if ($_pc_txt = $_REQUEST["pc_txt"]) { // $pcode_plain = stripslashes($_pc_txt); $pcode_plain = $_pc_txt; } unset($_pc_txt); if ($pcf = $_FILES["pc_txt_file"]) { if ($pcf["error"]+0 == 0) $pcode_plain = file_get_contents($pcf["tmp_name"]); // unset($pcf); //need this below } $pcode_sonic = oldisnew($pcode_plain, $pc_opts); if ($download) { if ($d_file = $pcf["name"]) $d_file = "sonic.www.".$d_file; else $d_file = time().".txt"; if ($_SERVER["SONIC_WWW_SELF"]) { $_SERVER["SONIC_WWW_SELF"]->sonic_www_php_header('Content-Disposition: attachment; filename='.$d_file); $_SERVER["SONIC_WWW_SELF"]->sonic_www_php_header('Content-Type: application/x-octet-stream'); $_SERVER["SONIC_WWW_SELF"]->sonic_www_php_header('Content-Description: http://dev.pedemont.com/sonic/'); } else { header('Content-Disposition: attachment; filename='.$d_file); // header('Content-Type: application/octet-stream'); //run dont ask header('Content-Type: application/x-octet-stream'); header('Content-Description: http://dev.pedemont.com/sonic/'); } echo $pcode_sonic; } else echo "" .''."\n" .''."\n" ."\n" ."exit the old style, enter the new\n" ."\n" ."\n" ."
\n" // ."
plain PHP code
\n" ." " ."" ."" ."
\n" // ."\n" // ."
\n" // ."\n" ." straight replacement
" ." backwards compatible replacement
" ." shift functions
" ." shift globals
" ." shift white space
\n" ."
download

\n" ."
\n" ."\n" ."\n" ." " ."
static replacements
\n" ."\n" ."
\n" // ."
sonic WWW PHP code
\n" ."
\n" ."\n" ."\n" ."\n" .""; //fin } //opt modes = straight, backwards function oldisnew($php_txt, $oin_params = array("mode" => "straight")) { $so_oinp = sizeof($oin_params); if ($so_oinp > 0); else return $php_txt; switch (strtolower($oin_params["mode"])) { case "straight": $oin_params["mode"] = "straight"; break; case "backwards": $oin_params["mode"] = "backwards"; break; default: $oin_params["mode"] = "straight"; } if (gettype($oin_params["func_replace"]) == "array"); else { global $oin_func_replace; if (gettype($oin_func_replace) == "array"); else return $php_txt; $oin_params["func_replace"] = $oin_func_replace; } $sonic_php_txt = $php_txt; //bak $func_replace = $oin_params["func_replace"]; if ($oin_params["mode"] == "straight") { //replace straight foreach ($func_replace as $php_func => $sonic_func) { $swap_patt = '/((?:\s+|\())(?:'.$php_func.')(\s*\()/i'; $subs_patt = '\\1$_SERVER["SONIC_WWW_SELF"]->'.$sonic_func.'\\2'; $sonic_php_txt = preg_replace($swap_patt, $subs_patt, $sonic_php_txt); } } else if ($oin_params["mode"] == "backwards") { //replace convert backwards compat foreach ($func_replace as $php_func => $sonic_func) { //not below $swap_patt[0] = '/([\s;\){]\s+)((?:'.$php_func.'))(\s*\([^;{}]*);/im'; $subs_patt[0] = '\\1($_SERVER["SONIC_WWW_SELF"] ? ' .'$_SERVER["SONIC_WWW_SELF"]->'.$sonic_func.'\\3' .' : ' .'\\2\\3' .');' .''; //in group or func call eg. yyy(xxx) $swap_patt[1] = '/(\s*\(\s*)((?:'.$php_func.'))(s*\(.*\)\s*)([,\)])/si'; $subs_patt[1] = '\\1($_SERVER["SONIC_WWW_SELF"] ? ' .'$_SERVER["SONIC_WWW_SELF"]->'.$sonic_func.'\\3' .': ' .'\\2\\3' .')\\4' .''; $sonic_php_txt = preg_replace($swap_patt, $subs_patt, $sonic_php_txt); } } /* //UMMMM.. riiiggght //this is some magic php crasher w/o /star star/ with slash slash // $swap_patt = '/<\?(?:php[0-9]+|\s*)\s+(.*)[\s\n\r]+(?:php[0-9]+|\s*)\?>/s'; // $subs_patt = ''; */ if ($oin_params["shift_globs"]) { // function _sptr_h_mglobs($check_header, $matches) { static $sg_count = array(); $_sptr_h = ""; foreach ($matches as $shift_glob) { //checking for previous hit if ($sg_count["$shift_glob"]); //not checking everything, just above our heads (so still chance for single repeats) else if (preg_match('/global\s+[^;]*\\'.$shift_glob.'[^;]*;/', $check_header)); else { $sg_count["$shift_glob"] = true; $_sptr_h .= ""; } } return $_sptr_h; } // $_warn_msg = ""; $braces = split_run($sonic_php_txt); $last_y = 0; $last_x = 0; $spt_rebuild = ""; foreach ($braces as $bi) { list($bi_start, $bi_end) = $bi; $x = $bi_start[1]; $y = $bi_end[1]; $l1 = $x - $last_x; $l2 = $y - $x; // echo substr($sonic_php_txt, $x, $y)."\n"; /* -len1- bs -len2- be last_x \n funct {x }y 0123456789012345678901234567890123456789012345678901 * * * 0 -30- m 30 -20- 50 split_left split_right */ $check_header = substr($sonic_php_txt, $last_x, ($l1 - 1)); $check_gap = '{'; $check_body = substr($sonic_php_txt, $x, $l2); // $check_all = substr($sonic_php_txt, $last_x, ($l1 + $l2)); $check_all = $check_header.$check_gap.$check_body; //no arrays [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* //http://php.net/language.variables if (preg_match('/\n{0,1}([\ ]*function\s+[^(]+\(.*\)[\s]*$)/s', $check_header, $matches)) { if (preg_match_all('/(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*=/s', $check_header, $matches)) { $_sptr_h = _sptr_h_mglobs($check_header, $matches[1]); $spt_rebuild = $_sptr_h.$spt_rebuild.$check_all; } else $spt_rebuild .= $check_all; } else if (preg_match_all('/(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*=/is', $check_all, $matches)) { $_sptr_h = _sptr_h_mglobs($check_header, $matches[1]); $spt_rebuild = $_sptr_h.$spt_rebuild.$check_all; } else $spt_rebuild .= $check_all; $last_x = $bi_end[1]; } $check_all = substr($sonic_php_txt, $last_x); if (preg_match_all('/(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*=/', $check_all, $matches)) { $_sptr_h = _sptr_h_mglobs($check_header, $matches[1]); $spt_rebuild = $_sptr_h.$spt_rebuild.$check_all; } else $spt_rebuild .= $check_all; $spt_rebuild = $_warn_msg.$spt_rebuild; $sonic_php_txt = preg_replace('/(?:\?>|[0-9]*php\?>)\s*(?:<\?php[0-9]*|<\?)/', "", $spt_rebuild); } if ($oin_params["shift_funcs"]) { $braces = split_run($sonic_php_txt); $last_y = 0; $last_x = 0; $spt_rebuild = ""; foreach ($braces as $bi) { list($bi_start, $bi_end) = $bi; $x = $bi_start[1]; $y = $bi_end[1]; $l1 = $x - $last_x; $l2 = $y - $x; // echo substr($sonic_php_txt, $x, $y)."\n"; /* -len1- bs -len2- be last_x \n funct {x }y 0123456789012345678901234567890123456789012345678901 * * * 0 -30- m 30 -20- 50 split_left split_right */ $check_header = substr($sonic_php_txt, $last_x, ($l1 - 1)); $check_gap = '{'; $check_body = substr($sonic_php_txt, $x, $l2); // $check_all = substr($sonic_php_txt, $last_x, ($l1 + $l2)); $check_all = $check_header.$check_gap.$check_body; if (preg_match('/\n{0,1}([\ ]*function\s+[^(]+\(.*\)[\s]*$)/s', $check_header, $matches)) { $m = strpos($sonic_php_txt, $matches[1], $last_x); $split_left = substr($sonic_php_txt, $last_x, $m - $last_x); $sptai = $y + 1; //-1 array +1 next chr $white_space_on = false; $white_space_ok = false; do { switch ($spta[$sptai]) { // case '/': // if ($spta[($sptai+1)] == '/') // $white_space_on = true; // else if ($spta[($sptai+1)] == '*') // $white_space_ok = false; // break; case ' ': case "\t": case "\r": $white_space_ok = true; break; case "\n": $white_space_ok = false; break; default: if ($white_space_on); else $white_space_ok = false; } $sptai++; //+1 on exit to map array index to real y } while ($white_space_ok); $sptai--; //array index fix if ($spta[$sptai] == "\n") $sptai-=2; else $sptai--; $split_right = substr($sonic_php_txt, $m, $sptai - $m); $spt_rebuild = "".$spt_rebuild.$split_left; } else $spt_rebuild .= $check_all; $last_x = $bi_end[1];// + 1; } $spt_rebuild .= substr($sonic_php_txt, $last_x); $sonic_php_txt = preg_replace('/(?:\?>|[0-9]*php\?>)\s*(?:<\?php[0-9]*|<\?)/', "", $spt_rebuild); } if ($oin_params["shift_space"]) return strip_space($sonic_php_txt); else return $sonic_php_txt; } function split_run($sonic_php_txt) { //move funcs to outter scope $spta = preg_split('//', $sonic_php_txt); $word = ""; $word_last = array(); $line_i = 0; $line = 0; $line_last = array(); $braces = array(); $brace_aug = 0; $brace_start = array(); $comment_on = false; foreach ($spta as $chi => $ch) { $line .= $ch; switch ($ch) { case "/": $word .= $ch; if ($spta[$chi-1] == "*") $bcomment_on = false; else if ($spta[$chi+1] == "*") $bcomment_on = true; break; case "{": $word .= $ch; if ($bcomment_on) continue; $brace_aug++; if ($brace_aug == 1) $brace_start = array($line_i, $chi); break; case "}": $word .= $ch; if ($bcomment_on) continue; $brace_aug--; if ($brace_aug == 0) { array_push($braces, array($brace_start, array($line_i, $chi))); $brace_start = array(); } break; case "\n": $line_i++; // array_push($line_last, array($line_i, $line)); $line = ""; break; case " ": case "\r": case "\t": // array_push($word_last, array($line_i, $chi, $word)); $word = ""; break; default: $word .= $ch; } } return $braces; } //http://au2.php.net/manual/en/function.php-strip-whitespace.php#77624 //modded if (defined ('T_ML_COMMENT')); else define ('T_ML_COMMENT', T_COMMENT); if (defined ('T_DOC_COMMENT')); else define ('T_DOC_COMMENT', T_ML_COMMENT); function strip_space($sContent) { $aTokens = token_get_all($sContent); $bLast = false; $sStr = ''; for ( $i = 0, $j = count($aTokens); $i < $j; $i++ ) { if ( is_string($aTokens[$i]) ) { $bLast = false; $sStr .= $aTokens[$i]; } else { switch ( $aTokens[$i][0] ) { case T_COMMENT: case T_ML_COMMENT: case T_DOC_COMMENT: break; case T_WHITESPACE: if (!$bLast) { $sStr .= ' '; $bLast = true; } break; default: $bLast = false; $sStr .= $aTokens[$i][1]; break; } } } $sStr = trim($sStr); $sStr = str_replace("\n", "", $sStr); $sStr = str_replace("\r", "", $sStr); return $sStr; } main(); ?>