Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top