简体   繁体   English

如何解码使用 goto 语句的 php 代码?

[英]How can I decode php code that using goto statement?

I have several large files as below:我有几个大文件如下:

public function index()
{
    goto E9e2246508a1d047;
    b59f99a7185ea4f4:
    return View("\x65\155\160\154\x6f\171\x65\162\56\x74\x72\x61\156\163\141\x63\x74\x69\x6f\156\x73", ["\x70\x61\147\x65" => $F44ac1942f77c961]);
    goto b4ef380f386bfff0;
    E021694d1d524d6a:
    $F44ac1942f77c961 = $C52f2627c8748472->lastpage();
    goto b59f99a7185ea4f4;
    E9e2246508a1d047:
    $C52f2627c8748472 = UserTransaction::where("\165\x73\145\162\x5f\x69\x64", Auth::id())->orderBy("\143\x72\x65\141\164\x65\x64\x5f\141\x74", "\x61\163\x63")->paginate(10);
    goto E021694d1d524d6a;
    b4ef380f386bfff0:
}

From UnPHP - The Online PHP Decoder I decode it to:UnPHP - 在线 PHP 解码器我将其解码为:

public function index()
{
    goto E9e2246508a1d047;
    b59f99a7185ea4f4:
    return View("employer.transactions", ["page" => $F44ac1942f77c961]);
    goto b4ef380f386bfff0;
    E021694d1d524d6a:
    $F44ac1942f77c961 = $C52f2627c8748472->lastpage();
    goto b59f99a7185ea4f4;
    E9e2246508a1d047:
    $C52f2627c8748472 = UserTransaction::where("user_id", Auth::id())->orderBy("created_at", "asc")->paginate(10);
    goto E021694d1d524d6a;
    b4ef380f386bfff0:
}

The name of the variables is not very important to me (Though it's better to be true).变量的名称对我来说不是很重要(尽管最好是真实的)。

But I want to delete goto command and have a clean code.但我想删除goto命令并拥有一个干净的代码。

Rewrite the code with gotos: 用gotos重写代码:

public function index()
{
    goto E9e2246508a1d047;
    E9e2246508a1d047:
    $C52f2627c8748472 = UserTransaction::where("user_id", Auth::id())->orderBy("created_at", "asc")->paginate(10);
    goto E021694d1d524d6a;
    E021694d1d524d6a:
    $F44ac1942f77c961 = $C52f2627c8748472->lastpage();
    goto b59f99a7185ea4f4;
    b59f99a7185ea4f4:
    return View("employer.transactions", ["page" => $F44ac1942f77c961]);
    goto b4ef380f386bfff0;
    b4ef380f386bfff0:
}

Then delete them: 然后删除它们:

public function index()
{
    $C52f2627c8748472 = UserTransaction::where("user_id", Auth::id())->orderBy("created_at", "asc")->paginate(10);
    $F44ac1942f77c961 = $C52f2627c8748472->lastpage();
    return View("employer.transactions", ["page" => $F44ac1942f77c961]);
}

here is my solution after passing the code through the parser from your provided url:这是我从您提供的 url 将代码通过解析器后的解决方案:

$result = $source; // source code
$goto = []; // collect all goto blocks to remove them after

$result = preg_replace_callback('/goto (\w+);*/', function($m) use ($source, &$goto) {
    $goto[] = $m[1].':';
    preg_match("/{$m[1]} *:(((?!goto).)*)/s", $source, $m);
    return $m[1];
}, $source);

$result = str_replace($goto, '', $result); // replace goto:

$result = preg_replace('/([\r\n])+\s+/', "\n", $result);

// view the result
echo '<pre>';
echo htmlentities($result);
echo '</pre>';die();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM