现在的位置: 首页 > 综合 > 正文

文件类型的判断

2012年05月24日 ⁄ 综合 ⁄ 共 675字 ⁄ 字号 评论关闭

 

public bool isExeDllFile(string sFileName)
{
                
bool xx=false;  //default the "sFileName" is not a .exe or .dll file;  
 
FileStream fs 
= new FileStream(sFileName, FileMode.Open, FileAccess.Read);
BinaryReader r 
= new BinaryReader(fs);
 
                        
string bx="";
byte buffer;
try
{
buffer
=r.ReadByte();
bx
=buffer.ToString();
buffer
=r.ReadByte();
bx
=bx+buffer.ToString();
}

catch
{

}


                        r.Close();
fs.Close();
if (bx=="7790" || bx=="8297" || bx=="8075" )//7790:exe  8297:rar   8075:pk
                        {  
   xx
=true;  
}

                  
    
return xx;
  
}


                dll:MZ
                exe:MZ
                rar:Rar
                zip:PK

抱歉!评论已关闭.