Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以使用PHP从.exe文件中获取信息吗_Php_Exe - Fatal编程技术网

我可以使用PHP从.exe文件中获取信息吗

我可以使用PHP从.exe文件中获取信息吗,php,exe,Php,Exe,我需要从.EXE文件中读取信息。使用PHP可以做到这一点吗 将.EXE文件上载到服务器后,我要检索:应用程序名称、版本号和图标。还有更多的信息要收集吗 使用PHP可以做到这一点吗 如果没有,是否有其他方法可以获取此信息? <?php // Code snippet to extract the icon from an exe file on a Linux system -- tested on Debian Wheezy // Install icoutils on your sy

我需要从.EXE文件中读取信息。使用PHP可以做到这一点吗

将.EXE文件上载到服务器后,我要检索:应用程序名称、版本号和图标。还有更多的信息要收集吗

使用PHP可以做到这一点吗

如果没有,是否有其他方法可以获取此信息?


<?php

// Code snippet to extract the icon from an exe file on a Linux system -- tested on Debian Wheezy

// Install icoutils on your system e.g. sudo apt-get install icoutils
// Web process must have write privileges to /tmp

///** Config **///

$input_file = '/path/to/program.exe';
$dest_file = '/path/to/image.png';
$dest_size = 64; // Will get the best quality icon at or below this size.

///** End Config **///


$temp_dir_base = '/tmp/iconextract/';
$tmp_offset = 0;
while(file_exists($temp_dir_base.$tmp_offset.'/')){ //Ensure working directory is empty
    $tmp_offset += 1;
}

$tmp_dir = $temp_dir_base.$tmp_offset.'/';

mkdir($tmp_dir,0777,true);  //Create a temporary folder to work in
exec('wrestool -x '.str_replace(' ','\\',$input_file).' -o '.$tmp_dir); //Extract ico files
$icon_files = glob($tmp_dir.'*.ico'); //Find all ico files

$max = 0;
$file = 0;
$index = 0;
foreach($icon_files as $file_offset=>$ico){ //loop each match
    exec('icotool -l '.$ico.' --icon',$list); //get each icon inside the file
    foreach($list as $i){ //Loop through each icon
        preg_match_all('/--index=(?P<index>\d+) --width=(?P<width>\d+) --height=(?P<height>\d+)/',$i,$a);
        if($a['width'][0] > $max and $a['width'][0] <= $dest_size){
            $max = $a['width'][0];
            $index = $a['index'][0];
            $file = $file_offset;
        }
    }
}

if($max > 0){ //If we found one, extract it to the destination
    exec('icotool -x '.$icon_files[$file].' -i '.$index.' -o '.str_replace(' ','\\',$dest_file));
}
else{
    exec('rm '.$tmp_dir.' -r'); //Clean out tmp files
    $error = "Could not find a sutiable icon file";
    throw new Exception($error);
}
exec('rm /tmp/iconextract -r'); //Clean out tmp files

?>
资料来源:

他使用一个名为icoutils的utillity来获取图标,并使用php来调用utillity

这是:

function GetFileVersion($FileName) {

$handle=fopen($FileName,'rb');
if (!$handle) return FALSE;
$Header=fread ($handle,64);
if (substr($Header,0,2)!='MZ') return FALSE;
$PEOffset=unpack("V",substr($Header,60,4));
if ($PEOffset[1]<64) return FALSE;
fseek($handle,$PEOffset[1],SEEK_SET);
$Header=fread ($handle,24);
if (substr($Header,0,2)!='PE') return FALSE;
$Machine=unpack("v",substr($Header,4,2));
if ($Machine[1]!=332) return FALSE;
$NoSections=unpack("v",substr($Header,6,2));
$OptHdrSize=unpack("v",substr($Header,20,2));
fseek($handle,$OptHdrSize[1],SEEK_CUR);
$ResFound=FALSE;
for ($x=0;x<$NoSections[1];$x++) {
    $SecHdr=fread($handle,40);
    if (substr($SecHdr,0,5)=='.rsrc') {         //resource section
        $ResFound=TRUE;
        break;
    }
}
if (!$ResFound) return FALSE;
$InfoVirt=unpack("V",substr($SecHdr,12,4));
$InfoSize=unpack("V",substr($SecHdr,16,4));
$InfoOff=unpack("V",substr($SecHdr,20,4));
fseek($handle,$InfoOff[1],SEEK_SET);
$Info=fread($handle,$InfoSize[1]);
$NumDirs=unpack("v",substr($Info,14,2));
$InfoFound=FALSE;
for ($x=0;$x<$NumDirs[1];$x++) {
    $Type=unpack("V",substr($Info,($x*8)+16,4));
    if($Type[1]==16) {                          //FILEINFO resource
        $InfoFound=TRUE;
        $SubOff=unpack("V",substr($Info,($x*8)+20,4));
        break;
    }
}
if (!$InfoFound) return FALSE;
$SubOff[1]&=0x7fffffff;
$InfoOff=unpack("V",substr($Info,$SubOff[1]+20,4)); //offset of first FILEINFO
$InfoOff[1]&=0x7fffffff;
$InfoOff=unpack("V",substr($Info,$InfoOff[1]+20,4));    //offset to data
$DataOff=unpack("V",substr($Info,$InfoOff[1],4));
$DataSize=unpack("V",substr($Info,$InfoOff[1]+4,4));
$CodePage=unpack("V",substr($Info,$InfoOff[1]+8,4));
$DataOff[1]-=$InfoVirt[1];
$Version=unpack("v4",substr($Info,$DataOff[1]+48,8));
$x=$Version[2];
$Version[2]=$Version[1];
$Version[1]=$x;
$x=$Version[4];
$Version[4]=$Version[3];
$Version[3]=$x;
return $Version;
}
函数GetFileVersion($FileName){ $handle=fopen($FileName,'rb'); 如果(!$handle)返回FALSE; $Header=fread($handle,64); if(substr($Header,0,2)!='MZ')返回FALSE; $PEOffset=unpack(“V”,substr($Header,60,4));
如果($PEOffset[1]虽然我不知道你的答案,但我想说你确定要将EXE文件上传到你的Web服务器吗?我想你最好将它们全部放在单独的ZIP文件或其他文件中,以防出现安全漏洞。问题仍然存在,我需要EXE文件中的信息。这里不需要关于安全性的评论。我只想知道是否这是可能的,如果是的话,怎么做?这个问题已经被问过了-你需要什么样的信息?php有很多函数来打开和读取文件,所以你可以这样做。你需要的是文件的结构描述。是的,你可以从一个exe文件中读取信息。每个文件在开始时都有一些代码来识别文件的类型和类型其他一些信息。你可以在[wikipedia][1]-文件中的幻数中找到这些信息的更多信息。也可以阅读[this post][2],它回答了类似的问题[1]:[2]: