1

I want to check that my program is not modified (cracked).

So I want program to calculate md5 from self exe and compare.

if(GetMD5FromSelf() != "hash")
    Application.Exit(); //modified so exit

But when I put hash to string then the md5 of file will get changed.

Is there any way to do this?

Dave
  • 171
  • 2
  • 11
  • 2
    If someone hacked your program, wouldn't they remove that check? – David_001 Oct 01 '16 at 19:54
  • 1
    My program has a lot of dialogs (forms) so I want to put check threads in every window and crash application if modified. Better any protection than no protection. – Dave Oct 01 '16 at 20:00

1 Answers1

2

These are some ways you could do it,

Option 1

You could store the hash online, This is probably safer because if someone is going to change your program they can also change the hash.

Option 2

You could add 4 bytes and a string to the end of your application and save the checksum there, Beware to not include those in your checksum and only validate your own file size, not the 4 bytes and the string.

code snippet

  List<byte> total = new List<byte>(File.ReadAllBytes(System.Reflection.Assembly.GetEntryAssembly().Location));
                byte[] totalByteArray = total.ToArray(); 
                int OwnSize = 115200;//Size of you exe file without checksum
                int Md5Length = BitConverter.ToInt32(totalByteArray, OwnSize+4);
                string NormalFileNameString = Encoding.ASCII.GetString(totalByteArray, OwnSize, Md5Length);
Pepernoot
  • 3,409
  • 3
  • 21
  • 46