简体   繁体   English

如何使用 C# 检查文件哈希值是否已更改

[英]How to check if file hash has changed with C#

I am a game devoloper, When i release a new games, BOOM!!!, That game will be modded, and i am running online games, Soo it's huge lose for me, I am making games with Unity, Hope u guys can understand me, I want to add HashCheck to the games main file, Like "If file hash changed, Game,close"我是一个游戏开发者,当我发布一个新游戏时,BOOM!!!,那个游戏将被修改,我正在运行网络游戏,这对我来说是巨大的损失,我正在用 Unity 制作游戏,希望你们能理解我,我想将 HashCheck 添加到游戏主文件中,例如“如果文件哈希更改,游戏,关闭”

Like :- I have Assembly-CSharp.dll as my main game data file, So if Modders want to mod my games, They Will just load Assembly-CSharp.dll into some decompiler and Edit the file就像:- 我有 Assembly-CSharp.dll 作为我的主要游戏数据文件,所以如果 Modders 想要修改我的游戏,他们只会将 Assembly-CSharp.dll 加载到一些反编译器中并编辑文件

I have also tried "HEX" Protection, But they Bypasses it我也尝试过“HEX”保护,但他们绕过它

So, I want to make, When Modders change Assembly-CSharp.dll the hash will be changed, If Hash chnaged "Application.quit"所以,我想制作,当 Modders 更改 Assembly-CSharp.dll 时,哈希值将更改,如果 Hash 更改为“Application.quit”

I am just trying to compare MD5 hash我只是想比较 MD5 哈希

But i am not getting, Even sample code anyware但我没有得到,即使是示例代码

I just need code to add HashCheck in Assembly-CSharp.dll我只需要在 Assembly-CSharp.dll 中添加 HashCheck 的代码

Mean I need C# code意味着我需要 C# 代码

Sounds like strong-name assembly-signing might help you. 听起来像 强名称程序集签名可能对您有所帮助。

Amongst others, one benefit of strong-naming your assemblies is that they are signed with a digital signature , which protects the assembly from being tampered with . 其中,强命名程序集的一个好处是它们 使用数字签名进行签名,从而 保护程序集不被篡改 If someone is to modify your assembly, the verification process which automatically occurs during assembly load will fail and throw an exception. 如果有人要修改您的程序集,程序集加载期间自动发生的验证过程将失败并抛出异常。

Strong names provide a strong integrity check [...] [, guaranteeing] that the contents of the assembly have not been changed since it was build. 强名称提供了强大的完整性检查 [...] [,保证] 程序集的内容自构建以来未被更改。

Taken from docs.microsoft . 取自docs.microsoft


Read more about how to use strong-naming here . 在此处阅读有关如何使用强命名的更多信息。


EDIT编辑

As toATwork has mentioned, strong-naming will not be of benefit here.正如toATwork所提到的,强命名在这里没有好处 Strong-naming insures your users that your assembly really comes from you and was not modified by others.强命名确保您的用户您的程序集确实来自您,并且未被其他人修改。

Users that want to modify your assembly will not be discouraged from tampering with your assembly!想要修改您的程序集的用户不会被阻止篡改您的程序集!

Since hash checks can easily be bypassed as well, what I recommend is to use obfuscation in combination with tamper checks .由于哈希检查也很容易被绕过,我建议将混淆与篡改检查结合使用 You could use Dotfuscator, which is already included in Visual Studio .您可以使用已包含在 Visual Studio 中的Dotfuscator。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM