jhtchina

判断文件类型(文件的真正类型,不是根据扩展名判断),通过文件头来判断

                bool xx=false;  //default sFileName is not Exe or Dll File
                System.IO.FileStream  fs=new System.IO.FileStream(sFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
                System.IO.BinaryReader r
=new System.IO.BinaryReader(fs);
                
string bx="";
                
byte buffer;
                
try
                
{
                    buffer
=r.ReadByte();
                    bx
=buffer.ToString();
                    buffer
=r.ReadByte();
                    bx
+=buffer.ToString();

                }

                
catch (Exception exc)
                
{
                    Console.WriteLine(exc.Message);
                }

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

                Console.WriteLine(bx);
                
return xx;
                dll:MZ
                exe:MZ
                rar:Rar
                zip:PK

分类:

技术点:

相关文章:

  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-11-11
  • 2021-12-09
  • 2021-10-06
猜你喜欢
  • 2021-10-06
  • 2022-12-23
  • 2021-10-21
  • 2021-11-29
  • 2021-12-01
  • 2022-02-21
  • 2022-12-23
相关资源
相似解决方案