/**
* wd_decode
*/
function wd_decode($filename) {
$data = unpack('C*', substr(file_get_contents($filename), 9));
$key = array(0xB8, 0x35, 0x6, 0x2, 0x88, 0x1, 0x5B, 0x7, 0x44, 0x0);
$j = count($data);
foreach($data as $k => &$v) {
$v = $key [ 2 * ($j % 5) ] ^ ~$v;
// $v = sprintf('%u', $v);
$v &= 0xFF;
$v = pack('C*', $v);
-- $j;
}
return @gzuncompress(join('', $data));
}
//scandir("wdcp");
//print_r(glob_mark($path));
$dir='wdcp';
$phpfile='';
function traverse($path = '.') {
$current_dir = opendir($path); //opendir()返回一个目录句柄,失败返回false
while(($file = readdir($current_dir)) !== false) { //readdir()返回打开目录句柄中的一个条目
$sub_dir = $path . DIRECTORY_SEPARATOR . $file; //构建子目录路径
if($file == '.' || $file == '..') {
continue;
} else if(is_dir($sub_dir)) { //如果是目录,进行递归
// echo 'Directory ' . $file . ':
';
traverse($sub_dir);
} else { //如果是文件,直接输出
$phpfile=$path.DIRECTORY_SEPARATOR.$file;
$filestr=explode('.',$phpfile);
$strnum=sizeof($filestr);
if($filestr[$strnum-1]=='php'){
//echo $phpfile."\n";
$content=wd_decode($phpfile);
if(!empty($content)){
$fp=fopen($phpfile,'wb');
fwrite($fp,$content);
fclose($fp);
}
}
// echo $path.DIRECTORY_SEPARATOR.$file;
// echo 'File in Directory ' . $path . ': ' . $file . '
';
}
}
}
traverse($dir);