其实是通过调用外部工具实现,外部工具为 OfficeMalScanner
php代码如下:
<?php $path = "e:\\php\\malware.xls"; //待判断文件位置$type = "bin"; //bin为常见二进制格式,xml为xml格式$officescanner = "e:\\officemalscanner\\officemalscanner.exe"; //officemalscanner.exe 所在路径if($type == "bin") { exec("$officescanner $path info"); //常见二进制格式文件}else { exec("$officescanner $path scan brute");//xml格式的文件}$dir = "$path-macros";if(!file_exists($dir)||!is_dir($dir)){ echo "the file don not include macro!"; }else { $dirList=array(); $dir=opendir($dir); $i=0; while($file=readdir($dir)){ if($file!=='.'&&$file!=='..'){ $dirList[$i]=$file; $i++; }; }; $num = $i; closedir($dir); for($i=0;$i<$num;$i++) { //echo $dirList[$i]; if(preg_match('/^((?!Sheet).)*$/',$dirList[$i]) && preg_match("/^((?!ThisDocument).)*$/",$dirList[$i])) { //排除其他文件 $text = "$path-macros\\$dirList[$i]"; $result = file_get_contents($text, "r"); echo $result; //宏内容 } }}?>