Показать сообщение отдельно

  #13  
Старый 21.01.2008, 12:13
groundhog
Познавший АНТИЧАТ
Регистрация: 12.05.2007
Сообщений: 1,235
Провел на форуме:
2238549

Репутация: 1318


Отправить сообщение для groundhog с помощью ICQ
По умолчанию

TheSystems, это функция на языке PHP. То есть, она выполняется на стороне веб-сервера, следовательно ты её должен вызывать из страницы, а страница в свою очередь должна парситься на предмет PHP-кода. Вот смотри пример (я несколько модифицировал функцию, чтобы привести к универсальной форме):

PHP код:
<?php

/**
* test.php - filtering output of the html code.
* This file is the proof of concept of filtering output
*
* Modified by: nobody
* Added: nothing
*
* @author  groundhog <groundhog[doggy]cccp[dot]su>
* @package  generic
* @version  $Revision: 1.0 $
*/

/**
* HTML code filter function
*
* Implemets JavaScript filter based on 'String.fromCharCode' call and
* XORed data
*
* @param  string Regexp of target HTML code
* @param  string Source of output
* @return  string Filtered output
*/
function protect_html_output($pattern$tpl_output) {
    if (
preg_match_all($pattern$tpl_output$matches)) {
        foreach(
$matches[0] as $target) {
            
$key rand (1255);
            
$result '';
            for(
$i 0$i strlen($target); $i++, $result .= $i != strlen($target) ? ';' '')
                
$result .= strval(ord($target[$i]) ^ $key);
            
$code  "<script>x=String('{$result}').split(';');for(i=0,z='';i<x.length;i++)";
            
$code .= "z+=String.fromCharCode(x[i]^{$key});document.write(z);</script>";
            
$tpl_output str_replace($target$code$tpl_output);
        }
    }

    return 
$tpl_output;
}

// Это код нашей страницы, он содержит тег textarea
$html_page =<<<HTML_PAGE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>Это тестовая страница</title>
    </head>
    <body>
        Это тестовая страница с зашифрованным тегом &lt;textarea&gt;
        <br /><br /><br />
        <textarea id="textarea" cols="20" rows="10">
            Hello, world!
        </textarea>
    </body>
</html>
HTML_PAGE;

// Делаем вывод пропарсеного HTML-кода. Код парсится по регулярке
// '/<textarea.*>.*<\/textarea.*>/iUs', которая цепляет любой тег
// textarea. Разумеется, модфицируя эту регулярку можно добиться
// шифрования чего угодно. Кодирование проходит с использованием
// ксорирования (ключ рандомный от 1 до 255).
echo protect_html_output('/<textarea.*>.*<\/textarea.*>/iUs'$html_page);

?>
В нашем примере кусок HTML-кода:

Код:
<textarea id="textarea" cols="20" rows="10">
Hello, world!
</textarea>
будет заменён на код:

Код:
<script>x=String('53;107;102;109;112;55;4;3;0;0;212;251;231;41;251;236;248;251;231;235;233;246;41;248;251;249;233;228;225;255;233;41;248;41;238;233;241;225;253;249;231;235;233;228;228;242;229;41;251;236;234;231;229;41;47;101;125;50;125;108;113;125;104;123;108;104;47;110;125;50;4;3;0;0;53;107;123;41;38;55;53;107;123;41;38;55;53;107;123;41;38;55;4;3;0;0;53;125;108;113;125;104;123;108;104;41;96;109;52;43;125;108;113;125;104;123;108;104;43;41;106;102;101;122;52;43;59;57;43;41;123;102;126;122;52;43;56;57;43;55;4;3;0;0;0;65;108;101;101;102;37;41;126;102;123;101;109;40;4;3;0;0;53;38;125;108;113;125;104;123;108;104;55;4;3;0;53;38;107;102;109;112;55').split(';');for(i=0,z='';i<x.length;i++)z+=String.fromCharCode(x[i]^9);document.write(z);</script>
Разумеется, ты можешь регуляркой задавать, какой кусок нужно выцепить для шифрования...
 
Ответить с цитированием