2

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.

Community
  • 1
  • 1
Pushkar
  • 1,300
  • 2
  • 15
  • 20
  • You'll need to be clearer. What do you mean by code -- C#/VB source, IL, machine code image, something else? And why would you want to checksum (couldn't you just use code signing)? – Pontus Gagge Mar 04 '09 at 14:18

4 Answers4

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.

Alex Fort
  • 18,459
  • 5
  • 42
  • 51
2

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
  • 52,015
  • 16
  • 101
  • 139
1

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

Stefan Thyberg
  • 3,445
  • 3
  • 23
  • 29
0

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
  • 189,189
  • 101
  • 473
  • 713