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

问题描述 投票:0回答:3

我有几个大文件如下:

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:
}

来自 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:
}

变量的名称对我来说不是很重要(尽管最好是真实的)。

但我想删除

goto
命令并拥有干净的代码。

php decode
3个回答
0
投票

用 goto 重写代码:

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:
}

然后删除它们:

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]);
}

0
投票

这是我从您提供的网址通过解析器传递代码后的解决方案:

$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();

0
投票

我面临同样的问题并找到了这篇文章。

我终于用递归Python脚本对我的代码进行了排序:

import sys
import re


def replace(elements: dict[str, str], key: str = "start") -> str:
    if key not in elements:
        return ""
    code = elements[key]
    for goto in re.findall(r"goto +([\w\d]*) *;", code):
        code = re.sub(f"goto +{goto} *;", replace(elements, goto), code)
    return code


def decode(file: str) -> str:
    elements: dict[str, str] = {}
    key = "start"
    elements[key] = ""
    for line in open(file, "r").readlines():
        if line.strip().endswith(":"):
            key = line.strip()[:-1]
            elements[key] = ""
        else:
            elements[key] += line
    decoded = replace(elements, "start")
    cleaned = re.sub(r"\n[\n ]+", "\n", decoded)
    return cleaned


def main() -> None:
    if len(sys.argv) > 1:
        file_to_decode = sys.argv[1]
    else:
        file_to_decode = input("Enter the path of file to decode: ")
    decoded = decode(file_to_decode)
    print(decoded)


if __name__ == "__main__":
    main()
© www.soinside.com 2019 - 2024. All rights reserved.