How to find if a file is an exe?
c#
Solution
It depends on your definition of "validity".
- If you want to validate that the user passes an "EXE" file, check the file extension.
- If you want to validate that the user passes a runnable EXE file (regardless of extension), check the first two bytes of the file. They should contain the value "MZ".
Problem
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 to make sure that the input is a valid exe.