Reputation: 1360
I have a C#.NET application running on a machine. How do I calculate the checksum of the entire code at runtime?
I do not want to calculate the checksum of the image in use but the actual code part.
Upvotes: 2
Views: 3238
Reputation: 192457
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?
Upvotes: 0
Reputation: 18821
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.
Upvotes: 2
Reputation: 52518
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.
Upvotes: 2
Reputation: 3544
In runtime you don't have access to the original written source code.
Upvotes: 1