GOTO解密脚本,破解微擎模块必备的解密工具,玩微擎的都知道,基本上微擎大部分都是goto加密的,看到好的模块,想要去学习他的代码,加密是万万不行的,所以用这个脚本就能无限解密模块加密文件,你想怎么学习就怎么学习。
因站长有phpgoto解密并且做一些二开,找了5-6小时后,在某站花168元在买的,亲测后两个字“完美”。
其它很多php源码会进行goto加密,比如很多微擎应用。对于已加密的应用很多人是不敢直接使用的,因为不知道里面有些什么内容。 今天,分享源码网为您整理分享一套goto解密的源码 直接上传服务器就可以使用的。PHP7及以上。
将要解密的代码上传到decodeFile文件夹,然后访问index.php文件即可
解压出来的文件在complete文件。 当然如果你有能力二开的话可以将这套封装成付费解压的小工具。这套我自己现在也在用。
代码如下:
<?php namespace app\acquiring\controller; use PhpParser\Error; use PhpParser\NodeDumper; use PhpParser\ParserFactory; use PhpParser\NodeTraverser; use PhpParser\PrettyPrinter; use PhpParser\NodeVisitor; use PhpParser\Node; use PhpParser\Node\Stmt\Function_; use PhpParser\NodeVisitorAbstract; foreach ([__DIR__ . '/vendor/autoload.php', __DIR__ . '/vendor/nikic/php-parser/vendor/autoload.php'] as $file) { if (file_exists($file)) { require $file; break; } } date_default_timezone_set('PRC'); $decodeObj = new Decode(); $decodeObj->batchDecode(); // $decodePath = __DIR__.'\\'.'decodeFile'; class Decode { //注意windos下和linux下路线格式不同 public $decodePath = __DIR__ .DIRECTORY_SEPARATOR. 'decodeFile'; public $completePath = __DIR__ . DIRECTORY_SEPARATOR . 'complete'.DIRECTORY_SEPARATOR; public $replaceTipStr = "change_code_"; public $replaceTip = "<?php change_code_;"; public $replaceTipAst; public $allTable = ""; public $tempObject = null; public $parserObj; public $printCount = 0; public $printCount1 = 0; public $printCount2 = 0; public $functionType = 1; public $foreachType = 2; public $switchType = 3; public $classType = 4; public $allFindLabel = ""; public $allFindLabelStr = ""; public $existValue = "1"; public $notLabelNum = 0; /** 遍历解密文件*/ public function batchDecode() { echo "解密后的文件存放路径:".$this->completePath; echo "<br>"; echo "获取需要解密的文件"; echo "<br>"; $file_list = $this->get_file_list($this->decodePath); echo "获取文件数:".count($file_list); echo "<br>"; foreach ($file_list as $fileName) { $this->startDecode($fileName); } } public function get_file_list($file_path) { if (empty($file_path)) { echo "未设置路径"; return false; } $file_list = []; // $file_path = resource_path($path); if (is_dir($file_path)) { $handler = opendir($file_path); while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { $file_list[] = $filename; } } closedir($handler); return $file_list; } else { echo "文件目录不存在"; echo "<br>"; return array(); } } //开始解密 public function startDecode($fileName) { if (empty($fileName)) { echo "未选择解密文件"; return false; } $code = file_get_contents($this->decodePath . '/' . $fileName); $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); $this->parserObj = $parser; $traverser = new NodeTraverser(); $prettyPrinter = new PrettyPrinter\Standard; // echo "<style>body{ background-color:#0C0C0C; color:green} font{ color: green;} </style>"; $dumper = new NodeDumper; try { $ast = $parser->parse($code); $satrt_ast = $traverser->traverse($ast); if(count($satrt_ast) >0 && get_class($satrt_ast[0]) == "PhpParser\Node\Stmt\Namespace_"){ $emptyStmts = array(); $stmtsArray = $satrt_ast[0] ->stmts; $satrt_ast[0] ->stmts = $emptyStmts; $satrt_ast = array_merge($satrt_ast,$stmtsArray); } // halt($ast); // $test_me = $prettyPrinter->prettyPrint($ast); // $dumper = new NodeDumper; // echo "<pre>"; // echo $dumper->dump($ast);die; $ast = $this->check_two_data($satrt_ast); $newdata = []; $alldata = $this->check_first_data($ast, $newdata); $newdata = $alldata['newdata']; if(!empty($alldata['startdata'])){ $startdata = $alldata['startdata']; $nextgoto_old = ''; foreach ($newdata as $key => $value) { if ($key == $startdata) { $nextgoto_old = $value->name->nextgoto; break; } } $newdata = $this->sortIfData($newdata,$startdata); } $newdata = $this->checkIfData($newdata, 0); if (!empty($alldata['startdata'])) { // code... $startdata = $alldata['startdata']; // halt($newdata); $firset_data = []; $nextgoto_old = ''; foreach ($newdata as $key => $value) { if ($key == $startdata) { if(get_class($value) != 'PhpParser\Node\Stmt\Goto_'){ $firset_data[] = $value; } $nextgoto_old = $value->name->nextgoto; break; } } // halt($firset_data); $res = $this->checkdata2($firset_data, $newdata, $nextgoto_old); $tempArray = array(); foreach ($newdata as $key_new => $value_new) { if($key_new == "startGoto"){ break; } if(strstr($key_new, "notLabel")){ $tempArray[] = $value_new; } } if(count($tempArray) > 0){ $res = array_merge_recursive($tempArray,$res); } } else { $res = $ast; } //一句一句解析。 // $contentCode = $this->getPrettyCode($prettyPrinter,$res); // $this->prettyWriteCode($this->completePath . '\\' . $fileName, $prettyPrinter,$res); echo "解密中..."; //直接全部一次性解析,大文件有可能会内存溢出 $contentCode = $prettyPrinter->prettyPrint($res); $contentCode = "<?php" . "\n" . $contentCode; $this->writeFile($this->completePath . $fileName, $contentCode); echo $fileName."解密成功"; } catch (Error $error) { echo "Parse error: {$error->getMessage()}\n"; return; } } public function check_two_data($ast) { $nodeValue = "1"; foreach ($ast as $key => $value) { if(get_class($ast[$key]) == 'PhpParser\Node\Stmt\If_' && !empty($value->stmts[0]) && get_class($value->stmts[0]) == 'PhpParser\Node\Stmt\Function_'){ $fore_arry = array(); $fore_arry[0] = $value->stmts[0]; $foreachData = $this->check_two_data($fore_arry); $ast[$key]->stmts[0] = $foreachData[0]; } if (get_class($ast[$key]) == 'PhpParser\Node\Stmt\TryCatch') { if (!empty($value->stmts[0]->name->name)) { $startdata = $value->stmts[0]->name->name; // var_dump($startdata);die; $newdata_new = []; $firset_data = []; $nextgoto_old = ''; foreach ($value->stmts as $key99 => $value99) { if (get_class($value99) == 'PhpParser\Node\Stmt\Foreach_') { $fore_arry[0] = $value99; $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\Switch_') { $fore_arry[0] = $value99; $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\Function_') { $fore_arry[0] = $value99; $value->stmts[$key99] = $this->check_two_data($fore_arry); } if (get_class($value99) == 'PhpParser\Node\Stmt\Label') { // var_dump($value99);die; // $newdata[$value->name->name] = $ast[$key+1]; if (!empty($value->stmts[$key99 + 1])) { if (get_class($value->stmts[$key99 + 1]) != 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 2]->name->name; } if (get_class($value->stmts[$key99 - 1]) == 'PhpParser\Node\Stmt\Label' && get_class($value->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 1]->name->name; foreach ($value->stmts as $key_node => $value_node){ if(!empty($value_node->name->name) && get_class($value_node) != 'PhpParser\Node\Stmt\Goto_' &&$value_node->name->name == $value->stmts[$key99 + 1]->name->name){ if(!empty($value->stmts[$key_node + 1])){ $value->stmts[$key_node+1]->name->isNode = &$nodeValue; $value_node->name->isNode = &$nodeValue; }else{ $value->stmts[$key_node]->name->isNode = &$nodeValue; } break; } } } if (get_class($value->stmts[$key99 - 1]) != 'PhpParser\Node\Stmt\Label' && get_class($value->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 1]->name->name; } }else { $newdata_new[$value99->name->name] = $value->stmts[$key99]; $value->stmts[$key99]->name->finish = &$nodeValue; } } } foreach ($newdata_new as $key998 => $value998) { if (empty($value998->name->nextgoto)) { $newdata_new[$key998]->name->nextgoto = null; } if ($key998 == $startdata) { if(get_class($value998) != 'PhpParser\Node\Stmt\Goto_' && get_class($value998) != 'PhpParser\Node\Stmt\Label'){ $firset_data[] = $value998; } $nextgoto_old = $value998->name->nextgoto; } } $newdata_new = $this->sortIfData($newdata_new,$startdata); $newdata_new = $this->checkIfData($newdata_new, $this->functionType); if(count($firset_data)>0 && get_class($firset_data[0]) == 'PhpParser\Node\Stmt\If_'){ $nextgoto_old = $firset_data[0]->name->nextgoto; } $res = $this->checkdata2($firset_data, $newdata_new, $nextgoto_old,$this->functionType); // var_dump($prettyPrinter->prettyPrint($res)); // die; // halt($res); $ast[$key]->stmts = $res; } } if (get_class($ast[$key]) == 'PhpParser\Node\Stmt\Function_') { // foreach ($ast[$key] as $key2 => $value2) { if (!empty($value->stmts[0]->name->name)) { $startdata = $value->stmts[0]->name->name; // var_dump($startdata);die; $newdata_new = []; $firset_data = []; $nextgoto_old = ''; foreach ($value->stmts as $key99 => $value99) { if (get_class($value99) == 'PhpParser\Node\Stmt\Foreach_') { $fore_arry[0] = $value99; //halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; // $value->stmts[$key99] = $this->check_two_data($fore_arry); } if (get_class($value99) == 'PhpParser\Node\Stmt\TryCatch') { $fore_arry[0] = $value99; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\Switch_') { $fore_arry[0] = $value99; $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\Function_') { $fore_arry[0] = $value99; // halt($fore_arry); $value->stmts[$key99] = $this->check_two_data($fore_arry); } if (get_class($value99) == 'PhpParser\Node\Stmt\Label') { // var_dump($value99);die; // $newdata[$value->name->name] = $ast[$key+1]; if (!empty($value->stmts[$key99 + 1])) { if (get_class($value->stmts[$key99 + 1]) != 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 2]->name->name; } if (get_class($value->stmts[$key99 - 1]) == 'PhpParser\Node\Stmt\Label' && get_class($value->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 1]->name->name; foreach ($value->stmts as $key_node => $value_node){ if(!empty($value_node->name->name) && get_class($value_node) != 'PhpParser\Node\Stmt\Goto_' &&$value_node->name->name == $value->stmts[$key99 + 1]->name->name){ if(!empty($value->stmts[$key_node + 1])){ $value->stmts[$key_node+1]->name->isNode = &$nodeValue; $value_node->name->isNode = &$nodeValue; }else{ $value->stmts[$key_node]->name->isNode = &$nodeValue; } break; } } } if (get_class($value->stmts[$key99 - 1]) != 'PhpParser\Node\Stmt\Label' && get_class($value->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 1]->name->name; } }else { $newdata_new[$value99->name->name] = $value->stmts[$key99]; $value->stmts[$key99]->name->finish = &$nodeValue; } }elseif (get_class($value99) != 'PhpParser\Node\Stmt\Goto_'){ if($key99 == 0 || ($key99 > 0 && get_class($value->stmts[$key99 - 1]) != 'PhpParser\Node\Stmt\Label')){ $tempKey = "notLabel".$this->notLabelNum; $this->notLabelNum = $this->notLabelNum + 1; $newdata_new[$tempKey] = $value->stmts[$key99]; if($key99 >0 && empty($value->stmts[$key99 - 1]->name->nextgoto)){ if(empty($value->stmts[$key99 - 1]->name)){ $value->stmts[$key99 - 1]->name = new \stdClass(); } $value->stmts[$key99 - 1]->name->nextgoto = $tempKey; } $astLength = count($value->stmts); if($key99 + 1 < $astLength && get_class($value->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_'){ if(empty($value->stmts[$key99]->name)){ $value->stmts[$key99]->name = new \stdClass(); } $value->stmts[$key99]->name->nextgoto = $value->stmts[$key99 + 1]->name->name; } } } } foreach ($newdata_new as $key998 => $value998) { if (empty($value998->name->nextgoto)) { // var_dump($value998->name);die; $newdata_new[$key998]->name->nextgoto = null; } if ($key998 == $startdata) { if(get_class($value998) != 'PhpParser\Node\Stmt\Goto_' && get_class($value998) != 'PhpParser\Node\Stmt\Label'){ $firset_data[] = $value998; } $nextgoto_old = $value998->name->nextgoto; } } // $test_code = $prettyPrinter->prettyPrint($newdata_new); // halt($newdata_new); // $newdata_new = $this->chekif($newdata_new, 2); $newdata_new = $this->sortIfData($newdata_new,$startdata); $newdata_new = $this->checkIfData($newdata_new, $this->functionType); if(count($firset_data)>0 && get_class($firset_data[0]) == 'PhpParser\Node\Stmt\If_'){ $nextgoto_old = $firset_data[0]->name->nextgoto; } $res = $this->checkdata2($firset_data, $newdata_new, $nextgoto_old,$this->functionType); // var_dump($prettyPrinter->prettyPrint($res)); // die; // halt($res); $ast[$key]->stmts = $res; }elseif(get_class($value->stmts[0]) == 'PhpParser\Node\Stmt\TryCatch'){ $fore_arry[0] = $value->stmts[0]; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value->stmts[0] = $foreachData[0]; } } if (get_class($ast[$key]) == 'PhpParser\Node\Stmt\Foreach_' || get_class($ast[$key]) == 'PhpParser\Node\Stmt\While_') { // foreach ($ast[$key] as $key2 => $value2) { if (!empty($value->stmts[0]->name->name)) { $startdata = $value->stmts[0]->name->name; // var_dump($startdata);die; $newdata_new = []; $firset_data = []; $nextgoto_old = ''; foreach ($value->stmts as $key99 => $value99) { if (get_class($value99) == 'PhpParser\Node\Stmt\Foreach_') { $fore_arry[0] = $value99; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\TryCatch') { $fore_arry[0] = $value99; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\Switch_') { $fore_arry[0] = $value99; $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } // $startdata = ''; if (get_class($value99) == 'PhpParser\Node\Stmt\Label') { // var_dump($value99);die; // $newdata[$value->name->name] = $ast[$key+1]; if (!empty($value->stmts[$key99 + 1])) { if (get_class($value->stmts[$key99 + 1]) != 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 2]->name->name; } if (get_class($value->stmts[$key99 - 1]) == 'PhpParser\Node\Stmt\Label' && get_class($value->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 1]->name->name; foreach ($value->stmts as $key_node => $value_node){ if(!empty($value_node->name->name) && get_class($value_node) != 'PhpParser\Node\Stmt\Goto_' &&$value_node->name->name == $value->stmts[$key99 + 1]->name->name){ if(!empty($value->stmts[$key_node + 1])){ $value->stmts[$key_node+1]->name->isNode = &$nodeValue; $value_node->name->isNode = &$nodeValue; }else{ $value->stmts[$key_node]->name->isNode = &$nodeValue; } break; } } } if (get_class($value->stmts[$key99 - 1]) != 'PhpParser\Node\Stmt\Label' && get_class($value->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value->stmts[$key99 + 1]; $value->stmts[$key99 + 1]->name->nextgoto = &$value->stmts[$key99 + 1]->name->name; } } else { $newdata_new[$value99->name->name] = $value->stmts[$key99]; $value->stmts[$key99]->name->finish = &$nodeValue; } } } foreach ($newdata_new as $key998 => $value998) { if (empty($value998->name->nextgoto)) { // var_dump($value998->name);die; $newdata_new[$key998]->name->nextgoto = null; } if ($key998 == $startdata) { if(get_class($value998) != 'PhpParser\Node\Stmt\Goto_' && get_class($value998) != 'PhpParser\Node\Stmt\Label'){ $firset_data[] = $value998; } $nextgoto_old = $value998->name->nextgoto; } } $newdata_new = $this->sortIfData($newdata_new,$startdata); $newdata_new = $this->checkIfData($newdata_new, $this->foreachType); if(count($firset_data)>0 && get_class($firset_data[0]) == 'PhpParser\Node\Stmt\If_'){ $nextgoto_old = $firset_data[0]->name->nextgoto; } $res = $this->checkdata2($firset_data, $newdata_new, $nextgoto_old,$this->foreachType); $ast[$key]->stmts = $res; } else { if (!empty($ast[$key]->stmts)) { foreach ($ast[$key]->stmts as $key9527 => $value9527) { // halt($ast[$key]->stmts); if (get_class($ast[$key]->stmts[$key9527]) == 'PhpParser\Node\Stmt\Label') { unset($ast[$key]->stmts[$key9527]); } } } } } if (get_class($ast[$key]) == 'PhpParser\Node\Stmt\Switch_') { foreach ($ast[$key]->cases as $key2 => $value2) { if (!empty($value2->stmts[0]->name->name)) { $startdata = $value2->stmts[0]->name->name; // var_dump($startdata);die; $newdata_new = []; $firset_data = []; $fore_arry = []; $nextgoto_old = ''; foreach ($value2->stmts as $key99 => $value99) { if (get_class($value99) == 'PhpParser\Node\Stmt\Foreach_') { $fore_arry[0] = $value99; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value2->stmts[$key99] = $foreachData[0]; // $value2->stmts[$key99] = $this->check_two_data($fore_arry); } if (get_class($value99) == 'PhpParser\Node\Stmt\Switch_') { $fore_arry[0] = $value99; $foreachData = $this->check_two_data($fore_arry); $value->stmts[$key99] = $foreachData[0]; } // $startdata = ''; if (get_class($value99) == 'PhpParser\Node\Stmt\Label') { // var_dump($value99);die; // $newdata[$value->name->name] = $ast[$key+1]; if (!empty($value2->stmts[$key99 + 1])) { if (get_class($value2->stmts[$key99 + 1]) != 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value2->stmts[$key99 + 1]; $value2->stmts[$key99 + 1]->name->nextgoto = &$value2->stmts[$key99 + 2]->name->name; } if (get_class($value2->stmts[$key99 - 1]) == 'PhpParser\Node\Stmt\Label' && get_class($value2->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value2->stmts[$key99 + 1]; $value2->stmts[$key99 + 1]->name->nextgoto = &$value2->stmts[$key99 + 1]->name->name; foreach ($value2->stmts as $key_node => $value_node){ if(!empty($value_node->name->name) && get_class($value_node) != 'PhpParser\Node\Stmt\Goto_' &&$value_node->name->name == $value2->stmts[$key99 + 1]->name->name){ if(!empty($value2->stmts[$key_node + 1])){ $value2->stmts[$key_node+1]->name->isNode = &$nodeValue; $value_node->name->isNode = &$nodeValue; }else{ $value2->stmts[$key_node]->name->isNode = &$nodeValue; } break; } } } if (get_class($value2->stmts[$key99 - 1]) != 'PhpParser\Node\Stmt\Label' && get_class($value2->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value2->stmts[$key99 + 1]; $value2->stmts[$key99 + 1]->name->nextgoto = &$value2->stmts[$key99 + 1]->name->name; } }else { $newdata_new[$value99->name->name] = $value2->stmts[$key99]; $value2->stmts[$key99]->name->finish = &$nodeValue; } } } foreach ($newdata_new as $key998 => $value998) { if (empty($value998->name->nextgoto)) { // var_dump($value998->name);die; $newdata_new[$key998]->name->nextgoto = null; } if ($key998 == $startdata) { if(get_class($value998) != 'PhpParser\Node\Stmt\Goto_' && get_class($value998) != 'PhpParser\Node\Stmt\Label'){ $firset_data[] = $value998; } $nextgoto_old = $value998->name->nextgoto; } } // $test_code = $prettyPrinter->prettyPrint($newdata_new); // halt($newdata_new); $newdata_new = $this->sortIfData($newdata_new,$startdata); $newdata_new = $this->checkIfData( $newdata_new, $this->switchType); if(count($firset_data)>0 && get_class($firset_data[0]) == 'PhpParser\Node\Stmt\If_'){ $nextgoto_old = $firset_data[0]->name->nextgoto; } // var_dump($newdata_new); // halt($newdata_new); $res = $this->checkdata2($firset_data, $newdata_new, $nextgoto_old,$this->switchType); // var_dump($prettyPrinter->prettyPrint($res)); // halt($res); $ast[$key]->cases[$key2]->stmts = $res; }else { if (!empty($value2) && !empty($value2->stmts)) { foreach ($value2->stmts as $key_remove => $value_remove) { // halt($ast[$key]->stmts); if (get_class($value_remove) == 'PhpParser\Node\Stmt\Label') { unset($value2->stmts[$key_remove]); } if(get_class($value_remove) == 'PhpParser\Node\Stmt\Goto_'){ $attributes = array(); $breakStd = new \PhpParser\Node\Stmt\Break_(null,$attributes); $value2->stmts[$key_remove] = $breakStd; } } } } } } if (get_class($ast[$key]) == 'PhpParser\Node\Stmt\Class_') { foreach ($ast[$key]->stmts as $key2 => $value2) { if (get_class($value2) == 'PhpParser\Node\Stmt\ClassMethod') { if (!empty($value2->stmts[0]->name->name)) { $startdata = $value2->stmts[0]->name->name; // var_dump($startdata);die; $newdata_new = []; $firset_data = []; $nextgoto_old = ''; foreach ($value2->stmts as $key99 => $value99) { if (get_class($value99) == 'PhpParser\Node\Stmt\Foreach_') { $fore_arry[0] = $value99; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value2->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\TryCatch') { $fore_arry[0] = $value99; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value2->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\Function_') { $fore_arry[0] = $value99; $foreachData = $this->check_two_data($fore_arry); $value2->stmts[$key99] = $foreachData[0]; } if (get_class($value99) == 'PhpParser\Node\Stmt\Switch_') { $fore_arry[0] = $value99; $foreachData = $this->check_two_data($fore_arry); $value2->stmts[$key99] = $foreachData[0]; } // $startdata = ''; if (get_class($value99) == 'PhpParser\Node\Stmt\Label') { // var_dump($value99);die; // $newdata[$value->name->name] = $ast[$key+1]; if (!empty($value2->stmts[$key99 + 1])) { if (get_class($value2->stmts[$key99 + 1]) != 'PhpParser\Node\Stmt\Goto_') { // if($value99->name->name == "g0ibM"){ // echo "g0ibM"; // } $newdata_new[$value99->name->name] = $value2->stmts[$key99 + 1]; $value2->stmts[$key99 + 1]->name->nextgoto = &$value2->stmts[$key99 + 2]->name->name; } if (get_class($value2->stmts[$key99 - 1]) == 'PhpParser\Node\Stmt\Label' && get_class($value2->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value2->stmts[$key99 + 1]; $value2->stmts[$key99 + 1]->name->nextgoto = &$value2->stmts[$key99 + 1]->name->name; // $value2->stmts[$key99 + 1]->name->isNode = &$nodeValue; foreach ($value2->stmts as $key_node => $value_node){ if(!empty($value_node->name->name) && get_class($value_node) != 'PhpParser\Node\Stmt\Goto_' &&$value_node->name->name == $value2->stmts[$key99 + 1]->name->name){ if(!empty($value2->stmts[$key_node + 1])){ $value2->stmts[$key_node+1]->name->isNode = &$nodeValue; $value_node->name->isNode = &$nodeValue; }else{ $value2->stmts[$key_node]->name->isNode = &$nodeValue; } break; } } } if (get_class($value2->stmts[$key99 - 1]) != 'PhpParser\Node\Stmt\Label' && get_class($value2->stmts[$key99 + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata_new[$value99->name->name] = $value2->stmts[$key99 + 1]; $value2->stmts[$key99 + 1]->name->nextgoto = &$value2->stmts[$key99 + 1]->name->name; } }else { $newdata_new[$value99->name->name] = $value2->stmts[$key99]; $value2->stmts[$key99]->name->finish = &$nodeValue; } } } foreach ($newdata_new as $key998 => $value998) { if (empty($value998->name->nextgoto)) { // var_dump($value998->name);die; $newdata_new[$key998]->name->nextgoto = null; } if ($key998 == $startdata) { if(get_class($value998) != 'PhpParser\Node\Stmt\Goto_' && get_class($value998) != 'PhpParser\Node\Stmt\Label'){ $firset_data[] = $value998; } $nextgoto_old = $value998->name->nextgoto; } } $newdata_new = $this->sortIfData($newdata_new,$startdata); $newdata_new = $this->checkIfData($newdata_new, $this->classType); if(count($firset_data)>0 && get_class($firset_data[0]) == 'PhpParser\Node\Stmt\If_'){ $nextgoto_old = $firset_data[0]->name->nextgoto; } $res = $this->checkdata2($firset_data, $newdata_new, $nextgoto_old,$this->classType); $ast[$key]->stmts[$key2]->stmts = $res; }else{ if (!empty($value2) && !empty($value2->stmts)) { foreach ($value2->stmts as $key_search => $value_search) { if (get_class($value_search) == 'PhpParser\Node\Stmt\TryCatch' || get_class($value_search) == 'PhpParser\Node\Stmt\Foreach_') { $fore_arry[0] = $value_search; // halt($fore_arry); $foreachData = $this->check_two_data($fore_arry); $value2->stmts[$key_search] = $foreachData[0]; } } } } } } } } return $ast; } public function check_first_data($ast, $newdata) { $nodeValue = "1"; $emptyString = ""; $astLength = count($ast); $classLabel = ""; $nodeLabel = ""; foreach ($ast as $key => $value) { if (get_class($value) == 'PhpParser\Node\Stmt\Label' && ($key + 1 < $astLength) && get_class($ast[$key + 1]) == 'PhpParser\Node\Stmt\Class_') { $classLabel = $classLabel.$ast[$key]->name->name.","; } } foreach ($ast as $key => $value) { if (get_class($value) == 'PhpParser\Node\Stmt\Goto_' && empty($startdata)) { $startdata = $ast[$key]->name->name; $newdata['startGoto'] = $ast[$key]; $alldata['startdata'] = $startdata; } if (get_class($value) == 'PhpParser\Node\Stmt\Goto_') { } if (get_class($value) == 'PhpParser\Node\Stmt\Label') { if (!empty($ast[$key + 1]) && !empty($ast[$key + 2])) { if (get_class($ast[$key + 1]) != 'PhpParser\Node\Stmt\Goto_') { $newdata[$value->name->name] = $ast[$key + 1]; $ast[$key + 1]->name->nextgoto = &$ast[$key + 2]->name->name; } if (get_class($ast[$key - 1]) == 'PhpParser\Node\Stmt\Label' && get_class($ast[$key + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata[$value->name->name] = $ast[$key + 1]; $ast[$key + 1]->name->nextgoto = &$ast[$key + 1]->name->name; if(!empty($ast[$key + 1]->name->name)){ if(!strstr($nodeLabel, $ast[$key + 1]->name->name)){ $nodeLabel = $nodeLabel.$ast[$key + 1]->name->name.","; } } } if (get_class($ast[$key - 1]) != 'PhpParser\Node\Stmt\Label' && get_class($ast[$key + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata[$value->name->name] = $ast[$key + 1]; $ast[$key + 1]->name->nextgoto = &$ast[$key + 1]->name->name; } }else if(!empty($ast[$key + 1]) && ($key + 2 == $astLength)){ if (get_class($ast[$key + 1]) != 'PhpParser\Node\Stmt\Goto_') { $newdata[$value->name->name] = $ast[$key + 1]; } if (get_class($ast[$key + 1]) == 'PhpParser\Node\Stmt\Goto_') { $newdata[$value->name->name] = $ast[$key + 1]; $ast[$key + 1]->name->nextgoto = &$ast[$key + 1]->name->name; } }elseif(($key + 1 == $astLength)){ $newdata[$value->name->name] = $ast[$key]; $value->name->finish = &$nodeValue; $value->name->exitFinish = &$nodeValue; if(get_class($ast[$key - 1]) == 'PhpParser\Node\Stmt\Label'){ $value->name->otherFinishLabel = &$ast[$key - 1]->name->name; } } }elseif (get_class($value) != 'PhpParser\Node\Stmt\Goto_'){ if($key == 0 || ($key > 0 && get_class($ast[$key - 1]) != 'PhpParser\Node\Stmt\Label')){ $tempKey = "notLabel".$this->notLabelNum; $this->notLabelNum = $this->notLabelNum + 1; $newdata[$tempKey] = $ast[$key]; if($key >0 && empty($ast[$key - 1]->name->nextgoto)){ if(empty($ast[$key - 1]->name)){ $ast[$key - 1]->name = new \stdClass(); } $ast[$key - 1]->name->nextgoto = $tempKey; } if($key + 1 < $astLength && get_class($ast[$key + 1]) == 'PhpParser\Node\Stmt\Goto_'){ if(empty($ast[$key]->name)){ $ast[$key]->name = new \stdClass(); } $ast[$key]->name->nextgoto = $ast[$key + 1]->name->name; } } } } foreach ($ast as $key_node => $value_node){ if(!empty($value_node->name->name) && get_class($value_node) != 'PhpParser\Node\Stmt\Goto_' && strstr($nodeLabel, $value_node->name->name)){ if(!empty($ast[$key_node + 1])){ $ast[$key_node+1]->name->isNode = &$nodeValue; $value_node->name->isNode = &$nodeValue; }else{ $ast[$key_node]->name->isNode = &$nodeValue; } } } foreach ($newdata as $key => $value) { if (empty($value->name->nextgoto)) { $newdata[$key]->name->nextgoto = &$emptyString; $newdata[$key]->name->nextgoto = null; } } $alldata['newdata'] = $newdata; return $alldata; } public function checkdata($firset_data, $newdata, $nextgoto_new) { MYGOD: foreach ($newdata as $key2 => $value2) { if ($nextgoto_new == $key2) { $firset_data[] = $value2; if (!empty($value2->name->nextgoto)) { $nextgoto_new = $value2->name->nextgoto; goto MYGOD; } } } return $firset_data; } public function packageData($firset_data, $newdata, $nextgoto_new,$stopStr="") { $this->allFindLabel = ""; if(empty($newdata)){ return $firset_data; }elseif($nextgoto_new == $stopStr){ return $firset_data; } $lastKey = ""; MYGOD: foreach ($newdata as $key2 => $value2) { if ($nextgoto_new == $key2) { if(!strstr($this->allFindLabel, $key2)){ $this->allFindLabel = $this->allFindLabel.$key2.";"; }else{ if(get_class($value2) == 'PhpParser\Node\Stmt\If_'){ if(!empty($value2->stmts[0]->name->name)){ $nextgoto_new = $value2->stmts[0]->name->name; goto MYGOD; } } goto MYGOD2; } if (get_class($value2) != 'PhpParser\Node\Stmt\Goto_' && get_class($value2) != 'PhpParser\Node\Stmt\Label') { $firset_data[$key2] = $value2; } if(get_class($value2) == 'PhpParser\Node\Stmt\Label' && !empty($value2->name->finish) && $value2->name->finish == "1"){ $firset_data[$key2] = $value2; } if (!empty($value2->name->nextgoto)) { if(!empty($stopStr)){ if($value2->name->nextgoto == $stopStr){ goto MYGOD2; } } $nextgoto_new = $value2->name->nextgoto; $lastKey = $key2; if(empty($newdata[$nextgoto_new])){ $firset_data[$key2] = $value2; } goto MYGOD; } } } MYGOD2: return $firset_data; } public function checkLoopData($firset_data, $newdata, $nextgoto_new,$type = 0,$stopStr="") { $this->allFindLabel = ""; if(empty($newdata)){ return $firset_data; } $lastKey = ""; MYGOD: foreach ($newdata as $key2 => $value2) { if ($nextgoto_new == $key2) { if(!strstr($this->allFindLabel, $key2)){ $this->allFindLabel = $this->allFindLabel.$key2.";"; }else{ goto MYGOD2; } if (get_class($value2) != 'PhpParser\Node\Stmt\Goto_' && get_class($value2) != 'PhpParser\Node\Stmt\Label') { $firset_data[] = &$value2; } if (get_class($value2) == 'PhpParser\Node\Stmt\Return_') { // code... goto MYGOD2; } if (!empty($value2->expr)) { if (get_class($value2->expr) == 'PhpParser\Node\Expr\Exit_') { // code... // var_dump(get_class($value2->expr)); goto MYGOD2; } } if (!empty($value2->name->nextgoto)) { $nextgoto_new = $value2->name->nextgoto; if($type == $this->switchType && empty($newdata[$nextgoto_new])){ $attributes = array(); $breakStd = new \PhpParser\Node\Stmt\Break_(null,$attributes); $firset_data[] = $breakStd; } if(!empty($stopStr)){ if($value2->name->nextgoto == $stopStr){ goto MYGOD2; } } $lastKey = $key2; goto MYGOD; } } } MYGOD2: return $firset_data; } //提取if的语句 public function extractIfData($newdata,$nextgoto_new,$lastLabel=""){ $ifDataArray = []; // $lastLabel = ""; while (!empty($nextgoto_new)){ if(!empty($newdata[$nextgoto_new]) && !strstr($this->allFindLabel, $nextgoto_new)){ $this->allFindLabel = $this->allFindLabel.$nextgoto_new.";"; $value = $newdata[$nextgoto_new]; if (get_class($value) == 'PhpParser\Node\Stmt\If_') { if(empty($value->name)){ $value->name = new \stdClass(); } if(empty($value->name->lastLabelOne)){ $value->name->lastLabelOne = $lastLabel; }else{ $value->name->lastLabelTwo = $lastLabel; } $ifDataArray[$nextgoto_new] = $value; if(!empty($value->stmts) && !empty($value->stmts[0]->name->name)){ if (get_class($value) != 'PhpParser\Node\Stmt\Goto_' && get_class($value) != 'PhpParser\Node\Stmt\Label'){ $lastLabel = $nextgoto_new; } $insideArray = $this->extractIfData($newdata,$value->stmts[0]->name->name,$lastLabel); $ifDataArray = array_merge($ifDataArray,$insideArray); } } if (!empty($value->name->nextgoto)) { if (get_class($value) != 'PhpParser\Node\Stmt\Goto_' && get_class($value) != 'PhpParser\Node\Stmt\Label'){ $lastLabel = $nextgoto_new; } // $lastLabel = $nextgoto_new; $nextgoto_new = $value->name->nextgoto; }else{ $nextgoto_new = ""; } }else { $nextgoto_new = ""; } } return $ifDataArray; } //把if按顺序排 public function sortIfData($newdata,$nextgoto_new) { $this->allFindLabel = ""; $ifDataArray = []; // $allDataArray = []; if(empty($newdata)){ return $ifDataArray; } $ifDataArray = $this->extractIfData($newdata,$nextgoto_new); $otherDataArray = array(); foreach ($newdata as $key => $value){ if(empty($ifDataArray[$key])){ // $ifDataArray[$key] = $value; $otherDataArray[$key] = $value; } } $allDataArray = array_merge_recursive($otherDataArray,$ifDataArray); return $allDataArray; } public function checkdata2($firset_data, &$newdata, $nextgoto_new,$type = 0,$stopStr="",$nowKey="") { $start_nextgot = $nextgoto_new; $this->allFindLabel = ""; if(!empty($nowKey)){ $this->allFindLabel = $nowKey.","; } if(empty($newdata)){ return $firset_data; } $lastKey = ""; MYGOD: foreach ($newdata as $key2 => $value2) { if ($nextgoto_new == $key2) { if(!strstr($this->allFindLabel, $key2)){ $this->allFindLabel = $this->allFindLabel.$key2.","; }else{ if($nowKey == $key2){ $newdata["$nowKey"]->name->isWhile = &$this->existValue; } goto MYGOD2; } if (get_class($value2) != 'PhpParser\Node\Stmt\Goto_' && get_class($value2) != 'PhpParser\Node\Stmt\Label') { $firset_data[] = $value2; } if (get_class($value2) == 'PhpParser\Node\Stmt\Return_') { // code... goto MYGOD2; } if (!empty($value2->expr)) { if (get_class($value2->expr) == 'PhpParser\Node\Expr\Exit_') { goto MYGOD2; } } //最后一个label if(!empty($value2->name->exitFinish) && $value2->name->exitFinish == 1 && get_class($value2) == 'PhpParser\Node\Stmt\Label'){ if(!empty($nowKey) && get_class($newdata[$nowKey]) == 'PhpParser\Node\Stmt\If_'){ if($start_nextgot != $newdata[$nowKey]->name->nextgoto){ $attributes = array(); $attributes['kind'] = 1; $exitStd = new \PhpParser\Node\Expr\Exit_(null,$attributes); $expressionStd = new \PhpParser\Node\Stmt\Expression($exitStd,$attributes); $firset_data[] = $expressionStd; } } } if (!empty($value2->name->nextgoto)) { $nextgoto_new = $value2->name->nextgoto; if($type == $this->switchType && empty($newdata[$nextgoto_new])){ $attributes = array(); $breakStd = new \PhpParser\Node\Stmt\Break_(null,$attributes); $firset_data[] = $breakStd; } if(!empty($stopStr)){ if($value2->name->nextgoto == $stopStr){ goto MYGOD2; } } $lastKey = $key2; goto MYGOD; } } } MYGOD2: return $firset_data; } //检查if语句部分的代码是否需要反向解密 public function checkIfData($newdata,$type) { foreach ($newdata as $key => $value) { if (get_class($value) == 'PhpParser\Node\Stmt\If_' || get_class($value) == 'PhpParser\Node\Stmt\Foreach_') { // halt($value); if (!empty($value->stmts[0]->name->name)) { $insideLabel = $value->stmts[0]->name->name; if(!empty($newdata[$insideLabel])){ $firset_data = []; // if($key == "YwAsH"){ // echo "UZkI3"; // } if (get_class($value) == 'PhpParser\Node\Stmt\If_' && !empty($value->name->nextgoto)){ $firstStr = $this->findIFLabel($value->stmts[0]->name->name, $newdata); if(!empty($firstStr) && empty($newdata[$firstStr]->name->nextgoto) && !empty($newdata[$firstStr]->name->finish) && $newdata[$firstStr]->name->finish == "1"){ if(!empty($newdata[$firstStr]->name->otherFinishLabel)){ $firstStr = $newdata[$firstStr]->name->otherFinishLabel; } } // echo "key:".$key.";"; $this->allFindLabelStr = ""; $nextStr = $this->compareNextLabel($value->name->nextgoto, $newdata,$firstStr,$type,$key); if(!empty($nextStr) && !empty($value->name->whileLabel) && $nextStr == $newdata[$value->name->whileLabel]->name->nextgoto){ $nextStr = ""; }elseif(!empty($value->name->whileLabel) && $value->name->whileLabel == $value->name->nextgoto){ $nextStr = ""; $value->name->isChange = ""; } if(!empty($nextStr) || !empty($value->name->isChange) || !empty($value->name->isWhile) || !empty($value->name->isBreak)){ // //条件跳转跟下一句的nextgoto跳转相同 // //条件需要反向的处理 if(get_class($value->cond) == 'PhpParser\Node\Expr\BooleanNot'){ $tempCond = $value->cond->expr; $value->cond = $tempCond; }else{ $tempCond = $value->cond; $attributes = $tempCond->getAttributes();; $user = new \PhpParser\Node\Expr\BooleanNot($tempCond,$attributes); $value->cond = $user; } $value->stmts[0]->name->name = $value->name->nextgoto; $value->name->nextgoto = $firstStr; if(!empty($value->name->isInsideLoop) && empty($value->name->isWhile)){ $value->name->stopgoto = $value->name->isInsideLoop; $value->name->isWhile = &$this->existValue; } if(!empty($value->name->isWhile) && !empty($this->allFindLabelStr)){ $this->allFindLabel = $key.","; $this->setWhileData($value->stmts[0]->name->name,$newdata,$key); } if(!empty($nextStr)){ $value->name->stopgoto = $nextStr; }elseif(!empty($value->name->isChange)){ $value->name->stopgoto = $value->name->isChange; if(!empty($value->name->isWhile)){ $checkDataResult = $this->packageData($firset_data, $newdata, $value->stmts[0]->name->name,$key); }else{ $checkDataResult = $this->packageData($firset_data, $newdata, $value->stmts[0]->name->name); } $firset_data = []; $checkNextDataResult = $this->packageData($firset_data, $newdata, $value->name->nextgoto,$value->name->stopgoto); $sameNodeStr = $this->selectSameNode($checkDataResult,$checkNextDataResult); if(!empty($sameNodeStr)){ //存在else的情况 $value->name->elseStr = $sameNodeStr; $newdata[$key]->name->oldnextgoto = $value->name->nextgoto; $newdata[$key]->name->nextgoto = $sameNodeStr; $value->name->stopgoto = ""; } }elseif(!empty($value->name->isWhile) && empty($value->name->stopgoto)){ $value->name->stopgoto = $key; } else { // $value->name->stopgoto = $value->name->isBreak; } }elseif(!empty($value->name->isInsideLoop)){ $value->name->stopgoto = $value->name->isInsideLoop; $value->name->isWhile = &$this->existValue; } else{ if(!empty($value->name->whileLabel)){ $whileLabel = $value->name->whileLabel; }else{ $whileLabel = ""; } $checkDataResult = $this->packageData($firset_data, $newdata, $insideLabel,$whileLabel); $checkNextDataResult = $this->packageData($firset_data, $newdata, $value->name->nextgoto,$whileLabel); $sameNodeStr = $this->selectSameNode($checkDataResult,$checkNextDataResult); if(!empty($sameNodeStr)){ //存在else的情况 $value->name->elseStr = $sameNodeStr; $newdata[$key]->name->oldnextgoto = $value->name->nextgoto; $newdata[$key]->name->nextgoto = $sameNodeStr; } } $newdata[$key]->name->oldIfLabel = $key; } } } } } //处理if中的 foreach ($newdata as $key => $value) { if (get_class($value) == 'PhpParser\Node\Stmt\If_' || get_class($value) == 'PhpParser\Node\Stmt\Foreach_') { // halt($value); if (!empty($value->stmts[0]->name->name)) { foreach ($newdata as $key996 => $value996) { if ($key996 == $value->stmts[0]->name->name) { $firset_data = []; if($type == $this->foreachType || $type == $this->switchType){ $code2 = '<?php break;'; $code2 = $this->parserObj->parse($code2); }else { $code2 = '<?php return false;'; $code2 = $this->parserObj->parse($code2); } // if($key == "UZkI3"){ // echo "UZkI3"; // } if (get_class($value) == 'PhpParser\Node\Stmt\If_' && !empty($value->name->nextgoto)){ if(!empty($value->name->stopgoto)){ if(!empty($value->name->isWhile)){ // $this ->restoreWhile($key,$newdata); // $checkDataResult = $this->checkdata2($firset_data, $newdata, $key996,$type,$stopStr); $checkDataResult = $this->checkdata2($firset_data, $newdata, $value->stmts[0]->name->name,0,$value->name->stopgoto,$key); $newdata[$key]->stmts = !empty($checkDataResult) ? $checkDataResult : $code2; }else{ $stopStr = $value->name->stopgoto; $checkDataResult = $this->checkdata2($firset_data, $newdata, $key996,$type,$stopStr,$key); if(!empty($value->name->whileLabel)){ if(!empty($value->name->isChange)){ $tempWhileLabel = $value->name->isChange; }else { $tempWhileLabel = $value->name->whileLabel; } //判断是否有break的情况 $whileLabelNext = $newdata[$tempWhileLabel]->name->nextgoto; if(strstr($this->allFindLabel,$whileLabelNext)){ $checkDataResult = $this->checkdata2($firset_data, $newdata, $key996,$type,$whileLabelNext,$key); $attributes = array(); $breakStd = new \PhpParser\Node\Stmt\Break_(null,$attributes); $checkDataResult[] = $breakStd; } } $newdata[$key]->stmts = !empty($checkDataResult) ? $checkDataResult : $code2; } }elseif(!empty($value->name->elseStr)){ // $this->judgeElseIf($newdata,$sameNodeStr,$key,$key996,$value->name->oldnextgoto,$type); //存在else的情况 $sameNodeStr = $value->name->elseStr; $checkDataResult = $this->checkdata2($firset_data, $newdata, $key996,$type,$sameNodeStr,$key); $newdata[$key]->stmts = $checkDataResult; $firset_data = []; $checkNextDataResult = $this->checkdata2($firset_data, $newdata, $value->name->oldnextgoto,$type,$sameNodeStr,$key); $attributes = array(); $elseStd = new \PhpParser\Node\Stmt\Else_($checkNextDataResult,$attributes); $newdata[$key]->else = $elseStd; $newdata[$key]->name->nextgoto = $sameNodeStr; }else{ if(!empty($value->name->whileLabel)){ $stopStr = $value->name->whileLabel; }else{ $stopStr = ""; } $checkDataResult = $this->checkdata2($firset_data, $newdata, $key996,$type,$stopStr,$key); $newdata[$key]->stmts = !empty($checkDataResult) ? $checkDataResult : $code2; } }else{ $checkDataResult = $this->checkdata2($firset_data, $newdata, $key996,$type,"",$key); $newdata[$key]->stmts = !empty($checkDataResult) ? $checkDataResult : $code2; } break; } } } } } $this->allFindLabelStr =""; foreach ($newdata as $key => $value){ if (get_class($value) == 'PhpParser\Node\Stmt\If_'){ $this->allFindLabelStr = $key.","; if(!empty($value->name->isWhile)){ //条件跳转跟下一句的nextgoto跳转相同 //条件反向的处理,并把if改为while $oldName = $value->name; $attributes = $value->cond->getAttributes(); $whileObj = new \PhpParser\Node\Stmt\While_( $value->cond,$value->stmts,$attributes); $value = $whileObj; $value->name = $oldName; $newdata[$key] = $value; if( !empty($newdata[$key] ->stmts)){ $this->restoreWhile($newdata[$key] ->stmts); $this->allFindLabelStr =""; } }elseif(!empty($newdata[$key] ->stmts)){ $this->restoreWhile($newdata[$key] ->stmts); $this->allFindLabelStr =""; if(!empty($newdata[$key] ->else->stmts)){ $this->restoreWhile($newdata[$key] ->else->stmts); $this->allFindLabelStr =""; } } } } // $this->restoreWhile($newdata); return $newdata; } // /* 判断是否存在elseIf的情况 */ // public function judgeElseIf(&$newdata, $sameNodeStr,$key,$startLabel,$oldnextgoto,$type){ // $firstStr = $this->findIFLabel($sameNodeStr, $newdata); // $elseIfArray = array(); // while(!empty($firstStr) && !empty($newdata[$firstStr]) && get_class($newdata[$firstStr]) == "PhpParser\Node\Stmt\If_"){ // $firset_data = []; // //存在elseif的情况 // $checkDataResult = $this->checkdata2($firset_data, $newdata, $startLabel,$type,$sameNodeStr); // $newdata[$key]->stmts = $checkDataResult; // $checkNextDataResult = $this->checkdata2($firset_data, $newdata, $oldnextgoto,$type,$sameNodeStr); // $attributes = array(); $newdata[$key]->elseifs[] = // $elseStd = new \PhpParser\Node\Stmt\Else_($checkNextDataResult,$attributes); // $elseIfArray // $newdata[$key]->else = $elseStd; // $newdata[$key]->name->nextgoto = $sameNodeStr; // } // if(!empty($firstStr) && !empty($newdata[$firstStr]) && get_class($newdata[$firstStr]) == "PhpParser\Node\Stmt\If_"){ // // } // } public function selectSameNode($startArray, $nextArray){ $tabelStr = ""; if(empty($startArray) || empty($nextArray)){ return $tabelStr; } $firstArray = array(); $secondArray = array(); foreach ($startArray as $key =>$value){ if(!empty($value->name->isNode) && $value->name->isNode == 1 ){ $firstArray[$key] = $value; } } foreach ($nextArray as $key =>$value){ if(!empty($value->name->isNode) && $value->name->isNode == 1 ){ $secondArray[$key] = $value; } } if(empty($firstArray) || empty($secondArray)){ return $tabelStr; } foreach ($secondArray as $key_second =>$value_second){ foreach ($firstArray as $key_first =>$value_first){ if($key_second == $key_first){ $tabelStr = $key_second; return $tabelStr; } } } return $tabelStr; } //寻找if语句goto的第一条有效代码的label public function findIFLabel($findStr, $res){ $tabelStr = ""; foreach ($res as $keyFind => $valueFind) { if ($keyFind == $findStr) { if(get_class($valueFind) == 'PhpParser\Node\Stmt\Goto_'){ $tabelStr = $this->findIFLabel($valueFind->name,$res); }elseif (get_class($valueFind) == 'PhpParser\Node\Stmt\Label' && !empty($valueFind->name->nextgoto)){ $tabelStr = $this->findIFLabel($valueFind->name->nextgoto,$res); } else{ $tabelStr = $keyFind; } break; } } return $tabelStr; } public function findFirstNextLabel($findStr, $res,$rowCount){ $tabelStr = ""; foreach ($res as $keyFind => $valueFind) { if ($keyFind == $findStr) { if(get_class($valueFind) == 'PhpParser\Node\Stmt\Goto_'){ $tabelStr = $this->findFirstNextLabel($valueFind->name,$res,$rowCount); }elseif(get_class($valueFind) == 'PhpParser\Node\Stmt\Label' && empty($valueFind->stmts)){ $tabelStr = $this->findFirstNextLabel($valueFind->name->nextgoto,$res,$rowCount); } else{ if($rowCount != 0){ $rowCount = $rowCount - 1; $tabelStr = $this->findFirstNextLabel($valueFind->name->nextgoto,$res,$rowCount); }else{ $tabelStr = $keyFind; } // $tabelStr = $keyFind; } break; } } return $tabelStr; } public function compareNextLabel2($findStr, &$res,$compareStr,$whileLabel = ""){ if(empty($compareStr) || empty($res)){ return ""; } STARTCOMPARE: $tabelStr = ""; if(!empty($res[$findStr])){ $valueFind = $res[$findStr]; //判断是否进入死循环 if(!strstr($this->allFindLabel, $findStr)){ $this->allFindLabel = $this->allFindLabel.$findStr.","; }else{ return ""; } if(!empty($whileLabel) && $findStr == $whileLabel){ return ""; } if(get_class($valueFind) == 'PhpParser\Node\Stmt\Goto_'){ // $tabelStr = $this->compareNextLabel2($valueFind->name->name,$res,$compareStr,$whileLabel); $findStr = $valueFind->name->name; goto STARTCOMPARE; }elseif(get_class($valueFind) == 'PhpParser\Node\Stmt\Label' && empty($valueFind->stmts) && !empty($valueFind->name->nextgoto)){ // $tabelStr = $this->compareNextLabel2($valueFind->name->nextgoto,$res,$compareStr,$whileLabel); $findStr = $valueFind->name->nextgoto; goto STARTCOMPARE; } else{ if($findStr == $compareStr){ if( $this->checkExistWhile($this->allFindLabelStr,$res)){ return ""; } $tabelStr = $findStr; goto STOPCOMPARE; }else{ if(!empty($this->allFindLabel)){ $allLabelAry = explode(',', $this->allFindLabel); if(count($allLabelAry)>480){ return ""; } } if(!empty($valueFind->name->nextgoto)){ // $tabelStr = $this->compareNextLabel2($valueFind->name->nextgoto,$res,$compareStr,$whileLabel); $findStr = $valueFind->name->nextgoto; goto STARTCOMPARE; } } } }else{ return ""; } STOPCOMPARE: return $tabelStr; } // public function compareNextLabel2($findStr, &$res,$compareStr,$whileLabel = ""){ // if(empty($compareStr)){ // return ""; // } // $tabelStr = ""; // foreach ($res as $keyFind => $valueFind) { // if ($keyFind == $findStr) { // //判断是否进入死循环 // if(!strstr($this->allFindLabel, $keyFind)){ // $this->allFindLabel = $this->allFindLabel.$keyFind.","; echo "$this->allFindLabel"; echo "<br>"; // }else{ if(get_class($valueFind) == 'PhpParser\Node\Stmt\If_'){ $tempNextgoto = $valueFind->stmts[0]->name->name; $ifNodeStr = $keyFind; }else{ $allLabelAry = explode(',', $this->allFindLabel); $ifNodeStr = $allLabelAry[count($allLabelAry)-2]; $tempNextgoto = $res[$ifNodeStr] ->stmts[0]->name->name; } $res[$ifNodeStr] ->name->isWhile = &$this->existValue; // $this->restoreWhile($ifNodeStr,$res); $tabelStr = $this->compareNextLabel2($tempNextgoto,$res,$compareStr); // return ""; // } // // if(!empty($whileLabel) && $keyFind == $whileLabel){ // return ""; // } // if(get_class($valueFind) == 'PhpParser\Node\Stmt\Goto_'){ // $tabelStr = $this->compareNextLabel2($valueFind->name->name,$res,$compareStr,$whileLabel); // }elseif(get_class($valueFind) == 'PhpParser\Node\Stmt\Label' && empty($valueFind->stmts) && !empty($valueFind->name->nextgoto)){ // $tabelStr = $this->compareNextLabel2($valueFind->name->nextgoto,$res,$compareStr,$whileLabel); // } // else{ // if($keyFind == $compareStr){ // if( $this->checkExistWhile($this->allFindLabelStr,$res)){ // return ""; // } // $tabelStr = $keyFind; // }else{ // if(!empty($this->allFindLabel)){ // $allLabelAry = explode(',', $this->allFindLabel); // if(count($allLabelAry)>480){ // return ""; // } // } // if(!empty($valueFind->name->nextgoto)){ // $tabelStr = $this->compareNextLabel2($valueFind->name->nextgoto,$res,$compareStr,$whileLabel); // } // } // } // break; // } // } // return $tabelStr; // } //比较后面代码是否有相同的label public function compareNextLabel($findStr, &$res,$compareStr,$type=0,$ifKey=""){ if(empty($compareStr)){ return ""; } if(empty($this->allFindLabelStr)){ if(get_class($res[$ifKey]) == 'PhpParser\Node\Stmt\If_' && !empty($res[$ifKey]->stmts)){ $this->allFindLabel = ""; if(!empty($res[$ifKey]->stmts[0]->name->name)){ $tabelStr = $this->compareNextLabel2($res[$ifKey]->stmts[0]->name->name,$res,$ifKey); if(!empty($tabelStr)){ if(!empty($res[$ifKey]->name->lastLabelOne) && strstr($this->allFindLabel, $res[$ifKey]->name->lastLabelOne)){ echo "tabelStr=".$tabelStr; }else{ // $res[$ifKey]->name->isWhile = &$this->existValue; $res[$ifKey]->name->isInsideLoop = $tabelStr; } } } } } $tabelStr = ""; foreach ($res as $keyFind => $valueFind) { if ($keyFind == $findStr) { if($keyFind == $ifKey){ if( $this->checkExistWhile($this->allFindLabelStr,$res)){ return ""; } $tempNextgoto = $valueFind->stmts[0]->name->name; $res[$keyFind] ->name->isWhile = &$this->existValue; // $tabelStr = $this->compareNextLabel($tempNextgoto,$res,$compareStr,$type,$ifKey); return $keyFind; } if(!empty($this->allFindLabelStr)){ $allLabelAry = explode(',', $this->allFindLabelStr); if(count($allLabelAry)>480){ return ""; } } //判断是否进入死循环 if(!strstr($this->allFindLabelStr, $keyFind)){ $this->allFindLabelStr = $this->allFindLabelStr.$keyFind.","; }else{ if(get_class($valueFind) == 'PhpParser\Node\Stmt\If_'){ $tempNextgoto = $valueFind->stmts[0]->name->name; $ifNodeStr = $keyFind; if($valueFind != $ifKey){ $tabelStr = $this->compareNextLabel($tempNextgoto,$res,$compareStr,$type,$ifKey); return $tabelStr; } }else{ $allLabelAry = explode(',', $this->allFindLabelStr); $ifNodeStr = $allLabelAry[count($allLabelAry)-2]; if(get_class( $res[$ifNodeStr]) != 'PhpParser\Node\Stmt\If_'){ return ""; } } $res[$ifNodeStr] ->name->isWhile = &$this->existValue; // $this->restoreWhile($ifNodeStr,$res); // $tabelStr = $this->compareNextLabel($tempNextgoto,$res,$compareStr,$type,$ifKey); return $keyFind; } if(get_class($valueFind) == 'PhpParser\Node\Stmt\If_' && !empty($valueFind->stmts)){ $this->allFindLabel = ""; if(!empty($valueFind->stmts[0]->name->name)){ if(!empty($res[$ifKey]->name->whileLabel)){ $whileLabel = $res[$ifKey]->name->whileLabel; }else{ $whileLabel = ""; } $tabelStr = $this->compareNextLabel2($valueFind->stmts[0]->name->name,$res,$ifKey,$whileLabel); if(!empty($tabelStr)){ if(!empty($res[$ifKey]->name->lastLabelOne) && strstr($this->allFindLabel, $res[$ifKey]->name->lastLabelOne)){ $tabelStr = ""; }else{ $res[$ifKey]->name->isWhile = &$this->existValue; $res[$keyFind]->name->isChange = $tabelStr; } } } } if(get_class($valueFind) == 'PhpParser\Node\Stmt\Goto_'){ if(empty($res[$valueFind->name->name]) && $type == $this->foreachType){ $res[$ifKey]->name->isBreak = $valueFind->name->name; } $tabelStr = $this->compareNextLabel($valueFind->name->name,$res,$compareStr,$type,$ifKey); }elseif(get_class($valueFind) == 'PhpParser\Node\Stmt\Label' && empty($valueFind->stmts) && !empty($valueFind->name->nextgoto)){ $tabelStr = $this->compareNextLabel($valueFind->name->nextgoto,$res,$compareStr,$type,$ifKey); } else{ if($keyFind == $compareStr){ $tabelStr = $keyFind; }else{ if(!empty($valueFind->name->nextgoto)){ $tabelStr = $this->compareNextLabel($valueFind->name->nextgoto,$res,$compareStr,$type,$ifKey); } } } break; } } return $tabelStr; } //给while块里面的if语句设置标签 public function setWhileData($findStr,&$res,$compareStr,$stopLabel=""){ if(empty($compareStr)){ return ""; } $tabelStr = ""; foreach ($res as $keyFind => $valueFind) { if ($keyFind == $findStr) { //判断是否进入死循环 if(!strstr($this->allFindLabel, $keyFind)){ $this->allFindLabel = $this->allFindLabel.$keyFind.","; }else{ return ""; } if(get_class($res[$keyFind]) == 'PhpParser\Node\Stmt\If_'){ $res[$keyFind]->name->whileLabel = $compareStr; if(!empty($valueFind->stmts[0]->name->name)){ $tabelStr = $this->setWhileData($valueFind->stmts[0]->name->name,$res,$compareStr,$stopLabel); } } if(get_class($valueFind) == 'PhpParser\Node\Stmt\Goto_'){ $tabelStr = $this->setWhileData($valueFind->name->name,$res,$compareStr,$stopLabel); }elseif(get_class($valueFind) == 'PhpParser\Node\Stmt\Label' && empty($valueFind->stmts) && !empty($valueFind->name->nextgoto)){ $tabelStr = $this->setWhileData($valueFind->name->nextgoto,$res,$compareStr,$stopLabel); } else{ if($keyFind == $compareStr){ $tabelStr = $keyFind; }else{ if(!empty($this->allFindLabel)){ $allLabelAry = explode(',', $this->allFindLabel); if(count($allLabelAry)>480){ return ""; } } if(!empty($valueFind->name->nextgoto)){ $tabelStr = $this->setWhileData($valueFind->name->nextgoto,$res,$compareStr,$stopLabel); } } } break; } } return $tabelStr; } //检查是否存在while语句 public function checkExistWhile($allFindStr,$res){ $allLabelAry = explode(',', $allFindStr); foreach ($allLabelAry as $key => $value){ if(!empty($value) && get_class($res[$value]) == "PhpParser\Node\Stmt\If_"){ if(!empty($res[$value]->name->isWhile) && $res[$value]->name->isWhile == $this->existValue){ return true; } } } return false; } //检查while语句 public function checkWhile($whileKey,&$res,$whileNext){ foreach ($res as $key => $value ){ if(get_class($value) == 'PhpParser\Node\Stmt\If_' && empty($value->name->oldIfLabel)){ if(!empty($value->stmts) && count($value->stmts)>0){ $this->checkWhile($whileKey,$value->stmts,$whileNext); } }elseif(get_class($value) == 'PhpParser\Node\Stmt\While_'){ if(!empty($value->stmts) && count($value->stmts)>0){ $this->checkWhile($whileKey,$value->stmts,$whileNext); } }else { if(!empty($value->name->oldIfLabel) && $value->name->oldIfLabel == $whileNext){ $attributes = array(); $breakStd = new \PhpParser\Node\Stmt\Break_(null,$attributes); $res[$key] = $breakStd; } } } } //恢复while语句 public function restoreWhile(&$res){ foreach ($res as $key => $value){ if (get_class($value) == 'PhpParser\Node\Stmt\If_'){ if(empty($res[$key]->name->oldIfLabel)){ continue; } $ifLabel = $res[$key]->name->oldIfLabel; if(!strstr($this->allFindLabelStr, $ifLabel)){ $this->allFindLabelStr = $this->allFindLabelStr.$ifLabel.","; // $failLabel = "t6X3c,IxelL,OTFhY,Ab4dP,c4iI1,wWVDk,aBDVw,cGQ2R,Hhab6,hxI8v"; // if(strstr($failLabel,$ifLabel)){ // echo $ifLabel; // } }else{ // if($ifLabel == "aBDVw"){ // echo $ifLabel; // } // echo $ifLabel."重复=".$this->allFindLabelStr.";<br>"; } if(!empty($value->name->isWhile)){ //条件跳转跟下一句的nextgoto跳转相同 //条件反向的处理,并把if改为while $oldName = $value->name; $attributes = $value->cond->getAttributes(); $whileObj = new \PhpParser\Node\Stmt\While_( $value->cond,$value->stmts,$attributes); $value = $whileObj; $value->name = $oldName; $res[$key] = $value; if( !empty($res[$key] ->stmts)){ $this->restoreWhile($res[$key] ->stmts); } }elseif(!empty($res[$key] ->stmts)){ $this->restoreWhile($res[$key] ->stmts); if(!empty($res[$key] ->else->stmts)){ $this->restoreWhile($res[$key] ->else->stmts); } } } } } public function getPrettyCode($prettyPrinter, $res){ $res_code = ""; if(!empty($res)){ $arrayLength = count($res); $tempArray = array(); $find = array("?>\n","?>","<?php","<?php"); for($i = 0;$i < $arrayLength;$i++){ if (get_class($res[$i]) == 'PhpParser\Node\Stmt\Switch_'&& !empty($res[$i]->cases) && count($res[$i]->cases)>0) { foreach ($res[$i]->cases as $key2 => $value2) { if (!empty($value2->stmts) && count($value2->stmts)>0) { echo date('h:i:s', time())." YY/"; $if_code = $this->getPrettyCode($prettyPrinter, $value2->stmts); if(!empty($this->parserObj)){ $if_code = str_ireplace( $find,"",$if_code,$count); $this->replaceTip = $this->parserObj->parse($if_code); } $value2->stmts = $this->replaceTip; $tempArray[0] = $value2; $old_code = $prettyPrinter->prettyPrint($tempArray); $one_code = str_ireplace( $find,"",$old_code,$count); echo date('h:i:s', time())." YY/"; $memoryValue = number_format(memory_get_usage()); echo $memoryValue . " /"; echo date('h:i:s', time())." /"; } } $tempArray[0] = $res[$i]; $old_code = $prettyPrinter->prettyPrint($tempArray); $one_code = str_ireplace( $find,"",$old_code,$count); }else if(get_class($res[$i]) == 'PhpParser\Node\Stmt\If_' && !empty($res[$i]->stmts) && count($res[$i]->stmts)>0){ $if_code = $this->getPrettyCode($prettyPrinter, $res[$i]->stmts); if(!empty($this->parserObj)){ $if_code = str_ireplace( $find,"",$if_code,$count); $this->replaceTip = $this->parserObj->parse($if_code); } $res[$i]->stmts = $this->replaceTip; $tempArray[0] = $res[$i]; $old_code = $prettyPrinter->prettyPrint($tempArray); // $one_code = str_ireplace( $this->replaceTipStr,$if_code,$old_code,$count); $one_code = str_ireplace( $find,"",$old_code,$count); $this->printCount = $this->printCount +1; }else if(get_class($res[$i]) == 'PhpParser\Node\Stmt\Foreach_' && !empty($res[$i]->stmts) && count($res[$i]->stmts)>0){ $if_code = $this->getPrettyCode($prettyPrinter, $res[$i]->stmts); if(!empty($this->parserObj)){ $if_code = str_ireplace( $find,"",$if_code,$count); $this->replaceTip = $this->parserObj->parse($if_code); } $res[$i]->stmts = $this->replaceTip; $tempArray[0] = $res[$i]; $old_code = $prettyPrinter->prettyPrint($tempArray); // $one_code = str_ireplace( $this->replaceTipStr,$if_code,$old_code,$count); $one_code = str_ireplace( $find,"",$old_code,$count); $this->printCount2 = $this->printCount2 +1; } else{ $tempArray[0] = $res[$i]; $one_code = $prettyPrinter->prettyPrint($tempArray); $this->printCount1 = $this->printCount1 +1; } $res_code = $res_code.$one_code; } } return $res_code; } public function prettyWriteCode($fileName,$prettyPrinter, $res){ if(!empty($res)){ $arrayLength = count($res); $myfile = fopen($fileName, "a+") or die("Unable to open file!"); $tempArray = array(); for($i = 0;$i < $arrayLength;$i++){ $tempArray[0] = $res[$i]; $res_code = $prettyPrinter->prettyPrint($tempArray); if($i == 0){ $res_code = "<?php" . "\n" . $res_code; } echo "i=".$i."\n"; fwrite($myfile, $res_code); } fclose($myfile); } } public function writeFile($fileName, $content) { $myfile = fopen($fileName, "w") or die("Unable to open file!"); fwrite($myfile, $content); fclose($myfile); } }
登录后复制
推荐学习:php视频教程
以上就是来咯,你想要的goto解密脚本它真的来咯!的详细内容,更多请关注Work网其它相关文章!