悬念 发表于 2021-6-11 12:55:28

C# Self Hashing Application

C# Self Hashing Application,C# 自散列应用程序计算哈希码
使用 MD5 和 SHA1 等算法计算文件的哈希码并不太困难。
但是一个计算自己哈希码的应用程序呢? 棘手的部分是在使用中读取应用程序文件。
打开文件
要计算正在运行的应用程序的哈希值,程序需要读取自己的执行文件。 但是,由于文件正在使用中,因此某些读取文件的方法会出现如下错误:
该进程无法访问文件“[文件路径]”,因为它正被另一个进程使用。
我们可以通过使用正确的 .NET 类来读取打开的文件来避免这种类型的错误。 例如,System.IO.File 类有一个静态函数 OpenRead,它返回一个流来读取文件的内容。
使用 OpenRead,C# 开发人员可以提取任何文件的字节数据,包括正在运行的应用程序之一。


(C# Self Hashing Application
Calculating Hash Code
Calculating the hash code of a file using algorithms such as MD5 and SHA1 is not too difficult.
But what about an application that computes its own hash code? The tricky part is reading the application file while it is in use.
Open File
To calculate the hash value of the running application the program needs to read its own executing file. However since the file is in use, some methods to read the file will give an error like this:
The process cannot access the file '' because it is being used by another process.
We can avoid this type of error by using the proper .NET classes to read an open file. For example, the System.IO.File class has a static function OpenRead which returns a stream to read the content of the files.
With OpenRead a C# developer can extract the byte data of any file, including the one of the running application.)


页: [1]
查看完整版本: C# Self Hashing Application