Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check checksum of application itself?

I would be interested in whether it is possible in some way to check my application against modifications by checking its checksum.

So, for example:

int main()
{
     const std::string checksum = "98123abc1239";
     std::string myChecksum = calculateChecksumOfThisApp();
     if(checksum != myChecksum)
         std::cerr << "This application is invalid. Please check if the download has been successful." << std::endl;
 }

Clearly, the issue here is that compiling my application, getting the executable's checksum and inserting it into my checksum changes the checksum of the application.

I could store the checksum externally in some file, but I would like to have the side-benefit of others not being able to manipulate the exe. They could just calculate the checksum once again and put it into the checksum file, so nothing would be gained from that.

Is there any way to create such a self-check?

like image 603
IceFire Avatar asked Oct 29 '22 10:10

IceFire


1 Answers

The easiest workaround is to make the checksumming routine aware of the position where the checksum itself is stored, and skip the bytes when calculating the checksum.

If calculating the position is too much hassle, you can prefix the checksum with a magic string and recognize that. Just make sure that the checksumming procedure doesn't store the magic string literally, as you don't want to escape that copy.

like image 137
Rafał Dowgird Avatar answered Nov 14 '22 05:11

Rafał Dowgird