How can I calculate the checksum of code at runtime?

故事扮演 提交于 2019-12-05 07:06:05

问题


I have a C#.NET application running on a machine. How do I calculate the checksum of the entire code at runtime?

Note:

I do not want to calculate the checksum of the image in use but the actual code part.


回答1:


I have never used this, but:

Using reflection you can navigate to the GetILAsByteArray and do a checksum (per method).

But I think it will be a lot easier to use code signing or the Assembly.GetExecutingAssembly and then do a checksum on the .dll or .exe.




回答2:


I would just use code signing, but if you really want to roll your own solution (which may be a bad idea. Code signing is a Good Thing) you could use reflection to look into the IL code and calculate a checksum based on that. That's not a very nice solution, and could cause some weird bugs, so please, save yourself some trouble and use code signing.




回答3:


In runtime you don't have access to the original written source code.




回答4:


a strong name on your assembly does this - but you sort of have to trust that it is working as advertised. what is the precise problem you are tying to solve?



来源:https://stackoverflow.com/questions/610758/how-can-i-calculate-the-checksum-of-code-at-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!