如何获取当前.exe的哈希值? [英] How do I get the hash of current .exe?

查看:519
本文介绍了如何获取当前.exe的哈希值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[已解决] :我复制了文件,并在该副本上运行了哈希器.

[SOLVED]: I copied the file and ran the hasher on that copy.

我需要我的应用程序才能找到EXE的当前MD5.我可以获取任何文件的MD5. 但是,无论我做什么,我都无法获得FileStream来读取打开的EXE.我尝试使用FileOptions.Asynchronous,但这没有帮助.

I need my app to find the EXE's current MD5. I can get the MD5 of any file. However, no matter what I do, I cannot get a FileStream to read the open EXE. I tried using FileOptions.Asynchronous but that didn't help.

我想我不太清楚.我希望我的应用能够自我读取.

I guess I'm not very clear. I want my app to be be able to read itself.

编辑代码:

private void GetMd5()
{
    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

    FileInfo fi = new FileInfo(Process.GetCurrentProcess().MainModule.FileName);
    FileStream stream = File.Create(Process.GetCurrentProcess().MainModule.FileName, (int)fi.Length, FileOptions.Asynchronous);

    md5.ComputeHash(stream);

    stream.Close();

    string rtrn = "";
    for (int i = 0; i < md5.Hash.Length; i++)
    {
        rtrn += (md5.Hash[i].ToString("x2"));
    }
    MessageBox.Show(rtrn.ToUpper());
}

推荐答案

文件.Create方法(字符串,Int32,FileOptions,FileSecurity):

使用指定的缓冲区创建或覆盖指定的文件 大小,文件选项和文件安全性.

Creates or overwrites the specified file with the specified buffer size, file options, and file security.

我相当确定这不是您要执行的操作.大概您要 FileInfo.Open方法(FileMode,FileAccess):

I'm fairly sure that's not what you intended to do. Presumably you want FileInfo.Open Method (FileMode, FileAccess):

FileInfo fi = new FileInfo(path); 
FileStream stream = File.Open(path, FileMode.Open); 

这篇关于如何获取当前.exe的哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆