tags:

views:

620

answers:

4

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  A: 

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

Stefan Thyberg
+2  A: 

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.

Alex Fort
+1  A: 

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.

GvS
A: 

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?

Cheeso