注册 登录
编程论坛 Perl论坛

判断是否是 pe 文件

zhu224039 发布于 2014-07-13 08:31, 5554 次点击
#!/usr/bin/perl
#$filename='D:\cs\counter-strike\hl.exe'  ;
print "please insert a file name,and i will tell you it is a pe file?\n",":";
chomp ($filename=<STDIN>);
open CDFD , '<' ,$filename or die $!;
read CDFD,$dir,400;
$mzdos=substr $dir,0,2;
if($mzdos ge 'MZ')
{
  #print $dir,"\n";
  $elname=substr $dir,60,4;
  $elname=unpack "l",$elname;
  #print $elname,"\n";
  $peHEAD=substr $dir,$elname-1,4;
  if($peHEAD ge "PE"){
      print "this is a pe file\n";
  }
  else{
       print "NO";
       exit 0;
  }

}
else{
     print "NO";
     exit 1;
}
0 回复
1