Last active
August 1, 2022 10:47
-
-
Save motebaya/5a693687c7bfae01b5159963f6edb6ff to your computer and use it in GitHub Desktop.
if ($vars !== readable) do using $this;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
here source https://stackoverflow.com/questions/32393232/php-rename-all-variables-inside-code | |
*/ | |
function clearvar($file, $out) | |
{ | |
$tokens = token_get_all(file_get_contents($file)); | |
$globals = array('$GLOBALS', '$_SERVER', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_REQUEST', '$_ENV'); | |
$registry = get_defined_functions(); | |
$registry = $registry['internal']; | |
foreach ($tokens as $key => $element) { | |
if (!is_array($element)) { | |
continue; | |
} | |
switch ($element[0]) { | |
case T_VARIABLE: | |
if (in_array($element[1], $globals)) { | |
continue 2; | |
} | |
$prefix = '$'; | |
$index = $key; | |
break; | |
default: | |
continue 2; | |
} | |
if (!isset($registry[$tokens[$index][1]])) { | |
$word = preg_split("/\r\n|\n|\r/", file_get_contents("word.txt")); | |
$x = 0; | |
do { | |
$replacement = $prefix . $word[$x]; | |
$x++; | |
} while (in_array($replacement, $registry)); | |
$registry[$tokens[$index][1]] = $replacement; | |
} | |
$tokens[$index][1] = $registry[$tokens[$index][1]]; | |
} | |
$rawdata = ""; | |
foreach ($tokens as $token) { | |
$rawdata .= $token[1] ?? $token; | |
} | |
echo $rawdata; | |
file_put_contents($out, $rawdata); | |
echo " done !"; | |
} | |
if (count($argv) < 2) { | |
die("usage: php main.php <file/php> <out/php>"); | |
} else { | |
clearvar($argv[1], $argv[2]); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment