-
-
[求助]C# Self Hashing Application
-
发表于: 2010-8-26 04:57 1254
-
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 '[file path]' 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.
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 '[file path]' 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.
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
赞赏
他的文章
看原图
赞赏
雪币:
留言: