本文介绍了如何找到,如果一个文件是exe文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何才能确保传递给我的程序文件是一个有效的exe文件?
How can I be sure that a file passed to my program is a valid exe file ?
其实我的程序需要一个文件作为输入,并运行它,但用户可以输入任何文件,所以我必须要确保输入的是一个有效的exe文件。
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.
推荐答案这取决于你的的定义有效性。
It depends on your definition of "validity".
- 如果您想验证用户传递一个EXE文件,检查文件的扩展名。
- 如果您想验证用户传递一个的可运行的的EXE文件(无论扩展名),检查文件的前两个字节。他们应该包含值MZ。
- 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".
更多推荐
如何找到,如果一个文件是exe文件?
发布评论