【问题标题】:Decode chr() function?解码 chr() 函数?
【发布时间】:2013-03-09 21:13:33
【问题描述】:

嘿,伙计们一直在努力研究 google 和 stackoverflow 这个...

我得到了用 php chr() 函数编码的 php 文件,这里是一些代码:

   <?php require_once chr(65).chr(100).chr(109).chr(105).chr(110).chr(67).chr(111).chr(110).chr(116).chr(114).chr(111).chr(108).chr(108).chr(101).chr(114).chr(46).chr(112).chr(104).chr(112);class WP_Amazonimportproducts_ImportController extends WP_Amazonimportproducts_AdminController{protected function _isAllowed(){return Mage::getSingleton(chr(97).chr(100).chr(109).chr(105).chr(110).chr(47).chr(115).chr(101).chr(115).chr(115).chr(105).chr(111).chr(110))->{"isAllowed"}(chr(99).chr(97).chr(116).chr(97).chr(108).chr(111).chr(103).chr(47).chr(97).chr(109).chr(97).chr(122).chr(111).chr(110).chr(105).chr(109).chr(112).chr(111).chr(114).chr(116).chr(112).chr(114).chr(111).chr(100).chr(117).chr(99).chr(116).chr(115).chr(47).chr(105).chr(109).chr(112).chr(111).chr(114).chr(116));}protected function _initImport(){$this->{"_title"}($this->{"__"}(chr(67).chr(97).chr(116).chr(97).chr(108).chr(111).chr(103)))->{"_title"}($this->{"__"}(chr(87).chr(80).chr(58).chr(32).chr(65).chr(109).chr(97).chr(122).chr(111).chr(110).chr(32).chr(73).chr(109).chr(112).chr(111).chr(114).chr(116)))->{"_title"}($this->{"__"}(chr(73).chr(109).chr(112).chr(111).chr(114).chr(116).chr(32).chr(80).chr(114).chr(111).chr(100).chr(117).chr(99).chr(116).chr(115)));return $this;}protected function _initProduct(){$   =Mage::getModel(chr(99).chr(97).chr(116).chr(97).chr(108).chr(111).chr(103).chr(47).chr(112).chr(114).chr(111).chr(100).chr(117).chr(99).chr(116));$    =Mage::getSingleton(chr(97).chr(100).chr(109).chr(105).chr(110).chr(47).chr(115).chr(101).chr(115).chr(115).chr(105).chr(111).chr(110))->{"getImportSettings"}();if (isset ($    [chr(105).chr(109).chr(112).chr(111).chr(114).chr(116).chr(95).chr(112).chr(97).chr(114).chr(97).chr(109).chr(115)][chr(99).chr(97).chr(116).chr(101).chr(103).chr(111).chr(114).chr(121).chr(95).chr(105).chr(100).chr(115)])){$   ->{"setCategoryIds"}($    [chr(105).chr(109).chr(112).chr(111).chr(114).chr(116).chr(95).chr(112).chr(97).chr(114).chr(97).chr(109).chr(115)][chr(99).chr(97).chr(116).chr(101).chr(103).chr(111).chr(114).chr(121).chr(95).chr(105).chr(100).chr(115)]);

据我所知,我一直在尝试寻找解码器,您可以使用 ord() php 函数对其进行解码吗?我找到了一个将文本编码为 chr(65) 的脚本,如果可以将其反转以使其解码用 chr(111).chr(65) 编码的 php 脚本,那将是惊人的,我有几页需要解码和如果它可以跳过非 chr(65) 代码,我认为它会起作用的唯一方法是我可以粘贴整个页面并对其进行解码。你们有什么感想?如何解码?

<html>
    <head>
        <title>Convert String To PHP ASCII in PHP chr() function</title>
    </head>
    <body>
        <b>Convert String To PHP ASCII in PHP chr() function:</b><br /><br />
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
            <textarea name="s" rows="20" cols="100"></textarea>
            <input type="submit">
        </form>
        <br />  

        <?php
        $string = stripslashes($_GET['s']); 
        $chrstring = "";
        for ($i=0; $i < strlen($string); $i++)
        {
            $chrstring .= "chr(" . ord(substr($string,$i,1)) . ")";
            $chrstring .= ($i==strlen($string)-1)?"":".";       
        }   

        $toscreenstring = htmlentities($string);

        echo "<b>Converted:</b><br />$toscreenstring<br /><b>To:</b><br />$chrstring<br /><br />-"; 
        ?>
    </body>
</html>

编辑!我找到了一个具有类似功能的 php 脚本来解码这个东西,但它只适用于数字(没有 chr(number).chr(number) 并且需要让它跳过非chr(number) 这样就可以粘贴整个脚本,它会解码需要的内容。

   <?php

   $charset = array(
        32 => ' ', 33 => '!', 34 => '"', 35 => '#', 36 => '$',
        37 => '%', 38 => '&', 39 => "'", 40 => '(', 41 => ')',
        42 => '*', 43 => '+', 44 => ',', 45 => '-', 46 => '.',
        47 => '/', 48 => '0', 49 => '1', 50 => '2', 51 => '3',
        52 => '4', 53 => '5', 54 => '6', 55 => '7', 56 => '8',
        57 => '9', 58 => ':', 59 => ';', 60 => '<', 61 => '=',
        62 => '>', 63 => '?', 64 => '@', 65 => 'A', 66 => 'B',
        67 => 'C', 68 => 'D', 69 => 'E', 70 => 'F', 71 => 'G',
        72 => 'H', 73 => 'I', 74 => 'J', 75 => 'K', 76 => 'L',
        77 => 'M', 78 => 'N', 79 => 'O', 80 => 'P', 81 => 'Q',
        82 => 'R', 83 => 'S', 84 => 'T', 85 => 'U', 86 => 'V',
        87 => 'W', 88 => 'X', 89 => 'Y', 90 => 'Z', 91 => '[',
        92 => '\\', 93 => ']', 94 => '^', 95 => '_', 96 => '`',
        97 => 'a', 98 => 'b', 99 => 'c', 100 => 'd', 101 => 'e',
        102 => 'f', 103 => 'g', 104 => 'h', 105 => 'i', 106 => 'j',
        107 => 'k', 108 => 'l', 109 => 'm', 110 => 'n', 111 => 'o',
        112 => 'p', 113 => 'q', 114 => 'r', 115 => 's', 116 => 't',
        117 => 'u', 118 => 'v', 119 => 'w', 120 => 'x', 121 => 'y',
        122 => 'z', 123 => '{', 124 => '|', 125 => '}'
    );

     function fromNumber($number)
    {
        $string = '';
        while($number)
        {
            $value = substr($number, 0, 2);
            $number = substr($number, 2);

            if($value < 32)
            {
                $value .= substr($number, 0, 1);
                $number = substr($number, 1);
            }

            $string .= $charset[ (int) $value];
        }
        return $string;
    }

 function fromString($string)
    {
        $number = '';
        foreach(str_split($string) as $char) $number .= ord($char);
        return $number;
    }


$string = 'this is my test string to convert';

$number = fromString($string);
$string = fromNumber($number);


?>

【问题讨论】:

  • 只需将require_once 替换为echo
  • @Gumbo 我应该在哪里执行这个 PHP?我试过 TryItEditor 它说错误
  • @Gumbo 在服务器上运行它,它只回显了第一个函数,但还有更多其他错误,例如 Fatal error: Class 'WP_Amazonimportproducts_AdminController' not found in
  • @MarkVoidale Here 例如
  • @Voitcus phpfiddle.org/main/code/ek5-421 在这里你可以看到完整的代码没有办法用 echo 解码它我的意思是你可以但它需要很长时间!

标签: php


【解决方案1】:

给你:

function callback($hits){
    return chr($hits['1']);
}
$php_content = file_get_contents("./myFile.php");
$php_content = preg_replace_callback('/chr\((\d+)\)(\.|)/', "callback", $php_content));
file_put_contents("./myFile.php", $php_content);

循环播放直到所有文件都被“解码”

编辑:

您只需要知道所有不可读的文件并将它们放入此数组中,例如:

$files = array();
$files[] = "./folder/file1.php";
$files[] = "./folder/file2.php";
$files[] = "./folder/file3.php";
$files[] = "./folder2/file4.php";
$files[] = "./folder2/file5.php";
$files[] = "./file1.php";

foreach($files as $file){
    $php_content = file_get_contents(file);
    $php_content = preg_replace_callback('/chr\((\d+)\)(\.|)/', "callback", $php_content));
    file_put_contents(file, $php_content);
}

或者如果它是一个包含文件和所有子文件夹等的整个文件夹,请查看http://php.net/manual/de/class.recursivedirectoryiterator.php

【讨论】:

  • 嘿,看起来确实如此!你能澄清一下如何循环吗?我把它放在 loop.php 和要解码的页面在同一个文件夹中,命名为 myFile.php 在 url 中运行脚本没有发生任何事情:)
  • 更新了我的答案。此脚本将读取 php 文件,将 chr(x) 替换为 char 并将其放回 php 文件中,因此脚本 itselt ( loop.php ) 将不显示任何内容,但您的文件将是可读的(如果没有错误是显示)
【解决方案2】:

编码的行是require_once 'AdminController.php' ; here is the echoed value 当您将 require_once 替换为 echo 时,包含被取消,因为您收到错误“致命错误:找不到类 'WP_Amazonimportproducts_AdminController'”。在您的代码中,您可以回显并要求该语句。

...    
require_once chr(65).chr(100).chr(109).chr(105).chr(110).chr(67).chr(111).chr(110).chr(116).chr(114).chr(111).chr(108).chr(108).chr(101).chr(114).chr(46).chr(112).chr(104).chr(112);        
echo chr(65).chr(100).chr(109).chr(105).chr(110).chr(67).chr(111).chr(110).chr(116).chr(114).chr(111).chr(108).chr(108).chr(101).chr(114).chr(46).chr(112).chr(104).chr(112);
...

【讨论】:

  • 这只是较大 php 的一小部分,您无法回显整个 php 文件检查此phpfiddle.org/main/code/ek5-421 我有 5 页这样的页面,需要将回显设置为 100 多个函数回显不是这种情况下的解决方案
【解决方案3】:

好吧,我知道这不是您期望的答案,但是虽然您知道如何对其进行解码,并且因为编写 php 程序只是为了解析另一个 php 文件太难了,所以我会这样做,我会将文件加载到 MS Word 或任何其他文本处理器之类的东西上,它可以是记事本,搜索 (Ctrl-F) 以查找 require/include 并删除不包含它的每一行,然后只需 @ 987654323@ 还剩下什么,正如 Vahe Shadunts 所写。

我知道这不是您问题的答案(“如何在 php 中做到这一点?”),但我真的认为这不值得努力,因为您可能没有那么多 include 或 require 函数。在我看来,在这种情况下编写 PHP 程序并不是最佳选择。

【讨论】:

  • 我认为我需要的一个函数非常简单,就像我最近编辑的代码一样,它几乎完成了我需要对该代码进行小的更改,它会将整个 php 文件批量更改为可读的,所以我认为这是值得的。它应该很容易,因为它很简单。我需要一个函数来读取整个 php 文件,并且每个 chr(100) 都用 ord() 函数更改为字母,最后我会得到我需要的...
猜你喜欢
  • 2021-11-23
  • 1970-01-01
  • 1970-01-01
  • 2012-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-02
  • 2019-03-06
相关资源
最近更新 更多