How to find if a file is an exe?

后端 未结 6 1774
粉色の甜心
粉色の甜心 2020-12-05 14:51

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

6条回答
  •  死守一世寂寞
    2020-12-05 15:38

    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".

提交回复
热议问题