How can I be sure that a file passed to my program is a valid exe file ?
actually my program takes a file as input and runs it, but user can input any file so I have
bool IsExeFile(string path) { var twoBytes = new byte[2]; using(var fileStream = File.Open(path, FileMode.Open)) { fileStream.Read(twoBytes, 0, 2); } return Encoding.UTF8.GetString(twoBytes) == "MZ"; }