I'm currently learning MSIL and wanted try, if I can "crack" an assembly only editing byte codes via Notepad++ (with Hex-Editor plugin). So I wrote a simple console application taking one argument, hashing it (SHA256), comparing it with an already set hash and writing "Right" or "Wrong" to the console. I opened this little application with ildasm.exe and saw that I only have to change 2 bytes to make my application say "Right" everytime. So I opened it in Notepad++, changed these two bytes and it worked. Now I wanted to try to protect my application against attacks like the one I tried. I came across strong name key files, but I was still able to change these to bytes two make my application say "Right" everytime.
So my question: Is there a way of protecting an .NET assembly from editing opcodes? I don't mean to protect it from opening in Notepad++, but I mean a mechanism that allows my application to detect changes made to the executable's file (without checking the file's modification date). I know that there is no full protection and there will be gaps everytime, but there have to be a way to give applications at least a little bit of modification protection.
For example: I could try to make a hash out of my application and compare to a given hash, but this can't work, because when I make a hash and put this hash into my application the application's hash will change.