如何找到,如果一个文件是exe文件?

编程入门 行业动态 更新时间:2024-10-06 18:31:20
本文介绍了如何找到,如果一个文件是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文件?

本文发布于:2023-07-04 09:21:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1022320.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   exe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!